/* ============================================================
   KingXSeller StoryBot — modern app-shell UI (no external deps)
   ============================================================ */
:root {
  --bg: #080b14;
  --bg-grad-1: #141d3a;
  --surface: #0e1424;
  --card: #121a2e;
  --card-2: #16203a;
  --elevated: #1a2540;
  --border: #222d4a;
  --border-soft: #1a2338;
  --text: #eaf0fb;
  --muted: #94a2c2;
  --faint: #6c7899;
  --primary: #6d6cff;
  --primary-2: #9a6bff;
  --primary-ink: #ffffff;
  --primary-soft: rgba(109, 108, 255, 0.14);
  --ring: rgba(109, 108, 255, 0.38);
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.28);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="light"] {
  --bg: #f3f6fc;
  --bg-grad-1: #dde6fb;
  --surface: #ffffff;
  --card: #ffffff;
  --card-2: #f7f9fe;
  --elevated: #ffffff;
  --border: #e4eaf5;
  --border-soft: #eef2f9;
  --text: #101828;
  --muted: #56617d;
  --faint: #8a94ac;
  --primary: #5b57f5;
  --primary-2: #8b5cf6;
  --primary-soft: rgba(91, 87, 245, 0.10);
  --ring: rgba(91, 87, 245, 0.30);
  --good: #059669;
  --warn: #b7791f;
  --bad: #e11d48;
  --shadow: 0 12px 40px rgba(30, 45, 90, 0.14);
  --shadow-sm: 0 4px 16px rgba(30, 45, 90, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(1100px 640px at 100% -8%, var(--bg-grad-1) 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-2); }
h1, h2, h3 { letter-spacing: -0.01em; }

/* ---------------- App shell ---------------- */
.app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
  padding: 18px 14px;
  background: linear-gradient(180deg, var(--surface), var(--bg));
  border-right: 1px solid var(--border-soft);
}
.side-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 18px; padding: 8px 10px 14px;
}
.side-brand .logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 6px 18px var(--ring); font-size: 16px;
}
.side-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); padding: 14px 12px 6px; }
.side-nav { display: flex; flex-direction: column; gap: 3px; }
.side-link {
  display: flex; align-items: center; gap: 11px; cursor: pointer;
  padding: 10px 12px; border-radius: var(--radius-sm); color: var(--muted);
  font-weight: 600; font-size: 14px; position: relative; transition: all .15s ease;
  border: 1px solid transparent;
}
.side-link svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side-link:hover { background: var(--card); color: var(--text); }
.side-link.active {
  background: var(--primary-soft); color: var(--text);
  border-color: color-mix(in srgb, var(--primary) 30%, transparent);
}
.side-link.active::before {
  content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: linear-gradient(180deg, var(--primary), var(--primary-2));
}
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 10px; }
.side-user {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid var(--border-soft); position: relative; cursor: pointer;
}
.side-user .who { overflow: hidden; }
.side-user .who .nm { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who .rl { font-size: 11px; color: var(--faint); }

.main { min-width: 0; display: flex; flex-direction: column; }
.main-head {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 16px 26px; border-bottom: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px);
}
.page-title { margin: 0; font-size: 19px; font-weight: 700; }
.head-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.hamburger { display: none; background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }
.content { padding: 24px 26px 72px; max-width: 1180px; width: 100%; }

/* mobile off-canvas */
.scrim { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; width: 256px;
    transform: translateX(-104%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 55; }
  .hamburger { display: block; }
}

/* ---------------- Cards / grid ---------------- */
.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
}
.card.hover { transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
.card.hover:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--primary) 26%, var(--border)); }
.card h2, .card h3 { margin: 0 0 14px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.section-title { font-size: 15px !important; color: var(--text) !important; text-transform: none !important; letter-spacing: -.01em !important; }

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: 1.35fr .95fr; }
@media (max-width: 980px) { .grid.stats { grid-template-columns: repeat(2, 1fr); } .grid.cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 520px) { .grid.stats { grid-template-columns: 1fr; } }

