/* ────────────────────────────────────────────────────────────────────── */
/* ── 1. CSS Variables (Design Tokens) ── */
/* ────────────────────────────────────────────────────────────────────── */

:root, [data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f6f8fa;
  --bg3: #e8ecf0;
  --fg: #1f2328;
  --fg2: #656d76;
  --accent: #0969da;
  --green: #1a7f37;
  --red: #cf222e;
  --yellow: #9a6700;
  --purple: #8250df;
  --border: #d0d7de;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --text-xs: 0.7rem;
  --text-sm: 0.8rem;
  --text-base: 0.9rem;
  --text-lg: 1rem;
  --text-xl: 1.2rem;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
  --transition: 150ms ease;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --fg: #c9d1d9;
  --fg2: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cdb;
  --border: #30363d;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --text-xs: 0.7rem;
  --text-sm: 0.8rem;
  --text-base: 0.9rem;
  --text-lg: 1rem;
  --text-xl: 1.2rem;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
  --transition: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0d1117;
    --bg2: #161b22;
    --bg3: #21262d;
    --fg: #c9d1d9;
    --fg2: #8b949e;
    --accent: #58a6ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d29922;
    --purple: #bc8cdb;
    --border: #30363d;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --text-xs: 0.7rem;
    --text-sm: 0.8rem;
    --text-base: 0.9rem;
    --text-lg: 1rem;
    --text-xl: 1.2rem;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --transition: 150ms ease;
  }
}

@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --bg: #ffffff;
    --bg2: #f6f8fa;
    --bg3: #e8ecf0;
    --fg: #1f2328;
    --fg2: #656d76;
    --accent: #0969da;
    --green: #1a7f37;
    --red: #cf222e;
    --yellow: #9a6700;
    --purple: #8250df;
    --border: #d0d7de;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --text-xs: 0.7rem;
    --text-sm: 0.8rem;
    --text-base: 0.9rem;
    --text-lg: 1rem;
    --text-xl: 1.2rem;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --transition: 150ms ease;
  }
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 2. Reset & Base ── */
/* ────────────────────────────────────────────────────────────────────── */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  overflow: hidden;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 3. Layout (Login, App, Header, Sidebar, Main) ── */
/* ────────────────────────────────────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 340px;
}

.login-box h1 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
  text-align: center;
}

.login-box input {
  width: 100%;
  padding: 0.7rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

.login-box button {
  width: 100%;
  padding: 0.7rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}

.login-box button:hover {
  opacity: 0.9;
}

.login-box .error {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.app {
  display: none;
  flex-direction: column;
  height: 100vh;
}

.app.active {
  display: flex;
}

header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

header h1 {
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

header h1 span {
  color: var(--accent);
}

.header-right {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-stat {
  font-size: 0.8rem;
  color: var(--fg2);
  white-space: nowrap;
}

.header-stat strong {
  color: var(--fg);
}

main {
  flex: 1;
  padding: 1rem;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 4. Tabs Navigation ── */
/* ────────────────────────────────────────────────────────────────────── */

