@import url("./tokens.css");

/* ==========================================================================
   RESET & BASE
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
ul { margin: 0; padding: 0; list-style: none; }
button { font-family: inherit; cursor: pointer; }
code, .mono { font-family: var(--font-mono); }

::selection { background: var(--signal-dim); color: var(--text-primary); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); border: 2px solid var(--bg-canvas); }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--dur-base) var(--ease-out);
}
.app-shell[data-sidebar="collapsed"] {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border-hairline);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}
.sidebar-brand .mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: radial-gradient(circle at 30% 30%, var(--signal), #2f3ad1 70%);
  box-shadow: var(--shadow-glow-signal);
  flex-shrink: 0;
}
.sidebar-brand .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
.sidebar-brand .sub {
  font-size: 10.5px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  white-space: nowrap;
}
.app-shell[data-sidebar="collapsed"] .name,
.app-shell[data-sidebar="collapsed"] .sub,
.app-shell[data-sidebar="collapsed"] .nav-label,
.app-shell[data-sidebar="collapsed"] .nav-badge,
.app-shell[data-sidebar="collapsed"] .nav-group-title {
  display: none;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px 20px; }
.nav-group { margin-bottom: 4px; }
.nav-group-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 14px 10px 6px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13.2px;
  font-weight: 500;
  position: relative;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.nav-item .icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item .nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover:not([aria-disabled="true"]) { background: var(--bg-surface-hover); color: var(--text-primary); }
.nav-item[aria-current="page"] {
  background: var(--signal-dim);
  color: var(--text-primary);
}
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px;
  background: var(--signal); border-radius: var(--radius-full);
}
.nav-item[aria-current="page"] .icon { opacity: 1; color: var(--signal); }
.nav-item[aria-disabled="true"] { color: var(--text-tertiary); cursor: not-allowed; opacity: 0.65; }
.nav-badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: var(--bg-inset);
  color: var(--text-tertiary);
  border: 1px solid var(--border-hairline);
  white-space: nowrap;
}

.sidebar-footer {
  border-top: 1px solid var(--border-hairline);
  padding: 12px;
  flex-shrink: 0;
}
.collapse-btn {
  width: 100%;
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 8px; border-radius: var(--radius-md);
  background: transparent; border: 1px solid var(--border-hairline); color: var(--text-secondary);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.collapse-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.collapse-btn svg { transition: transform var(--dur-base) var(--ease-out); }
.app-shell[data-sidebar="collapsed"] .collapse-btn svg { transform: rotate(180deg); }

/* ---- Main column ---- */
.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-hairline);
  background: color-mix(in srgb, var(--bg-canvas) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-family: var(--font-display); font-size: 15.5px; font-weight: 600; }
.topbar-crumb { color: var(--text-tertiary); font-size: 12.5px; font-family: var(--font-mono); }

.search-trigger {
  display: flex; align-items: center; gap: 10px;
  margin-left: auto;
  padding: 7px 10px 7px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--text-tertiary);
  font-size: 12.5px;
  min-width: 240px;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--bg-surface-hover); }
.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--bg-inset);
  border: 1px solid var(--border-hairline);
  color: var(--text-tertiary);
  margin-left: auto;
}

.icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  background: transparent; border: 1px solid transparent; color: var(--text-secondary);
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.icon-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); border-color: var(--border-hairline); }
.icon-btn svg { width: 17px; height: 17px; }

.main-content { flex: 1; padding: 28px 32px 48px; max-width: 1360px; width: 100%; margin: 0 auto; }

/* ==========================================================================
   PRIMITIVES
   ========================================================================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-hover { transition: border-color var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out); }
.card-hover:hover { border-color: var(--border-strong); transform: translateY(-2px); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-signal { background: var(--signal-dim); color: var(--signal); border-color: color-mix(in srgb, var(--signal) 35%, transparent); }
.badge-beacon { background: var(--beacon-dim); color: var(--beacon); border-color: color-mix(in srgb, var(--beacon) 35%, transparent); }
.badge-amber { background: var(--amber-dim); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 35%, transparent); }
.badge-coral { background: var(--coral-dim); color: var(--coral); border-color: color-mix(in srgb, var(--coral) 35%, transparent); }
.badge-sage { background: var(--sage-dim); color: var(--sage); border-color: color-mix(in srgb, var(--sage) 35%, transparent); }
.badge-neutral { background: var(--bg-inset); color: var(--text-tertiary); border-color: var(--border-hairline); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 12.8px; font-weight: 600;
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast);
}
.btn:hover { background: var(--bg-surface-hover); border-color: var(--border-strong); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn-primary:hover { background: #4b5eea; border-color: #4b5eea; }

.divider { height: 1px; background: var(--border-hairline); border: none; margin: 0; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-inset) 25%, var(--bg-surface-hover) 37%, var(--bg-inset) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.fade-in { animation: fadeIn var(--dur-slow) var(--ease-out); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================================================
   DASHBOARD — STAT STRIP
   ========================================================================== */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card { display: flex; flex-direction: column; gap: 10px; }
.stat-card .stat-label { font-size: 11.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 30px; font-weight: 600; letter-spacing: -0.02em; }
.stat-card .stat-delta { font-family: var(--font-mono); font-size: 11.5px; display: flex; align-items: center; gap: 4px; }
.stat-delta.up { color: var(--sage); }
.stat-delta.down { color: var(--coral); }

/* ==========================================================================
   DASHBOARD — SIGNAL RADAR (signature element)
   ========================================================================== */
.radar-panel {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: center;
}
.radar-canvas-wrap { position: relative; width: 220px; height: 220px; }
.radar-readout { display: flex; flex-direction: column; gap: 14px; }
.radar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.radar-row .k { color: var(--text-secondary); font-size: 12.5px; }
.radar-row .v { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; }

/* ==========================================================================
   MODULE GRID
   ========================================================================== */
.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.module-card {
  display: flex; flex-direction: column; gap: 10px;
  min-height: 128px;
}
.module-card .m-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.module-card .m-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-inset); color: var(--signal);
  border: 1px solid var(--border-hairline);
}
.module-card .m-title { font-family: var(--font-display); font-weight: 600; font-size: 14px; }
.module-card .m-desc { font-size: 12px; color: var(--text-tertiary); line-height: 1.45; }
.module-card[aria-disabled="true"] { opacity: 0.55; }
.module-card[aria-disabled="true"]:hover { transform: none; border-color: var(--border-hairline); }

.section-heading {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 32px 0 14px;
}
.section-heading h2 { font-size: 16px; font-weight: 600; }
.section-heading .hint { font-size: 12px; color: var(--text-tertiary); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 1080px) {
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .radar-panel { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40; transform: translateX(-100%); transition: transform var(--dur-base) var(--ease-out); box-shadow: var(--shadow-md); }
  .app-shell[data-sidebar="open-mobile"] .sidebar { transform: translateX(0); }
  .main-content { padding: 20px 16px 40px; }
  .search-trigger { min-width: 0; flex: 1; }
  .search-trigger .kbd-hint { display: none; }
}
