/* ── Reset & Variables ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d1117;
  --bg2:        #161b22;
  --bg3:        #21262d;
  --border:     #30363d;
  --text:       #c9d1d9;
  --muted:      #8b949e;
  --green:      #2ea043;
  --green-dim:  #1a3a2a;
  --green-text: #3fb950;
  --blue:       #388bfd;
  --blue-dim:   #0d2a4a;
  --yellow:     #d29922;
  --yellow-dim: #3a2e0a;
  --red:        #da3633;
  --red-dim:    #3d1a1a;
  --red-text:   #f07070;
  --radius:     8px;
  --shadow:     0 2px 12px rgba(0,0,0,.4);
}

/* Light theme — toggled via data-theme="light" on <html>, set by theme.js */
:root[data-theme="light"] {
  --bg:         #ffffff;
  --bg2:        #f6f8fa;
  --bg3:        #eaeef2;
  --border:     #d0d7de;
  --text:       #1f2328;
  --muted:      #6e7781;
  --green:      #1a7f37;
  --green-dim:  #dafbe1;
  --green-text: #1a7f37;
  --blue:       #0969da;
  --blue-dim:   #ddf4ff;
  --yellow:     #9a6700;
  --yellow-dim: #fff8c5;
  --red:        #cf222e;
  --red-dim:    #ffebe9;
  --red-text:   #cf222e;
  --shadow:     0 2px 12px rgba(0,0,0,.08);
}

/* Respect system preference when the user hasn't explicitly chosen (no
   data-theme attribute yet — theme.js sets one from localStorage on load,
   this only covers the very first visit / cleared storage). */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg:         #ffffff;
    --bg2:        #f6f8fa;
    --bg3:        #eaeef2;
    --border:     #d0d7de;
    --text:       #1f2328;
    --muted:      #6e7781;
    --green:      #1a7f37;
    --green-dim:  #dafbe1;
    --green-text: #1a7f37;
    --blue:       #0969da;
    --blue-dim:   #ddf4ff;
    --yellow:     #9a6700;
    --yellow-dim: #fff8c5;
    --red:        #cf222e;
    --red-dim:    #ffebe9;
    --red-text:   #cf222e;
    --shadow:     0 2px 12px rgba(0,0,0,.08);
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  font-weight: 700; font-size: 16px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.logo span { color: var(--green); }
nav { display: flex; align-items: center; gap: 4px; }
nav a {
  color: var(--muted); padding: 6px 12px; border-radius: var(--radius);
  font-size: 14px; transition: color .15s, background .15s;
}
nav a:hover, nav a.active { color: var(--text); background: var(--bg3); text-decoration: none; }

/* Session-scoped utilities (tenant badge, theme toggle, logout) — visually
   separated from the primary nav links they sit next to. */
.nav-utils {
  display: flex; align-items: center; gap: 8px;
  margin-left: 12px; padding-left: 12px;
  border-left: 1px solid var(--border);
}

