:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2f5fd0;
  --accent-soft: #e8effc;
  --good: #0f8a5f;
  --warn: #b4690e;
  --bad: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* The drawer and the progress bar carry display rules of their own, which
   would otherwise beat the browser default for [hidden]. */
[hidden] { display: none !important; }

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

h1, h2, h3 { margin: 0; font-weight: 640; letter-spacing: -.01em; }
p { margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 17px; }
.brand-sub { color: var(--muted); font-size: 12.5px; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.queue-badge {
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 5px 10px; border-radius: 999px;
}

main { max-width: 1400px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-size: 13.5px; font-weight: 550;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: #cbd5e1; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2850b4; border-color: #2850b4; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon {
  border: 0; background: transparent; font-size: 24px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 6px;
}
.input {
  width: 100%; padding: 8px 11px; font: inherit; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: var(--text);
}
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); cursor: pointer; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat-value { font-size: 24px; font-weight: 660; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.stat.is-warn .stat-value { color: var(--warn); }
.stat.is-bad .stat-value { color: var(--bad); }

/* ---------- panels ---------- */
/* Shown while no API key is configured — without one nothing can be analysed,
   so this needs to be impossible to miss rather than a line in a dialog. */
.setup-notice {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 18px; border-radius: var(--radius);
  border: 1px solid var(--warn); background: #fdf6e9; color: #6b4708;
}
.setup-notice-text { flex: 1 1 320px; display: flex; flex-direction: column; gap: 3px; }
.setup-notice-text span { font-size: 13px; }
.setup-notice .btn { flex: 0 0 auto; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 15px; }
.panel-head p { color: var(--muted); font-size: 13px; margin-top: 3px; }
.panel-head.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.panel-tools { display: flex; align-items: center; gap: 10px; }
.panel-tools .input { width: 200px; }

/* ---------- dropzone ---------- */
.dropzone {
  margin: 20px; padding: 32px; border: 2px dashed #cbd5e1; border-radius: var(--radius);
  background: var(--surface-2); text-align: center; transition: border-color .15s, background .15s;
  cursor: pointer;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { width: 34px; height: 34px; color: var(--accent); }
.dz-title { font-weight: 600; margin-top: 8px; }
.dz-hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.dz-buttons { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }

.upload-log {
  margin: 0 20px 16px; max-height: 190px; overflow: auto;
  border: 1px solid var(--border); border-radius: 10px; font-size: 13px;
}
.upload-log div { padding: 6px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; }
.upload-log div:last-child { border-bottom: 0; }
.upload-log .tag { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.upload-log .queued .tag { color: var(--good); }
.upload-log .duplicate .tag, .upload-log .retry .tag { color: var(--warn); }
.upload-log .rejected .tag, .upload-log .failed .tag { color: var(--bad); }

.progress { margin: 0 20px 20px; }
.progress-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.progress p { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 620; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); text-align: center; padding: 28px; }

.matrix th.year { text-align: center; }
.matrix th.company, .matrix td.company { position: sticky; left: 0; background: var(--surface); z-index: 2; min-width: 210px; }
.matrix th.company { background: var(--surface-2); }
.matrix td.cell { cursor: pointer; min-width: 150px; border-left: 1px solid var(--border); }
.matrix td.cell:hover { background: var(--accent-soft); }
.matrix td.cell.is-empty { cursor: default; color: var(--muted); text-align: center; }
.matrix td.cell.is-empty:hover { background: transparent; }
.cell-figure { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.cell-figure b { font-weight: 600; }
.cell-figure .k { color: var(--muted); font-size: 11.5px; }
.cell-meta { margin-top: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.company-name { font-weight: 600; }
.company-sub { color: var(--muted); font-size: 12px; }

.chip {
  font-size: 10.5px; font-weight: 640; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.chip.good { background: #e7f6ef; color: var(--good); border-color: #bfe6d4; }
.chip.warn { background: #fdf1de; color: var(--warn); border-color: #f3ddb6; }
.chip.bad  { background: #fdecea; color: var(--bad);  border-color: #f5cdc7; }
.chip.info { background: var(--accent-soft); color: var(--accent); border-color: #c9dcfa; }

.files tbody td:last-child { white-space: nowrap; text-align: right; }
.files tbody td:last-child .btn + .btn { margin-left: 6px; }
.neg { color: var(--bad); }

.name-cell { display: flex; flex-direction: column; gap: 2px; }
.path { color: var(--muted); font-size: 11.5px; word-break: break-all; }

/* ---------- drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%);
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 40; display: flex; flex-direction: column;
  box-shadow: -12px 0 40px rgba(15, 23, 42, .12);
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 15px; }
.drawer-body { padding: 20px; overflow-y: auto; display: grid; gap: 16px; }

.doc-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface-2); }
.doc-card h3 { font-size: 13.5px; word-break: break-all; }
.doc-card .doc-meta { display: flex; gap: 6px; flex-wrap: wrap; margin: 7px 0; }
.doc-card p { font-size: 13px; color: #334155; }
.doc-card .figures { display: flex; gap: 18px; margin-top: 8px; font-variant-numeric: tabular-nums; font-size: 13px; }
.note { background: #fdf8ec; border: 1px solid #f0e0bd; color: #6b4d0f; padding: 10px 12px; border-radius: 9px; font-size: 13px; }
.summary-text { white-space: pre-wrap; font-size: 13px; color: #334155; }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; }
.field .hint { color: var(--muted); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-status { font-size: 13px; min-height: 18px; }
.form-status.ok { color: var(--good); }
.form-status.err { color: var(--bad); }
.danger summary { cursor: pointer; color: var(--bad); font-weight: 600; font-size: 13.5px; }
.danger p { color: var(--muted); font-size: 13px; margin: 8px 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; z-index: 60; box-shadow: var(--shadow);
}
.toast.err { background: var(--bad); }

@media (max-width: 720px) {
  main { padding: 14px; }
  .topbar { flex-wrap: wrap; }
  .grid-2 { grid-template-columns: 1fr; }
}
