:root {
  --blue: #004d93;
  --blue-2: #0b62b5;
  --red: #e3111b;
  --ink: #1b1f24;
  --ink-2: #4b5563;
  --muted: #6b7280;
  --line: #e2e6ea;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --sea: #d6e8f5;
  --warn: #b45309;
  --ok: #047857;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(16, 24, 40, 0.12);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; }
input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; }
.brand-title { font-weight: 700; color: var(--blue); }
.brand-sub { font-size: 12px; color: var(--muted); }
.search { position: relative; flex: 1; max-width: 460px; }
.search svg { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search input { width: 100%; padding: 9px 12px 9px 36px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); outline: none; }
.search input:focus { border-color: var(--blue-2); background: #fff; box-shadow: 0 0 0 3px rgba(11, 98, 181, 0.15); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 20; max-height: 380px; overflow: auto; }
.search-results li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.search-results li[aria-selected="true"], .search-results li:hover { background: #eef4fb; }
.search-results .nr { font-weight: 700; font-variant-numeric: tabular-nums; width: 44px; }
.search-results .who { margin-left: auto; font-size: 12px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.me { font-size: 12px; color: var(--muted); max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { background: #f3f5f7; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-2); }
.btn-danger { color: #b91c1c; border-color: #f3c4c4; }
.btn-danger:hover { background: #fdf0f0; }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn[aria-pressed="true"] { background: #fff4e5; border-color: #f0b46a; color: #8a4b00; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 18px; line-height: 1; color: var(--ink); }
.icon-btn:hover { background: #f3f5f7; }

.banner { display: flex; gap: 10px; align-items: center; padding: 8px 16px; background: #fff7e6; border-bottom: 1px solid #f5d9a8; color: #7a4a00; font-size: 14px; }
.banner span { margin-right: auto; }

/* layout */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 310px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; }
.tab { flex: 1; padding: 8px; border: none; background: none; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-weight: 600; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.panel { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel-tools { display: flex; gap: 8px; align-items: center; padding: 10px 12px; justify-content: space-between; }
.panel-tools input { flex: 1; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.list { overflow: auto; padding: 0 8px 12px; flex: 1; }
.group-h { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 6px 4px; display: flex; align-items: center; gap: 6px; }
.group-h i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.item:hover { background: #f3f6f9; }
.item.active { background: #eaf2fb; border-color: #c6dcf3; }
.item.brush { background: #fff4e5; border-color: #f0b46a; }
.swatch { width: 22px; height: 22px; border-radius: 6px; flex: none; border: 1px solid rgba(0, 0, 0, .15); }
.item .code { font-weight: 700; font-size: 14px; }
.item .name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { margin-left: auto; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.item .txt { min-width: 0; flex: 1; }
.item .edit { opacity: 0; border: none; background: none; cursor: pointer; padding: 4px; border-radius: 6px; color: var(--ink-2); }
.item:hover .edit { opacity: 1; }
.item .edit:hover { background: #e5e9ee; }
.brush-hint { margin: 10px 12px 0; padding: 8px 10px; border-radius: 8px; background: #fff4e5; color: #7a4a00; font-size: 13px; }
.brush-hint b { color: #5a3400; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 10px 14px; display: grid; gap: 6px; font-size: 13px; }
.toggle { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.stats { font-size: 12px; color: var(--muted); }
.stats b { color: #b91c1c; }

/* map */
.map-wrap { position: relative; flex: 1; min-width: 0; background: var(--sea); }
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map.editing { cursor: crosshair; }
#map:active { cursor: grabbing; }
#map.editing:active { cursor: crosshair; }
.area { stroke: #5f6368; stroke-width: .35; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.area:hover { filter: brightness(.93); }
.area.dim { opacity: .28; }
.area.pending { stroke: #111; stroke-width: 1.6; stroke-dasharray: 3 2; }
.mesh-tech { fill: none; stroke: #2b2b2b; stroke-width: .9; vector-effect: non-scaling-stroke; pointer-events: none; }
.mesh-coord { fill: none; stroke: var(--red); stroke-width: 3; vector-effect: non-scaling-stroke; pointer-events: none; stroke-linejoin: round; stroke-linecap: round; }
.mesh-coast { fill: none; stroke: #47657a; stroke-width: .7; vector-effect: non-scaling-stroke; pointer-events: none; }
.hl { fill: none; stroke: #111; stroke-width: 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.hl-pulse { animation: pulse 1.2s ease-out 2; }
@keyframes pulse { 0% { stroke-width: 9; stroke-opacity: .2 } 100% { stroke-width: 3; stroke-opacity: 1 } }
.lbl { pointer-events: none; font-family: Arial, Helvetica, sans-serif; text-anchor: middle; dominant-baseline: central; }
.lbl-pc { fill: #222; }
.lbl-tech { fill: var(--red); font-weight: 700; paint-order: stroke; stroke: #fff; stroke-linejoin: round; }
.lbl-coord { fill: #fff; font-weight: 700; paint-order: stroke; stroke: rgba(30, 30, 30, .75); stroke-linejoin: round; letter-spacing: .04em; }
.inset-frame { fill: var(--sea); stroke: #47657a; stroke-width: .8; vector-effect: non-scaling-stroke; }
.inset-title { font: 700 11px Arial, sans-serif; fill: var(--blue); text-anchor: middle; }
.map-tools { position: absolute; right: 14px; bottom: 18px; display: grid; gap: 6px; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-2); background: rgba(214, 232, 245, .7); font-weight: 600; }
.loading.error { color: #991b1b; background: #fff; padding: 24px; text-align: center; white-space: pre-line; }
.tooltip { position: absolute; pointer-events: none; background: rgba(20, 24, 30, .92); color: #fff; padding: 6px 9px; border-radius: 7px; font-size: 12px; white-space: nowrap; z-index: 6; }
.tooltip b { font-weight: 700; }

.card { position: absolute; top: 14px; right: 14px; width: 300px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 14px; z-index: 7; font-size: 14px; }
.card h3 { margin: 0 32px 2px 0; font-size: 18px; }
.card .sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.card .close { position: absolute; top: 8px; right: 8px; }
.card label { display: block; font-size: 12px; color: var(--ink-2); margin: 10px 0 4px; }
.card select { width: 100%; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.card .row { display: flex; align-items: center; gap: 8px; }
.card .contact { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.card .contact a { color: var(--blue-2); }
.card .foot { margin-top: 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }
.card .pcs { font-size: 12px; color: var(--ink-2); max-height: 64px; overflow: auto; }

/* pending */
.pending-bar { position: fixed; left: 50%; bottom: 18px; translate: -50% 0; display: flex; gap: 8px; align-items: center; background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; z-index: 15; border: 1px solid #f0b46a; width: min(720px, calc(100vw - 32px)); }
.pending-bar span { font-weight: 600; color: #8a4b00; white-space: nowrap; }
.pending-bar input { flex: 1; min-width: 0; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); }

/* drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: #fff; box-shadow: var(--shadow); z-index: 30; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.drawer-head .tabs { flex: 1; padding: 0; }
.drawer-body { overflow: auto; flex: 1; padding: 12px; }
.batch { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; cursor: pointer; }
.batch:hover { border-color: #c6dcf3; }
.batch.active { border-color: var(--blue-2); box-shadow: 0 0 0 2px rgba(11, 98, 181, .15); }
.batch-h { display: flex; gap: 8px; align-items: baseline; }
.batch-h b { font-size: 14px; }
.batch-h .when { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.batch .who { font-size: 12px; color: var(--ink-2); }
.batch .note { font-size: 13px; margin-top: 4px; font-style: italic; }
.batch ul { margin: 6px 0 0; padding-left: 16px; font-size: 13px; color: var(--ink-2); }
.batch .acts { margin-top: 8px; display: flex; gap: 6px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: #eef1f4; color: var(--ink-2); }
.tag.rev { background: #fde8e8; color: #991b1b; }
.mini-sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, .2); }

/* dialog */
.dlg { border: none; border-radius: 14px; padding: 0; box-shadow: var(--shadow); width: min(520px, calc(100vw - 32px)); }
.dlg.wide { width: min(980px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(15, 23, 42, .4); }
.dlg form, .dlg .body { padding: 18px 20px; }
.dlg h2 { margin: 0 0 12px; font-size: 18px; }
.dlg .field { margin-bottom: 12px; }
.dlg .field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.dlg .field input, .dlg .field select, .dlg .field textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.dlg .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; align-items: center; }
.dlg .acts .left { margin-right: auto; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.palette button { width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, .2); cursor: pointer; padding: 0; }
.palette button.used { opacity: .35; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] { width: 46px; height: 36px; padding: 2px; }
.err { color: #b91c1c; font-size: 13px; min-height: 18px; }
.pdf-layout { display: grid; grid-template-columns: 280px 1fr; gap: 18px; }
.pdf-preview { background: #e9edf1; border-radius: 10px; display: grid; place-items: center; padding: 10px; height: 70vh; overflow: hidden; }
.pdf-preview svg { height: 100%; width: auto; box-shadow: 0 2px 12px rgba(0, 0, 0, .18); background: #fff; }
.checks { display: grid; gap: 6px; font-size: 14px; }
.conflicts { max-height: 220px; overflow: auto; font-size: 13px; background: #fafafa; border-radius: 8px; padding: 8px 12px; }

.toasts { position: fixed; left: 50%; top: 70px; translate: -50% 0; display: grid; gap: 8px; z-index: 50; }
.toast { background: #1f2937; color: #fff; padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow); font-size: 14px; max-width: 520px; }
.toast.error { background: #991b1b; }
.toast.ok { background: var(--ok); }

/* login */
.auth { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: linear-gradient(160deg, #e8f1fa, #d6e8f5); padding: 16px; }
.auth-card { width: min(420px, 100%); background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.auth-card .brand { margin-bottom: 18px; }
.auth-card h1 { font-size: 22px; margin: 0 0 8px; }
.auth-card form { display: grid; gap: 12px; margin-top: 14px; }
.auth-card label { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.auth-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
.auth-card input:focus { outline: none; border-color: var(--blue-2); box-shadow: 0 0 0 3px rgba(11, 98, 181, .15); }
.auth-card .btn { justify-content: center; padding: 10px; font-weight: 600; }
.auth-card a { color: var(--blue-2); }
/* users */
.u-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.u-add input:not([type=checkbox]) { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; flex: 1; min-width: 140px; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
table.users th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); }
table.users td { padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.u-acts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.invite-box { background: #eef6ee; border: 1px solid #b9dcbc; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; display: grid; gap: 6px; }
.invite-box .row { display: flex; gap: 6px; }
.invite-box input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }

@media (max-width: 900px) {
  .sidebar { width: 250px; }
  .brand-sub, .btn span, .me { display: none; }
  .brand { min-width: 0; }
  .pdf-layout { grid-template-columns: 1fr; }
  .pdf-preview { height: 45vh; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .topbar { gap: 8px; padding: 8px 10px; }
  .brand > div { display: none; }
  .search { min-width: 0; }
  .top-actions { gap: 4px; }
  .card { left: 14px; width: auto; }
}
@media print { body { display: none; } }
