/* ============================================================
   Admin UI — vanilla, no framework.
   Visually consistent with the marketing site (Inter, indigo accent).
   ============================================================ */
:root {
  --bg: #f7f8fc;
  --surface: #ffffff;
  --text: #0b1020;
  --muted: #4a5170;
  --subtle: #7a82a0;
  --border: #e6e8f0;
  --border-soft: #eef0f7;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: rgba(79, 70, 229, 0.10);
  --success: #047857;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.08);
  --grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: #fff;
  border-right: 1px solid var(--border-soft);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.sidebar .brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--grad);
  display: grid; place-items: center;
  color: #fff;
}
.sidebar .brand-mark svg { width: 16px; height: 16px; }
.sidebar .nav-section {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--subtle); padding: 14px 10px 6px;
}
.sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.sidebar a:hover { background: var(--bg); color: var(--text); }
.sidebar a.active { background: var(--primary-soft); color: var(--primary); }
.sidebar a svg { width: 16px; height: 16px; }
.sidebar .spacer { flex: 1; }
.sidebar .me {
  font-size: 12px;
  color: var(--subtle);
  padding: 10px;
  border-top: 1px solid var(--border-soft);
  display: flex; justify-content: space-between; align-items: center;
}

.main { padding: 24px 32px 64px; max-width: 1200px; width: 100%; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head h1 {
  font-size: 24px; font-weight: 700; letter-spacing: -0.01em;
}
.page-sub { color: var(--muted); margin-top: 4px; font-size: 14px; }

/* ---------- Site switcher ---------- */
.site-switcher {
  display: inline-flex;
  align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  height: 38px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.site-switcher:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}
.site-switcher select {
  border: 0; outline: 0; background: transparent; font-weight: 600;
  width: auto;
  padding: 0;
  height: 100%;
  cursor: pointer;
  appearance: none;
  padding-right: 18px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%237a82a0'%3E%3Cpath d='M5.25 7.5 10 12.25 14.75 7.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  background-size: 14px;
}
.site-switcher .label { font-size: 11px; color: var(--subtle); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 22px;
}
.card + .card { margin-top: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 800px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: #fff; border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg); padding: 18px;
}
.stat .k { color: var(--subtle); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }

.table-wrap {
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left; padding: 12px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
th {
  background: var(--bg);
  font-weight: 600; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
}
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg); }

.empty {
  padding: 60px 30px; text-align: center; color: var(--subtle);
}
.empty .big { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 6px; }

/* ---------- Forms ---------- */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--text); }
.input,
input:where(:not([type]), [type="text"], [type="email"], [type="password"], [type="url"], [type="number"], [type="search"], [type="tel"], [type="datetime-local"], [type="date"], [type="time"]),
select, textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  transition: border-color 0.12s, box-shadow 0.12s;
  box-sizing: border-box;
}
.input::placeholder, input::placeholder, textarea::placeholder { color: #aab0c4; }
.input:hover, input:hover, select:hover, textarea:hover { border-color: #cfd3e2; }
.input:focus, input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}
select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%237a82a0'%3E%3Cpath d='M5.25 7.5 10 12.25 14.75 7.5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  cursor: pointer;
}
textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.55;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.hint { font-size: 12px; color: var(--subtle); margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #fff;
  color: var(--text);
  font-weight: 600; font-size: 13.5px;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s, transform 0.06s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.22); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover { filter: brightness(1.05); box-shadow: var(--shadow-sm); }
