:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #dde1e7;
  --text: #16191f;
  --muted: #5d6573;
  --accent: #1f5fd6;
  --accent-text: #ffffff;
  --danger: #c4321f;
  --danger-text: #ffffff;
  --ok: #17803d;
  --warn: #9a6200;
  --warn-bg: #fff6e0;
  --error-bg: #fdecea;
  --mark: #fde68a;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #22262e;
    --border: #2f343d;
    --text: #e7e9ee;
    --muted: #9aa2b1;
    --accent: #5b8ef0;
    --accent-text: #0b0d11;
    --danger: #e5604c;
    --danger-text: #0b0d11;
    --ok: #4cc27a;
    --warn: #f0b94a;
    --warn-bg: #2d2412;
    --error-bg: #3a1c18;
    --mark: #6b5513;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono, code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-all; }
[hidden] { display: none !important; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-text); }
.btn-danger:hover:not(:disabled) { background: var(--danger); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }

.alert { padding: 10px 12px; border-radius: var(--radius); margin: 12px 0; }
.alert-error { background: var(--error-bg); color: var(--danger); }

.chip {
  display: inline-block; padding: 2px 8px; margin-left: 8px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-weight: 400;
}

/* login */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; padding: 32px 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  text-align: center;
}
.login-card .btn { margin-top: 16px; height: 42px; }

/* layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; font-weight: 600; min-width: 0; white-space: nowrap; }
.brand-divider { width: 1px; height: 20px; margin: 0 12px; background: var(--border); }

/* logo */
.logo { display: block; }
.logo img { display: block; width: 100%; height: auto; }
.logo-sm { width: 76px; }
.logo-lg { width: 150px; margin: 0 auto 20px; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who form { margin: 0; }
.page { max-width: 960px; margin: 0 auto; padding: 24px 24px 120px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.section-head p { margin: 0; max-width: 60ch; }

/* batches */
.batches { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.batch.has-warning { border-color: var(--warn); }
.batch-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-width: 0; }
.batch-index { color: var(--muted); font-weight: 600; }
.batch-file { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.batch-head .remove, .batch-head .badge { margin-left: auto; }

.fields { display: grid; grid-template-columns: repeat(3, auto) 1fr; gap: 12px 20px; align-items: end; }
.field { border: 0; margin: 0; padding: 0; min-width: 0; }
.field legend, .field .legend { display: block; padding: 0; margin-bottom: 4px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.req { color: var(--danger); }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: block; padding: 6px 12px; font-size: 13px; border-left: 1px solid var(--border); white-space: nowrap; }
.segmented label:first-child span { border-left: 0; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* combobox */
.combobox { position: relative; }
.combobox input {
  width: 100%; height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit;
}
.combobox-list {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 260px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / .15);
}
.combobox-list li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.combobox-list li.active { background: var(--surface-2); }
.combobox-list li.custom { border-bottom: 1px solid var(--border); border-radius: 6px 6px 0 0; }
.combobox-list li.empty { cursor: default; }
.combobox-list li.error { color: var(--danger); }
mark { background: var(--mark); color: inherit; border-radius: 2px; }

/* dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  margin-top: 12px; padding: 22px 16px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--surface-2); }

/* preview */
.batch-preview { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.stat { display: flex; flex-direction: column; }
.stat strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat.warn strong { color: var(--warn); }
.warnings { margin: 0; padding: 8px 12px 8px 28px; background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); }
details summary { cursor: pointer; color: var(--muted); }
details pre { margin-top: 6px; max-height: 160px; overflow: auto; }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.code { padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius); }
table.state { border-collapse: collapse; width: 100%; font-size: 13px; }
table.state th, table.state td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); }
table.state th { color: var(--muted); font-weight: 500; font-family: var(--mono); font-size: 12px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

/* action bar */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 12px max(24px, calc((100vw - 912px) / 2));
  background: var(--surface); border-top: 1px solid var(--border);
}
.actionbar p { margin: 0 auto 0 0; }
.status-error { color: var(--danger); }
.status-ok { color: var(--ok); }

/* results */
.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); }
.badge-done { color: var(--ok); }
.badge-failed { color: var(--danger); background: var(--error-bg); }
.badge-skipped { color: var(--muted); }
.result-failed { border-color: var(--danger); }
#result-list .stats { margin-bottom: 8px; }
#result-list p { margin: 6px 0; word-break: break-all; }

/* dialog */
dialog {
  max-width: 440px; width: calc(100% - 32px); padding: 22px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@media (max-width: 720px) {
  .topbar, .page { padding-left: 16px; padding-right: 16px; }
  .who > span { display: none; }
  .brand .chip { display: none; }
  .fields { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr; }
  .actionbar { padding: 10px 16px; flex-wrap: wrap; }
  .actionbar p { flex-basis: 100%; }
  .section-head { flex-direction: column; }
}
