:root {
  --bg: #0f1115;
  --panel: #151820;
  --surface: #1b1f29;
  --surface-hover: #222735;
  --line: #272d3b;
  --line-strong: #363f52;
  --text: #eceef2;
  --text-soft: #b8c0d0;
  --muted: #828ba0;
  --accent: #e59a28;
  --accent-soft: rgba(229, 154, 40, 0.14);
  --accent-ink: #1a1200;
  --ok: #2fb373;
  --ok-soft: rgba(47, 179, 115, 0.14);
  --bad: #e55353;
  --bad-soft: rgba(229, 83, 83, 0.14);
  --info: #4b91f7;
  --info-soft: rgba(75, 145, 247, 0.14);
  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --surface: #f0f2f5;
  --surface-hover: #e7ebf0;
  --line: #dfe3ea;
  --line-strong: #c7ceda;
  --text: #141821;
  --text-soft: #3c4454;
  --muted: #687387;
  --accent: #c97a08;
  --accent-soft: rgba(201, 122, 8, 0.12);
  --accent-ink: #ffffff;
  --ok: #1d8a55;
  --ok-soft: rgba(29, 138, 85, 0.12);
  --bad: #c93737;
  --bad-soft: rgba(201, 55, 55, 0.12);
  --info: #2563eb;
  --info-soft: rgba(37, 99, 235, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.48 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--info);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}
.auth-msg {
  margin: 16px 0 0;
  color: var(--text-soft);
}
.ticket-form {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ticket-form label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.ticket-row {
  display: flex;
  gap: 8px;
}
.ticket-row input {
  flex: 1;
  min-width: 0;
}

/* Brand mark */
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.radar-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  position: relative;
  flex: 0 0 auto;
}
.radar-mark::before,
.radar-mark::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
}
.radar-mark::after {
  inset: 11px;
  background: var(--accent);
  border: 0;
}
.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--muted);
}

/* Desktop App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.nav-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  cursor: pointer;
  color: var(--text-soft);
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}
.nav-item-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.nav-icon {
  width: 18px;
  text-align: center;
  flex: 0 0 auto;
  font-size: 15px;
}
.nav-badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}
.nav-item.active .nav-badge {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.sidebar-foot {
  padding: 10px 10px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.status-pill {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-pill:hover { border-color: var(--line-strong); }
.foot-actions { display: flex; gap: 4px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--accent); }

/* Main area */
.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  height: 52px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right { display: flex; align-items: center; gap: 6px; }
.count-chip {
  font-family: var(--mono);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}

/* Toolbar */
.toolbar {
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.toolbar:empty { display: none; }

input[type="text"],
input[type="search"],
input[type="password"],
select,
textarea {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
.search-input {
  width: 240px;
  max-width: 100%;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-soft);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.subtabs {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.subtab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 11px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.subtab.active {
  background: var(--surface-hover);
  color: var(--text);
}

/* Buttons */
.btn, .icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover, .icon-btn:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.icon-btn { width: 32px; height: 32px; padding: 0; }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}
.btn.bad {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}
.btn.active-fire {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* Split Workspace */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  overflow: hidden;
}
.list-pane {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.detail-pane {
  overflow-y: auto;
  padding: 18px 22px 32px;
  background: var(--bg);
}
.full-pane {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 32px;
}

/* List Row Cards */
.row-card {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 11px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.row-card:hover { background: var(--surface); border-color: var(--line-strong); }
.row-card.selected {
  border-color: var(--accent);
  background: var(--surface);
}
.row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.row-title {
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--text);
}
.row-snippet {
  font-size: 12.5px;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.score-high { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.score-mid { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.score-low { background: var(--surface); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

/* Detail Blocks */
.detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.detail-head h2 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.3;
}
.detail-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.detail-section h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  color: var(--text);
}
.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px 14px;
}
.kv-item .k { font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.kv-item .v { font-size: 13.5px; color: var(--text); word-break: break-word; }

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.reply-box {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--text-soft);
  margin-bottom: 12px;
}
.notice.warn { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.notice.bad { border-color: var(--bad); background: var(--bad-soft); color: var(--text); }
.notice.ok { border-color: var(--ok); background: var(--ok-soft); color: var(--text); }

/* Chat Bubbles (Dialogues) */
.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.out {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: rgba(229, 154, 40, 0.35);
}
.bubble.in { align-self: flex-start; }
.bubble-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* Tables & Grids */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}
.data-table th, .data-table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.data-table th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface);
}
.data-table tr:last-child td { border-bottom: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat-tile .label { font-size: 12px; color: var(--muted); }
.stat-tile .val {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}
.stat-tile .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
}
.unit-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.unit-name {
  font-family: var(--mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 20px;
}
.modal-card h3 { margin: 0 0 10px; font-size: 16px; }
.modal-preview {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
  margin: 10px 0;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Toast */
.toast-root {
  position: fixed;
  right: 16px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
}
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }

/* Mobile */
.bottom-nav { display: none; }
.mobile-only { display: none; }

@media (max-width: 959px) {
  .mobile-only { display: inline-flex; }
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .sidebar { display: none; }
  .topbar {
    padding: env(safe-area-inset-top) 12px 0;
    height: calc(50px + env(safe-area-inset-top));
  }
  .toolbar { padding: 8px 12px; }
  .search-input { width: 100%; }
  .workspace {
    grid-template-columns: 1fr;
  }
  .workspace .detail-pane { display: none; }
  .workspace.mobile-detail .list-pane { display: none; }
  .workspace.mobile-detail .detail-pane {
    display: block;
    padding: 14px 12px 24px;
  }
  .full-pane { padding: 12px 12px 24px; }
  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .bnav-item {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 5px 2px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    cursor: pointer;
  }
  .bnav-item.active {
    color: var(--accent);
    font-weight: 600;
  }
  .bnav-icon { font-size: 16px; line-height: 1.1; }
  .toast-root {
    left: 12px;
    right: 12px;
    bottom: calc(64px + env(safe-area-inset-bottom));
  }
  .data-table { display: block; overflow-x: auto; }
}