.btn-ghost { border-color: var(--border); color: var(--text); background: #fff; }
.btn-ghost:hover { background: var(--bg); border-color: #cfd3e2; }
.btn-danger { color: var(--danger); border-color: var(--border); background: #fff; }
.btn-danger:hover { background: rgba(185,28,28,0.06); border-color: rgba(185,28,28,0.30); }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; }

/* ---------- Filter bar ---------- */
.filter-bar {
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.filter-bar .filter-label {
  font-size: 11px; color: var(--subtle);
  text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600;
  padding: 0 4px;
}
.filter-bar select,
.filter-bar input {
  height: 34px;
  font-size: 13px;
}
.filter-bar .filter-sm { max-width: 200px; }
.filter-bar .filter-md { max-width: 280px; flex: 1; min-width: 200px; }
.filter-bar .grow { flex: 1; min-width: 0; }

/* ---------- Progress list (mass generate) ---------- */
.progress-list {
  display: flex; flex-direction: column;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--bg);
}
.progress-line {
  font-size: 13px; line-height: 1.5;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border-soft);
  border-radius: 7px;
}
.progress-line a { color: var(--primary); font-weight: 500; }
.progress-line a:hover { text-decoration: underline; }
.progress-line.err { background: rgba(185,28,28,0.05); border-color: rgba(185,28,28,0.18); }
.progress-line.queued { opacity: 0.65; }
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.dot-busy    { background: var(--primary); animation: dot-pulse 1.4s ease-in-out infinite; }
.dot-ok      { background: var(--success); }
.dot-err     { background: var(--danger); }
.dot-pending { background: transparent; border: 1.5px solid var(--border); }
@keyframes dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Tag ---------- */
.tag {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  white-space: nowrap;
}

/* ---------- Pills ---------- */
.pill {
  display: inline-block;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 999px;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}
.pill.draft     { background: #eef0f7; color: var(--muted); }
.pill.scheduled { background: rgba(245,158,11,0.14); color: var(--warning); }
.pill.published { background: rgba(16,185,129,0.14); color: var(--success); }
.pill.new       { background: rgba(79,70,229,0.10); color: var(--primary); }
.pill.read      { background: #eef0f7; color: var(--muted); }
.pill.archived  { background: #e3e6f0; color: var(--subtle); }
.pill.active    { background: rgba(16,185,129,0.14); color: var(--success); }
.pill.abandoned { background: #eef0f7; color: var(--muted); }
.pill.completed { background: rgba(79,70,229,0.10); color: var(--primary); }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1000px 500px at 20% -10%, rgba(124, 58, 237, 0.10), transparent 60%),
    radial-gradient(800px 400px at 90% 110%, rgba(79, 70, 229, 0.12), transparent 60%),
    var(--bg);
}
.login .card { width: 100%; max-width: 400px; padding: 32px; box-shadow: var(--shadow-md); }
.login .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-weight: 700; }
.login .brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--grad); display: grid; place-items: center; color: #fff; }
.login .brand-mark svg { width: 18px; height: 18px; }
.login h1 { font-size: 20px; }
.login p.sub { color: var(--muted); margin: 6px 0 22px; }
.login .btn { width: 100%; justify-content: center; height: 44px; }
.login .err { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

/* ---------- Modal / drawer ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 16, 32, 0.45);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 24px;
  width: min(560px, 92vw);
  max-height: 88vh; overflow: auto;
  box-shadow: var(--shadow-md);
}
.modal h2 { font-size: 18px; margin-bottom: 14px; }
.modal-actions {
  margin-top: 18px;
  display: flex; gap: 10px; justify-content: flex-end;
}
.drawer-wide { width: min(820px, 92vw); }

/* ---------- Chat transcript ---------- */
.transcript { display: grid; gap: 14px; }
.msg {
  border-radius: 12px;
  padding: 14px 16px;
  max-width: 88%;
  font-size: 14px;
  white-space: pre-wrap;
  line-height: 1.55;
}
.msg.user { background: var(--primary-soft); color: var(--text); align-self: flex-end; margin-left: auto; }
.msg.assistant { background: #fff; border: 1px solid var(--border-soft); }
.msg .meta { font-size: 11px; color: var(--subtle); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }

/* ---------- Utility ---------- */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.subtle { color: var(--subtle); }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md); z-index: 60;
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
