/* NTA Commissioning — brand crimson #B50937 */
:root {
  --brand: #B50937;
  --brand-600: #9A072F;
  --brand-700: #7E0626;
  --brand-50: #FBEFF2;
  --brand-100: #F5D6DE;
  --bg: #F5F4F2;
  --surface: #FFFFFF;
  --surface-2: #FAF9F8;
  --border: #E4E1DE;
  --border-strong: #CFCAC5;
  --text: #1E1B1A;
  --text-2: #5C5652;
  --text-3: #8C8580;
  --pass: #1E7F45;
  --pass-bg: #E3F4EA;
  --fail: #D3361B;
  --fail-bg: #FDE8E3;
  --na: #6B6560;
  --na-bg: #ECEAE8;
  --warn: #B26A00;
  --warn-bg: #FFF2DB;
  --info: #1D5FA8;
  --info-bg: #E5EFFA;
  --mine: #B50937;
  --shadow: 0 1px 2px rgba(30, 20, 20, .06), 0 2px 8px rgba(30, 20, 20, .05);
  --shadow-lg: 0 10px 40px rgba(20, 10, 10, .22);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 56px;
  --tabbar-h: 62px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #D8264F; --brand-600: #E04466; --brand-700: #F07A93; --brand-50: #2A1419; --brand-100: #46202A;
    --bg: #121011; --surface: #1C191A; --surface-2: #232021; --border: #332E2F; --border-strong: #4A4344;
    --text: #F2EEEC; --text-2: #BDB5B2; --text-3: #8A8280;
    --pass: #4CC47E; --pass-bg: #15301F; --fail: #FF7A5C; --fail-bg: #3A1D16; --na: #A9A19D; --na-bg: #2C2828;
    --warn: #F0B04A; --warn-bg: #36290F; --info: #79B1F0; --info-bg: #142538; --mine: #A3122F;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 40px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #D8264F; --brand-600: #E04466; --brand-700: #F07A93; --brand-50: #2A1419; --brand-100: #46202A;
  --bg: #121011; --surface: #1C191A; --surface-2: #232021; --border: #332E2F; --border-strong: #4A4344;
  --text: #F2EEEC; --text-2: #BDB5B2; --text-3: #8A8280;
  --pass: #4CC47E; --pass-bg: #15301F; --fail: #FF7A5C; --fail-bg: #3A1D16; --na: #A9A19D; --na-bg: #2C2828;
  --warn: #F0B04A; --warn-bg: #36290F; --info: #79B1F0; --info-bg: #142538; --mine: #A3122F;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 10px 40px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 750; letter-spacing: -.01em; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 0 0 .6em; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; opacity: .9; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }
.mono { font-family: var(--mono); font-size: .92em; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.stack > * + * { margin-top: 12px; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 40; background: var(--brand); color: #fff; padding-top: env(safe-area-inset-top); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
:root[data-theme="dark"] .topbar { background: #7E0626; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar { background: #7E0626; } }
.topbar-inner { height: var(--header-h); display: flex; align-items: center; gap: 10px; padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); max-width: 1400px; margin: 0 auto; }
.topbar .logo { height: 26px; display: block; }
.topbar .title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .95; }
.topbar .divider { width: 1px; height: 22px; background: rgba(255,255,255,.35); }
.topbar nav { display: flex; gap: 2px; }
.topbar nav a { color: #fff; opacity: .85; padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; position: relative; }
.topbar nav a:hover { text-decoration: none; background: rgba(255,255,255,.12); opacity: 1; }
.topbar nav a.active { background: rgba(255,255,255,.18); opacity: 1; }
.iconbtn { background: transparent; border: 0; color: inherit; width: 40px; height: 40px; border-radius: 10px; display: inline-grid; place-items: center; cursor: pointer; position: relative; flex: none; }
.iconbtn:hover { background: rgba(127,127,127,.14); }
.topbar .iconbtn:hover { background: rgba(255,255,255,.15); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 700; font-size: 12.5px; color: #fff; flex: none; letter-spacing: .02em; }
.topbar .avatar { background: rgba(255,255,255,.22); border: 1px solid rgba(255,255,255,.4); }
.badge-dot { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; border-radius: 9px; background: #fff; color: var(--brand); font-size: 11px; font-weight: 800; display: grid; place-items: center; padding: 0 5px; }
nav a .badge-dot { position: static; margin-left: 2px; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; background: var(--surface); border-top: 1px solid var(--border); display: none; padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; color: var(--text-3); font-size: 11px; font-weight: 600; position: relative; }
.tabbar a.active { color: var(--brand); }
.tabbar a:hover { text-decoration: none; }
.tabbar .badge-dot { top: 3px; right: calc(50% - 22px); background: var(--brand); color: #fff; }
@media (max-width: 760px) {
  .topbar nav { display: none; }
  .tabbar { display: flex; }
  body.has-tabbar main { padding-bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
  .topbar .title { font-size: 14px; }
  .hide-mobile { display: none !important; }
}
@media (min-width: 761px) { .hide-desktop { display: none !important; } }

main { max-width: 1400px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left)); }
main.narrow { max-width: 860px; }

.offline-bar { background: var(--warn-bg); color: var(--warn); font-weight: 600; font-size: 13px; text-align: center; padding: 6px 12px; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px; }
.card-h { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-b { padding: 16px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.crumbs { font-size: 13px; color: var(--text-3); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--text-2); }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 650; font-size: 14px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, transform .05s; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn.danger { color: var(--fail); border-color: color-mix(in srgb, var(--fail) 45%, var(--border)); }
.btn.danger:hover { background: var(--fail-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(127,127,127,.12); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.btn.xs { height: 26px; padding: 0 8px; font-size: 12px; border-radius: 7px; gap: 4px; }
.btn.block { width: 100%; }
.btn svg { flex: none; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; font-weight: 650; color: var(--text-2); margin-bottom: 5px; }
.input, select.input, textarea.input { width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s; font-size: 16px; }
@media (min-width: 761px) { .input, select.input, textarea.input { font-size: 14.5px; } }
textarea.input { min-height: 84px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.input.sm { min-height: 34px; padding: 5px 10px; border-radius: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; max-width: 100%; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 650; font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- pills / progress ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 11.5px; font-weight: 700; background: var(--na-bg); color: var(--na); white-space: nowrap; letter-spacing: .01em; }
.pill.pass, .pill.complete { background: var(--pass-bg); color: var(--pass); }
.pill.fail, .pill.High { background: var(--fail-bg); color: var(--fail); }
.pill.in_progress, .pill.Medium, .pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.info, .pill.Low { background: var(--info-bg); color: var(--info); }
.pill.brand { background: var(--brand-50); color: var(--brand); }
.pill.Closed { background: var(--pass-bg); color: var(--pass); }
.pill.Open { background: var(--fail-bg); color: var(--fail); }
.bar { height: 6px; border-radius: 3px; background: var(--na-bg); overflow: hidden; display: flex; }
.bar > i { display: block; height: 100%; background: var(--pass); }
.bar > i.f { background: var(--fail); }
.bar.lg { height: 10px; border-radius: 5px; }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; background: conic-gradient(var(--pass) calc(var(--p) * 1%), var(--na-bg) 0); display: grid; place-items: center; flex: none; }
.ring > span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 800; font-size: 14px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
.stat { padding: 14px 16px; }
.stat .k { font-size: 12px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.stat .v { font-size: 26px; font-weight: 800; margin-top: 2px; letter-spacing: -.02em; }
.stat .v small { font-size: 14px; color: var(--text-3); font-weight: 650; }

/* ---------- project cards ---------- */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.proj-card { padding: 18px; display: block; color: inherit; border-top: 4px solid var(--brand); }
.proj-card:hover { text-decoration: none; border-color: var(--brand); }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 220px; min-width: 160px; position: relative; }
.toolbar .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.toolbar .search .input { padding-left: 36px; }
.toolbar select.input { width: auto; min-width: 130px; }

/* ---------- room grid ---------- */
.room-groups > h3 { margin: 18px 2px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
@media (max-width: 480px) { .room-grid { grid-template-columns: 1fr 1fr; gap: 8px; } }
.room-card { display: block; padding: 12px 13px 11px; color: inherit; position: relative; border-left: 4px solid var(--border-strong); transition: transform .08s, box-shadow .12s; }
.room-card:hover { text-decoration: none; box-shadow: 0 4px 16px rgba(0,0,0,.08); transform: translateY(-1px); }
.room-card.complete { border-left-color: var(--pass); }
.room-card.in_progress { border-left-color: var(--warn); }
.room-card.has-fail { border-left-color: var(--fail); }
.room-card .nm { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.room-card .ty { font-size: 12.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 9px; }
.room-card .meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--text-3); margin-top: 7px; flex-wrap: wrap; }
.room-card .meta .ic { display: inline-flex; align-items: center; gap: 3px; }
.room-card .pct { position: absolute; top: 12px; right: 12px; font-weight: 800; font-size: 13px; color: var(--text-2); }
.room-card.complete .pct { color: var(--pass); }

/* ---------- room page ---------- */
.room-head { padding: 16px; display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; }
@media (max-width: 760px) { .room-head { grid-template-columns: 1fr auto; } .room-head .ring { grid-row: 1; grid-column: 2; } .room-head .head-actions { grid-column: 1 / -1; } }
.room-head .nm { font-size: 26px; font-weight: 850; letter-spacing: -.02em; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; margin-top: 14px; }
.kv label > span { display: block; font-size: 11.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.subtabs { position: sticky; top: calc(var(--header-h) + env(safe-area-inset-top)); z-index: 30; background: var(--bg); padding: 10px 0 8px; margin: 0 -2px; }
.subtabs .seg { width: 100%; }
.subtabs .seg button { flex: 1; }
.secnav { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.secnav::-webkit-scrollbar { display: none; }
.secnav a { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.secnav a:hover { text-decoration: none; border-color: var(--text-3); }
.secnav a.done { background: var(--pass-bg); color: var(--pass); border-color: transparent; }
.secnav a.hasfail { background: var(--fail-bg); color: var(--fail); border-color: transparent; }

.section { margin-top: 14px; scroll-margin-top: calc(var(--header-h) + 120px); }
.section-h { display: flex; align-items: center; gap: 10px; padding: 13px 14px; cursor: pointer; user-select: none; }
.section-h h2 { font-size: 16px; flex: 1; min-width: 0; }
.section-h .chev { transition: transform .15s; color: var(--text-3); }
.section.collapsed .chev { transform: rotate(-90deg); }
.section.collapsed .section-b { display: none; }
.section-b { border-top: 1px solid var(--border); }
.section-note { padding: 10px 14px; background: var(--info-bg); color: var(--info); font-size: 13px; font-weight: 600; white-space: pre-wrap; }
.group-h { padding: 10px 14px 6px; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.group-h h4 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--brand); flex: 1; }
.group + .group { border-top: 1px solid var(--border); }

.item { display: grid; grid-template-columns: 30px 1fr; gap: 4px 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); position: relative; }
.item:last-child { border-bottom: 0; }
.item .code { font-weight: 800; color: var(--text-3); font-size: 13px; padding-top: 1px; text-align: right; }
.item .t { font-weight: 620; }
.item .d { color: var(--text-2); font-size: 13.5px; margin-top: 2px; }
.item .d code, .item .d .mono { background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.item .actions { grid-column: 2; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.item .by { font-size: 11.5px; color: var(--text-3); }
.item.pass { background: color-mix(in srgb, var(--pass-bg) 45%, transparent); }
.item.fail { background: color-mix(in srgb, var(--fail-bg) 60%, transparent); }
.item.na { opacity: .75; }
.item .remark { grid-column: 2; margin-top: 6px; font-size: 13px; padding: 7px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--text); white-space: pre-wrap; }
.item .expand { grid-column: 1 / -1; margin-top: 8px; }
.item.pulse { animation: pulse 1.2s ease-out; }
@keyframes pulse { from { box-shadow: inset 0 0 0 2px var(--brand); } to { box-shadow: inset 0 0 0 2px transparent; } }

.sbtns { display: inline-flex; gap: 6px; }
.sbtn { height: 36px; min-width: 64px; padding: 0 12px; border-radius: 9px; border: 1.5px solid var(--border-strong); background: var(--surface); font-weight: 750; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px; color: var(--text-2); transition: all .1s; -webkit-tap-highlight-color: transparent; }
.sbtn:hover { border-color: var(--text-3); }
.sbtn.pass.on { background: var(--pass); border-color: var(--pass); color: #fff; }
.sbtn.fail.on { background: var(--fail); border-color: var(--fail); color: #fff; }
.sbtn.na.on { background: var(--na); border-color: var(--na); color: #fff; }
@media (max-width: 480px) { .sbtn { min-width: 0; flex: 1; } .sbtns { flex: 1; } .item .actions { gap: 6px; } }
.mini { height: 32px; padding: 0 9px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text-2); font-size: 12.5px; font-weight: 650; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.mini:hover { background: var(--surface-2); }
.mini.has { color: var(--brand); border-color: var(--brand-100); background: var(--brand-50); }

/* table rows as cards */
.rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; padding: 12px; }
@media (max-width: 480px) { .rows { grid-template-columns: 1fr; padding: 10px; } }
.trow { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface); border-left: 4px solid var(--border-strong); }
.trow.pass { border-left-color: var(--pass); background: color-mix(in srgb, var(--pass-bg) 40%, var(--surface)); }
.trow.fail { border-left-color: var(--fail); background: color-mix(in srgb, var(--fail-bg) 50%, var(--surface)); }
.trow.na { border-left-color: var(--na); opacity: .8; }
.trow .hd { display: flex; align-items: center; gap: 8px; }
.trow .hd .ttl { font-weight: 750; font-size: 14px; flex: 1; min-width: 0; word-break: break-word; }
.trow dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 4px 12px; margin: 8px 0 0; }
.trow dt { font-size: 10.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.trow dd { margin: 0; font-size: 13px; font-family: var(--mono); word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { height: 32px; padding: 0 10px; border-radius: 16px; border: 1.5px solid var(--border-strong); background: var(--surface); font-size: 12.5px; font-weight: 700; color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; -webkit-tap-highlight-color: transparent; }
.chip .bx { width: 15px; height: 15px; border-radius: 4px; border: 1.5px solid currentColor; display: grid; place-items: center; }
.chip.on { background: var(--pass); border-color: var(--pass); color: #fff; }
.chip.on .bx { background: #fff; color: var(--pass); border-color: #fff; }
.tin { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 10px; }
.tin label > span { display: block; font-size: 10.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; margin-bottom: 2px; }

/* ---------- notes / feed ---------- */
.composer { padding: 12px; }
.composer textarea { min-height: 70px; }
.composer .bar2 { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.previews .pv { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; background: var(--na-bg); }
.previews .pv img { width: 100%; height: 100%; object-fit: cover; }
.previews .pv button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; display: grid; place-items: center; padding: 0; }
.feed { margin-top: 14px; }
.note { padding: 14px; display: grid; grid-template-columns: 36px 1fr; gap: 10px; }
.note + .note { border-top: 1px solid var(--border); }
.note .who { font-weight: 700; }
.note .when { font-size: 12px; color: var(--text-3); }
.note .body { white-space: pre-wrap; word-wrap: break-word; margin-top: 4px; }
.note .ref { display: inline-flex; margin-top: 6px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin-top: 8px; max-width: 560px; }
.photos.one { grid-template-columns: minmax(0, 320px); }
.photos a { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--na-bg); }
.photos.one a { aspect-ratio: auto; max-height: 360px; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .file { display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--text-2); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.gallery a { aspect-ratio: 1; border-radius: 10px; overflow: hidden; position: relative; background: var(--na-bg); display: block; }
.gallery img { width: 100%; height: 100%; object-fit: cover; }
.gallery .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 7px 5px; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; font-size: 10.5px; font-weight: 600; }

/* ---------- chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - var(--header-h) - env(safe-area-inset-top) - 36px); min-height: 380px; }
@media (max-width: 760px) { .chat-wrap { height: calc(100dvh - var(--header-h) - env(safe-area-inset-top) - var(--tabbar-h) - env(safe-area-inset-bottom) - 20px); } body.has-tabbar main.chat-main { padding-bottom: 0; } }
.chat-head { padding: 10px 14px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.online { display: flex; gap: -6px; }
.online .avatar { width: 26px; height: 26px; font-size: 10.5px; margin-left: -6px; border: 2px solid var(--surface); }
.chat-scroll { flex: 1; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msg { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.msg.cont { margin-top: 3px; }
.msg.cont .avatar { visibility: hidden; }
.msg .bub { max-width: min(78%, 560px); background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px 16px 16px 4px; padding: 8px 12px; word-wrap: break-word; }
.msg .bub .nm { font-size: 12px; font-weight: 750; color: var(--brand); margin-bottom: 2px; }
.msg .bub .tx { white-space: pre-wrap; }
.msg .bub .tm { font-size: 10.5px; color: var(--text-3); margin-top: 3px; text-align: right; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .bub { background: var(--mine); color: #fff; border-color: var(--mine); border-radius: 16px 16px 4px 16px; }
.msg.mine .bub .tm { color: rgba(255,255,255,.75); }
.msg.mine .bub .nm { display: none; }
.msg .bub .photos { margin-top: 6px; }
.msg .roomtag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 9px; background: var(--brand-50); color: var(--brand); margin-bottom: 4px; }
.msg.mine .roomtag { background: rgba(255,255,255,.2); color: #fff; }
.msg .del { opacity: 0; transition: opacity .1s; }
.msg:hover .del { opacity: 1; }
.msg .deleted { font-style: italic; opacity: .7; }
.day { text-align: center; margin: 16px 0 6px; }
.day span { font-size: 11.5px; font-weight: 700; color: var(--text-3); background: var(--bg); padding: 3px 10px; border-radius: 10px; border: 1px solid var(--border); }
.chat-compose { border-top: 1px solid var(--border); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.chat-compose textarea { min-height: 42px; max-height: 140px; resize: none; border-radius: 21px; padding: 10px 16px; }
.chat-compose .previews { margin: 0 0 8px; }

/* ---------- lists / tables ---------- */
.list > .li { padding: 12px 16px; display: flex; gap: 12px; align-items: center; }
.list > .li + .li { border-top: 1px solid var(--border); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.dim td { opacity: .55; }
.tbl-wrap { overflow-x: auto; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-2); }
.empty svg { color: var(--text-3); margin-bottom: 8px; }

/* punch */
.punch { padding: 12px 14px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.punch + .punch { border-top: 1px solid var(--border); }
.punch .iss { font-weight: 650; white-space: pre-wrap; }
.punch.closed .iss { text-decoration: line-through; color: var(--text-3); }

/* sign-off */
.sign { padding: 14px 16px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.sign + .sign { border-top: 1px solid var(--border); }
.sign img.sig { height: 52px; background: #fff; border-radius: 6px; border: 1px solid var(--border); }
.sigpad { width: 100%; height: 180px; border: 1.5px dashed var(--border-strong); border-radius: 10px; background: #fff; touch-action: none; display: block; }

/* activity */
.act { padding: 10px 16px; display: flex; gap: 10px; font-size: 13.5px; }
.act + .act { border-top: 1px solid var(--border); }
.act .when { color: var(--text-3); font-size: 12px; white-space: nowrap; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 8, 10, .5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .15s ease-out; }
.modal.wide { max-width: 900px; }
.modal-h { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-h h2 { flex: 1; }
.modal-b { padding: 18px; overflow-y: auto; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 640px) {
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(12px); opacity: 0; } }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.94); display: flex; flex-direction: column; animation: fade .12s; }
.lightbox .lb-top { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; color: #fff; }
.lightbox .lb-top .iconbtn { color: #fff; }
.lightbox .lb-img { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: pan-y pinch-zoom; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; background: rgba(255,255,255,.1); border: 0; color: #fff; cursor: pointer; border-radius: 8px; }
.lightbox .nav.prev { left: 10px; } .lightbox .nav.next { right: 10px; }

/* toasts */
#toasts { position: fixed; z-index: 300; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
@media (max-width: 760px) { body.has-tabbar #toasts { bottom: calc(var(--tabbar-h) + 14px + env(safe-area-inset-bottom)); } }
.toast { background: #221D1E; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); animation: pop .15s; pointer-events: auto; max-width: 90vw; }
.toast.err { background: var(--fail); }
.toast.ok { background: var(--pass); }

/* menu */
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 60; }
.menu a, .menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); background: none; border: 0; text-align: left; cursor: pointer; font-size: 14px; font-weight: 550; }
.menu a:hover, .menu button:hover { background: var(--surface-2); text-decoration: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.menu .hd { padding: 8px 10px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand) 0%, var(--brand-700) 100%); }
.login .card { width: 100%; max-width: 400px; padding: 30px 26px; border: 0; }
.login .logo { width: 220px; display: block; margin: 0 auto 6px; }
.login .tag { text-align: center; color: var(--text-2); font-weight: 600; margin-bottom: 22px; font-size: 14px; }

/* admin */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: start; }
.admin-nav { position: sticky; top: calc(var(--header-h) + 18px); padding: 8px; }
.admin-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; color: var(--text-2); font-weight: 650; font-size: 14px; }
.admin-nav a:hover { background: var(--surface-2); text-decoration: none; }
.admin-nav a.active { background: var(--brand-50); color: var(--brand); }
@media (max-width: 900px) { .admin-layout { grid-template-columns: 1fr; } .admin-nav { position: static; display: flex; overflow-x: auto; gap: 4px; } .admin-nav a { flex: none; } }
.master-sec { margin-bottom: 12px; }
.master-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 14px; border-top: 1px solid var(--border); }
.master-item .cnt { font-size: 12px; font-weight: 700; color: var(--text-3); white-space: nowrap; }
.master-item .acts { display: flex; gap: 4px; opacity: .6; }
.master-item:hover .acts { opacity: 1; }
.typechips { display: flex; flex-wrap: wrap; gap: 6px; }
.typechips button { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 16px; padding: 4px 11px; font-size: 12.5px; font-weight: 650; cursor: pointer; color: var(--text-2); }
.typechips button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.pwbox { font-family: var(--mono); font-size: 20px; font-weight: 700; padding: 12px 14px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 10px; text-align: center; letter-spacing: .04em; user-select: all; }
.editbar { display: flex; gap: 4px; flex-wrap: wrap; }
.edit-on .item, .edit-on .trow { outline: 1px dashed var(--border-strong); outline-offset: -3px; }

/* print */
@media print {
  .topbar, .tabbar, .subtabs, .secnav, .composer, .no-print, .actions .mini, #toasts { display: none !important; }
  body { background: #fff; font-size: 11px; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid-page; }
  .section.collapsed .section-b { display: block !important; }
  .item { break-inside: avoid; padding: 5px 8px; }
  .sbtn:not(.on) { display: none; }
  .rows { grid-template-columns: 1fr 1fr; }
  .trow { break-inside: avoid; }
}

/* ---------- refinements ---------- */
.sbtn svg, .chip svg, .mini svg { flex: none; }
@media (min-width: 900px) {
  .item { grid-template-columns: 30px 1fr auto; align-items: start; }
  .item .actions { grid-column: 3; grid-row: 1; margin-top: 0; justify-content: flex-end; flex-wrap: nowrap; }
  .item .actions .grow { display: none; }
  .item .actions .by { order: -1; text-align: right; max-width: 130px; line-height: 1.25; margin-right: 4px; }
  .item .remark, .item .expand { grid-column: 2 / -1; }
}
@media (max-width: 760px) {
  h1 { font-size: 20px; }
  .page-head > .grow { flex-basis: 100%; }
  .stat { padding: 10px 12px; }
  .stat .v { font-size: 22px; }
  .toolbar select.input { flex: 1 1 40%; min-width: 0; }
  .room-head { padding: 14px; gap: 10px; }
  .room-head .nm { font-size: 21px; white-space: nowrap; }
  .room-head .ring { width: 56px; height: 56px; }
  .room-head .ring > span { width: 44px; height: 44px; font-size: 13px; }
  .item { padding: 11px 12px; grid-template-columns: 24px 1fr; gap: 3px 8px; }
  .section-h { padding: 12px; }
  .section-h h2 { font-size: 15px; }
}
.kv-toggle { display: none; }
@media (max-width: 760px) {
  .kv-toggle { display: inline-flex; grid-column: 1 / -1; justify-self: start; }
  .room-head:not(.kv-open) .kv { display: none; }
}
@media (max-width: 760px) {
  .subtabs .seg button { padding: 7px 6px; font-size: 13px; }
  .subtabs .seg button svg { display: none; }
  .chat-compose .iconbtn { width: 36px; }
}
.tabbar .badge-dot { position: absolute; }

/* login page: neutral background (white in light mode, dark in dark mode) */
.login { background: var(--bg); }
.login .card { border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