.theme-toggle {
  padding: 6px 10px; font-size: 15px; line-height: 1;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); cursor: pointer; transition: background .15s, border-color .15s;
}
.theme-toggle:hover { background: var(--bg3); border-color: var(--muted); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.page { max-width: 1200px; margin: 0 auto; padding: 32px 24px; }
.page-title { font-size: 22px; font-weight: 600; margin-bottom: 24px; }
.page-title small { font-size: 14px; font-weight: 400; color: var(--muted); margin-left: 8px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 15px; font-weight: 600; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}

/* ── Upload zone ──────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--green);
  background: var(--green-dim);
}
.upload-zone input[type=file] { display: none; }
.upload-icon { font-size: 40px; margin-bottom: 12px; }
.upload-zone p { color: var(--muted); margin-top: 6px; font-size: 13px; }
.upload-zone strong { color: var(--text); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px; font-size: 14px;
  font-weight: 500; cursor: pointer; border: 1px solid transparent;
  transition: opacity .15s, background .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--green);  color: #fff; border-color: var(--green); }
.btn-primary:hover:not(:disabled)  { background: #3bb54a; }
.btn-blue     { background: var(--blue);   color: #fff; border-color: var(--blue); }
.btn-blue:hover:not(:disabled)     { background: #4d9bff; }
.btn-danger   { background: var(--red);    color: #fff; border-color: var(--red); }
.btn-danger:hover:not(:disabled)   { background: #e84644; }
.btn-ghost    { background: transparent;   color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled)    { background: var(--bg3); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
}
.badge-green  { background: var(--green-dim);  color: var(--green-text); border: 1px solid #2ea04333; }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow);     border: 1px solid #d2992233; }
.badge-red    { background: var(--red-dim);    color: var(--red-text);  border: 1px solid #da363333; }
.badge-blue   { background: var(--blue-dim);   color: var(--blue);      border: 1px solid #388bfd33; }
.badge-gray   { background: var(--bg3);        color: var(--muted);    border: 1px solid var(--border); }

/* ── Progress bar ─────────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: var(--bg3); border-radius: 4px; height: 6px; overflow: hidden;
}
.progress-bar {
  height: 100%; border-radius: 4px; background: var(--green);
  transition: width .3s ease;
}

/* ── Table ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 12px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }
tbody td { padding: 12px; vertical-align: middle; }

/* ── Form fields ──────────────────────────────────────────────────────────── */
.field-group { margin-bottom: 16px; }
label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .4px;
  margin-bottom: 4px;
}
input[type=text], input[type=number], input[type=password],
input[type=email], input[type=date], textarea, select {
  width: 100%; padding: 8px 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 14px;
  transition: border-color .15s;
  outline: none;
}
input[type=text]:focus, input[type=number]:focus, input[type=password]:focus,
input[type=email]:focus, input[type=date]:focus,
textarea:focus, select:focus { border-color: var(--blue); }
textarea { resize: vertical; min-height: 64px; }
.field-null input, .field-null textarea { color: var(--muted); font-style: italic; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 16px; }
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.stat-value { font-size: 32px; font-weight: 700; line-height: 1; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--green);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Overlay ──────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 999; gap: 16px;
}
.overlay p { color: var(--text); font-size: 15px; }

/* ── PDF preview modal ────────────────────────────────────────────────────── */
.pdf-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
.pdf-modal-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(900px, 100%); height: min(90vh, 1100px);
  display: flex; flex-direction: column; overflow: hidden;
}
.pdf-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 14px;
}
.pdf-modal-card iframe { flex: 1; border: none; background: #fff; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 20px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; z-index: 9999;
  opacity: 0; transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--green);  color: #fff; }
.toast-error   { background: var(--red);    color: #fff; }

/* ── Two-column review layout ─────────────────────────────────────────────── */
.review-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) { .review-grid { grid-template-columns: 1fr; } }

.doc-preview {
  position: sticky; top: 80px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  min-height: 400px; display: flex; align-items: center; justify-content: center;
}
.doc-preview img { width: 100%; height: auto; display: block; }
.doc-preview iframe { width: 100%; height: 700px; border: none; }
.doc-preview .no-preview {
  color: var(--muted); text-align: center; padding: 48px 24px;
}
.doc-preview .no-preview .icon { font-size: 48px; margin-bottom: 12px; }

/* ── Review action bar ────────────────────────────────────────────────────── */
.action-bar {
  display: flex; gap: 12px; align-items: center;
  padding: 16px 24px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 24px;
  position: sticky; bottom: 16px;
}
.action-bar .spacer { flex: 1; }

/* ── Completeness ring ────────────────────────────────────────────────────── */
.completeness-ring {
  display: inline-flex; align-items: center; gap: 10px;
}
.ring-wrap { position: relative; width: 48px; height: 48px; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}

/* ── Inline table inputs (line items) ────────────────────────────────────── */
/* table-layout:auto (default) + min-width per column lets the table grow
   past the card's width on narrow screens — .table-wrap scrolls horizontally
   instead of squeezing inputs down to nothing. */
