:root {
  --bg: #070b14;
  --bg-elevated: #0c1220;
  --panel: #111827;
  --panel-hover: #151f31;
  --line: rgba(148, 163, 184, 0.12);
  --line-strong: rgba(148, 163, 184, 0.22);
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;
  --accent: #22d3ee;
  --accent-2: #6366f1;
  --accent-glow: rgba(34, 211, 238, 0.15);
  --warn: #fbbf24;
  --danger: #f87171;
  --ok: #34d399;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
  --transition: 0.18s ease;
  --sidebar-w: 260px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font: 14px/1.55 "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  background:
    radial-gradient(ellipse 80% 50% at 0% -10%, rgba(99, 102, 241, 0.12), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(34, 211, 238, 0.08), transparent 50%),
    var(--bg);
}

/* ── Sidebar ── */
aside {
  background: rgba(8, 12, 22, 0.92);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  z-index: 30;
}

.brand-wrap { padding: 4px 10px 0; }
.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.brand span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.nav-flow {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  margin: 16px 10px 20px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition);
}

.nav-icon {
  width: 20px;
  text-align: center;
  font-size: 14px;
  opacity: 0.7;
}

nav button:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

nav button.active {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.12), rgba(99, 102, 241, 0.1));
  border-color: rgba(34, 211, 238, 0.25);
  color: var(--text);
  font-weight: 600;
}
nav button.active .nav-icon { opacity: 1; color: var(--accent); }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 10px 4px;
  font-size: 11px;
  line-height: 1.4;
  border-top: 1px solid var(--line);
}

/* ── Main ── */
main {
  padding: 24px 28px 48px;
  min-width: 0;
}

header {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.header-titles { flex: 1; min-width: 0; }
header h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.header-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 400;
}

.menu {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
}

/* ── Buttons ── */
button {
  font: inherit;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition);
}

button:not(:disabled):hover { transform: translateY(-1px); }
button:not(:disabled):active { transform: translateY(0); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

header button, .row button, td button, .tabs button, .toolbar button, .list-actions button, .sync-actions button {
  background: var(--panel);
  color: var(--text-secondary);
  border: 1px solid var(--line-strong);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

header button:hover, .row button:hover, td button:hover, .tabs button:hover,
.toolbar button:hover, .list-actions button:hover, .sync-actions button:hover {
  background: var(--panel-hover);
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.35);
}

.primary {
  background: linear-gradient(135deg, var(--accent), #38bdf8) !important;
  color: #042f2e !important;
  font-weight: 700 !important;
  border: none !important;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.primary:hover {
  box-shadow: 0 6px 24px rgba(34, 211, 238, 0.25);
}

.danger {
  color: var(--danger) !important;
  border-color: rgba(248, 113, 113, 0.35) !important;
}
.danger:hover {
  background: rgba(248, 113, 113, 0.08) !important;
}

.primary.send {
  font-size: 14px;
  padding: 10px 18px;
  white-space: nowrap;
}

.send-hero {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #042f2e;
  font-weight: 700;
  font-size: 15px;
  padding: 14px 24px !important;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(34, 211, 238, 0.2);
  margin-top: 8px;
}

.stop-btn {
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px !important;
  border: 1px solid rgba(248, 113, 113, 0.5) !important;
  background: rgba(248, 113, 113, 0.08) !important;
  color: var(--danger) !important;
}

/* ── Cards & Grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.card > span, .card .muted-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.card b {
  display: block;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 2px;
  line-height: 1.1;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
}

.card p { margin: 6px 0; font-size: 13px; color: var(--text-secondary); }

.prep {
  font-size: 14px;
  line-height: 1.75;
}
.prep div { padding: 2px 0; }

/* ── Status colors ── */
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* ── Tables ── */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.2);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr {
  transition: background var(--transition);
}
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td { border-bottom: none; }

/* ── Forms ── */
input, select, textarea {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 100%;
  font: inherit;
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(34, 211, 238, 0.5);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder { color: #64748b; }

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
  align-items: center;
}
.row input, .row select { width: auto; min-width: 140px; flex: 1; }

/* ── Pager ── */
.pager {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  padding: 4px 0;
}
.pager button {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  color: var(--text-secondary);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.pager button:disabled { opacity: 0.35; }

/* ── Progress ── */
.bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 99px;
  overflow: hidden;
  margin: 12px 0;
  border: 1px solid var(--line);
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ── Images ── */
.logo {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
}
.poster {
  width: 44px;
  height: 62px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
}

/* ── Toast ── */
#toast {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.1), rgba(99, 102, 241, 0.08));
  border: 1px solid rgba(34, 211, 238, 0.25);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.25s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.url {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  color: var(--muted);
  font-size: 12px;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  width: fit-content;
  max-width: 100%;
}

.tabs button {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--muted);
}
.tabs button:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tabs button.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line-strong);
}

/* ── Add box ── */
.add-box {
  border: 1px dashed rgba(34, 211, 238, 0.3);
  border-radius: var(--radius-lg);
  padding: 20px;
  background: rgba(34, 211, 238, 0.03);
  margin: 16px 0;
}
.add-box h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}

