:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eef2f7; --border: #d9dee7;
  --text: #0f172a; --muted: #5b6577; --accent: #0369a1; --accent-ink: #ffffff; --accent-soft: #e0f2fe;
  --critical: #b91c1c; --critical-soft: #fee2e2; --warning: #b45309; --warning-soft: #fef3c7;
  --info: #1d4ed8; --info-soft: #dbeafe; --ok: #15803d; --ok-soft: #dcfce7;
  --radius: 12px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --nav-h: 60px; --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #121a2b; --surface-2: #1a2438; --border: #27324a;
    --text: #e6ebf5; --muted: #98a4bb; --accent: #38bdf8; --accent-ink: #06202e; --accent-soft: #0c3550;
    --critical: #f87171; --critical-soft: #3b1414; --warning: #fbbf24; --warning-soft: #3a2a08;
    --info: #93c5fd; --info-soft: #14284d; --ok: #4ade80; --ok-soft: #0f2e1b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: .8em 0 .25em; }
input, select, textarea { width: 100%; padding: .65em .75em; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-height: 44px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 84px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; margin-right: .4em; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .6em; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.right { margin-left: auto; }
.mt { margin-top: 1em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; padding: .6em 1em; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-danger { color: var(--critical); border-color: var(--critical); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: .35em .7em; font-size: .9rem; }
.btn[disabled] { opacity: .6; cursor: wait; }

/* login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: .55em; margin-bottom: 1.2em; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: #0f172a; position: relative; flex: none; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; width: 8px; height: 8px; border-radius: 2px; background: #38bdf8; }
.brand-mark::before { left: 6px; top: 6px; box-shadow: 10px 10px 0 #38bdf8; }
.brand-mark::after { left: 16px; top: 6px; opacity: .55; box-shadow: -10px 10px 0 #38bdf8; }
.brand-name { font-weight: 700; font-size: 1.25rem; letter-spacing: -.01em; }
.form-error { color: var(--critical); font-size: .9rem; margin: .7em 0 0; }
.login-card .btn-block { margin-top: 1.2em; }

/* shell */
.shell { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--safe-b)); }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px; display: flex; align-items: center; gap: 10px; }
.topbar .brand { margin: 0; }
.topbar .brand-name { font-size: 1.05rem; }
.topbar select { width: auto; max-width: 48vw; min-height: 38px; padding: .35em .6em; }
.topbar .user { margin-left: auto; white-space: nowrap; }
.content { padding: 14px 16px 24px; max-width: 1080px; margin: 0 auto; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(6, 1fr); z-index: 20; }
.nav button { background: none; border: 0; padding: 6px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .68rem; color: var(--muted); cursor: pointer; }
.nav button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button.active { color: var(--accent); font-weight: 600; }
.nav .badge { position: absolute; margin-left: 22px; margin-top: -2px; }
@media (min-width: 900px) {
  .shell { padding-bottom: 0; padding-left: 200px; }
  .nav { left: 0; right: auto; top: 0; bottom: 0; width: 200px; height: auto; border-top: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; padding-top: 64px; }
  .nav button { flex-direction: row; gap: 10px; padding: 12px 18px; font-size: .95rem; justify-content: flex-start; }
  .topbar { padding-left: 216px; margin-left: -200px; }
}

