/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --hover: #f1f3f6;
  --text: #16191f;
  --text-2: #3d4452;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-text: #ffffff;
  --ok-bg: #ecfdf3; --ok-text: #067647;
  --warn-bg: #fffaeb; --warn-text: #b54708;
  --err-bg: #fef3f2; --err-text: #b42318;
  --info-bg: #eff4ff; --info-text: #3538cd;
  --chip-bg: #f2f4f7; --chip-text: #344054;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18), 0 4px 8px -4px rgba(16, 24, 40, .06);
  --radius: 10px;
  --radius-sm: 7px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1115; --surface: #171a21; --surface-2: #1c2029; --hover: #222733;
    --text: #eceef2; --text-2: #c5cad3; --muted: #9098a6; --border: #262b36; --border-strong: #353c4a;
    --accent: #818cf8; --accent-hover: #a5b4fc; --accent-soft: #232848; --accent-text: #0f1115;
    --ok-bg: #0f2a1d; --ok-text: #75e0a7;
    --warn-bg: #2d2210; --warn-text: #fdb022;
    --err-bg: #2f1414; --err-text: #fda29b;
    --info-bg: #1b2140; --info-text: #a4bcfd;
    --chip-bg: #232834; --chip-text: #d0d5dd;
    --shadow-sm: none;
    --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6);
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 16px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--chip-bg); padding: 1px 5px; border-radius: 5px; }
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8;
        stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.icon.lg { width: 20px; height: 20px; }
