:root { color-scheme: light; --ink:#15181C; --text:#15181C; --muted:#4B5563; --line:#D9DCD6; --bg:#F3F4F1; --card:#FFFFFF; --field:#FFFFFF; --field-line:#C9CDC5; --press:#FAFAF8; --surface2:#F1F2EF; --track:#E5E7E2; --check-line:#9CA3AF; --chip-ink:#374151; --primary:var(--ink); --accent:#C2410C; --accent-d:#9A3412; --accent-bg:#FDEBDD; --blue:#1D4ED8; --blue-bg:#E7EEFB; --blue-ink:#1E3A8A; --good:#15803D; --good-bg:#E8F5EC; --chip:#ECEDEA; --mark:#C2410C; }
/* Dark theme. Brand colors (--ink, --accent, --mark) come from the org profile and are kept; only surfaces and text change.
   Plan sheets (.osd) stay white in both themes so drawings and markups look as they do on paper. */
:root[data-theme=dark] { color-scheme: dark; --text:#E8EEF6; --muted:#9AA9BD; --line:#24364F; --bg:#0A1424; --card:#12223A; --field:#0E1B2E; --field-line:#33475F; --press:#182B47; --surface2:#1A2C47; --track:#24364F; --check-line:#6B7D95; --chip:#1C2E48; --chip-ink:#C9D4E2; --primary:var(--accent);
  --accent-d:color-mix(in srgb, var(--accent) 45%, #fff); --accent-bg:color-mix(in srgb, var(--accent) 22%, var(--card));
  --blue-bg:#13294A; --blue-ink:#A9C8F5; --good:#6FD39A; --good-bg:#12321F; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.top { background: var(--card); border-bottom: 1px solid var(--line); padding: calc(8px + env(safe-area-inset-top)) 8px 8px; display: flex; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 10; }
.top.dark { background: var(--ink); color: #fff; border-color: rgba(255,255,255,.12); }
.top h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; padding-left: 8px; }
.top .t2 { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top .t2 b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .t2 span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { width: 44px; height: 44px; border: none; background: transparent; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; }
.iconbtn:active { background: rgba(127,127,127,.15); }
.avatar { width: 40px; height: 40px; border-radius: 20px; background: var(--primary); color: #fff; font-weight: 700; font-size: 14px; border: none; flex-shrink: 0; cursor: pointer; }
main.pad { padding: 14px; max-width: 760px; width: 100%; margin: 0 auto; flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 6px 2px 8px; }
.btn { min-height: 48px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--field-line); background: var(--card); font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; font-size: 14px; padding: 0 12px; }
.btn:disabled { opacity: .45; cursor: default; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input { min-height: 50px; border: 1px solid var(--field-line); border-radius: 10px; padding: 0 14px; font-size: 17px; background: var(--field); }
.err { color: var(--accent-d); background: var(--accent-bg); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.note { font-size: 13px; line-height: 1.45; padding: 10px 12px; border-radius: 10px; background: var(--blue-bg); color: var(--blue-ink); margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 13px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--field); border: 1px solid var(--field-line); border-radius: 12px; padding: 0 12px; min-height: 50px; margin-bottom: 12px; }
.search input { border: none; outline: none; flex: 1; font-size: 17px; background: transparent; min-width: 0; height: 48px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-align: left; width: 100%; cursor: pointer; min-height: 56px; }
.row:active { background: var(--press); }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row .k { font-size: 12px; font-weight: 700; color: var(--muted); }
.row .big { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sm { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-flex; align-items: center; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; background: var(--chip); color: var(--chip-ink); flex-shrink: 0; }
.chip.blue { background: var(--blue-bg); color: var(--blue-ink); }
.chip.orange { background: var(--accent-bg); color: var(--accent-d); }
.chip.green { background: var(--good-bg); color: var(--good); }
.check { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--check-line); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.bottombar { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); font-size: 14px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--track); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; z-index: 100; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.on { opacity: 1; }

/* sheet modal */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; max-height: 86dvh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; overflow: hidden; }
.sheet .sh-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.sheet .sh-head b { flex: 1; font-size: 16px; }
.sheet .sh-body { overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.crumbs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 13px; margin-bottom: 10px; }
.crumbs button { border: none; background: var(--chip); border-radius: 6px; padding: 6px 8px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text); }

/* viewer */
.viewer { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--surface2); }
.vtop { background: var(--ink); color: #fff; padding: calc(6px + env(safe-area-inset-top)) 6px 6px; display: flex; align-items: center; gap: 4px; }
.vtop .iconbtn { color: #fff; }
.vtop .iconbtn:active { background: rgba(255,255,255,.1); }
.sheetbtn { flex: 1; min-width: 0; min-height: 44px; border: none; background: transparent; color: #fff; text-align: left; display: flex; flex-direction: column; justify-content: center; padding: 0 6px; cursor: pointer; }
.sheetbtn b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheetbtn span { font-size: 12px; color: #C9CDC5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settabs { display: flex; gap: 6px; padding: 6px 8px; background: color-mix(in srgb, var(--ink), #000 30%); overflow-x: auto; scrollbar-width: none; }
.settabs::-webkit-scrollbar { display: none; }
.settab { min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid #4B5563; background: transparent; color: #fff; font-size: 13px; font-weight: 700; white-space: nowrap; cursor: pointer; flex-shrink: 0; }
.settab.on { background: var(--accent); border-color: var(--accent); }
.osd { flex: 1; position: relative; background: #fff; min-height: 0; }
.osd-status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px; background: rgba(255,255,255,.92); z-index: 5; font-size: 14px; color: var(--muted); text-align: center; padding: 20px; }
.vbottom { background: var(--card); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 52px 1fr 52px; gap: 8px; align-items: center; }
.vbottom .mid { display: flex; gap: 6px; justify-content: center; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.thumb { border: 2px solid var(--line); border-radius: 10px; background: var(--card); padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.thumb.on { border-color: var(--accent); }
.thumb .img { aspect-ratio: 3 / 2; background: #fff; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb b { font-size: 14px; }
.progress { height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; width: 220px; max-width: 70vw; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* theme picker */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--chip); padding: 4px; border-radius: 12px; }
.seg button { min-height: 42px; border: none; border-radius: 9px; background: transparent; font-weight: 700; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
