/* ============================================================================
   WayR Admin Dashboard — tokens mirror Wayr/src/contexts/ThemeContext.tsx
   (lightTheme / darkTheme) so the dashboard reads as part of the same product.
   ========================================================================== */

:root {
  --primary: #0fa896;      /* Route Teal */
  --secondary: #7fd8cf;    /* Mist Teal */
  --background: #f5f8f8;
  --surface: #f4f1e8;
  --card: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #6b6b6b;
  --border: #e2e2e2;
  --error: #ff3b30;
  --warning: #ff9500;
  --success: #0fa896;
  --info: #007aff;
  --overlay: rgba(0, 0, 0, 0.5);
  --shadow: 0 1px 2px rgba(28, 28, 30, 0.06), 0 4px 16px rgba(28, 28, 30, 0.06);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #0fa896;
    --secondary: #7fd8cf;
    --background: #192221;
    --surface: #1e2b29;
    --card: #1c2b29;
    --text: #ffffff;
    --text-secondary: #a1a1a1;
    --border: #2c3a38;
    --error: #ff453a;
    --warning: #ff9f0a;
    --success: #0fa896;
    --info: #0a84ff;
    --overlay: rgba(255, 255, 255, 0.08);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --primary: #0fa896;
  --secondary: #7fd8cf;
  --background: #192221;
  --surface: #1e2b29;
  --card: #1c2b29;
  --text: #ffffff;
  --text-secondary: #a1a1a1;
  --border: #2c3a38;
  --error: #ff453a;
  --warning: #ff9f0a;
  --success: #0fa896;
  --info: #0a84ff;
  --overlay: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

a { color: var(--primary); }

button {
  font-family: inherit;
  cursor: pointer;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Login screen ─────────────────────────────────────────────────────── */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.login-brand img { width: 40px; height: 40px; border-radius: 10px; }
.login-brand h1 { font-size: 18px; margin: 0; }
.login-brand span { display: block; font-size: 12px; color: var(--text-secondary); }

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

.field input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--text);
  font-size: 14px;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
}

.field-checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}

.field-checkbox input {
  width: auto;
  margin: 0;
}

.btn-link {
  display: block;
  width: 100%;
  margin-top: 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  padding: 6px;
}

.btn-link:hover {
  color: var(--text);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s ease, transform 0.05s ease;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--error); border: 1px solid var(--error); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

.login-error {
  background: color-mix(in srgb, var(--error) 12%, transparent);
  color: var(--error);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.login-error.visible { display: block; }

/* ── App shell ────────────────────────────────────────────────────────── */

#app-shell { display: none; min-height: 100vh; flex-direction: column; }
#app-shell.visible { display: flex; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; margin-right: 8px; }
.topbar-brand img { width: 28px; height: 28px; border-radius: 7px; }
.topbar-brand strong { font-size: 15px; }

.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.tab-btn:hover { background: var(--overlay); }
.tab-btn.active { background: var(--primary); color: #fff; }

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

.live-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(15, 168, 150, 0.5);
  animation: pulse 2s infinite;
}

.live-dot.down { background: var(--error); animation: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(15, 168, 150, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(15, 168, 150, 0); }
  100% { box-shadow: 0 0 0 0 rgba(15, 168, 150, 0); }
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.icon-btn:hover { background: var(--overlay); }

main { flex: 1; padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; animation: fadein 0.15s ease; }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

h2.view-title { font-size: 18px; margin: 0 0 16px; }

/* ── Stat tiles ───────────────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

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

.stat-tile .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-tile .stat-value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 6px;
}

.stat-tile .stat-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.stat-tile.warn .stat-value { color: var(--warning); }
.stat-tile.bad .stat-value { color: var(--error); }
.stat-tile.good .stat-value { color: var(--success); }

/* ── Panels / cards ───────────────────────────────────────────────────── */

.panel-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .panel-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.panel h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  margin: 0 0 14px;
}

#traffic-chart { width: 100%; height: 160px; display: block; }

/* ── Toolbar (search / filters) ───────────────────────────────────────── */

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar input[type="text"], .toolbar select {
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
}

.toolbar input[type="text"] { min-width: 240px; flex: 1; max-width: 360px; }

/* ── Tables ───────────────────────────────────────────────────────────── */

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

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--overlay); }

.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--text-secondary); }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
}

.badge-neutral { background: var(--overlay); color: var(--text-secondary); }
.badge-success { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.badge-warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.badge-error { background: color-mix(in srgb, var(--error) 18%, transparent); color: var(--error); }
.badge-info { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }

.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; }

.empty-state, .loading-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Modal / detail drawer ───────────────────────────────────────────── */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}

.modal-backdrop.visible { display: flex; }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 640px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 { margin: 0; font-size: 16px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 20px;
  font-size: 13px;
  margin-bottom: 16px;
}

.detail-grid .dt { color: var(--text-secondary); }
.detail-grid .dd { font-weight: 600; }

.modal h4 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 18px 0 8px;
}

/* ── Toast ────────────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--error);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 100;
  display: none;
  max-width: 340px;
}

#toast.visible { display: block; }

/* ── Response snippet ─────────────────────────────────────────────────── */

pre.snippet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow: auto;
  margin: 6px 0 0;
}
