@font-face { font-family: "Manrope"; src: url("fonts/Manrope.ttf") format("truetype"); font-weight: 200 800; font-display: swap; }
html { -webkit-tap-highlight-color: transparent; }
body { margin: 0; }
[hidden] { display: none !important; }
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }

/* Layout: navy app bar, section rail at left on tablet (tabs on phone), one form column of large tap targets. */
:root {
  --navy: #213974;
  --orange: #ED7402;
  --bg: #F2F4F8;
  --surface: #FFFFFF;
  --surface-2: #E8ECF4;
  --line: #CBD3E2;
  --fg: #16203A;
  --muted: #5A6684;
  --accent: #213974;
  --accent-fg: #FFFFFF;
  --hi: #ED7402;
  --hi-soft: #FDEBDB;
  --ok: #1E7A45;
  --ok-soft: #DDF1E4;
  --bad: #B3261E;
  --bad-soft: #FADCD9;
  --na: #6B7488;
  --na-soft: #E4E7EE;
  --bar: #213974;
  --bar-fg: #FFFFFF;
  --font: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D1322; --surface: #151D33; --surface-2: #1D2843; --line: #2D3A5C;
    --fg: #E6EAF3; --muted: #9AA6C2; --accent: #8FA8E8; --accent-fg: #0D1322;
    --hi: #FF9636; --hi-soft: #3A2814; --ok: #6FD39A; --ok-soft: #173326;
    --bad: #FF8A80; --bad-soft: #3B1A1A; --na: #A3ACC0; --na-soft: #262F45;
    --bar: #18254B; --bar-fg: #FFFFFF; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D1322; --surface: #151D33; --surface-2: #1D2843; --line: #2D3A5C;
  --fg: #E6EAF3; --muted: #9AA6C2; --accent: #8FA8E8; --accent-fg: #0D1322;
  --hi: #FF9636; --hi-soft: #3A2814; --ok: #6FD39A; --ok-soft: #173326;
  --bad: #FF8A80; --bad-soft: #3B1A1A; --na: #A3ACC0; --na-soft: #262F45;
  --bar: #18254B; --bar-fg: #FFFFFF; color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bar); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bar); color: var(--bar-fg);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 10px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-bottom: 3px solid var(--orange); }
.bar svg.logo { height: 22px; width: auto; flex: none; }
.bar .ttl { font-weight: 700; font-size: 15px; letter-spacing: .01em; opacity: .9; }
.bar .grow { flex: 1; }
.chip-id { font-family: var(--mono); font-size: 13px; background: rgba(255,255,255,.12); padding: 4px 10px; border-radius: 6px; max-width: 100%; overflow-wrap: anywhere; }
.sync { font-size: 13px; opacity: .85; }
.btn { border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 700; min-height: 44px; display: inline-flex; align-items: center; gap: 8px; }
.btn-primary { background: var(--orange); color: #FFFFFF; }
.btn-ghost { background: transparent; color: inherit; border: 1.5px solid currentColor; }
.btn-quiet { background: var(--surface-2); color: var(--fg); }
.btn-danger { background: var(--bad-soft); color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }

.wrap { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 20px 60px; max-width: 1180px; margin: 0 auto; }

/* Home */
.home-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.home-head h1 { margin: 0; font-size: 28px; font-weight: 800; text-wrap: balance; }
.home-head p { margin: 4px 0 0; color: var(--muted); max-width: 60ch; }
.list { display: grid; gap: 10px; }
.row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center; }
.row .rid { font-family: var(--mono); font-size: 14px; font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
.row .meta { color: var(--muted); font-size: 14px; }
.row .acts { grid-row: span 2; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tag-ej { font-family: var(--font); font-size: 11px; font-weight: 800; letter-spacing: .08em; background: var(--hi-soft); color: var(--hi); padding: 2px 8px; border-radius: 4px; margin-left: 8px; vertical-align: middle; }
.empty { background: var(--surface); border: 1.5px dashed var(--line); border-radius: var(--r); padding: 28px; display: grid; gap: 10px; justify-items: start; }
.empty h2 { margin: 0; font-size: 20px; }
.empty p { margin: 0; color: var(--muted); max-width: 60ch; }

/* Editor */
.ed { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.rail { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 80px); display: grid; gap: 4px; }
.rail button { text-align: left; background: transparent; border: 0; border-radius: 8px; padding: 10px 12px; min-height: 44px; display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--fg); font-weight: 600; }
.rail button[aria-current="true"] { background: var(--surface); box-shadow: inset 3px 0 0 var(--orange); }
.rail .cnt { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; }
.back { margin-bottom: 8px; }
@media (max-width: 820px) {
  .ed { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; display: flex; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .rail button { white-space: nowrap; flex: none; background: var(--surface); }
  .rail button[aria-current="true"] { box-shadow: inset 0 -3px 0 var(--orange); }
}
.sec-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 0 0 14px; }
.sec-h h2 { margin: 0; font-size: 24px; font-weight: 800; text-wrap: balance; }
.sec-h .hint { color: var(--muted); font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 14px; }
.card > summary, .card > .ch { list-style: none; padding: 14px 16px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; min-height: 52px; }
.card > summary::-webkit-details-marker { display: none; }
.card > summary .cnt { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; }
.card[open] > summary { border-bottom: 1px solid var(--line); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 16px 20px; padding: 16px; }
.f { display: grid; gap: 6px; align-content: start; min-width: 0; }
.f.wide { grid-column: 1 / -1; }
.f label, .f .lbl { font-size: 14px; font-weight: 600; color: var(--fg); }
.f .ref { font-size: 12px; color: var(--muted); font-weight: 500; }
.f .new { font-size: 10px; font-weight: 800; letter-spacing: .08em; color: var(--hi); margin-left: 6px; }
.inp { display: flex; align-items: stretch; border: 1.5px solid var(--line); border-radius: 8px; background: var(--bg); min-height: 48px; }
.inp:focus-within { border-color: var(--accent); }
.inp input, .inp select, .inp textarea { flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 12px; font-size: 17px; outline: none; }
.inp textarea { min-height: 96px; resize: vertical; }
.inp .u { display: flex; align-items: center; padding: 0 12px; font-family: var(--mono); font-size: 13px; color: var(--muted); border-left: 1px solid var(--line); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { min-height: 48px; min-width: 64px; padding: 8px 14px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--bg); font-weight: 700; color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.seg.sino button[data-v="SI"][aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.seg.sino button[data-v="NO"][aria-pressed="true"] { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.seg.sino button[data-v="NA"][aria-pressed="true"] { background: var(--na); border-color: var(--na); color: var(--surface); }
.calc { min-height: 48px; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums; }
.calc .u { color: var(--muted); font-size: 13px; }
.warn { font-size: 13px; font-weight: 700; color: var(--bad); }
.okm { font-size: 13px; font-weight: 700; color: var(--ok); }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.tabs .t { min-height: 48px; padding: 8px 16px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; color: var(--fg); }
.tabs .t[aria-pressed="true"] { border-color: var(--orange); box-shadow: inset 0 -3px 0 var(--orange); }
.tabs .t small { font-family: var(--mono); font-weight: 400; color: var(--muted); margin-left: 6px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 14px; }
.alerts { display: grid; gap: 8px; }
.al { display: grid; grid-template-columns: auto 1fr; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--bad); border-radius: 8px; padding: 12px 14px; }
.al b { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 500; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: grid; gap: 12px; margin-bottom: 16px; }
.panel h3 { margin: 0; font-size: 18px; }
.panel p { margin: 0; color: var(--muted); max-width: 70ch; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }
.idbox { font-family: var(--mono); font-size: 18px; font-weight: 500; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg); padding: 12px 18px; border-radius: 10px; font-weight: 600; z-index: 20; max-width: calc(100% - 32px); }
.stats { display: flex; gap: 18px; flex-wrap: wrap; font-size: 14px; color: var(--muted); }
.stats b { color: var(--fg); font-family: var(--mono); font-weight: 500; }
.confirm { display: inline-flex; gap: 6px; }

/* ---- v2 ---- */
.loading { color: var(--muted); }
.user { background: rgba(255,255,255,.14); color: #FFFFFF; border: 0; border-radius: 999px; padding: 8px 14px; min-height: 40px; font-weight: 700; }
.sync.warn-s { color: #FFD3A8; }
.login { max-width: 420px; margin: 8vh auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 16px; }
.login h1 { margin: 0; font-size: 26px; font-weight: 800; }
.login p { margin: 0; color: var(--muted); }
.login .err { color: var(--bad); font-weight: 700; }
.who { color: var(--muted); font-size: 13px; }
.who b { color: var(--fg); font-weight: 600; }
.pend { font-size: 11px; font-weight: 800; letter-spacing: .06em; color: var(--hi); background: var(--hi-soft); border-radius: 4px; padding: 2px 6px; margin-left: 8px; vertical-align: middle; }
.filter { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.photos { padding: 0 16px 16px; display: grid; gap: 8px; }
.photos .ph-h { font-size: 13px; font-weight: 700; color: var(--muted); }
.strip { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.thumb { width: 96px; height: 96px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); object-fit: cover; padding: 0; overflow: hidden; display: block; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.addph { width: 96px; height: 96px; border-radius: 8px; border: 1.5px dashed var(--line); background: var(--bg); display: grid; place-items: center; text-align: center; font-weight: 700; font-size: 13px; color: var(--accent); cursor: pointer; position: relative; }
.addph input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(8,12,24,.88); display: grid; grid-template-rows: auto 1fr auto; padding: calc(12px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); gap: 12px; color: #FFFFFF; }
.overlay img { max-width: 100%; max-height: 100%; object-fit: contain; margin: auto; display: block; }
.overlay .ov-h { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.overlay .btns { justify-content: center; }
.modal { background: var(--surface); color: var(--fg); border-radius: 14px; padding: 22px; max-width: 420px; width: 100%; margin: auto; display: grid; gap: 14px; }
.modal h3 { margin: 0; }