.icon.xl { width: 40px; height: 40px; stroke-width: 1.4; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 28px; padding: 0 24px; height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 680; font-size: 15.5px; color: var(--text); letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
}
.brand-mark .icon { stroke: #fff; width: 17px; height: 17px; stroke-width: 2.2; }
.brand .tag { font-weight: 500; font-size: 12px; color: var(--muted); padding: 1px 8px; border: 1px solid var(--border); border-radius: 999px; margin-left: 0; }
header.top nav { display: flex; gap: 4px; flex: 1; align-self: stretch; }
header.top nav a {
  display: flex; align-items: center; gap: 7px; padding: 0 12px; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent;
}
header.top nav a:hover { color: var(--text); text-decoration: none; }
header.top nav a.active { color: var(--text); border-bottom-color: var(--accent); }
.account { display: flex; align-items: center; gap: 10px; color: var(--text-2); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 12.5px;
  background: var(--accent-soft); color: var(--accent); flex: none;
}

main { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; }
main.wide { max-width: none; padding: 0; }

/* ---------- cards, stats ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm); overflow-x: auto;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; word-break: break-word; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

/* ---------- badges, chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 20px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.completed { background: var(--ok-bg); color: var(--ok-text); }
.badge.processing, .badge.queued { background: var(--info-bg); color: var(--info-text); }
.badge.processing::before { animation: pulse 1.2s ease-in-out infinite; }
.badge.failed { background: var(--err-bg); color: var(--err-text); }
.badge.inactive { background: var(--warn-bg); color: var(--warn-text); }
@keyframes pulse { 50% { opacity: .25; } }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--chip-bg); color: var(--chip-text); font-size: 12px; margin-right: 4px; }
.tag { display: inline-block; padding: 0 6px; border-radius: 5px; border: 1px solid var(--border); color: var(--muted); font-size: 11px; margin-left: 6px; vertical-align: 1px; font-weight: 500; }

/* ---------- flashes ---------- */
.flash { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }
.flash.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner { padding: 10px 24px; background: var(--err-bg); color: var(--err-text); border-bottom: 1px solid var(--border); }

/* ---------- forms ---------- */
form.stack { display: grid; gap: 14px; }
form.cols { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 7px 11px; width: 100%; min-height: 38px; box-shadow: var(--shadow-sm);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; padding: 0; accent-color: var(--accent); box-shadow: none; cursor: pointer; margin: 0; }
select { width: auto; cursor: pointer; }
select.compact { padding: 3px 6px; font-size: 12.5px; max-width: 180px; min-height: 0; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-weight: 550; cursor: pointer; border-radius: var(--radius-sm); padding: 7px 14px; min-height: 38px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap; box-shadow: var(--shadow-sm);
}
button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
button.secondary:hover, .btn.secondary:hover { background: var(--hover); }
button.danger, .btn.danger { background: var(--err-text); border-color: var(--err-text); color: #fff; }
button.danger:hover { filter: brightness(.92); background: var(--err-text); }
button.ghost-danger { background: var(--surface); color: var(--err-text); border-color: var(--border-strong); }
button.ghost-danger:hover { background: var(--err-bg); border-color: var(--border-strong); }
button.link { background: none; border: none; color: var(--muted); padding: 0; font-weight: 500; min-height: 0; box-shadow: none; }
button.link:hover { color: var(--text); background: none; }
button.link.accent { color: var(--accent); }
button.link.danger-text { color: var(--err-text); }
button.sm, .btn.sm { padding: 3px 10px; min-height: 30px; font-size: 13px; }
.icon-btn { background: none; border: 1px solid transparent; color: var(--muted); padding: 5px; min-height: 0; box-shadow: none; border-radius: 6px; }
.icon-btn:hover { background: var(--hover); color: var(--text); border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }

/* ---------- misc ---------- */
.keybox {
  font-family: ui-monospace, monospace; background: var(--surface-2); border: 1px dashed var(--accent);
  padding: 12px; border-radius: var(--radius-sm); word-break: break-all; margin: 8px 0;
}
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; margin: 8px 0 14px; font-size: 12.5px; line-height: 1.6; }
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.dl a { margin-right: 8px; }
.card.blocked { border-color: var(--err-text); background: var(--err-bg); }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 14px; }
.steps li::marker { color: var(--muted); font-weight: 600; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.login { width: 100%; max-width: 400px; padding: 32px; }
.login h1 { font-size: 20px; margin-bottom: 6px; }
.login p { margin: 0 0 20px; }
.login button { width: 100%; }

/* ---------- portal app shell ---------- */
.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - 60px); }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; }
.side-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; min-width: 0;
}
.side-item:hover { background: var(--hover); text-decoration: none; }
.side-item.active { background: var(--accent-soft); color: var(--accent); }
.side-item .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-item.active .count { color: var(--accent); }
.side-heading { display: flex; align-items: center; justify-content: space-between; padding: 18px 4px 6px 10px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.side-empty { padding: 4px 10px; color: var(--muted); font-size: 12.5px; margin: 0; }
.side-groups { display: flex; flex-direction: column; gap: 2px; }
.content { padding: 24px 28px 64px; min-width: 0; }
.content > .flash:first-child { margin-top: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 2px 0 6px; display: flex; align-items: center; gap: 10px; }
.page-head h1 .icon { color: var(--muted); }
.crumb { font-size: 12.5px; color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; display: flex; gap: 6px 16px; flex-wrap: wrap; }
.meta strong { color: var(--text-2); font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search .icon { position: absolute; left: 11px; top: 11px; color: var(--muted); }
.search input { padding-left: 34px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel .table-wrap { overflow-x: auto; }
.panel table { border-radius: var(--radius); }
.files td { padding: 10px 12px; }
.files th.cb, .files td.cb { width: 40px; padding-right: 0; padding-left: 16px; }
.files th:last-child, .files td:last-child { padding-right: 16px; }
.files tr.selected td { background: var(--accent-soft); }
.file-name { display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 440px; }
.file-icon { width: 32px; height: 32px; border-radius: 8px; background: var(--chip-bg); color: var(--muted); display: grid; place-items: center; flex: none; }
.file-name .name { font-weight: 550; color: var(--text); }
.file-name .err { color: var(--err-text); font-size: 12px; white-space: normal; }
.group-link { color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; max-width: 200px; }
.group-link:hover { color: var(--accent); }

.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 9px 16px;
  background: var(--accent-soft); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0;
}
.bulkbar strong { font-weight: 600; }
.bulkbar select, .bulkbar input { min-height: 32px; padding: 3px 10px; }
.bulkbar input[type=text] { width: 190px; }
.bulkbar .spacer { flex: 1; }

.menu { position: relative; display: inline-block; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  display: grid; gap: 1px;
}
.menu-list a, .menu-list button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border-radius: 6px; border: none; min-height: 0;
  background: none; color: var(--text-2); font-weight: 450; font-size: 13.5px; box-shadow: none; justify-content: flex-start;
}
.menu-list a:hover, .menu-list button:hover { background: var(--hover); text-decoration: none; color: var(--text); }
.menu-list .danger-item { color: var(--err-text); }
.menu-label { padding: 6px 10px 2px; font-size: 11.5px; color: var(--muted); font-weight: 600; }

.empty { text-align: center; padding: 56px 24px; color: var(--muted); }
.empty .icon { color: var(--border-strong); margin-bottom: 6px; }
.empty h3 { color: var(--text); font-size: 15px; margin: 4px 0 4px; }
.empty p { margin: 0 0 16px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(540px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(15, 17, 21, .45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-body { padding: 16px 20px 20px; display: grid; gap: 14px; }
.dlg-body p { margin: 0; color: var(--text-2); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }

.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 26px 16px; text-align: center;
  cursor: pointer; display: grid; gap: 4px; justify-items: center; color: var(--muted); font-weight: 400; transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--text-2); }
.dropzone .icon { color: var(--accent); }
.dropzone strong { color: var(--accent); font-weight: 600; }
.dropzone input { display: none; }
.upload-list { display: grid; gap: 10px; max-height: 220px; overflow-y: auto; }
.upload-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 13px; }
.upload-item .progress { grid-column: 1 / -1; }
.upload-item .state { color: var(--muted); font-size: 12px; }
.upload-item.done .state { color: var(--ok-text); }
.upload-item.error .state { color: var(--err-text); }
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 500; }
details.more[open] summary { margin-bottom: 12px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); padding: 10px 16px; gap: 6px; align-items: center; }
  .side-heading, .side-empty { display: none; }
  .side-groups { flex-direction: row; gap: 6px; }
  .side-item { white-space: nowrap; border: 1px solid var(--border); flex: none; }
  .content { padding: 18px 16px 48px; }
}
@media (max-width: 640px) {
  header.top { padding: 0 16px; gap: 10px; }
  header.top nav a span, .account .who, .brand .tag, .brand .brand-name { display: none; }
  main { padding: 20px 16px 48px; }
  .options-grid { grid-template-columns: 1fr; }
  .search { max-width: none; }
}
