/* Kagan — Operator admin shell (PF/UI). Reuses the panel's dark + acid-lime
   brand tokens. Vanilla CSS, no preprocessor. */

:root {
  /* Brand "Volt": Lemon primary + Indigo secondary. Parity: shared/constants.js
     + panel/css/themes.css. */
  --accent: #e5f23b;
  --accent-light: #e5f23b;
  --accent-2: #6c79e8;
  --accent-dim: rgba(229, 242, 59, 0.1);
  --accent-glow: rgba(229, 242, 59, 0.45);
  --shadow-accent-glow: 0 0 16px var(--accent-glow);
  /* Accent used as text/ink — theme-aware for WCAG AA. Dark: lemon reads on the
     dark shell; light theme switches to deep indigo (html.theme-light) since
     lemon is unreadable on white. */
  --accent-ink: var(--accent-light);
  --on-accent: #15171f;
  --bg-app: #0b0b0c;
  --bg-panel: #121316;
  --bg-card: #17191d;
  --bg-elev: #1d2025;
  --border: #26292f;
  --border-2: #31353c;
  --text: #e9edf1;
  --text-dim: #9aa3ad;
  --text-faint: #6b7280;
  --danger: #ff5d5d;
  --warn: #ffb84d;
  --ok: var(--accent);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
html.theme-light {
  --on-accent: #15171f;
  /* Deep indigo for accent-text on light surfaces (lemon fails AA on white).
     #4a5ac2 → ~6:1 on #fff, passes AA for body text. */
  --accent-ink: #4a5ac2;
  --accent-2: #6c79e8;
  --bg-app: #f4f5f7;
  --bg-panel: #ffffff;
  --bg-card: #ffffff;
  --bg-elev: #f0f2f5;
  --border: #e3e6ea;
  --border-2: #d4d8de;
  --text: #14171a;
  --text-dim: #5b636d;
  --text-faint: #98a0aa;
  --shadow: 0 8px 24px rgba(20, 23, 26, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
button { font-family: inherit; }

/* Scrollbars — themed, thin. Firefox honours scrollbar-width/color. */
html { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- focus-visible (a11y) ---------------- */
.btn:focus-visible,
.input:focus-visible,
.chip:focus-visible,
.card:focus-visible,
.lead-card:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.input:focus-visible { outline-offset: 1px; }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--bg-elev); color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all .12s ease;
}
.btn:hover { border-color: var(--text-faint); }
.btn--primary {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
  box-shadow: 0 0 0 0 transparent;
}
.btn--primary:hover { box-shadow: var(--shadow-accent-glow); border-color: var(--accent); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn--ghost:hover { color: var(--text); background: var(--bg-elev); }
.btn--sm { padding: 6px 10px; font-size: 12px; }
.btn--danger { color: var(--danger); border-color: var(--border-2); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------- inputs ---------------- */
.field { display: block; margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--bg-app); color: var(--text);
  font-size: 14px; outline: none;
}
.input:focus { border-color: var(--text-faint); }
.input:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- disabled + skeleton (a11y / loading) ---------------- */
.is-disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

@keyframes admin-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--bg-elev) 25%, var(--border-2) 37%, var(--bg-elev) 63%);
  background-size: 200% 100%;
  animation: admin-shimmer 1.4s ease-in-out infinite;
}
.skeleton-line { height: 12px; margin: 8px 0; }
.skeleton-line.short { width: 45%; }
.skeleton-block { height: 60px; }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ---------------- login ---------------- */
.login {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-logo {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent);
  display: grid; place-items: center; color: var(--on-accent); font-weight: 800;
}
.login-title { font-size: 18px; font-weight: 700; }
.login-sub { color: var(--text-dim); font-size: 12px; margin: 2px 0 22px; }
.login-err { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 8px; }

