:root {
  --bg: #f6f7f9; --card: #fff; --fg: #1d2330; --muted: #6b7385; --line: #e2e5eb;
  --accent: #2f6fde; --yes: #1f8a4c; --partial: #b7791f; --no: #b8bcc6;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171d; --card: #1c2029; --fg: #e6e9ef; --muted: #98a0b3; --line: #2c3240;
          --accent: #6b9cff; --yes: #4cc483; --partial: #e0a84a; --no: #555c6b; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--fg); }
header { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
header h1 { margin: 0; font-size: 1.3rem; }
.sub { color: var(--muted); }
.spacer { flex: 1; }
.layout { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; padding: 1rem; }
aside { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .8rem; max-height: calc(100vh - 90px); overflow: auto; position: sticky; top: 70px; }
main { min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .9rem 1rem; margin-bottom: 1rem; }
h2 { font-size: 1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: 12px; }
input[type=number], input[type=search] { padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--fg); }
input[type=search] { width: 100%; margin: .4rem 0; }
label { display: flex; flex-direction: column; gap: .2rem; font-size: 12px; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; gap: .35rem; color: var(--fg); }
button { cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 5px; padding: .3rem .7rem; font: inherit; }
button.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .5; cursor: wait; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: .6rem 1rem; }
.presets { display: flex; gap: .4rem; align-items: end; }
.presets .tier { flex: 1; }
.presets select { width: 100%; padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--fg); font: inherit; font-size: 13px; }
.presets button { font-size: 12px; padding: .3rem .6rem; }
details.cat { margin: .3rem 0; }
details.cat summary { cursor: pointer; font-weight: 600; }
.app { display: flex; flex-direction: row; gap: .4rem; align-items: flex-start; padding: .1rem 0 .1rem .4rem; font-size: 13px; }
.app small { color: var(--muted); display: block; }
.sizing { margin-top: .8rem; display: grid; grid-template-columns: 300px 1fr; gap: 1rem; }
.spec { display: flex; gap: .6rem; }
.spec div { flex: 1; text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; }
.spec b { display: block; font-size: 1.5rem; }
.spec .ovr { width: 4.5em; text-align: center; margin-top: .2rem; }
.breakdown { max-height: min(70vh, 560px); overflow: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 1rem 2rem; margin-bottom: .6rem; }
.filters .wide { flex: 1 1 600px; }
.chips { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.chip { border: 1px solid var(--line); border-radius: 12px; padding: .1rem .55rem; cursor: pointer; user-select: none; font-size: 12px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs { display: flex; gap: .3rem; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: .5rem; margin-bottom: .6rem; }
.tabs button[data-tab] { background: transparent; color: var(--fg); border-color: transparent; }
.tabs button[data-tab].active { border-color: var(--accent); color: var(--accent); }
.hidden { display: none; }
.tab { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { padding: .3rem .45rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--card); cursor: pointer; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.row:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); cursor: pointer; }
.total { font-weight: 700; }
.badge { display: inline-block; min-width: 2.6em; text-align: center; border-radius: 4px; padding: 0 .25rem; margin-right: 2px; font-size: 11px; color: #fff; }
.badge.yes { background: var(--yes); } .badge.partial { background: var(--partial); } .badge.no { background: var(--no); }
.conf-low { color: var(--partial); } .conf-medium { color: var(--muted); }
.lat { font-variant-numeric: tabular-nums; text-align: right; }
.matrix td.lat { min-width: 2.6em; font-size: 11.5px; }
.matrix th.city { writing-mode: vertical-rl; transform: rotate(180deg); height: 8em; font-weight: 500; }
dialog { max-width: 1000px; width: 92vw; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.notes p, .notes li { max-width: 1000px; }
.warn { border-left: 3px solid var(--partial); padding: .3rem .7rem; background: color-mix(in srgb, var(--partial) 10%, transparent); margin: .5rem 0; }
.cmp { margin-top: .5rem; font-size: 13px; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } aside { position: static; max-height: none; } .sizing { grid-template-columns: 1fr; } .grid4 { grid-template-columns: repeat(2, 1fr); } }

#editor table select { min-width: 7.5em; }
#editor table input, #editor table select { width: 100%; min-width: 4em; padding: .2rem .3rem; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--fg); font: inherit; }
#editor table input.w-name { min-width: 9em; } #editor table input.w-note { min-width: 10em; }
#editor textarea { width: 100%; min-height: 7em; font: 12px ui-monospace, monospace; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 5px; }
#editor .row-inline { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; margin: .5rem 0; }
#editor .actions { display: flex; gap: .5rem; margin-top: 1rem; }
#editor .err { color: #c0392b; }
.dlg-close { display: flex; justify-content: flex-end; margin: .5rem 0 0; }
.dlg-close.top { float: right; margin: .9rem 0 0 1rem; }

/* account menu & dialogs */
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); min-width: 190px; padding: .3rem; z-index: 10; display: flex; flex-direction: column; }
.menu-list.hidden { display: none; }
.menu-list button { background: transparent; color: var(--fg); border: 0; text-align: left; padding: .4rem .6rem; border-radius: 5px; }
.menu-list button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.menu-info { padding: .3rem .6rem .4rem; border-bottom: 1px solid var(--line); margin-bottom: .2rem; }
#account { max-width: 900px; }
#account input, #account select { padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--fg); font: inherit; }
#account .row-inline { display: flex; gap: .8rem; flex-wrap: wrap; align-items: end; margin: .6rem 0; }
#account td button { font-size: 12px; padding: .15rem .5rem; }
.newkey { font: 13px ui-monospace, monospace; padding: .6rem; border: 1px dashed var(--accent); border-radius: 6px; word-break: break-all; background: var(--bg); }
.err { color: #c0392b; } .ok { color: var(--yes); }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 .3rem; }
/* login page */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(360px, 92vw); display: flex; flex-direction: column; gap: .7rem; padding: 1.6rem; }
.login-card h1 { margin: 0; }
.login-card input { padding: .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); font: inherit; font-size: 14px; }
.login-card button { padding: .5rem; }
