:root {
  --navy: #1F3864;
  --navy-2: #2B4A7E;
  --navy-ink: #13254A;
  --blue-soft: #D9E1F2;
  --blue-pale: #EEF2F9;
  --accent: #2F6FD0;
  --bg: #F4F6FA;
  --panel: #FFFFFF;
  --line: #DCE2EC;
  --line-2: #C7D0DE;
  --ink: #1B2333;
  --ink-2: #4A5568;
  --ink-3: #7A8699;
  --good: #1E8E4E; --good-bg: #DDF3E5;
  --fair: #A86B00; --fair-bg: #FFF0C2;
  --poor: #C0392B; --poor-bg: #FBDCD8;
  --na: #6B7584;   --na-bg: #E8EBF0;
  --c1: #D93025; --c2: #E8A200; --c3: #1E8E4E;
  --radius: 6px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 13px/1.4 var(--font); color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
#app { display: grid; grid-template-columns: 208px 1fr; height: 100vh; }

/* ---------- sidebar ---------- */
#side { background: var(--navy); color: #fff; display: flex; flex-direction: column; padding: 14px 10px; gap: 14px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 12px; border-bottom: 1px solid rgba(255,255,255,.14); }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; font-size: 17px; letter-spacing: .5px; }
.brand span { display: block; font-size: 10.5px; opacity: .72; line-height: 1.25; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.86); text-decoration: none; padding: 8px 10px; border-radius: var(--radius); font-weight: 500; }
nav a svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav a.active { background: #fff; color: var(--navy); }
.side-foot { margin-top: auto; font-size: 11px; opacity: .75; padding: 0 8px; display: grid; gap: 4px; }
.side-foot .link { color: #fff; text-align: left; padding: 0; }

/* ---------- main ---------- */
#main-wrap { display: flex; flex-direction: column; min-height: 0; min-width: 0; height: 100vh; }
#main { overflow: auto; position: relative; flex: 1; }
#warn-banner { background: #FFF0C2; color: #5C3D00; border-bottom: 1px solid #F3DE9C; padding: 8px 26px; font-weight: 600; font-size: 12.5px; }
#warn-banner[hidden] { display: none; }
code { background: var(--blue-pale); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.page { padding: 20px 26px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; font-weight: 650; color: var(--navy-ink); }
.page-head .sub { color: var(--ink-3); }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: #fff; padding: 6px 12px; border-radius: var(--radius); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--navy-2); }
.btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { color: var(--poor); }
.btn.danger:hover { border-color: var(--poor); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--blue-pale); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }

/* ---------- cards / forms ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 16px; }
.card > h2 { margin: 0; font-size: 13.5px; font-weight: 650; letter-spacing: .3px; text-transform: uppercase; color: #fff; background: var(--navy); padding: 8px 14px; border-radius: 7px 7px 0 0; display: flex; align-items: center; gap: 10px; }
.card > h2 .n { opacity: .65; }
.card > h2 .right { margin-left: auto; text-transform: none; font-weight: 500; letter-spacing: 0; font-size: 12px; opacity: .85; }
.card-body { padding: 14px; }
.sub-h { font-size: 12px; font-weight: 650; color: var(--navy); text-transform: uppercase; letter-spacing: .4px; margin: 16px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: baseline; }
.sub-h:first-child { margin-top: 0; }
.sub-h .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px 16px; }
.fld { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fld > label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; }
.fld.req > label::after { content: " *"; color: var(--poor); }
.inp, .fld input, .fld select, .fld textarea, .tbl-in {
  border: 1px solid var(--line-2); border-radius: 5px; padding: 5px 8px; background: #fff; min-height: 30px; width: 100%;
}
.fld textarea { min-height: 56px; resize: vertical; }
.inp:focus, .fld input:focus, .fld select:focus, .fld textarea:focus, .tbl-in:focus { outline: 2px solid rgba(47,111,208,.35); border-color: var(--accent); }
.fld input.big { font-size: 16px; font-weight: 650; }
.fld .err { color: var(--poor); font-size: 11.5px; }
input.invalid { border-color: var(--poor) !important; background: #FFF6F5; }
select.empty, select:invalid { color: var(--ink-3); }
select option { color: var(--ink); }

/* segmented choice (conditions, critical level, yes/no) */
.fld > .seg { align-self: flex-start; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 5px; overflow: hidden; background: #fff; min-height: 30px; }
.seg button { border: 0; background: transparent; padding: 0 10px; cursor: pointer; font-weight: 600; font-size: 12px; color: var(--ink-2); border-right: 1px solid var(--line); min-width: 38px; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--blue-pale); }
.seg button.on { color: #fff; }
.seg button.on[data-v="Good"], .seg button.on[data-v="C3"] { background: var(--good); }
.seg button.on[data-v="Fair"], .seg button.on[data-v="C2"] { background: var(--c2); color: #2a1d00; }
.seg button.on[data-v="Poor"], .seg button.on[data-v="C1"] { background: var(--poor); }
.seg button.on[data-v="N/A"] { background: var(--na); }
.seg button.on.plain { background: var(--navy); }

/* visual check / component tables */
.vtable { width: 100%; border-collapse: collapse; }
.vtable th { text-align: left; font-size: 11.5px; color: var(--ink-2); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.vtable td { padding: 4px 6px; border-bottom: 1px solid #EEF1F6; vertical-align: middle; }
.vtable tr:last-child td { border-bottom: 0; }
.vtable td.item { width: 32%; font-weight: 500; }
.vtable td.cond { width: 210px; }
.ctable td { padding: 3px 4px; }
.ctable .num { width: 30px; color: var(--ink-3); text-align: right; }
.ctable .qty { width: 64px; }
.ctable .rm { width: 32px; }
.tbl-in { min-height: 28px; padding: 3px 6px; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 4px; border-radius: 4px; display: inline-flex; }
.icon-btn:hover { color: var(--poor); background: var(--poor-bg); }
.icon-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ---------- editor header ---------- */
.edit-bar { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line); padding: 10px 26px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.edit-bar .title { font-size: 19px; font-weight: 700; color: var(--navy-ink); }
.edit-bar .state { font-size: 12px; color: var(--ink-3); }
.edit-bar .state.dirty { color: var(--fair); font-weight: 600; }
.edit-wrap { padding: 16px 26px 80px; max-width: 1280px; }
.edit-layout { display: grid; grid-template-columns: 180px 1fr; gap: 20px; align-items: start; }
.toc { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; }
.toc a { color: var(--ink-2); text-decoration: none; padding: 5px 10px; border-radius: 5px; border-left: 3px solid transparent; }
.toc a:hover { background: #fff; }
.toc a.on { color: var(--navy); font-weight: 600; border-left-color: var(--navy); background: #fff; }
.toc .prog { font-size: 11px; color: var(--ink-3); padding: 8px 10px 0; }

/* chips */
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 650; }
.chip.C1 { background: var(--c1); color: #fff; }
.chip.C2 { background: var(--c2); color: #2a1d00; }
.chip.C3 { background: var(--c3); color: #fff; }
.chip.Good { background: var(--good-bg); color: var(--good); }
.chip.Fair { background: var(--fair-bg); color: var(--fair); }
.chip.Poor { background: var(--poor-bg); color: var(--poor); }
.chip.NA { background: var(--na-bg); color: var(--na); }

/* ---------- tag list ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.search { position: relative; flex: 1; min-width: 240px; max-width: 420px; }
.search input { padding-left: 30px; }
.search svg { position: absolute; left: 9px; top: 8px; width: 15px; height: 15px; fill: none; stroke: var(--ink-3); stroke-width: 2; }
.toolbar select { width: auto; }
.list { background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { position: sticky; top: 0; background: var(--blue-pale); text-align: left; font-size: 11.5px; font-weight: 650; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
table.data th .arr { opacity: .5; }
table.data td { padding: 7px 10px; border-bottom: 1px solid #EEF1F6; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: #F6F9FE; }
table.data td.tag { font-weight: 650; color: var(--navy-ink); }
.empty { padding: 48px 20px; text-align: center; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }
.empty .btn { margin: 14px 4px 0; }

/* ---------- photos ---------- */
.photos { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.ph { display: flex; flex-direction: column; gap: 6px; }
.ph .slot { aspect-ratio: 4/3; border: 1.5px dashed var(--line-2); border-radius: 6px; background: var(--blue-pale); display: flex; align-items: center; justify-content: center; text-align: center; color: var(--ink-3); cursor: pointer; position: relative; overflow: hidden; font-size: 12px; padding: 8px; }
.ph .slot:hover, .ph .slot.drag { border-color: var(--accent); color: var(--accent); }
.ph .slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ph .slot .x { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 4px; padding: 2px 7px; cursor: pointer; font-size: 12px; z-index: 2; }
.ph .slot .busy { position: absolute; inset: 0; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; z-index: 3; color: var(--navy); font-weight: 600; }
.ph .lbl { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }

/* ---------- dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; border-top: 4px solid var(--navy); }
.tile .k { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.tile .v { font-size: 30px; font-weight: 700; color: var(--navy-ink); line-height: 1.15; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 11.5px; color: var(--ink-3); }
.tile.C1 { border-top-color: var(--c1); } .tile.C2 { border-top-color: var(--c2); } .tile.C3 { border-top-color: var(--c3); }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 70px; gap: 10px; align-items: center; font-size: 12.5px; }
.bar-row .track { height: 14px; background: var(--blue-pale); border-radius: 3px; overflow: hidden; display: flex; }
.bar-row .track span { display: block; height: 100%; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.stack-legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--ink-2); margin-bottom: 10px; }
.stack-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
table.mini { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.mini th, table.mini td { padding: 5px 8px; border-bottom: 1px solid #EEF1F6; text-align: right; font-variant-numeric: tabular-nums; }
table.mini th:first-child, table.mini td:first-child { text-align: left; }
table.mini th { font-size: 11.5px; color: var(--ink-2); background: var(--blue-pale); }
table.mini tr.tot td { font-weight: 700; border-top: 1px solid var(--line-2); }

/* ---------- reports screen ---------- */
.rep-layout { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }
.rep-side { position: sticky; top: 16px; display: grid; gap: 12px; }
.rep-list { max-height: calc(100vh - 360px); overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.rep-list label { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-bottom: 1px solid #EEF1F6; cursor: pointer; }
.rep-list label:hover { background: #F6F9FE; }
.rep-list label.cur { background: var(--blue-soft); }
.rep-list .t { font-weight: 600; flex: 1; }
.preview { background: #8A94A6; border-radius: 8px; padding: 22px; overflow: auto; max-height: calc(100vh - 110px); }
.preview .sheet { margin: 0 auto 22px; box-shadow: 0 4px 20px rgba(0,0,0,.25); }
.radio-row { display: flex; gap: 6px; }

/* ---------- modal / toast ---------- */
#modal { position: fixed; inset: 0; background: rgba(15,25,45,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
#modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 10px; width: min(620px, 92vw); max-height: 86vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-box h3 { margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--line); font-size: 15px; }
.modal-box .mb { padding: 16px 18px; }
.modal-box .mf { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--navy-ink); color: #fff; padding: 9px 16px; border-radius: 6px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: 80vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--poor); }
.note { background: var(--blue-pale); border: 1px solid var(--blue-soft); border-radius: 6px; padding: 10px 12px; color: var(--ink-2); font-size: 12.5px; }
.note.warn { background: #FFF6DD; border-color: #F3DE9C; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 12.5px; }
.kv b { color: var(--ink-2); font-weight: 600; }
textarea.list-edit { width: 100%; min-height: 240px; font-family: var(--font); }

#print-root { display: none; }

@media (max-width: 1100px) {
  .edit-layout { grid-template-columns: 1fr; }
  .toc { display: none; }
  .photos { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .dgrid { grid-template-columns: 1fr; }
}

/* ---------- printing ---------- */
@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff; height: auto; }
  #app, #toast, #modal { display: none !important; }
  #print-root { display: block; }
}

/* ---------- sign-in (AVeRD Server) ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--navy); grid-column: 1 / -1; }
.login-card { background: #fff; border-radius: 10px; width: min(400px, 100%); padding: 26px 26px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h2 { font-size: 18px; margin: 18px 0 6px; color: var(--navy-ink); }
.login-card form { display: grid; gap: 12px; margin-top: 12px; }
.login-card .btn { justify-content: center; padding: 9px 12px; }
.login-card .err { color: var(--poor); font-size: 12.5px; min-height: 1em; }
.login-brand { display: flex; gap: 12px; align-items: center; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.login-brand img { width: 40px; height: 40px; background: var(--navy); border-radius: 8px; padding: 4px; }
.login-brand b { display: block; font-size: 18px; color: var(--navy-ink); }
.login-brand span { font-size: 12px; color: var(--ink-3); }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #side { flex-direction: row; flex-wrap: wrap; padding: 8px 10px; gap: 6px; }
  .brand { border: 0; padding: 0 6px 0 0; }
  .brand span { display: none; }
  nav { flex-direction: row; flex-wrap: wrap; }
  nav a { padding: 6px 8px; }
  .side-foot { display: none; }
  #main-wrap { height: auto; }
  .page, .edit-wrap { padding-left: 12px; padding-right: 12px; }
  .grid3, .grid4, .tiles, .photos { grid-template-columns: 1fr 1fr; }
  .rep-layout { grid-template-columns: 1fr; }
}

/* ---------- team, status, setup wizard ---------- */
.note.ok { background: var(--good-bg); border-color: #B9E3C8; color: #14532D; }
.chip.admin { background: var(--navy); color: #fff; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #C7CED9; margin-right: 8px; vertical-align: 1px; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px rgba(30,142,78,.18); }
.team-add { display: grid; grid-template-columns: 1.4fr 1fr 140px auto; gap: 10px; align-items: end; }
.btn.small { padding: 3px 8px; font-size: 12px; }
table.team-t td.acts { white-space: nowrap; text-align: right; }
table.team-t tr.off td { opacity: .55; }
table.team-t tbody tr { cursor: default; }
table.data td.wrap { white-space: normal; max-width: 420px; }
table.data tr.warnrow td { background: #FFF6F5; }
.seg.tabs button { padding: 0 16px; min-height: 32px; }
.tile .small-v { font-size: 18px; padding: 6px 0 3px; }
pre.cred { background: var(--blue-pale); border: 1px solid var(--blue-soft); border-radius: 6px; padding: 12px; white-space: pre-wrap; font: 13px/1.5 Consolas, "Cascadia Mono", monospace; user-select: all; }
.kv span.wrap { word-break: break-all; }
.wiz { max-width: 900px; }
.wiz-steps { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.wiz-step { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 5px 12px 5px 5px; cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 12.5px; }
.wiz-step span { width: 22px; height: 22px; border-radius: 50%; background: var(--blue-pale); display: inline-flex; align-items: center; justify-content: center; font-size: 11.5px; }
.wiz-step.on { border-color: var(--navy); color: var(--navy); }
.wiz-step.on span { background: var(--navy); color: #fff; }
.wiz-step.done span { background: var(--good); color: #fff; }
.wiz-body h2 { margin: 2px 0 8px; font-size: 19px; color: var(--navy-ink); }
.wiz-body p { max-width: 70ch; }
.wiz-list { line-height: 1.8; padding-left: 20px; }
.wiz-foot { display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--line); margin-top: 20px; padding-top: 14px; }
details.howto { background: var(--blue-pale); border: 1px solid var(--blue-soft); border-radius: 6px; padding: 8px 12px; margin: 10px 0 14px; }
details.howto summary { cursor: pointer; font-weight: 600; color: var(--navy); }
details.howto ol { line-height: 1.8; margin: 8px 0 2px; }
@media (max-width: 760px) { .team-add { grid-template-columns: 1fr 1fr; } table.team-t td.acts { white-space: normal; } }

[hidden] { display: none !important; }
