:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #5d6877;
  --accent: #1f5fbf;
  --accent-soft: #e6eefb;
  --ok: #1e7a46;
  --ok-soft: #e3f4ea;
  --warn: #9a6100;
  --warn-soft: #fdf1dc;
  --bad: #b3261e;
  --bad-soft: #fbe5e3;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --surface-2: #232a34;
    --border: #323b47;
    --text: #e6e9ee;
    --muted: #9aa5b3;
    --accent: #6ea2ff;
    --accent-soft: #1d2d4a;
    --ok: #5cc98a;
    --ok-soft: #173326;
    --warn: #f0b252;
    --warn-soft: #3a2c12;
    --bad: #ff8a80;
    --bad-soft: #3d1c1a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

header.top { background: var(--surface); border-bottom: 1px solid var(--border); }
header.top .inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; height: 52px; }
header.top .brand { font-weight: 700; color: var(--text); font-size: 16px; }
header.top nav { display: flex; gap: 4px; flex: 1; }
header.top nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
header.top nav a.active, header.top nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
header.top form input { width: 240px; }
main { max-width: 1280px; margin: 0 auto; padding: 24px 16px 64px; }
main.wide { max-width: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stat { font-size: 26px; font-weight: 600; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 10px; font-size: 13px; }

label { display: block; font-weight: 500; margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
.field { margin-bottom: 12px; }
.field .error { color: var(--bad); font-size: 12px; margin-top: 3px; }
.field.has-error input, .field.has-error select { border-color: var(--bad); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 16px; }
.inline { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.revisar, .badge.pendiente, .badge.procesando { background: var(--accent-soft); color: var(--accent); }
.badge.validado { background: var(--ok-soft); color: var(--ok); }
.badge.duplicado { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--bad-soft); color: var(--bad); }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { display: none; }

.review { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(380px, 1fr); gap: 20px; align-items: start; }
.viewer { position: sticky; top: 16px; height: calc(100vh - 120px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
.viewer iframe { width: 100%; height: 100%; border: 0; }
.viewer img { width: 100%; display: block; }
.viewer pre { white-space: pre-wrap; padding: 16px; margin: 0; }
.tax-table input { padding: 5px 7px; }
.tax-table td { padding: 4px 6px; }
.tax-table th { padding: 6px; }
mark { background: var(--warn-soft); color: inherit; padding: 0 2px; border-radius: 2px; }
details summary { cursor: pointer; color: var(--muted); }

@media (max-width: 900px) {
  .review { grid-template-columns: 1fr; }
  .viewer { position: static; height: 60vh; }
  header.top .inner { flex-wrap: wrap; height: auto; padding: 8px 16px; gap: 8px; }
  header.top form input { width: 100%; }
  table { display: block; overflow-x: auto; }
}
