:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #5d6877;
  --line: #e2e6ec;
  --accent: #0e6b68;
  --accent-ink: #ffffff;
  --accent-soft: #e4f2f1;
  --ok: #1b7a48; --ok-bg: #e6f4ec;
  --warn: #8a5a00; --warn-bg: #fdf2d8;
  --info: #1f5ea8; --info-bg: #e7effa;
  --grey: #5d6877; --grey-bg: #eef0f3;
  --bad: #b42318; --bad-bg: #fdeceb;
  --radius: 10px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; margin: 18px 0 6px; }
p { margin: 2px 0 0; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error-text { color: var(--bad); margin: 8px 0 0; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
}
.top nav { display: flex; gap: 6px; white-space: nowrap; }
.top nav form { margin: 0; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { color: var(--muted); font-size: 12.5px; }
.mark {
  flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(140deg, #0b5a57 0%, #0e6b68 45%, #17968f 100%);
  box-shadow: 0 1px 2px rgba(14, 107, 104, .25), inset 0 1px 0 rgba(255, 255, 255, .15);
}
.mark svg { width: 26px; height: 26px; }

main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 120px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 860px) { .steps { grid-template-columns: 1fr; } main, .top { padding-left: 16px; padding-right: 16px; } }
.step-head { display: flex; gap: 12px; margin-bottom: 14px; }
.step-head p { color: var(--muted); font-size: 13px; }
.num {
  flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: inline-grid; place-items: center; font-weight: 700; font-size: 12.5px;
}
h2 .num { margin-right: 6px; vertical-align: 1px; }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 108px; padding: 16px; border: 2px dashed #c9d0d9; border-radius: var(--radius);
  background: #fafbfc; cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
}
.drop span { color: var(--muted); font-size: 13px; }
.drop:hover, .drop:focus-visible { border-color: var(--accent); outline: none; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.done { min-height: 64px; }

.summary { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--grey-bg); font-size: 13px; }
.summary.bad { background: var(--bad-bg); color: var(--bad); }
.notice { margin-bottom: 16px; padding: 10px 14px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.map-grid { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; align-items: center; margin: 10px 0; }
.map-grid label { color: var(--muted); font-size: 13px; }
.map-grid select { width: 100%; }

.filelist { list-style: none; margin: 10px 0 0; padding: 0; max-height: 260px; overflow: auto; }
.filelist li { display: flex; gap: 10px; justify-content: space-between; padding: 6px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.filelist li:last-child { border-bottom: 0; }
.filelist .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.filelist .fstate { flex: none; color: var(--muted); }
.filelist .fstate.bad { color: var(--bad); }

button { cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 7px 14px; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.secondary { background: var(--card); border-color: #c9d0d9; }
.secondary:hover:not(:disabled) { border-color: var(--accent); }
.ghost { background: transparent; color: var(--muted); }
.ghost:hover { background: var(--grey-bg); color: var(--ink); }
.linklike { background: none; border: 0; padding: 6px 0 0; color: var(--accent); font-size: 13px; }
.linklike:hover { text-decoration: underline; }

input[type=text], input:not([type]), input[inputmode], input[type=date], input[type=password], select {
  border: 1px solid #cfd5dd; border-radius: 6px; padding: 5px 8px; background: #fff; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.review-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.filters { display: flex; gap: 6px; }
.chip { background: var(--grey-bg); color: var(--muted); padding: 5px 12px; border-radius: 999px; font-size: 13px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.table-wrap { overflow-x: auto; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 1180px; }
th { position: sticky; top: 0; background: #f8f9fb; text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.off td { opacity: .45; }
tr.written td { background: #f4faf6; }
td input:not([type=checkbox]), td select { width: 100%; }
td.r, th.r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.c-inc { width: 30px; }
.w-date { width: 132px; } .w-vendor { min-width: 150px; } .w-card { width: 130px; } .w-rec { min-width: 170px; }
.w-for { min-width: 170px; } .w-ledger { width: 120px; } .w-com { min-width: 140px; }
.sub { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.sub a { color: var(--accent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-grey { background: var(--grey-bg); color: var(--grey); }
.b-bad { background: var(--bad-bg); color: var(--bad); }

#orphans { margin-top: 18px; }
.orphan-list { list-style: none; padding: 0; margin: 8px 0 0; }
.orphan-list li { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.orphan-list .o-name { flex: 1 1 240px; min-width: 0; }
.orphan-list select { max-width: 360px; }

.writebar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(20, 30, 45, .06);
}
.actions { display: flex; gap: 8px; justify-content: flex-end; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 30, 45, .35); }
.dialog-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 6px; }
.dialog-body > label { margin-top: 8px; font-weight: 600; font-size: 13px; }
.dialog-body .actions { margin-top: 16px; }
.dialog-body .linklike { align-self: flex-start; }
.row-inline { display: flex; gap: 8px; }
.row-inline input { flex: 1; }
.card-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 8px; margin-bottom: 6px; }
#preview { width: min(900px, calc(100vw - 32px)); height: min(88vh, 1000px); }
#preview[open] { display: flex; flex-direction: column; }
.preview-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
#preview-frame { flex: 1; border: 0; width: 100%; }

body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 8px; }
.login-card .brand { margin-bottom: 12px; }
.login-card .mark { width: 48px; height: 48px; border-radius: 13px; }
.login-card .mark svg { width: 34px; height: 34px; }
.login-card label { font-weight: 600; font-size: 13px; }
.login-card button { margin-top: 8px; }