/* cards & lists */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.tile .n { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.tile .l { color: var(--muted); font-size: .8rem; }
.tile.critical .n { color: var(--critical); } .tile.warning .n { color: var(--warning); } .tile.ok .n { color: var(--ok); }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; text-align: left; width: 100%; }
.item:hover { background: var(--surface-2); }
.item .thumb { width: 52px; height: 52px; border-radius: 8px; background: var(--surface-2); flex: none; object-fit: cover; display: grid; place-items: center; color: var(--muted); font-size: 1.3rem; overflow: hidden; }
.item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item .body { min-width: 0; flex: 1; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .15em .5em; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.critical { background: var(--critical-soft); color: var(--critical); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: .35em .8em; font-size: .85rem; cursor: pointer; min-height: 36px; }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.seg button { border: 0; background: var(--surface); padding: .5em 1em; min-height: 40px; cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input[type="search"] { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.fab { position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 15; border-radius: 999px; padding: 0 20px; height: 52px; font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
@media (min-width: 900px) { .fab { bottom: 24px; } }

/* sheet (modal) */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 96dvh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; box-shadow: var(--shadow); }
@media (min-width: 720px) { .sheet-back { align-items: center; } .sheet { border-radius: 16px; max-height: 92dvh; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); border-radius: 16px 16px 0 0; }
.sheet-head h2 { margin: 0; flex: 1; font-size: 1.05rem; }
.sheet-body { overflow: auto; padding: 12px 16px calc(16px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 8px; }
.sheet-foot .btn { flex: 1; }
.icon-btn { background: none; border: 0; min-width: 44px; min-height: 44px; font-size: 1.4rem; cursor: pointer; color: var(--muted); border-radius: 10px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 12px 12px; margin: 12px 0; background: var(--surface); }
legend { font-weight: 700; font-size: .9rem; padding: 0 6px; color: var(--muted); }
.yesno { display: flex; gap: 6px; }
.yesno button { flex: 1; }
.yesno button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 999px; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 1rem; line-height: 1; }
.photo .pending { position: absolute; left: 4px; bottom: 4px; }
.photo-add { aspect-ratio: 1; border: 2px dashed var(--border); border-radius: 10px; display: grid; place-items: center; color: var(--muted); cursor: pointer; font-size: .8rem; text-align: center; padding: 6px; background: var(--surface); }
.scanner { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; object-fit: cover; }
.scanner .bar { padding: 12px 16px calc(12px + var(--safe-b)); display: flex; gap: 8px; align-items: center; color: #fff; background: #000; }
.scanner .bar .btn { color: #fff; background: #222; border-color: #444; }

/* detail */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .95rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.gallery { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.gallery img { height: 140px; border-radius: 10px; flex: none; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* findings */
.finding { border-left: 4px solid var(--border); }
.finding.critical { border-left-color: var(--critical); }
.finding.warning { border-left-color: var(--warning); }
.finding.info { border-left-color: var(--info); }
.finding.acked { opacity: .55; }
.finding .t { font-weight: 600; }
.finding .d { color: var(--muted); font-size: .9rem; }
.finding .m { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }

/* tree */
.tree ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed var(--border); }
.tree > ul { padding-left: 0; border: 0; }
.tree li { margin: 6px 0; }
.tree .node { display: inline-flex; gap: 8px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; cursor: pointer; max-width: 100%; }
.tree .node .ic { font-size: 1.1rem; }
.tree .node .nm { font-weight: 600; }
.tree .node .ct { color: var(--muted); font-size: .8rem; }

/* svg map */
.mapbox { overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.mapbox svg { display: block; min-width: 100%; }
.mapbox text { font-family: system-ui, sans-serif; fill: var(--text); }
.mapbox .edge { stroke: var(--muted); stroke-width: 1.5; fill: none; }
.mapbox .edge.wifi { stroke-dasharray: 4 4; }
.mapbox .nodebox { fill: var(--surface-2); stroke: var(--border); }
.mapbox .nodebox.gw { fill: var(--accent-soft); stroke: var(--accent); }
.mapbox .nodebox.infra { fill: var(--info-soft); stroke: var(--info); }
.mapbox .nodebox.bad { stroke: var(--critical); }
.mapbox .cloud { fill: var(--surface-2); stroke: var(--muted); }
.loc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.loc-grid .card { margin: 0; }
.loc-grid .dev { display: flex; gap: 6px; align-items: center; padding: 4px 0; font-size: .92rem; cursor: pointer; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.tablewrap { overflow-x: auto; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 80px); background: var(--text); color: var(--bg); padding: .6em 1em; border-radius: 10px; z-index: 70; box-shadow: var(--shadow); max-width: 92vw; }
.toast.err { background: var(--critical); color: #fff; }
.temp-pw { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.1rem; background: var(--surface-2); padding: .5em .7em; border-radius: 8px; user-select: all; word-break: break-all; }
.notice { background: var(--warning-soft); color: var(--warning); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: .92rem; }
