/* ── Theme variables ─────────────────────────────────────────────────────── */
:root {
  --bg:        #f0f2f5;
  --surface:   #ffffff;
  --surface2:  #f8f9fa;
  --border:    #dee2e6;
  --text:      #212529;
  --text-muted:#6c757d;
  --accent:    #0d6efd;
  --accent-h:  #0b5ed7;
  --danger:    #dc3545;
  --success:   #198754;
  --warning:   #fd7e14;
  --card-shadow: 0 1px 4px rgba(0,0,0,.08);
  --radius:    8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Consolas', monospace;
}

[data-theme="dark"] {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #242736;
  --border:    #2d3045;
  --text:      #e2e4ec;
  --text-muted:#8b8fa8;
  --accent:    #4d8ef0;
  --accent-h:  #6ba3f5;
  --danger:    #e05c6a;
  --success:   #3dba7a;
  --warning:   #f0934a;
  --card-shadow: 0 1px 6px rgba(0,0,0,.4);
}

[data-theme="high-contrast"] {
  --bg:        #000000;
  --surface:   #000000;
  --surface2:  #111111;
  --border:    #ffffff;
  --text:      #ffffff;
  --text-muted:#ffff00;
  --accent:    #ffff00;
  --accent-h:  #ffffff;
  --danger:    #ff4444;
  --success:   #00ff00;
  --warning:   #ff8800;
  --card-shadow: 0 0 0 2px #ffffff;
}

[data-theme="neon"] {
  --neon-a: #ff00ff;
  --neon-b: #00ffff;
  --neon-c: #ff0066;
  --neon-d: #00ff99;
  --neon-e: #6600ff;
  --bg:        #050505;
  --surface:   #0a0a0a;
  --surface2:  #111111;
  --border:    var(--neon-a);
  --text:      var(--neon-b);
  --text-muted:var(--neon-d);
  --accent:    var(--neon-a);
  --accent-h:  var(--neon-e);
  --danger:    var(--neon-c);
  --success:   var(--neon-d);
  --warning:   var(--neon-e);
  --card-shadow: 0 0 12px var(--neon-a);
}

[data-theme="neon"] body {
  animation: neon-bg 2.4s linear infinite;
}

[data-theme="neon"] .card {
  box-shadow: 0 0 16px var(--neon-a), inset 0 0 8px rgba(0,0,0,.8);
  border-color: var(--neon-a);
  animation: neon-border 2.4s linear infinite;
}

[data-theme="neon"] header {
  box-shadow: 0 0 20px var(--neon-b);
  border-bottom-color: var(--neon-b);
  animation: neon-header 2.4s linear infinite;
}

[data-theme="neon"] .logo {
  text-shadow: 0 0 10px var(--neon-a), 0 0 20px var(--neon-a);
  animation: neon-text 2.4s linear infinite;
}

@keyframes neon-bg {
  0%   { background-color: #050505; }
  50%  { background-color: #000308; }
  100% { background-color: #050505; }
}

@keyframes neon-border {
  0%   { border-color: var(--neon-a); box-shadow: 0 0 16px var(--neon-a); }
  33%  { border-color: var(--neon-c); box-shadow: 0 0 16px var(--neon-c); }
  66%  { border-color: var(--neon-d); box-shadow: 0 0 16px var(--neon-d); }
  100% { border-color: var(--neon-a); box-shadow: 0 0 16px var(--neon-a); }
}

@keyframes neon-header {
  0%   { box-shadow: 0 0 20px var(--neon-b); border-bottom-color: var(--neon-b); }
  33%  { box-shadow: 0 0 20px var(--neon-e); border-bottom-color: var(--neon-e); }
  66%  { box-shadow: 0 0 20px var(--neon-a); border-bottom-color: var(--neon-a); }
  100% { box-shadow: 0 0 20px var(--neon-b); border-bottom-color: var(--neon-b); }
}

@keyframes neon-text {
  0%   { text-shadow: 0 0 10px var(--neon-a), 0 0 20px var(--neon-a); }
  33%  { text-shadow: 0 0 10px var(--neon-c), 0 0 20px var(--neon-c); }
  66%  { text-shadow: 0 0 10px var(--neon-b), 0 0 20px var(--neon-b); }
  100% { text-shadow: 0 0 10px var(--neon-a), 0 0 20px var(--neon-a); }
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .2s, color .2s;
}

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

code, pre, .mono { font-family: var(--font-mono); font-size: .875rem; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.page-wrap { max-width: 1600px; margin: 0 auto; padding: 0 1rem; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--card-shadow);
  position: sticky; top: 0; z-index: 100;
}

.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1.5rem;
  max-width: 1600px; margin: 0 auto;
}

.logo {
  font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em;
  color: var(--accent);
}
.logo span { color: var(--text); font-weight: 400; }

.header-actions { display: flex; align-items: center; gap: .75rem; }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: .75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted);
  margin-bottom: 1rem;
  display: flex; align-items: center; justify-content: space-between;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem 1rem; border-radius: 6px; border: none;
  font-size: .875rem; font-weight: 500; cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-h); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: #b02a37; }
