:root {
  --slate: #46515a;
  --slate-dark: #343d44;
  --ink: #2b3237;
  --muted: #6b767d;
  --line: #e3e0d8;
  --bg: #faf9f6;
  --card: #ffffff;
  --gold: #c19552;
  --gold-soft: #f4ead9;
  --amber: #a35a00;
  --amber-soft: #fff3df;
  --red: #b3261e;
  --red-soft: #fdecea;
  --green: #1e7d32;
  --green-soft: #e8f4ea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
a { color: var(--slate); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; min-height: 80vh; color: var(--muted); }

/* layout */
.top { position: sticky; top: 0; z-index: 20; background: var(--slate); color: #fff; display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.top img { width: 34px; height: 34px; border-radius: 50%; background: #fff; }
.top .title { font-weight: 600; letter-spacing: .2px; flex: 1; }
.top .title small { display: block; font-weight: 400; opacity: .75; font-size: 12px; }
.top button { background: transparent; border: 1px solid rgba(255, 255, 255, .35); color: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.shell { display: flex; min-height: calc(100vh - 54px); }
.nav { width: 220px; flex: none; border-right: 1px solid var(--line); background: #f3f1ec; padding: 12px 8px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.nav a.on { background: var(--card); box-shadow: var(--shadow); font-weight: 600; }
.nav .sep { height: 1px; background: var(--line); margin: 10px 8px; }
.badge { background: var(--gold); color: #fff; border-radius: 999px; font-size: 12px; padding: 1px 8px; font-weight: 600; }
.badge.red { background: var(--red); }
main { flex: 1; min-width: 0; padding: 20px; max-width: 1100px; }
.drawer-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 30; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: 260px; background: #f3f1ec; z-index: 31; padding: 16px 8px; overflow-y: auto; }
.menu-btn { display: none; }
@media (max-width: 760px) {
  .nav.side { display: none; }
  .menu-btn { display: inline-block; }
  main { padding: 14px; }
}

/* text */
h1 { font-size: 22px; margin: 0 0 4px; color: var(--slate-dark); }
h2 { font-size: 17px; margin: 22px 0 10px; color: var(--slate-dark); }
.sub { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* cards & forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field.warn > span { color: var(--amber); font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; border: 1px solid #cfcac0; border-radius: 8px; padding: 10px 12px; background: #fff; min-height: 42px;
}
.field.warn input, .field.warn select { border-color: var(--amber); background: var(--amber-soft); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
textarea { min-height: 70px; resize: vertical; }
label.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 14px; color: var(--ink); }
label.check input { width: 18px; height: 18px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--slate); background: var(--slate); color: #fff; border-radius: 10px; padding: 10px 16px; min-height: 44px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--slate-dark); }
.btn.ghost { background: #fff; color: var(--slate); }
.btn.gold { background: var(--gold); border-color: var(--gold); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.big { min-height: 64px; font-size: 18px; border-radius: 14px; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.linkish { background: none; border: none; color: var(--slate); text-decoration: underline; cursor: pointer; padding: 0; }

.msg { border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.msg.err { background: var(--red-soft); color: var(--red); }
.msg.ok { background: var(--green-soft); color: var(--green); }
.msg.warn { background: var(--amber-soft); color: var(--amber); }
.msg.info { background: var(--gold-soft); color: #6b4f22; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; background: #eceae4; color: var(--muted); white-space: nowrap; }
.pill.filed { background: var(--green-soft); color: var(--green); }
.pill.attention, .pill.error { background: var(--amber-soft); color: var(--amber); }
.pill.filing { background: var(--gold-soft); color: #6b4f22; }
.pill.pending { background: var(--gold-soft); color: #6b4f22; }
.pill.disabled { background: var(--red-soft); color: var(--red); }

/* auth */
.auth { max-width: 400px; margin: 6vh auto; padding: 0 16px; }
.auth .brand { text-align: center; margin-bottom: 18px; }
.auth .brand img { width: 72px; height: 72px; border-radius: 50%; }
.auth .brand h1 { margin-top: 8px; }

/* tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--card); }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: #f7f5f0; }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #fbfaf7; }
.items { list-style: none; padding: 0; margin: 0; }
.items li { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; display: flex; gap: 10px; align-items: center; }
.items li .grow { flex: 1; min-width: 0; }

/* scanning */
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.thumb { position: relative; width: 96px; height: 128px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .n { position: absolute; left: 6px; top: 6px; background: rgba(0, 0, 0, .6); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; }
.thumb button { position: absolute; right: 4px; top: 4px; width: 26px; height: 26px; border-radius: 50%; border: none; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; }
.thumb.pdf { display: grid; place-items: center; font-weight: 700; color: var(--slate); }
.seg { display: inline-flex; border: 1px solid var(--slate); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: #fff; color: var(--slate); padding: 8px 14px; cursor: pointer; }
.seg button.on { background: var(--slate); color: #fff; }
.progress { text-align: center; padding: 40px 10px; }
.spinner { width: 36px; height: 36px; border: 4px solid #e2ddd2; border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.check-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .check-grid { grid-template-columns: 1fr; } }
.viewer { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.viewer img { width: 100%; display: block; }
.viewer .hl { position: absolute; border: 3px solid var(--gold); background: rgba(193, 149, 82, .18); border-radius: 4px; pointer-events: none; }
.viewer .pager { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-top: 1px solid var(--line); font-size: 14px; }
.sticky-view { position: sticky; top: 70px; }
@media (max-width: 900px) { .sticky-view { position: static; } }
table.lines { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 4px; font-weight: 600; }
table.lines td { padding: 3px; }
table.lines input { min-height: 34px; padding: 6px 8px; font-size: 14px; }
table.lines td.del button { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 18px; }
.reasons { margin: 0; padding-left: 18px; }
iframe.pdf { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

/* layout editor */
.layout-editor { position: relative; user-select: none; touch-action: none; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.layout-editor img { width: 100%; display: block; pointer-events: none; }
.layout-editor .box { position: absolute; border: 2px solid; border-radius: 3px; }
.layout-editor .box .tag { position: absolute; left: -2px; top: -22px; color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.layout-editor .box .handle { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid; }
.field-list { list-style: none; padding: 0; margin: 0; }
.field-list li { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; cursor: pointer; }
.field-list li.on { background: var(--gold-soft); }
.field-list .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