/* ── Pipeline & Steps ── */
.pipeline { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin: 16px 0; }
.pipe {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font-size: 13px;
  background: var(--bg-elevated);
  min-width: 200px;
}
.pipe.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pipe.done { border-color: rgba(52, 211, 153, 0.4); color: var(--ok); }
.pipe-arrow { color: var(--muted); font-size: 14px; margin-left: 18px; }

.steps { display: flex; flex-direction: column; gap: 4px; margin: 14px 0; }
.steps span {
  padding: 8px 12px;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.steps span.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.steps span.done { border-color: var(--ok); color: var(--ok); }

/* ── Notice & headings ── */
.notice {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 14px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

h2, h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 20px 0 10px;
  letter-spacing: -0.01em;
}

.algo { margin: 0; padding-left: 20px; color: var(--muted); }
.algo li { margin: 6px 0; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.toolbar select { width: auto; min-width: 140px; }
.check { width: auto; min-width: 0; accent-color: var(--accent); }

/* ── Badges ── */
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
}
.badge.ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge.warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }

.row-excluded { opacity: 0.5; }
.row-prepared td input { border-color: rgba(99, 102, 241, 0.5); }
.row-new td input[data-f="name"] { border-color: rgba(52, 211, 153, 0.5); }

.back {
  margin-bottom: 12px;
  background: transparent !important;
  border: 1px solid var(--line) !important;
  color: var(--muted) !important;
  font-size: 13px;
}
.back:hover { color: var(--text) !important; }

.hidden { display: none; }

/* ── List cards ── */
.list-card { margin-bottom: 16px; }
.list-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.list-name {
  font-size: 16px;
  font-weight: 700;
  padding: 0 !important;
  border: 0 !important;
  background: transparent !important;
  color: var(--text) !important;
  letter-spacing: -0.01em;
}
.list-name:hover { color: var(--accent) !important; }

.list-counts {
  color: var(--muted);
  font-size: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr));
  gap: 6px 20px;
  text-align: right;
}
.list-card .list-counts b {
  display: inline;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-top: 0;
}

.list-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.list-meta span {
  color: var(--muted);
  font-weight: 600;
  margin-right: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.list-actions, .sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 4px;
}

.scope-box {
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.scope-box h3 { margin: 0 0 10px; font-size: 14px; }

.sync-options {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin: 14px 0;
  padding: 14px 16px;
}
.sync-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}
.sync-options input { width: auto; min-width: 0; accent-color: var(--accent); }
.sync-opt-dup { margin-left: auto; }
.sync-progress b { display: inline; font-size: inherit; }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-xl);
  margin: 16px 0;
}

.empty-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: 50%;
  color: var(--accent);
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.empty-state p {
  margin: 0 auto;
  max-width: 360px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

.page-intro {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
  max-width: 640px;
  line-height: 1.55;
}

/* ── Scrim ── */
.scrim { display: none; }

/* ── Responsive ── */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  aside {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    z-index: 40;
    transition: transform 0.25s ease;
    width: 280px;
    box-shadow: var(--shadow-lg);
  }
  aside.open { transform: none; }
  .menu { display: inline-flex; align-items: center; justify-content: center; }
  .scrim.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: 35;
  }
  main { padding: 16px 16px 40px; }
  header h1 { font-size: 20px; }
  .primary.send { font-size: 13px; padding: 9px 14px; }
  table { min-width: 520px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .sync-opt-dup { margin-left: 0; width: 100%; }
  .tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .list-head { flex-direction: column; }
  .list-counts { text-align: left; }
}
