:root {
  --bg: #0a0b0f;
  --bg2: #12131a;
  --panel: #161722;
  --text: #e8e9ed;
  --muted: #8b8d9a;
  --line: #1f2233;
  --accent: #00cfe8;
  --accent-2: #00b8d4;
  --good: #00d2a0;
  --warn: #f3a447;
  --bad: #ff6b6b;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f4f6fb;
  --bg2: #ffffff;
  --panel: #eef2fb;
  --text: #1f2430;
  --muted: #5e6a81;
  --line: #d7deec;
  --accent: #2364ff;
  --accent-2: #4a85ff;
  --good: #0a9f7a;
  --warn: #ca7c1e;
  --bad: #cb3d4b;
  --shadow: 0 10px 26px rgba(20, 32, 56, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  background: radial-gradient(900px 700px at 10% -20%, rgba(0, 207, 232, 0.14), transparent 60%), var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

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

#app {
  min-height: 100vh;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.admin-sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(22, 23, 34, 0.96), rgba(10, 11, 15, 0.98));
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #00131a;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.brand-title {
  font-weight: 700;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-links {
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow: auto;
  padding-right: 4px;
}

.sidebar-link {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 13px;
  color: var(--muted);
}

.sidebar-link:hover {
  border-color: #2a2e44;
  color: var(--text);
}

.sidebar-link.active {
  border-color: rgba(0, 207, 232, 0.35);
  background: rgba(0, 207, 232, 0.12);
  color: #c8f8ff;
}

.admin-main {
  padding: 22px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.pn-topbar {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg2);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-bottom: 12px;
  position: relative;
}

.pn-topbar-left h1 {
  margin: 0;
  font-size: 20px;
}

.pn-topbar-left p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.pn-topbar-right {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.pn-topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pn-topbar-action,
.pn-topbar-menu-action,
.pn-topbar-overflow-toggle {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  padding: 7px 9px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pn-topbar-badge {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.pn-topbar-overflow-toggle {
  display: none;
}

.pn-topbar-overflow-menu {
  position: absolute;
  top: calc(100% - 2px);
  right: 14px;
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg2);
  box-shadow: var(--shadow);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 6px;
  z-index: 80;
}

.pn-topbar-overflow-menu.open {
  display: flex;
}

.pn-topbar-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 220;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.pn-topbar-panel.open {
  display: flex;
}

.pn-topbar-panel-dialog {
  width: min(420px, 100%);
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.pn-topbar-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.pn-topbar-panel-close {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 6px 9px;
  cursor: pointer;
}

.pn-topbar-panel-body {
  padding: 12px 14px;
}

.pn-topbar-panel-block {
  margin-bottom: 10px;
  color: var(--muted);
}

.pn-topbar-panel-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pn-topbar-panel-link,
.pn-topbar-panel-mode {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 10px;
  text-decoration: none;
  cursor: pointer;
}

.pn-topbar-panel-mode.active {
  border-color: var(--accent);
}

.page-head h1 {
  margin: 0;
  font-size: 24px;
}

.page-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.grid {
  display: grid;
  gap: 12px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
}

.kpi-value {
  margin-top: 6px;
  font-size: 28px;
  font-weight: 700;
}

.stat-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.workload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.workload-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0f111a;
}

.workload-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.workload-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.row.between {
  justify-content: space-between;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 140px;
}

label {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(0, 207, 232, 0.5);
  box-shadow: 0 0 0 3px rgba(0, 207, 232, 0.16);
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  color: #001218;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.btn:hover {
  filter: brightness(1.05);
}

.btn.secondary {
  color: var(--text);
  border-color: #30354b;
  background: transparent;
}

.btn.good {
  color: #00140d;
  background: linear-gradient(135deg, #00d2a0, #00b88f);
}

.btn.warn {
  color: #211100;
  background: linear-gradient(135deg, #f8be5a, #f39b39);
}

.btn.danger {
  color: #fff;
  background: linear-gradient(135deg, #ee4f4f, #d83f3f);
}

.notice {
  border-radius: 10px;
  border: 1px solid rgba(0, 207, 232, 0.4);
  background: rgba(0, 207, 232, 0.1);
  color: #c8f8ff;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

.notice.error {
  border-color: rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.1);
  color: #ffc4c4;
}

.notice.ok {
  border-color: rgba(0, 210, 160, 0.4);
  background: rgba(0, 210, 160, 0.1);
  color: #b8ffec;
}

.skeleton-line {
  display: inline-block;
  height: 14px;
  min-width: 60px;
  max-width: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.06) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-table .skeleton-line { min-width: 40px; }
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: var(--bg2);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
  z-index: 1;
}

.status-pill {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.status-pill.good {
  background: rgba(0, 210, 160, 0.2);
  color: #98f3db;
}

.status-pill.warn {
  background: rgba(243, 164, 71, 0.2);
  color: #ffd8ab;
}

.status-pill.bad {
  background: rgba(255, 107, 107, 0.2);
  color: #ffc2c2;
}

.status-pill.neutral {
  background: rgba(139, 141, 154, 0.2);
  color: #d5d7e4;
}

.json-block {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: #0b0e17;
  border: 1px solid var(--line);
  overflow: auto;
  color: #c7d4df;
  font-size: 12px;
  line-height: 1.5;
}

.tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.tab-btn {
  border: none;
  border-right: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

.tab-btn:last-child {
  border-right: none;
}

.tab-btn.active {
  color: #c8f8ff;
  background: rgba(0, 207, 232, 0.16);
}

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.auth-card {
  width: min(520px, 100%);
  background: linear-gradient(150deg, rgba(0, 207, 232, 0.08), var(--bg2));
  border: 1px solid rgba(0, 207, 232, 0.3);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 18px;
}

.modal {
  width: min(960px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 1;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #0b0e17;
}

.chat-empty {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 10px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  max-width: 78%;
}

.chat-msg.inbound {
  align-self: flex-start;
}

.chat-msg.outbound {
  align-self: flex-end;
  background: rgba(0, 207, 232, 0.14);
  border-color: rgba(0, 207, 232, 0.35);
}

.chat-msg .meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}

.chat-msg .body {
  font-size: 13px;
  color: var(--text);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.pill.high {
  background: rgba(255, 107, 107, 0.2);
  color: #ffc2c2;
}

.pill.medium {
  background: rgba(243, 164, 71, 0.2);
  color: #ffd8ab;
}

.pill.low {
  background: rgba(0, 210, 160, 0.2);
  color: #98f3db;
}

.pill.sla-bad {
  background: rgba(255, 107, 107, 0.16);
  color: #ffb5b5;
}

.pill.sla-warn {
  background: rgba(243, 164, 71, 0.18);
  color: #ffd8ab;
}

.pill.sla-ok {
  background: rgba(0, 210, 160, 0.18);
  color: #b8ffec;
}

.list-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.agent-card,
.kb-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.agent-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.pn-quick-buttons {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg2);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.pn-quick-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.pn-quick-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pn-quick-btn {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.token-page {
  display: grid;
  gap: 12px;
}

.token-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.token-hero h2 {
  margin: 0;
}

.token-subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.token-meta-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.token-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  background: var(--panel);
  color: var(--muted);
}

.token-live-label {
  font-size: 12px;
  color: var(--muted);
}

.token-live-price {
  margin-top: 4px;
  font-size: 30px;
  font-weight: 700;
}

.token-live-change {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
}

.token-live-change.up {
  color: var(--good);
}

.token-live-change.down {
  color: var(--bad);
}

.token-chart {
  width: 100%;
  height: 170px;
}

.token-chart polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.token-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
}

.token-contract-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.token-contract {
  word-break: break-all;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  flex: 1;
}

.token-links {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.token-link {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  background: var(--panel);
  font-size: 12px;
}

.token-empty {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1080px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
    height: auto;
  }

  .sidebar-links {
    max-height: 200px;
  }

  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .admin-main {
    padding: 14px;
  }

  .pn-topbar {
    grid-template-columns: 1fr;
  }

  .pn-topbar-actions {
    display: none;
  }

  .pn-topbar-overflow-toggle {
    display: inline-flex;
  }

  .page-head {
    flex-direction: column;
  }

  .grid.cols-3,
  .grid.cols-2,
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }

  .row {
    flex-direction: column;
  }

  .field {
    min-width: 0;
  }

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

  .token-hero {
    flex-direction: column;
  }
}

/* Modal overlay for dialogs */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-overlay .card {
  animation: modal-in 0.2s ease-out;
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
