:root {
  --bg: #F5F3FF;
  --foreground: #1E1B4B;
  --card: #FFFFFF;
  --card-foreground: #1E1B4B;
  --muted: #EBEFF9;
  --muted-foreground: #64748B;
  --border: #E0E7FF;
  --primary: #6366F1;
  --on-primary: #FFFFFF;
  --secondary: #818CF8;
  --accent: #7C3AED;
  --destructive: #DC2626;
  --ring: #6366F1;
  --success: #059669;

  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(30, 27, 75, 0.06);
  --shadow-md: 0 4px 16px rgba(30, 27, 75, 0.08);
  --shadow-lg: 0 12px 32px rgba(30, 27, 75, 0.12);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F172A;
    --foreground: #F8FAFC;
    --card: #192134;
    --card-foreground: #F8FAFC;
    --muted: #131936;
    --muted-foreground: #94A3B8;
    --border: rgba(255, 255, 255, 0.08);
    --primary: #6366F1;
    --on-primary: #FFFFFF;
    --secondary: #818CF8;
    --accent: #A78BFA;
    --destructive: #F87171;
    --ring: #818CF8;
    --success: #34D399;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.32);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at 15% -10%, color-mix(in srgb, var(--primary) 16%, transparent) 0%, transparent 45%),
    radial-gradient(circle at 100% 0%, color-mix(in srgb, var(--accent) 12%, transparent) 0%, transparent 40%),
    var(--bg);
  color: var(--foreground);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.icon { width: 1em; height: 1em; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------- Layout shell ---------- */
.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

@media (min-width: 768px) {
  .app { padding: 48px 32px 80px; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand-mark .icon { width: 20px; height: 20px; }

.brand-text h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.brand-text p { font-size: 13px; color: var(--muted-foreground); margin: 2px 0 0; }

.stats { display: flex; gap: 20px; font-size: 13px; color: var(--muted-foreground); }
.stats strong { color: var(--foreground); font-family: var(--font-mono); font-weight: 600; }

.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted-foreground);
  padding: 7px 12px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  transition: border-color 180ms var(--ease-out), color 180ms var(--ease-out), background 180ms var(--ease-out);
}
.icon-btn:hover { color: var(--foreground); border-color: var(--muted-foreground); background: var(--muted); }
.icon-btn .icon { width: 15px; height: 15px; }

/* ---------- Gate ---------- */
.gate {
  min-height: 70dvh;
  display: flex; align-items: center; justify-content: center;
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  text-align: center;
  animation: rise 420ms var(--ease-out);
}
.gate-icon {
  width: 52px; height: 52px; margin: 0 auto 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.gate-icon .icon { width: 24px; height: 24px; }
.gate-card h2 { font-size: 18px; margin: 0 0 6px; }
.gate-card p { font-size: 13.5px; color: var(--muted-foreground); margin: 0 0 22px; line-height: 1.5; }

.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--muted-foreground); }
.field input {
  width: 100%; font-size: 14px; padding: 10px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--foreground);
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.field input:focus { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 20%, transparent); outline: none; }
.field-error { font-size: 12.5px; color: var(--destructive); margin-top: 6px; min-height: 16px; }

.btn {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--primary); color: var(--on-primary);
  border: none; border-radius: var(--radius-sm);
  padding: 11px 16px; font-size: 14px; font-weight: 600;
  transition: transform 120ms var(--ease-out), box-shadow 180ms var(--ease-out), opacity 150ms var(--ease-out);
  box-shadow: var(--shadow-sm);
}
.btn:hover { box-shadow: var(--shadow-md); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; pointer-events: none; }
.btn .icon { width: 16px; height: 16px; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  animation: spin 700ms linear infinite;
}

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: border-color 180ms var(--ease-out), background 180ms var(--ease-out), transform 180ms var(--ease-out);
  margin-bottom: 20px;
}
.dropzone:hover { border-color: var(--secondary); }
.dropzone.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--card)); transform: scale(1.005); }
.dropzone-icon {
  width: 46px; height: 46px; margin: 0 auto 14px;
  border-radius: var(--radius-md);
  background: var(--muted);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
}
.dropzone-icon .icon { width: 22px; height: 22px; }
.dropzone strong { color: var(--foreground); font-weight: 600; }
.dropzone .hint { font-size: 12.5px; margin-top: 6px; color: var(--muted-foreground); }
.dropzone input[type="file"] { display: none; }

