/* ==========================================================================
   Signal Deck — design tokens
   Dark: deep ink navy surfaces, signal-blue accent, amber for pending state
   Light: paper surfaces, same accent family
   ========================================================================== */

:root {
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  --bg: #0b0e14;
  --bg-elevated: #10141d;
  --surface: #131926;
  --surface-2: #1a2233;
  --border: #262f42;
  --border-strong: #384158;

  --text: #e9ecf4;
  --text-muted: #8d96ac;
  --text-faint: #5b6478;

  --accent: #6c8cff;
  --accent-strong: #8aa3ff;
  --accent-soft: rgba(108, 140, 255, 0.14);

  --success: #35d488;
  --success-soft: rgba(53, 212, 136, 0.14);
  --danger: #ff5c7a;
  --danger-soft: rgba(255, 92, 122, 0.14);
  --warning: #ffb84d;
  --warning-soft: rgba(255, 184, 77, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-pop: 0 20px 60px rgba(0, 0, 0, 0.45);

  --dur-fast: 120ms;
  --dur-med: 220ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

  color-scheme: dark;
}

[data-theme='light'] {
  --bg: #f3f2ee;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f6f2;
  --border: #e2e0d8;
  --border-strong: #cbc8bc;

  --text: #191a1e;
  --text-muted: #5c5f6b;
  --text-faint: #8b8e99;

  --accent: #3f5cdb;
  --accent-strong: #2f49bd;
  --accent-soft: rgba(63, 92, 219, 0.1);

  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 6px 20px rgba(20, 20, 30, 0.08);
  --shadow-pop: 0 20px 50px rgba(20, 20, 30, 0.16);

  color-scheme: light;
}

[data-reduce-motion='true'] * {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.4em;
}

code, .mono { font-family: var(--font-mono); }

::selection { background: var(--accent-soft); }

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 0;
  z-index: 200;
}
.skip-link:focus { left: 0; }

/* ---------- App shell ---------- */

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

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #b28dff);
  position: relative;
  flex-shrink: 0;
}

.brand-mark::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 3px;
  background: var(--bg);
  animation: pulse-dot 2.4s var(--ease) infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nav-link svg { flex-shrink: 0; }

.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 16px 12px 6px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 50;
}

.hamburger {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--text);
}

.content {
  padding: 32px 40px 60px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

.page-head {
  margin-bottom: 28px;
}

.page-eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.page-eyebrow .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.page-title { font-size: 26px; margin-bottom: 6px; }
.page-desc { color: var(--text-muted); max-width: 60ch; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.card-pad { padding: 24px; }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform var(--dur-med) var(--ease), border-color var(--dur-med) var(--ease), box-shadow var(--dur-med) var(--ease);
}

.tool-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-pop);
}

.tool-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tool-card h3 { font-size: 16px; margin-bottom: 2px; }
.tool-card p { color: var(--text-muted); font-size: 13.5px; margin: 0; flex-grow: 1; }

.tool-card .go {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-strong);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 22px;
  margin-top: 6px;
}

/* ---------- Forms ---------- */

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.field .hint {
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 6px;
}

.input, .textarea, .select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  font-family: var(--font-body);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.input.mono, .textarea.mono { font-family: var(--font-mono); font-size: 13px; }

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.input.invalid, .textarea.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.textarea { min-height: 110px; resize: vertical; }

.field-error {
  font-size: 12.5px;
  color: var(--danger);
  margin-top: 6px;
  display: none;
}

.field-error.show { display: block; }

.char-count {
  font-size: 11.5px;
  color: var(--text-faint);
  text-align: right;
  margin-top: 4px;
  font-family: var(--font-mono);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
  font-family: var(--font-body);
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--border-strong); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }

.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ---------- Toast ---------- */

.toast-region {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
  max-width: 360px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-pop);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toast-in var(--dur-med) var(--ease);
  border-left: 3px solid var(--accent);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

.toast.leaving { animation: toast-out var(--dur-med) var(--ease) forwards; }

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