/* ---------------- app shell ---------------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: grid; place-items: center; color: var(--on-accent); font-weight: 800; font-size: 14px;
}
.brand-name { font-weight: 700; }
.brand-tag { font-size: 11px; color: var(--text-faint); }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text-dim); cursor: pointer; font-size: 13px; font-weight: 500; border: 0; background: transparent; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.is-active { background: var(--bg-elev); color: var(--text); }
.nav-item.is-active::before {
  content: ""; width: 3px; height: 16px; border-radius: 3px; background: var(--accent); margin-left: -10px; margin-right: 7px;
}
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.nav-item.is-active .nav-dot { background: var(--accent); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; padding: 0 22px; background: var(--bg-panel);
}
.topbar-title { font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.who-email { font-size: 13px; }
.who-role { font-size: 11px; color: var(--accent-ink); text-transform: uppercase; letter-spacing: .5px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--bg-elev); border: 1px solid var(--border-2);
  display: grid; place-items: center; font-size: 12px; color: var(--text-dim);
}
.content { padding: 24px; overflow-y: auto; }

/* ---------------- ui kit ---------------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; }
.page-title { font-size: 20px; font-weight: 700; }
.page-sub { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.stat:hover { transform: translateY(-2px); border-color: var(--border-2); box-shadow: var(--shadow); }
.stat-label { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; font-family: var(--mono); }
.stat-delta { font-size: 12px; margin-top: 6px; }
.stat-delta.up { color: var(--accent-ink); }
.stat-delta.down { color: var(--danger); }

.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-weight: 600; }
.card-body { padding: 18px; }

.filterbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.filterbar .input { max-width: 280px; }
.chip {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border-2); background: var(--bg-card);
  color: var(--text-dim); font-size: 12px; cursor: pointer;
}
.chip.is-active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th {
  text-align: left; padding: 11px 14px; color: var(--text-faint); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border);
}
.tbl tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.tbl tbody tr:hover { background: var(--bg-elev); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--bg-elev); color: var(--text-dim); border: 1px solid var(--border-2);
}
.badge.ok { color: var(--accent-ink); border-color: var(--accent-glow); }
.badge.warn { color: var(--warn); border-color: rgba(255,184,77,.4); }
.badge.bad { color: var(--danger); border-color: rgba(255,93,93,.4); }
.num { font-family: var(--mono); }

.empty { padding: 40px; text-align: center; color: var(--text-faint); }
.placeholder {
  border: 1px dashed var(--border-2); border-radius: var(--radius); padding: 48px; text-align: center; color: var(--text-faint);
}
.placeholder b { color: var(--text-dim); display: block; margin-bottom: 6px; font-size: 15px; }

/* sparkline / mini chart */
.spark { width: 100%; height: 60px; display: block; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 2; }
.spark path.area { fill: var(--accent-dim); stroke: none; }

/* toast */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--border-2); color: var(--text);
  padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 13px; min-width: 200px;
}
.toast.error { border-color: rgba(255,93,93,.5); }
.toast.success { border-left: 3px solid var(--accent); }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 40; padding: 20px;
}
.modal {
  width: 100%; max-width: 420px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal--wide { max-width: 560px; }
.modal--wide .modal-body { max-height: 74vh; overflow-y: auto; }

/* ---------------- upload form (templates "New template") ---------------- */
@keyframes admin-spin { to { transform: rotate(360deg); } }

.form-section-label {
  font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase;
  color: var(--text-faint); margin: 16px 0 9px;
}
.form-section-label:first-child { margin-top: 2px; }

.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.upload-grid .field { margin-bottom: 0; }
.upload-grid .field.col-span { grid-column: 1 / -1; }

.upload-drops { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Dropzone — empty prompt; drag-drop + click; filled shows an upload row. */
.upload-drop {
  position: relative; min-height: 96px; padding: 14px; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center;
  border: 1.5px dashed var(--border-2); border-radius: var(--radius-sm); background: var(--bg-app);
  transition: border-color .14s, background .14s;
}
.upload-drop:hover { border-color: var(--text-faint); }
.upload-drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.upload-drop.is-dragover { border-color: var(--accent); background: var(--accent-dim); }
.upload-drop[data-filled="1"] { cursor: default; padding: 10px 12px; border-style: solid; border-color: var(--border); }
.upload-drop-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.upload-drop-prompt { display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; pointer-events: none; }
.upload-drop[data-filled="1"] .upload-drop-prompt { display: none; }
.upload-drop-icon { color: var(--text-faint); line-height: 0; margin-bottom: 2px; }
.upload-drop-label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.upload-drop-hint { font-size: 10.5px; color: var(--text-faint); }
.upload-drop-cta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.upload-drop-body { display: none; }
.upload-drop[data-filled="1"] .upload-drop-body { display: block; }

/* Upload row — thumb + name/size + progress + status. */
.upload-row { display: flex; align-items: center; gap: 10px; }
.upload-row-thumb {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 6px;
  background: var(--bg-elev) center / cover no-repeat; border: 1px solid var(--border);
}
.upload-row-info { flex: 1; min-width: 0; }
.upload-row-name { font-size: 12px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row-meta { font-size: 10.5px; color: var(--text-faint); font-family: var(--mono); }

.upload-progress { display: none; width: 68px; height: 5px; flex-shrink: 0; border-radius: 999px; background: var(--bg-elev); overflow: hidden; }
.upload-row[data-status="uploading"] .upload-progress { display: block; }
.upload-progress.upload-overall { display: block; width: 100%; height: 6px; margin-top: 4px; }
.upload-progress-fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .18s ease; }

.upload-row-status {
  width: 22px; height: 22px; flex-shrink: 0; padding: 0; border: 0; background: transparent;
  border-radius: 50%; cursor: default; display: inline-flex; align-items: center; justify-content: center;
}
.upload-row[data-status="queued"] .upload-row-status::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); }
.upload-row[data-status="uploading"] .upload-row-status { width: 16px; height: 16px; border: 2px solid var(--border-2); border-top-color: var(--accent); animation: admin-spin .7s linear infinite; }
.upload-row[data-status="done"] .upload-row-status::after { content: "\2713"; font-size: 14px; font-weight: 800; color: var(--accent-ink); }
.upload-row[data-status="error"] .upload-row-status { cursor: pointer; }
.upload-row[data-status="error"] .upload-row-status::after { content: "\21BB"; font-size: 15px; font-weight: 800; color: var(--danger); }