/* ---------- Upload queue ---------- */
.queue { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.queue-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  animation: rise 280ms var(--ease-out);
}
.queue-item .name { flex: 1; min-width: 0; font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-item .pct { font-family: var(--font-mono); font-size: 12px; color: var(--muted-foreground); width: 38px; text-align: right; }
.progress-track { flex: 1.4; height: 5px; border-radius: 4px; background: var(--muted); overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 4px; transition: width 150ms var(--ease-out); }
.queue-item.error .name { color: var(--destructive); }
.queue-item .status-icon { width: 16px; height: 16px; color: var(--success); flex-shrink: 0; }
.queue-item .status-icon.err { color: var(--destructive); }

/* ---------- Section header ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 14px; }
.section-head h2 { font-size: 14px; font-weight: 700; margin: 0; color: var(--muted-foreground); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- File grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 180ms var(--ease-out), box-shadow 180ms var(--ease-out), border-color 180ms var(--ease-out);
  animation: rise 320ms var(--ease-out);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--secondary); }

.thumb {
  aspect-ratio: 4 / 3;
  background: var(--muted);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  color: var(--muted-foreground);
  overflow: hidden;
}
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .icon { width: 28px; height: 28px; }
.type-badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(15, 23, 42, 0.65);
  color: #fff;
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 10.5px; font-weight: 600;
  display: flex; align-items: center; gap: 4px;
  backdrop-filter: blur(4px);
}
.type-badge .icon { width: 11px; height: 11px; }

.card-body { padding: 10px 12px 12px; }
.card-name {
  font-size: 12.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 3px;
}
.card-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted-foreground); margin-bottom: 10px; }
.card-actions { display: flex; gap: 6px; }
.chip-btn {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  background: var(--muted); color: var(--foreground);
  border: none; border-radius: 7px;
  padding: 7px 8px; font-size: 12px; font-weight: 600;
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out);
}
.chip-btn:hover { background: var(--primary); color: var(--on-primary); }
.chip-btn.copied { background: var(--success); color: #fff; }
.chip-btn .icon { width: 13px; height: 13px; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted-foreground);
}
.empty .icon { width: 34px; height: 34px; margin-bottom: 12px; opacity: 0.6; }
.empty p { font-size: 13.5px; margin: 0; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--card); color: var(--foreground);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  animation: toast-in 220ms var(--ease-out);
}
.toast .icon { width: 15px; height: 15px; color: var(--success); }
.toast.error .icon { color: var(--destructive); }

/* ---------- Animations ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

[hidden] { display: none !important; }

/* ---------- Shell (post-login) ---------- */
.shell { display: flex; min-height: 100dvh; }

.sidebar {
  width: 216px; flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh;
}
.sidebar .brand { padding: 0 6px 22px; }

.tabs { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.tab-btn {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: none; text-align: left;
  color: var(--muted-foreground);
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500;
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out);
}
.tab-btn .icon { width: 17px; height: 17px; }
.tab-btn:hover { background: var(--muted); color: var(--foreground); }
.tab-btn.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }

.content { flex: 1; min-width: 0; padding: 24px 28px 64px; }
@media (min-width: 768px) { .content { padding: 36px 40px 80px; } }

.content-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.content-header h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.content-header .stats { margin-left: auto; }

.select {
  font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 30px 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card); color: var(--foreground);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 14px;
}