.tabs-container {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tabs {
  display: flex;
  padding: 0 1rem;
  gap: 0;
  white-space: nowrap;
}

.tab {
  padding: 0.6rem 1rem;
  cursor: pointer;
  color: var(--fg2);
  border-bottom: 2px solid transparent;
  font-size: 0.85rem;
  flex-shrink: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.tab:hover {
  color: var(--fg);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-btn {
  padding: 0.6rem 1rem;
  cursor: pointer;
  color: var(--fg2);
  border-bottom: 2px solid transparent;
  font-size: 0.85rem;
  flex-shrink: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  background: none;
  border: none;
}

.tab-btn:hover {
  color: var(--fg);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 5. Buttons ── */
/* ────────────────────────────────────────────────────────────────────── */

.btn-sm {
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
  min-height: 32px;
}

.btn-sm:hover {
  border-color: var(--accent);
}

.btn-sm:active {
  background: var(--accent);
  color: #fff;
}

.btn {
  padding: 0.6rem 1rem;
  border-radius: 4px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 44px;
}

.btn:hover {
  opacity: 0.9;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-cancel {
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--border);
}

.btn-cancel:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
}

.btn-danger:hover {
  opacity: 0.85;
}

.menu-toggle {
  display: none;
  width: 32px;
  height: 32px;
  padding: 0;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 6. Forms (inputs, selects, textareas) ── */
/* ────────────────────────────────────────────────────────────────────── */

.input {
  padding: 0.6rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.9rem;
  font-family: inherit;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(9, 105, 218, 0.1);
}

input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
  padding: 0.6rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.9rem;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(9, 105, 218, 0.1);
}

textarea {
  resize: vertical;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 7. Tables ── */
/* ────────────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  padding: 0.6rem;
  color: var(--fg2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  background: var(--bg3);
}

td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  word-break: break-word;
}

tr:hover td {
  background: rgba(88, 166, 255, 0.05);
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 8. Cards (agent-card, fleet-card, message-card, kb-card) ── */
/* ────────────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.8rem;
}

.card h3 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--accent);
}

.card-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.8rem;
}

.card-label {
  color: var(--fg2);
  font-weight: 500;
}

.card-value {
  color: var(--fg);
}

.agent-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.agent-card h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  font-size: 0.95rem;
}

.agent-field {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.8rem;
}

.agent-field-label {
  color: var(--fg2);
}

.agent-field-value {
  color: var(--fg);
  font-family: monospace;
  word-break: break-all;
}

.message-card {
  background: var(--bg2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 0.8rem;
  margin-bottom: 0.8rem;
}

.message-card.instruction {
  border-left-color: var(--accent);
}

.message-card.report {
  border-left-color: var(--green);
}

.message-card.report.failure {
  border-left-color: var(--red);
}

.message-card.status {
  border-left-color: var(--yellow);
}

.message-card.knowledge {
  border-left-color: var(--purple);
}

.message-card.vote {
  border-left-color: var(--yellow);
}

.message-card .msg-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.message-card .msg-from {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.85rem;
}

.message-card .msg-time {
  color: var(--fg2);
  font-size: 0.7rem;
}

.msg-body {
  max-width: 500px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
}

.message-card .msg-body {
  margin: 0.4rem 0 0 0;
}

.msg-meta {
  font-size: 0.75rem;
  color: var(--fg2);
}

.message-card .msg-thread {
  font-size: 0.75rem;
  color: var(--purple);
  margin: 0.3rem 0 0 0;
  cursor: pointer;
}

.message-card .msg-thread:hover {
  text-decoration: underline;
}

.message-card .metadata {
  font-size: 0.75rem;
  color: var(--fg2);
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}

.kb-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.kb-card:hover {
  border-color: var(--accent);
}

.kb-card-title {
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 0.4rem;
}

.kb-card-category {
  display: inline-block;
  margin-bottom: 0.4rem;
}

.kb-card-tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
  font-size: 0.7rem;
}

.kb-card-tag {
  display: inline-block;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.2rem 0.5rem;
}

.kb-card-snippet {
  font-size: 0.8rem;
  color: var(--fg2);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.4rem;
  max-height: 60px;
  overflow: hidden;
}

.kb-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--fg2);
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 9. Badges & Tags ── */
/* ────────────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-green {
  background: rgba(63, 185, 80, 0.2);
  color: var(--green);
}

.badge-blue {
  background: rgba(88, 166, 255, 0.2);
  color: var(--accent);
}

.badge-yellow {
  background: rgba(210, 153, 34, 0.2);
  color: var(--yellow);
}

.badge-red {
  background: rgba(248, 81, 73, 0.2);
  color: var(--red);
}

.badge-purple {
  background: rgba(188, 140, 219, 0.2);
  color: var(--purple);
}

.priority-badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.priority-low {
  background: rgba(139, 148, 158, 0.3);
  color: var(--fg2);
}

.priority-medium {
  background: rgba(210, 153, 34, 0.3);
  color: var(--yellow);
}

.priority-high {
  background: rgba(248, 81, 73, 0.3);
  color: #ff6b6b;
}

.priority-critical {
  background: rgba(248, 81, 73, 0.5);
  color: var(--red);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.status-dot.offline {
  background: var(--fg2);
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 10. Modals ── */
/* ────────────────────────────────────────────────────────────────────── */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: -1;
}

.modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  width: 100%;
  max-width: 600px;
  position: relative;
}

.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  position: relative;
  z-index: 1000;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--fg2);
  cursor: pointer;
  font-size: 1.5rem;
  min-height: auto;
}