/* stat card */
.stat { display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.stat .ic {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; margin-bottom: 4px;
  background: var(--primary-soft); color: var(--primary);
}
.stat .ic svg { width: 20px; height: 20px; }
.stat .value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat.good .ic { background: rgba(52,211,153,.14); color: var(--good); }
.stat.bad .ic { background: rgba(251,113,133,.14); color: var(--bad); }
.stat.warn .ic { background: rgba(251,191,36,.14); color: var(--warn); }

/* kpi (admin overview) */
.kpi { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
@media (max-width: 980px){ .kpi { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 520px){ .kpi { grid-template-columns: 1fr; } }
.kpi .k-val { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .k-lbl { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* ---------------- Forms ---------------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 11px 13px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font-size: 14px; outline: none; font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
textarea { min-height: 74px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
.input-wrap { position: relative; }
.input-wrap .toggle-eye { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); background: none; border: 0; cursor: pointer; color: var(--faint); font-size: 15px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--elevated); color: var(--text);
  padding: 10px 16px; border-radius: 11px; font-size: 14px; font-weight: 600; font-family: inherit;
  transition: transform .05s ease, background .15s, border-color .15s, box-shadow .15s; white-space: nowrap;
}
.btn:hover { background: var(--card-2); border-color: color-mix(in srgb, var(--primary) 34%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px var(--ring);
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 34%, var(--border)); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 11px; font-size: 12.5px; border-radius: 9px; }
.btn.icon { padding: 8px; width: 38px; height: 38px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
thead th { color: var(--faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; background: color-mix(in srgb, var(--surface) 60%, transparent); }
tbody tr { transition: background .12s; }
tbody tr:hover { background: color-mix(in srgb, var(--primary) 6%, transparent); }
tbody tr:last-child td { border-bottom: 0; }

/* ---------------- Badges / pills ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .01em; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.posted, .badge.approved { background: rgba(52,211,153,.14); color: var(--good); }
.badge.failed, .badge.suspended, .badge.error { background: rgba(251,113,133,.14); color: var(--bad); }
.badge.active, .badge.queued, .badge.uploading, .badge.encoding, .badge.downloading,
.badge.shortening, .badge.broadcasting { background: var(--primary-soft); color: var(--primary); }
.badge.paused, .badge.draft, .badge.skipped { background: rgba(148,162,194,.14); color: var(--muted); }
.badge.completed, .badge.pending { background: rgba(251,191,36,.14); color: var(--warn); }

.pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); }
.pill .dot2 { width: 8px; height: 8px; border-radius: 50%; }
.pill.ok .dot2 { background: var(--good); box-shadow: 0 0 8px var(--good); }
.pill.warn .dot2 { background: var(--warn); box-shadow: 0 0 8px var(--warn); }

/* ---------------- Misc ---------------- */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.right { text-align: right; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 18px; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.grow { flex: 1; }
.actions-cell { display: inline-flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.infobox { background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 24%, transparent); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); margin: 6px 0; }
.infobox.warn { background: rgba(251,191,36,.09); border-color: rgba(251,191,36,.32); }

.hint { font-size: 12.5px; margin-top: 7px; min-height: 16px; }
.hint.ok { color: var(--good); } .hint.bad { color: var(--bad); } .hint.busy { color: var(--muted); }
.field-row { display: flex; gap: 8px; align-items: stretch; }
.field-row input, .field-row select { flex: 1; }

.bar { height: 7px; border-radius: 6px; background: var(--surface); overflow: hidden; border: 1px solid var(--border-soft); }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--good)); transition: width .4s ease; }

.copy { cursor: pointer; border: 0; background: none; color: var(--primary); font-size: 12.5px; display: inline-flex; align-items: center; gap: 4px; }
.copy:hover { color: var(--primary-2); }

/* search box */
.search { position: relative; }
.search input { padding-left: 34px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); }

/* empty state */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; opacity: .7; }

/* spinner */
.spin { display:inline-block; width:13px; height:13px; border:2px solid var(--border); border-top-color: var(--primary); border-radius:50%; animation: sp .7s linear infinite; vertical-align:-2px; }
@keyframes sp { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--card) 25%, var(--elevated) 50%, var(--card) 75%); background-size: 200% 100%; animation: sk 1.3s infinite; border-radius: 8px; height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------------- Menus / dropdown ---------------- */
.menu-pop {
  position: absolute; left: 0; bottom: 56px; min-width: 210px; z-index: 40;
  background: var(--elevated); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 8px; display: none;
}
.menu-pop.open { display: block; }
.menu-item { padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 14px; display: flex; gap: 9px; align-items: center; color: var(--text); }
.menu-item:hover { background: var(--card-2); }
.menu-sep { height: 1px; background: var(--border-soft); margin: 6px 4px; }
.avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; font-weight: 700; font-size: 14px; flex: none; }

/* theme toggle button */
.theme-btn { background: var(--card); border: 1px solid var(--border); color: var(--text); width: 38px; height: 38px; border-radius: 11px; cursor: pointer; font-size: 16px; display: grid; place-items: center; }
.theme-btn:hover { border-color: var(--primary); }

/* ---------------- Tabs (kept for compatibility, unused when sidebar drives) ---------------- */
.navtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.navtab { padding: 10px 16px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.navtab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabpane { display: none; }
.tabpane.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------- Modal ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(4,7,15,.62); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 80; padding: 16px; animation: fade .18s ease; }
.modal { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { margin: 0; font-size: 18px; color: var(--text); text-transform: none; letter-spacing: -.01em; }

/* ---------------- Toast ---------------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px); background: var(--elevated); border: 1px solid var(--border); color: var(--text); padding: 13px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 100; opacity: 0; transition: all .22s ease; max-width: 90vw; font-size: 14px; font-weight: 500; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--bad); }
.toast.ok { border-color: var(--good); }

/* ---------------- Auth ---------------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } .auth-side { display: none !important; } }
.auth-side {
  position: relative; display: flex; flex-direction: column; justify-content: center; padding: 56px;
  background:
    radial-gradient(700px 500px at 20% 10%, rgba(109,108,255,.35), transparent 60%),
    radial-gradient(600px 500px at 90% 90%, rgba(154,107,255,.28), transparent 60%),
    var(--surface);
  border-right: 1px solid var(--border-soft);
}
.auth-side h1 { font-size: 34px; margin: 0 0 12px; }
.auth-side p { color: var(--muted); font-size: 16px; max-width: 400px; line-height: 1.5; }
.auth-feats { margin-top: 26px; display: flex; flex-direction: column; gap: 12px; }
.auth-feat { display: flex; align-items: center; gap: 11px; font-size: 14px; color: var(--text); }
.auth-feat .fic { width: 30px; height: 30px; border-radius: 9px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.auth-feat svg { width: 17px; height: 17px; }
.auth-main { display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; }
.brand-row { display: flex; align-items: center; gap: 10px; justify-content: center; font-weight: 800; font-size: 19px; margin-bottom: 20px; }
.brand-row .logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 6px 18px var(--ring); }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); padding: 4px; border-radius: 12px; margin-bottom: 8px; }
.tab { flex: 1; text-align: center; padding: 9px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; transition: all .15s; }
.tab.active { background: var(--elevated); color: var(--text); box-shadow: var(--shadow-sm); }

/* utility text sizes */
.t-sm { font-size: 12.5px; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface); padding: 1px 5px; border-radius: 5px; border: 1px solid var(--border-soft); }