@media (max-width: 767px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 12px 16px; overflow-x: auto; }
  .sidebar .brand { padding: 0 12px 0 0; flex-shrink: 0; }
  .tabs { flex-direction: row; flex: none; }
  .tab-btn span.label { display: none; }
  .sidebar-foot { border: none; margin: 0 0 0 8px; padding: 0; }
}

/* ---------- Panels ---------- */
.panel { animation: rise 260ms var(--ease-out); }

.panel-toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.panel-toolbar input[type="text"] {
  flex: 1; min-width: 180px;
  font-size: 13px; padding: 9px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--card); color: var(--foreground);
}

.placeholder-panel {
  border: 1px dashed var(--border); border-radius: var(--radius-lg);
  padding: 56px 20px; text-align: center; color: var(--muted-foreground);
}
.placeholder-panel .icon { width: 30px; height: 30px; margin-bottom: 10px; opacity: 0.6; }
.placeholder-panel strong { display: block; color: var(--foreground); font-size: 14px; margin-bottom: 4px; }
.placeholder-panel p { font-size: 13px; margin: 0; }

/* ---------- Data table ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted-foreground); font-weight: 700;
  padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--muted);
}
.dtable td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.dtable tr:last-child td { border-bottom: none; }
.dtable tr:hover td { background: color-mix(in srgb, var(--primary) 4%, transparent); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
}
.badge.on { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.off { background: color-mix(in srgb, var(--muted-foreground) 16%, transparent); color: var(--muted-foreground); }

.account-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--muted); border-radius: 999px;
  padding: 3px 9px 3px 9px; font-size: 11.5px; font-family: var(--font-mono);
  margin: 2px 4px 2px 0;
}
.account-chip button { background: none; border: none; color: var(--muted-foreground); padding: 0; display: flex; }
.account-chip button:hover { color: var(--destructive); }
.account-chip .icon { width: 11px; height: 11px; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.text-btn {
  background: none; border: none; color: var(--muted-foreground);
  font-size: 12.5px; font-weight: 600; padding: 4px 6px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 4px;
}
.text-btn:hover { color: var(--primary); background: var(--muted); }
.text-btn.danger:hover { color: var(--destructive); }
.text-btn .icon { width: 13px; height: 13px; }

/* ---------- Inline add form ---------- */
.add-form {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px; margin-bottom: 16px;
}
.add-form .field { margin: 0; flex: 1; min-width: 160px; }
.add-form .btn { width: auto; padding: 10px 16px; }

.mini-form { display: flex; gap: 6px; margin-top: 8px; }
.mini-form input { flex: 1; font-size: 12.5px; padding: 6px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); color: var(--foreground); }
.mini-form .btn { width: auto; padding: 6px 12px; font-size: 12px; }

/* ---------- KPI score cards ---------- */
.score-badge {
  position: absolute; top: 8px; right: 8px;
  min-width: 40px; text-align: center;
  border-radius: 8px; padding: 4px 8px;
  font-family: var(--font-mono); font-size: 13px; font-weight: 700;
  backdrop-filter: blur(4px);
  box-shadow: var(--shadow-sm);
}
.score-badge.good { background: color-mix(in srgb, var(--success) 88%, transparent); color: #fff; }
.score-badge.mid { background: rgba(217, 119, 6, 0.88); color: #fff; }
.score-badge.low { background: color-mix(in srgb, var(--destructive) 88%, transparent); color: #fff; }
.score-badge.none { background: rgba(100, 116, 139, 0.75); color: #fff; }

.kpi-meta { font-size: 11px; color: var(--muted-foreground); margin-bottom: 8px; }
.kpi-meta strong { color: var(--foreground); font-weight: 600; }

.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.stat-tile { background: var(--muted); border-radius: 7px; padding: 6px 8px; }
.stat-tile .label { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted-foreground); }
.stat-tile .value { font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; }