.modal-close:hover {
  color: var(--fg);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.modal-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.modal-field label {
  font-weight: 600;
  color: var(--fg2);
  font-size: 0.9rem;
}

.modal-field input,
.modal-field select,
.modal-field textarea {
  padding: 0.6rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.9rem;
  font-family: inherit;
}

.modal-field textarea {
  min-height: 120px;
  resize: vertical;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.modal-actions .btn {
  margin: 0;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 11. Search Modal ── */
/* ────────────────────────────────────────────────────────────────────── */

.search-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
  overflow-y: auto;
}

.search-modal.active {
  display: flex;
}

.search-modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.search-modal-input {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.search-modal-input input {
  width: 100%;
  padding: 0.8rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-size: 1rem;
}

.search-modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}

.search-modal-tab {
  padding: 0.6rem 1rem;
  cursor: pointer;
  color: var(--fg2);
  border-bottom: 2px solid transparent;
  font-size: 0.85rem;
  flex: 1;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.search-modal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.search-modal-results {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem;
}

.search-result {
  padding: 0.8rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 0.6rem;
  cursor: pointer;
  transition: all 0.2s;
}

.search-result:hover {
  background: var(--bg3);
  border-color: var(--accent);
}

.search-result.selected {
  background: var(--bg3);
  border-color: var(--accent);
}

.search-result-icon {
  font-size: 1.2rem;
  margin-right: 0.5rem;
}

.search-result-title {
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 0.3rem;
}

.search-result-snippet {
  font-size: 0.8rem;
  color: var(--fg2);
}

.search-result-meta {
  font-size: 0.75rem;
  color: var(--fg2);
  margin-top: 0.3rem;
}

mark {
  background: var(--yellow);
  color: var(--fg);
  padding: 0.1rem 0.2rem;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 12. Kanban Board ── */
/* ────────────────────────────────────────────────────────────────────── */

.kanban-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.kanban-col, .kanban-column {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  min-height: 500px;
}

.kanban-col.kanban-col--drag-over, .kanban-column.kanban-col--drag-over {
  border: 2px dashed var(--accent);
  background: rgba(88,166,255,0.05);
}

.kanban-col-header, .kanban-column-header {
  font-weight: 600;
  color: var(--fg2);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.kanban-col-body, .kanban-column-cards {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.task-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
}

.task-card:hover {
  border-color: var(--accent);
}

.task-card[draggable="true"] {
  cursor: grab;
}

.task-card[draggable="true"]:active {
  cursor: grabbing;
  opacity: 0.7;
}

.task-card.overdue {
  border-left: 3px solid var(--red);
}

.task-card-title {
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 0.4rem;
}

.task-card-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  align-items: center;
}

.task-card-badges {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 13. Stats Grid ── */
/* ────────────────────────────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.stat-card .num {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--fg2);
  margin-top: 0.3rem;
  text-transform: uppercase;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 14. Fleet Grid ── */
/* ────────────────────────────────────────────────────────────────────── */

.fleet-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 481px) and (max-width: 768px) {
  .fleet-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 769px) {
  .fleet-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.kb-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

@media (min-width: 769px) {
  .kb-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1025px) {
  .kb-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 15. Filters ── */
/* ────────────────────────────────────────────────────────────────────── */

.filters {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem;
  margin-bottom: 1rem;
}

.filters.collapsed {
  max-height: 40px;
  overflow: hidden;
}

.filters-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
}

.filters-content {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.filters-content input,
.filters-content select {
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.85rem;
}

.filters-content button {
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 16. Live Feed ── */
/* ────────────────────────────────────────────────────────────────────── */

.live-feed {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  max-height: 600px;
  overflow-y: auto;
  margin-top: 0.5rem;
}

.live-item {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.live-item:last-child {
  border-bottom: none;
}

.live-time {
  color: var(--fg2);
  font-size: 0.7rem;
  float: right;
}

.live-from {
  font-weight: 600;
  color: var(--accent);
}

.live-arrow {
  color: var(--fg2);
  margin: 0 0.3rem;
}

.live-to {
  color: var(--green);
}

.live-text {
  margin-top: 0.2rem;
  color: var(--fg);
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 17. Chat Interface ── */
/* ────────────────────────────────────────────────────────────────────── */

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding: 0.8rem 0;
}

.chat-compose {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem;
}

.chat-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.chat-controls select {
  padding: 0.4rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.8rem;
}

.chat-textarea {
  padding: 0.6rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg);
  font-size: 0.85rem;
  min-height: 60px;
  resize: vertical;
  font-family: monospace;
}

.chat-send {
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.brainstorm-header {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.brainstorm-topic {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.brainstorm-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.brainstorm-moderator {
  font-size: 0.8rem;
  color: var(--fg2);
}

.knowledge-item {
  background: var(--bg2);
  border-left: 3px solid var(--purple);
  border-radius: 4px;
  padding: 0.8rem;
  margin-bottom: 0.8rem;
}

.knowledge-topic {
  color: var(--purple);
  font-weight: 600;
  font-size: 0.8rem;
}

.knowledge-text {
  margin-top: 0.4rem;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 18. Reactions ── */
/* ────────────────────────────────────────────────────────────────────── */

.reaction-bar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.15rem 0.5rem;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.reaction-pill:hover {
  background: var(--bg2);
  border-color: var(--accent);
}

.reaction-pill--mine {
  background: rgba(88,166,255,0.15);
  border-color: var(--accent);
}

.reaction-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.reaction-add:hover {
  background: var(--bg2);
  border-color: var(--accent);
}

.reaction-add-btn {
  padding: 0.3rem 0.5rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  font-size: 1rem;
  min-width: 28px;
  text-align: center;
}

.reaction-add-btn:hover {
  border-color: var(--accent);
}

.emoji-picker {
  position: absolute;
  bottom: 110%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  display: none;
  gap: 0.25rem;
  flex-wrap: wrap;
  width: 200px;
  z-index: 200;
  box-shadow: var(--shadow-md);
}

.emoji-picker.active {
  display: flex;
}

.emoji-option {
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
}

.emoji-option:hover {
  background: var(--bg3);
}

.reaction-emoji {
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.2rem;
  border-radius: 4px;
  transition: all 0.2s;
}

.reaction-emoji:hover {
  background: var(--bg3);
}

.reaction-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem;
  display: none;
  z-index: 100;
  gap: 0.2rem;
  flex-wrap: wrap;
  width: auto;
  max-width: 150px;
}

.reaction-dropdown.active {
  display: flex;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 19. Skeleton Loaders ── */
/* ────────────────────────────────────────────────────────────────────── */

.skeleton-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg2) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  height: 12px;
  margin-bottom: 8px;
}

.skeleton-line {
  width: 100%;
}

.skeleton-line--title {
  height: 16px;
  width: 60%;
}

.skeleton-line--short {
  width: 40%;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 20. Toast Notifications ── */
/* ────────────────────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  max-width: 360px;
  pointer-events: none;
}

.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  pointer-events: all;
  position: relative;
  overflow: hidden;
  animation: toast-in 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.toast-close {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: none;
  border: none;
  color: var(--fg2);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
}

.toast-close:hover {
  color: var(--fg);
}

.toast--success {
  border-left: 3px solid var(--green);
}

.toast--error {
  border-left: 3px solid var(--red);
}

.toast--warning {
  border-left: 3px solid var(--yellow);
}

.toast--info {
  border-left: 3px solid var(--accent);
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  transition: width linear;
}

.toast--success .toast-progress {
  background: var(--green);
}

.toast--error .toast-progress {
  background: var(--red);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 21. Footer Shortcut Bar ── */
/* ────────────────────────────────────────────────────────────────────── */

.shortcut-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 0.35rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  font-size: var(--text-xs);
  color: var(--fg2);
  z-index: 100;
}

.shortcut-bar .shortcut-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.shortcut-bar kbd {
  display: inline-block;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  font-size: 0.65rem;
  font-family: monospace;
  color: var(--fg);
  line-height: 1.4;
}

.app {
  padding-bottom: 2.5rem;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 22. Confirm Modal ── */
/* ────────────────────────────────────────────────────────────────────── */

.confirm-modal .modal-body {
  text-align: center;
  padding: 1.5rem;
}

.confirm-modal .confirm-title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.confirm-modal .confirm-message {
  color: var(--fg2);
  margin-bottom: 0.5rem;
}

.confirm-modal .confirm-target {
  font-weight: 600;
  color: var(--fg);
  font-style: italic;
  margin-bottom: 1rem;
}

.confirm-modal .confirm-warning {
  color: var(--red);
  font-size: var(--text-sm);
  margin-bottom: 1.5rem;
}

.confirm-modal .btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
}

.confirm-modal .btn-danger:hover {
  opacity: 0.85;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 23. Empty States ── */
/* ────────────────────────────────────────────────────────────────────── */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--fg2);
  padding: 2rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--fg2);
  grid-column: 1/-1;
}

.empty-state__icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 0.4rem;
}

.empty-state__subtitle {
  font-size: var(--text-sm);
  margin-bottom: 1.5rem;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 24. Audit Log Tab ── */
/* ────────────────────────────────────────────────────────────────────── */

.audit-table td {
  vertical-align: top;
}

.audit-action {
  display: inline-block;
  background: var(--bg3);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-size: var(--text-xs);
  font-family: monospace;
  color: var(--accent);
}

.audit-ip {
  font-size: var(--text-xs);
  color: var(--fg2);
  font-family: monospace;
}

.pagination {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  margin-top: 1rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.section-header h2 {
  font-size: 1.1rem;
  margin: 0;
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 25. Agent Management Additions ── */
/* ────────────────────────────────────────────────────────────────────── */

.key-fingerprint {
  font-family: monospace;
  font-size: var(--text-xs);
  background: var(--bg3);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  color: var(--fg2);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--fg2);
  font-size: 0.7rem;
  padding: 0;
}

.copy-btn:hover {
  color: var(--accent);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--fg2);
  border-radius: 20px;
  transition: background var(--transition);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--green);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(16px);
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 26. Theme Switcher ── */
/* ────────────────────────────────────────────────────────────────────── */

.theme-switcher {
  display: flex;
  background: var(--bg3);
  border-radius: 20px;
  padding: 2px;
  border: 1px solid var(--border);
}

.theme-btn {
  width: 32px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 16px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  color: var(--fg2);
}

.theme-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.theme-btn:hover:not(.active) {
  background: var(--bg2);
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── 27. Responsive (768px, 480px) ── */
/* ────────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  header {
    padding: 0.6rem 0.8rem;
  }

  header h1 {
    font-size: 0.95rem;
  }

  main {
    padding: 0.8rem;
  }

  .header-right {
    font-size: 0.75rem;
  }

  .menu-toggle {
    display: block;
  }

  .tabs-container {
    max-height: 44px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.8rem;
  }

  .stat-card {
    padding: 0.8rem;
  }

  .stat-card .num {
    font-size: 1.5rem;
  }

  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: 0.4rem;
  }

  .card {
    padding: 0.8rem;
    margin-bottom: 0.6rem;
  }

  .kanban-container {
    grid-template-columns: 1fr;
  }

  .kb-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    max-width: 95vw;
  }

  .search-modal-content {
    width: 95%;
  }

  .app {
    padding-bottom: 3rem;
  }
}

@media (max-width: 480px) {
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  header h1 {
    font-size: 0.9rem;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
    font-size: 0.7rem;
  }

  main {
    padding: 0.6rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }

  .stat-card {
    padding: 0.6rem;
  }

  .stat-card .num {
    font-size: 1.3rem;
  }

  .card {
    padding: 0.6rem;
    margin-bottom: 0.5rem;
  }

  .tabs {
    padding: 0 0.5rem;
  }

  .tab {
    padding: 0.5rem 0.8rem;
    font-size: 0.75rem;
    min-height: 40px;
  }

  .filters-content {
    grid-template-columns: 1fr;
  }

  .fleet-grid {
    grid-template-columns: 1fr;
  }

  .agent-card {
    padding: 0.8rem;
  }

  .app {
    padding-bottom: 3rem;
  }
}

/* ────────────────────────────────────────────────────────────────────── */
/* ── End of admin.css ── */
/* ────────────────────────────────────────────────────────────────────── */
