:root {
  --bg: #f2f2f7; --card: #ffffff; --text: #1c1c1e; --muted: #6e6e73; --line: #d9d9de;
  --field: #f2f2f7; --blue: #2563eb; --blue-text: #ffffff; --err-bg: #fdecec; --err: #b3261e;
  --ok: #1f8a4c; --warn-bg: #fff4d6; --warn: #8a5a00; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --card: #1c1c1e; --text: #f5f5f7; --muted: #98989f; --line: #38383a;
    --field: #2c2c2e; --blue: #3b82f6; --err-bg: #3a1614; --err: #ff8a80; --ok: #4cd37f;
    --warn-bg: #3a2e0c; --warn: #f5c451; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
.screen { max-width: 560px; margin: 0 auto; padding: 12px 16px 40px; }
h1 { font-size: 28px; margin: 0; letter-spacing: -.3px; }
h2 { font-size: 20px; margin: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 0; }
.hello { margin: 2px 0 14px; color: var(--muted); }
.hero { text-align: center; padding: 28px 0 18px; }
.hero .logo { border-radius: 20px; box-shadow: var(--shadow); }
.hero h1 { margin-top: 12px; }
.sub { color: var(--muted); margin: 6px 0 0; }
.card, .sheet-card { background: var(--card); border-radius: 18px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
label { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=date], input[type=password], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--field); border: 1px solid transparent; border-radius: 12px; appearance: none; -webkit-appearance: none;
}
input[type=date] { display: block; min-width: 0; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 > div { min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 52px;
  padding: 12px 18px; font: inherit; font-weight: 600; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--field); color: var(--blue);
}
.btn.primary { background: var(--blue); color: var(--blue-text); }
.btn.ghost { background: transparent; color: var(--blue); }
.btn.big { min-height: 96px; font-size: 22px; border-radius: 20px; }
.btn:active { opacity: .8; transform: scale(.99); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.actions { display: grid; gap: 8px; margin-top: 18px; }
.hint { color: var(--muted); font-size: 15px; margin: 10px 0 0; text-align: center; }
.hint.small { font-size: 13px; text-align: left; margin-top: 4px; }
.error { background: var(--err-bg); color: var(--err); border-radius: 12px; padding: 10px 12px; margin: 12px 0 0; font-size: 15px; }
.badge { display: inline-block; margin: 14px 0 0; padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--field); color: var(--ok); }
.badge.medium, .badge.low { background: var(--warn-bg); color: var(--warn); }
.preview { display: block; width: 100%; max-height: 260px; object-fit: contain; background: var(--field); border-radius: 12px; }
.analyzing { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 18px 0 6px; color: var(--muted); font-weight: 600; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--field); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { min-height: 46px; border: 0; border-radius: 10px; background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.seg button[aria-checked=true] { background: var(--blue); color: var(--blue-text); }
.icon-btn { width: 48px; height: 48px; border: 0; border-radius: 24px; background: transparent; color: var(--blue); display: grid; place-items: center; cursor: pointer; }
.sec-head { display: flex; align-items: center; justify-content: space-between; }
.link { background: none; border: 0; color: var(--blue); font: inherit; font-weight: 600; min-height: 44px; padding: 0 4px; cursor: pointer; }
.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .s { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .a { font-weight: 600; font-variant-numeric: tabular-nums; }
.list .m { grid-column: 1 / -1; color: var(--muted); font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; min-height: 44px; margin: 4px 0 0; }
.check input { width: 22px; height: 22px; }
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { width: 100%; max-width: 560px; margin: 0; border-radius: 22px 22px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: #1c1c1e; color: #fff; padding: 12px 18px; border-radius: 99px; max-width: calc(100% - 32px); text-align: center; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
.toast.err { background: #b3261e; }

.capture-btns { display: grid; gap: 10px; }
.btn.big:not(.primary) { background: var(--field); }
.thumbs { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; }
.thumb { position: relative; flex: 0 0 auto; width: 84px; height: 112px; border-radius: 10px; background: var(--field); overflow: hidden; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .pdf { font-weight: 700; color: var(--blue); text-align: center; font-size: 14px; padding: 4px; word-break: break-all; }
.thumb .pdf small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; margin-top: 2px; }
.thumb .num { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; border-radius: 8px; padding: 1px 6px; }
.thumb .rm { position: absolute; top: 2px; right: 2px; width: 30px; height: 30px; border: 0; border-radius: 15px; background: rgba(0,0,0,.65); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.pages-actions { margin-top: 4px; }
.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); border-radius: 12px; padding: 10px 12px; margin: 14px 0 0; font-size: 15px; font-weight: 600; }
.list .m .flag { color: var(--warn); font-weight: 700; }