.toast-title { font-size: 13.5px; font-weight: 600; margin-bottom: 2px; }
.toast-msg { font-size: 12.5px; color: var(--text-muted); }
.toast-close { margin-left: auto; color: var(--text-faint); cursor: pointer; background: none; border: none; }

/* ---------- Result / status states ---------- */

.result-panel {
  margin-top: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 18px;
  display: none;
}

.result-panel.show { display: block; }

.result-panel.state-success { border-color: rgba(53, 212, 136, 0.35); background: var(--success-soft); }
.result-panel.state-error { border-color: rgba(255, 92, 122, 0.35); background: var(--danger-soft); }
.result-panel.state-pending { border-color: var(--border-strong); background: var(--surface-2); }

.result-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.online { background: var(--success-soft); color: var(--success); }
.badge.offline { background: var(--danger-soft); color: var(--danger); }
.badge.pending { background: var(--warning-soft); color: var(--warning); }

.meta-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin-top: 12px; }
.meta-item .k { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.meta-item .v { font-family: var(--font-mono); font-size: 13.5px; margin-top: 2px; word-break: break-word; }

.avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--surface-2);
}

/* ---------- Packet trail signature animation ---------- */

.packet-trail {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0;
  height: 26px;
}

.packet-trail .node {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.packet-trail .track {
  flex-grow: 1;
  height: 2px;
  background: var(--border);
  position: relative;
  overflow: hidden;
  border-radius: 2px;
}

.packet-trail .packet {
  position: absolute;
  top: 50%;
  left: -10%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  opacity: 0;
}

.packet-trail.active .packet {
  animation: packet-move 1.1s var(--ease) infinite;
}

@keyframes packet-move {
  0% { left: -6%; opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { left: 106%; opacity: 0; }
}

/* ---------- Confirm dialog ---------- */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.6);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 250;
  padding: 20px;
}

.dialog-backdrop.show { display: flex; }

.dialog {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-pop);
  animation: dialog-in var(--dur-med) var(--ease);
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog h3 { font-size: 17px; margin-bottom: 8px; }
.dialog p { color: var(--text-muted); font-size: 14px; margin-bottom: 18px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Loading ---------- */

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

.btn-secondary .spinner, .btn-ghost .spinner { border: 2px solid var(--border-strong); border-top-color: var(--text); }

@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skeleton-shine 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-shine {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

.empty-state .glyph {
  width: 54px;
  height: 54px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--text-faint);
}

.empty-state h4 { color: var(--text); margin-bottom: 4px; font-size: 15px; }
.empty-state p { font-size: 13.5px; max-width: 32ch; margin: 0 auto; }

/* ---------- Settings ---------- */

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  gap: 20px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row .label { font-weight: 600; font-size: 14px; }
.settings-row .desc { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background var(--dur-fast) var(--ease);
  cursor: pointer;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.switch input:checked + .track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--accent); }

.theme-options { display: flex; gap: 10px; }
.theme-chip {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.theme-chip.active { border-color: var(--accent); color: var(--accent-strong); background: var(--accent-soft); }

/* ---------- Footer / static pages ---------- */

.static-content h2 { font-size: 18px; margin-top: 28px; }
.static-content p, .static-content li { color: var(--text-muted); font-size: 14px; }
.static-content ul { padding-left: 20px; }

.site-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 18px;
  font-size: 12.5px;
  color: var(--text-faint);
  flex-wrap: wrap;
}

/* ---------- 404 ---------- */

.error-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
}
.error-code {
  font-family: var(--font-mono);
  color: var(--accent-strong);
  font-size: 14px;
  letter-spacing: 0.1em;
}
.error-page h1 { font-size: 40px; margin: 8px 0 12px; }
.error-page p { color: var(--text-muted); margin-bottom: 22px; }

/* ---------- Mobile nav ---------- */

.mobile-nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.55);
  z-index: 90;
  display: none;
}
.mobile-nav-backdrop.show { display: block; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform var(--dur-med) var(--ease);
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .content { padding: 24px 18px 50px; }
  .two-col { grid-template-columns: 1fr; }
  .meta-list { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .page-title { font-size: 22px; }
  .content { padding: 20px 14px 44px; }
}