.btn-ghost    { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover    { background: var(--surface2); }
.btn-sm       { padding: .3rem .7rem; font-size: .8rem; }
#admin-link   { display: none; }
.hidden        { display: none; }
#alert-box     { max-width: 720px; margin: 0 auto 1rem; }
.lookup-link   { cursor: pointer; color: var(--accent); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.lookup-link:hover { text-decoration-style: solid; }
.dd-th { padding:.3rem .6rem; border-bottom:2px solid var(--border); text-align:left; background:var(--bg-card); position:sticky; top:0; z-index:1; white-space:nowrap; }
.dd-td { padding:.3rem .6rem; border-bottom:1px solid var(--border); white-space:nowrap; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; }
.hint { font-size: .78rem; color: var(--text-muted); margin-top: .25rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; padding: .55rem .75rem;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: .9rem;
  font-family: var(--font); transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13,110,253,.15);
}

/* ── Toggle switch ───────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: .6rem; }
.toggle {
  position: relative; width: 42px; height: 24px;
  display: inline-block; flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 24px; cursor: pointer; transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle input:disabled + .toggle-slider { opacity: .4; cursor: not-allowed; }

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: .2rem .55rem;
  border-radius: 20px; font-size: .72rem; font-weight: 600;
}
.badge-success { background: rgba(25,135,84,.15); color: var(--success); }
.badge-warning { background: rgba(253,126,20,.15); color: var(--warning); }
.badge-muted   { background: var(--surface2);      color: var(--text-muted); }
.badge-danger  { background: rgba(220,53,69,.15);  color: var(--danger); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; padding: .6rem .75rem; border-bottom: 2px solid var(--border); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; overflow-x: auto; }
.tab-btn {
  padding: .7rem 1.25rem; font-size: .875rem; font-weight: 500;
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); cursor: pointer; white-space: nowrap;
  margin-bottom: -2px; transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Auth pages ──────────────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { font-size: 1.6rem; margin-bottom: .25rem; }
.auth-card .tagline { color: var(--text-muted); font-size: .875rem; margin-bottom: 1.5rem; }

/* ── Theme toggle button ─────────────────────────────────────────────────── */
#theme-toggle {
  background: none; border: 1px solid var(--border);
  border-radius: 20px; padding: .3rem .75rem;
  cursor: pointer; font-size: .8rem; color: var(--text-muted);
  transition: border .15s, color .15s;
}
#theme-toggle:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Alert / toast ───────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem;
  font-size: .875rem; border-left: 3px solid;
}
.alert-error   { background: rgba(220,53,69,.1);  border-color: var(--danger);  color: var(--danger); }
.alert-success { background: rgba(25,135,84,.1);  border-color: var(--success); color: var(--success); }
.alert-info    { background: rgba(13,110,253,.1); border-color: var(--accent);  color: var(--accent); }

/* ── Search / enrich input ───────────────────────────────────────────────── */
.search-wrap {
  display: flex; gap: .5rem;
  margin-top: 5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .5rem; box-shadow: var(--card-shadow);
}
#query-input {
  flex: 1; border: none; background: transparent;
  font-size: 1rem; padding: .35rem .5rem;
  color: var(--text); font-family: var(--font-mono);
}
#query-input:focus { outline: none; box-shadow: none; }
.phone-hint { font-size: .78rem; color: var(--text-muted); margin-top: .4rem; padding-left: .25rem; }

/* ── Result sections ─────────────────────────────────────────────────────── */
.result-meta {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  font-size: .875rem; color: var(--text-muted); margin-bottom: 1rem;
}
.result-meta .query-val { font-family: var(--font-mono); color: var(--text); font-size: .95rem; }
.result-meta .type-badge { font-weight: 600; }

.section-card { margin-bottom: .75rem; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
}
.section-header:hover { opacity: .85; }
.section-chevron { transition: transform .2s; }
.section-card.collapsed .section-chevron { transform: rotate(-90deg); }
.section-card.collapsed .section-body { display: none; }
.section-body { margin-top: .75rem; }

.kv-table { width: 100%; font-size: .875rem; }
.kv-table td:first-child { color: var(--text-muted); width: 38%; padding-right: 1rem; white-space: nowrap; }
.kv-table td { padding: .3rem 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv-table tr:last-child td { border-bottom: none; }

.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag { background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; padding: .15rem .5rem; font-size: .78rem; }

.port-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.port { background: rgba(13,110,253,.1); color: var(--accent); border-radius: 4px; padding: .15rem .5rem; font-size: .8rem; font-family: var(--font-mono); }

.disabled-section { opacity: .6; }
.disabled-msg { font-size: .85rem; color: var(--text-muted); padding: .5rem 0; }

/* ── Loader ──────────────────────────────────────────────────────────────── */
#loader  { display: none; }
.loader  { display: flex; align-items: center; gap: .75rem; color: var(--text-muted); font-size: .9rem; padding: 2rem 0; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Download bar ────────────────────────────────────────────────────────── */
.dl-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

/* ── Transcript ──────────────────────────────────────────────────────────── */
#transcript-panel { margin-top: 2rem; }
.transcript-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .45rem .5rem; border-radius: 6px; font-size: .85rem;
  cursor: pointer;
}
.transcript-item:hover { background: var(--surface2); }
.transcript-item .ts-query { font-family: var(--font-mono); flex: 1; }
.transcript-item .ts-time  { color: var(--text-muted); font-size: .78rem; white-space: nowrap; }

/* ── Admin API key rows ──────────────────────────────────────────────────── */
.api-key-row { display:grid; grid-template-columns:180px 1fr auto auto; gap:.75rem; align-items:center; padding:.65rem 0; border-bottom:1px solid var(--border); }
.api-key-row:last-child { border-bottom:none; }
.api-key-row .svc-name { font-weight:600; font-size:.9rem; }
.api-key-row .key-field-wrap { display:flex; gap:.4rem; }
.api-key-row .key-field-wrap input { font-family:var(--font-mono); font-size:.82rem; }
@media(max-width:700px) { .api-key-row { grid-template-columns:1fr; } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-inner { padding: .6rem 1rem; }
  .card { padding: 1rem; }
}