#lineTable td { padding: 6px 8px; }
#lineTable input[type=text],
#lineTable input[type=number] {
  width: 100%; padding: 5px 8px;
  background: var(--bg3); border: 1px solid transparent;
  border-radius: 4px; color: var(--text); font-size: 13px;
  box-sizing: border-box;
}
#lineTable textarea.li-field {
  width: 100%; padding: 5px 8px;
  background: var(--bg3); border: 1px solid transparent;
  border-radius: 4px; color: var(--text); font-size: 13px;
  box-sizing: border-box; resize: vertical; overflow: hidden;
  min-height: 32px; line-height: 1.4; font-family: inherit;
}
#lineTable textarea.li-field:focus { border-color: var(--blue); outline: none; }
#lineTable .li-desc      { min-width: 140px; }
#lineTable .li-qty       { min-width: 48px; }
#lineTable .li-price,
#lineTable .li-net,
#lineTable .li-gross     { min-width: 84px; }
#lineTable .li-vat       { min-width: 48px; }
#lineTable .li-gl-select { min-width: 110px; }
#lineTable input:focus { border-color: var(--blue); outline: none; }
#lineTable input::placeholder { color: var(--muted); font-style: italic; }

/* ── GL coding (Phase 2) ──────────────────────────────────────────────────── */
.gl-cell { display: flex; flex-direction: column; gap: 4px; }
.gl-cell select {
  width: 100%; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 6px; font-size: 12px; font-family: monospace;
}
.gl-cell-actions { display: flex; align-items: center; gap: 6px; }

/* Searchable GL-code combobox — type-to-filter over a potentially large
   chart of accounts, click (or Enter) to pick. */
.gl-combo { position: relative; width: 100%; }
.gl-combo input.li-gl-select {
  width: 100%; background: var(--bg3); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 6px; font-size: 12px; font-family: monospace;
  box-sizing: border-box;
}
.gl-combo-list {
  display: none; max-height: 220px; overflow-y: auto;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--shadow);
}
/* Portaled to <body> (see gl.js) and positioned in JS at the active
   input's on-screen coordinates — position:fixed so it floats above the
   line-items table instead of being clipped by .table-wrap's horizontal
   scroll (overflow-x:auto on one axis forces the other to clip too). */
.gl-combo-portal { position: fixed; z-index: 2000; }
.gl-combo-item {
  padding: 6px 8px; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.gl-combo-item:hover, .gl-combo-item.is-active { background: var(--bg3); }
.gl-combo-code { font-family: monospace; color: var(--blue); }
.gl-combo-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.gl-combo-type { flex-shrink: 0; font-size: 10px; padding: 1px 6px; margin: 0; }
.gl-combo-empty { padding: 6px 8px; font-size: 12px; color: var(--muted); }
.gl-refresh-btn {
  flex-shrink: 0; padding: 4px 6px; font-size: 12px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 6px; color: var(--muted); cursor: pointer;
  line-height: 1;
}
.gl-refresh-btn:hover { color: var(--text); border-color: var(--blue); }
.gl-refresh-btn.is-loading { animation: gl-spin .8s linear infinite; }
@keyframes gl-spin { to { transform: rotate(360deg); } }
.gl-conf-badge {
  font-size: 10px; font-family: monospace; padding: 1px 5px;
  border-radius: 4px; flex-shrink: 0; white-space: nowrap;
}
.gl-conf-high { background: var(--green-dim);  color: var(--green); }
.gl-conf-mid  { background: var(--yellow-dim); color: var(--yellow); }
.gl-conf-low  { background: var(--red-dim);    color: var(--red); }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.empty { color: var(--muted); text-align: center; padding: 48px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.retrain-banner {
  background: var(--yellow-dim); border: 1px solid var(--yellow);
  border-radius: var(--radius); padding: 16px 20px;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px;
}