/* Tags chip input. */
.chip-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px;
  border: 1px solid var(--border-2); border-radius: var(--radius-sm); background: var(--bg-app);
}
.chip-input .input { border: 0; background: transparent; padding: 4px 2px; flex: 1; min-width: 90px; }
.chip-input .input:focus { border: 0; }
.chip-tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 4px 3px 9px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border-2); font-size: 11px; color: var(--text-dim);
}
.chip-tag button { border: 0; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 3px; }
.chip-tag button:hover { color: var(--danger); }

/* Uploading — lock the form, keep the drop rows readable. */
.upload-form[data-uploading="1"] .upload-grid,
.upload-form[data-uploading="1"] .chip-input { opacity: .55; pointer-events: none; }
.upload-form[data-uploading="1"] .upload-drop { pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .upload-row[data-status="uploading"] .upload-row-status { animation-duration: 1.6s; }
  .upload-progress-fill { transition: none; }
}
@media (max-width: 560px) {
  .upload-grid, .upload-drops { grid-template-columns: 1fr; }
}

/* leads pipeline board */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.board-col { flex: 1 0 180px; min-width: 180px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; }
.board-col-head { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); display: flex; justify-content: space-between; align-items: center; }
.board-col-count { color: var(--text-faint); font-family: var(--mono); }
.board-col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.lead-card { background: var(--bg-elev); border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 10px; cursor: pointer; transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; }
.lead-card:hover { border-color: var(--text-faint); transform: translateY(-2px); box-shadow: var(--shadow); }
.lead-card-email { font-size: 13px; font-weight: 600; word-break: break-all; }
.lead-card-meta { font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.timeline { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.timeline-item { font-size: 12px; color: var(--text-dim); border-left: 2px solid var(--accent); padding-left: 10px; }

.dev-flag {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--warn); color: #1a1205; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
}

/* ---------------- responsive (D8) ----------------
   Narrow viewports collapse the fixed 232px sidebar into a horizontal,
   scrollable top strip. CSS-only — no JS hamburger needed. */
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; min-height: 100vh; }
  .sidebar {
    flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .brand { padding: 2px 6px 2px 2px; flex-shrink: 0; }
  .brand-tag { display: none; }
  .nav { flex-direction: row; gap: 6px; overflow-x: auto; flex: 1; }
  .nav-item { white-space: nowrap; width: auto; flex-shrink: 0; }
  .nav-item.is-active::before { display: none; }
  .topbar { height: 52px; padding: 0 14px; }
  .who-email { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: 16px; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .filterbar .input { max-width: none; flex: 1 1 160px; }
}

@media (max-width: 460px) {
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .modal, .login-card { max-width: none; }
}
