:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #5d6573;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --accent-soft: #e8edff;
  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --warn: #a86400;
  --warn-soft: #fff3dc;
  --bad: #c62f2f;
  --bad-soft: #fde8e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #e8eaee;
    --muted: #9aa2b1;
    --accent: #7b93ff;
    --accent-ink: #0f1115;
    --accent-soft: #232b4a;
    --ok: #4cc283;
    --ok-soft: #173326;
    --warn: #f0b04b;
    --warn-soft: #3a2c12;
    --bad: #ff7a7a;
    --bad-soft: #3d1c1c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 26px; letter-spacing: -.01em; }
h2 { font-size: 16px; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
[hidden] { display: none !important; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800;
}
.brand .sub { color: var(--muted); font-weight: 500; }
.tag {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn); letter-spacing: .03em; text-transform: uppercase;
}

/* controls */
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: .55; cursor: not-allowed; }
input[type=text], input[type=email], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.check { display: inline-flex; align-items: center; gap: 7px; margin-right: 14px; cursor: pointer; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card > h2 + p { margin-top: -2px; }

/* notices */
.notice { border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 13.5px; }
.notice.error { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--text); }

/* tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; max-height: 460px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; z-index: 1; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.SUCCESS, .pill.VALIDATED, .pill.ACTIVE, .pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.FAILED, .pill.error { background: var(--bad-soft); color: var(--bad); }
.pill.SKIPPED, .pill.PAUSED, .pill.running { background: var(--warn-soft); color: var(--warn); }
.pill.admin, .pill.superadmin { background: var(--accent-soft); color: var(--accent); }

/* login page */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; text-align: center; padding: 32px 28px; }
.login-card .brand { justify-content: center; margin-bottom: 22px; }
.login-card h1 { margin-bottom: 6px; }
.login-card .gbtn { display: flex; justify-content: center; margin: 22px 0 8px; min-height: 44px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 18px 0 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2); object-fit: cover; }
.avatar.sm { width: 28px; height: 28px; }
.foot { margin-top: 18px; font-size: 12px; color: var(--muted); }

/* dashboard */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 24px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.topbar select { width: auto; min-width: 230px; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--text); }
.user-chip .who { line-height: 1.2; }
.tabs { display: flex; gap: 4px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 12px 12px;
  color: var(--muted); white-space: nowrap;
}
.tabs button[aria-selected=true] { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 1180px; margin: 0 auto; padding: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid-2 > .card + .card { margin-top: 0; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; padding: 3px; background: var(--surface-2); }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 7px; color: var(--muted); }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop.over, .drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { color: var(--text); }

.progress { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 14px 0; }
.stat { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat.ok .v { color: var(--ok); }
.stat.bad .v { color: var(--bad); }
.stat.warn .v { color: var(--warn); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* profile menu + chip menu */
.menu-wrap { position: relative; }
button.user-chip { border-color: transparent; background: transparent; padding: 4px 8px; text-align: left; font-weight: 400; }
button.user-chip:hover, button.user-chip[aria-expanded=true] { background: var(--surface-2); border-color: var(--border); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .14);
}
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu button { display: flex; width: 100%; border: 0; background: none; padding: 8px 10px; font-weight: 500; border-radius: 6px; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu button[aria-checked=true] { color: var(--accent); font-weight: 600; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.chip-menu { position: fixed; right: auto; top: auto; }

/* filter chips */
.filter-row { margin-top: 12px; gap: 14px; }
.chipbox {
  flex: 1; min-width: 260px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; background: var(--surface);
}
.chipbox:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.chipbox input { border: 0; outline: none; padding: 4px 2px; flex: 1; min-width: 180px; width: auto; background: transparent; }
.chipbox input:focus { outline: none; }
#chips { display: contents; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; border-radius: 6px; font-size: 12.5px;
  background: var(--accent-soft); color: var(--text); border: 1px solid transparent; padding: 0;
}
.chip.not { background: var(--bad-soft); }
.chip .label { border: 0; background: none; padding: 3px 4px 3px 8px; font-weight: 500; font-size: 12.5px; border-radius: 6px 0 0 6px; }
.chip .label b { font-weight: 700; }
.chip .x { border: 0; background: none; padding: 3px 7px 3px 3px; font-size: 14px; line-height: 1; color: var(--muted); border-radius: 0 6px 6px 0; }
.chip .x:hover { color: var(--bad); }
button.tiny { padding: 3px 8px; font-size: 12px; }

/* upload */
.uploads { gap: 14px; }
.drop-title { font-weight: 600; margin-bottom: 6px; }
.uploads .drop { padding: 22px 16px; }
.uploads .drop.has-file { border-style: solid; border-color: var(--ok); background: var(--ok-soft); color: var(--text); }
#cfile-summary { margin-top: 6px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: 13.5px; z-index: 100; max-width: calc(100% - 32px);
}

@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .topbar, .tabs { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px; }
  .topbar select { min-width: 0; width: 100%; }
}
