:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c2430;
  --panel: #131922;
  --line: #232c39;
  --line-2: #2d3848;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #38bdf8;
  --accent-2: #22d3ee;
  --ref: #f59e0b;
  --meas: #34d399;
  --danger: #f87171;
  --warn-bg: #2a210f;
  --warn-line: #5a4410;
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(56, 189, 248, 0.10), transparent 60%),
    radial-gradient(700px 500px at -10% 0%, rgba(34, 211, 238, 0.06), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 17, 23, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo-link { display: block; flex: none; border-radius: 6px; transition: opacity 0.15s ease; }
.brand-logo-link:hover { opacity: 0.8; }
.brand-logo-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.brand-logo { height: 46px; width: auto; flex: none; display: block; }
.brand-divider { width: 1px; height: 34px; background: var(--line-2); flex: none; }
.brand-text h1 {
  font-size: 18px; margin: 0; letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 8px;
}
.brand-by {
  font-size: 11px; font-weight: 500; letter-spacing: 0.02em;
  color: var(--muted); text-transform: none;
}
.brand-text p { font-size: 12px; margin: 2px 0 0; color: var(--muted); }

.brand-right { display: flex; align-items: center; gap: 18px; }
.client {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  padding-right: 18px; border-right: 1px solid var(--line);
}
.client-label {
  font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted);
}
.client-logo { height: 46px; width: auto; display: block; }
.brand-badge {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em;
  color: #fbbf24; border: 1px solid rgba(251,191,36,.45);
  padding: 5px 11px; border-radius: 999px; background: rgba(251,191,36,.1); flex: none;
}
@media (max-width: 720px) {
  .brand-text p, .brand-badge { display: none; }
  .brand-logo { height: 38px; }
  .client { border-right: none; padding-right: 0; }
}

/* Tabs */
.tabs {
  display: flex; gap: 4px; padding: 12px 20px 0;
  overflow-x: auto; border-bottom: 1px solid var(--line);
  position: sticky; top: 77px; background: var(--bg); z-index: 15;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent; border: none; color: var(--muted);
  font-size: 13.5px; font-weight: 500; padding: 12px 16px;
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-num {
  font-family: var(--mono); font-size: 11px;
  width: 20px; height: 20px; display: grid; place-items: center;
  border-radius: 6px; background: var(--bg-3); color: var(--muted);
}
.tab.active .tab-num { background: var(--accent); color: #04222f; }

/* Layout */
main { max-width: 1680px; margin: 0 auto; padding: 22px 28px 32px; }
.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-head { margin-bottom: 22px; }
.panel-head h2 { margin: 0 0 8px; font-size: 22px; letter-spacing: -0.02em; }
.panel-head p { margin: 0; color: var(--muted); line-height: 1.55; }

.warn {
  margin-top: 12px; padding: 12px 14px; border-radius: 10px;
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  color: #f3d8a0; font-size: 13px; line-height: 1.5;
}
.warn strong { color: #fbbf24; }
.panel-head.compact { margin-bottom: 14px; }
.warn-collapse { padding: 9px 14px; }
.warn-collapse summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.warn-collapse summary::-webkit-details-marker { display: none; }
.warn-collapse summary::before { content: "\25B8"; color: #fbbf24; font-size: 11px; transition: transform .15s ease; }
.warn-collapse[open] summary::before { transform: rotate(90deg); }
.warn-collapse .warn-body { margin-top: 8px; }

.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

/* Buttons */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 10px 16px; border-radius: 9px; cursor: pointer;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line-2);
  transition: background .15s, transform .05s, border-color .15s, opacity .15s;
}
.btn:hover { background: #232d3b; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04222f; border-color: transparent;
}
.btn.primary:hover { filter: brightness(1.07); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-2); }
.btn.danger { color: var(--danger); border-color: #4a2530; }
.btn.danger:hover { background: #2a1a1f; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.full { width: 100%; margin-top: 6px; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--line-2); border-radius: var(--radius);
  background: var(--bg-2); padding: 48px 24px; text-align: center;
  cursor: pointer; transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: #182230; }
.dz-icon {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 12px;
  background: var(--bg-3); border: 1px solid var(--line-2); position: relative;
}
.dz-icon::before {
  content: ""; position: absolute; left: 50%; top: 54%; width: 16px; height: 16px;
  border-left: 2.5px solid var(--accent); border-top: 2.5px solid var(--accent);
  transform: translate(-50%, -50%) rotate(45deg);
}
.dz-icon::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 2.5px; height: 22px;
  background: var(--accent); transform: translate(-50%, -40%);
}
.dz-title { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
.dz-sub { color: var(--muted); font-size: 13px; margin: 0; }
.link { color: var(--accent); text-decoration: underline; }

.thumb-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-top: 22px;
}
.thumb {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--bg-2);
}
.thumb img { width: 100%; height: 110px; object-fit: cover; display: block; }
.thumb .cap { padding: 8px 10px; font-size: 11px; color: var(--muted); font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 10px 12px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.data-table th {
  background: var(--bg-2); color: var(--muted); font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  position: sticky; top: 0;
}
.data-table td { font-family: var(--mono); font-size: 12.5px; }
.data-table tbody tr:hover { background: var(--bg-2); }
.data-table .col-name { color: var(--text); font-weight: 500; }
.empty-state { padding: 40px; text-align: center; color: var(--muted); }

/* Single image layout */
.single-layout, .recon-layout { display: grid; grid-template-columns: 1fr 360px; gap: 22px; }
@media (max-width: 920px) { .single-layout, .recon-layout { grid-template-columns: 1fr; } }

.viewer-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.viewer-toolbar label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
select, input, textarea {
  font-family: inherit; font-size: 13.5px; background: var(--bg-3);
  color: var(--text); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 10px; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; }

.canvas-wrap {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: #07090d; display: flex; align-items: center; justify-content: center;
  min-height: 380px;
}
#measureCanvas { max-width: 100%; cursor: crosshair; display: block; }
.step-hint {
  margin-top: 10px; font-size: 13px; color: var(--accent-2);
  font-family: var(--mono); min-height: 18px;
}

.controls-col { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.card h3 { margin: 0 0 14px; font-size: 14px; letter-spacing: -0.01em; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.field input, .field select, .field textarea { color: var(--text); }
.input-unit { display: flex; gap: 8px; }
.input-unit input { flex: 1; }
.input-unit select { width: 72px; }

.click-status { display: flex; gap: 8px; margin: 6px 0 14px; }
.pin {
  flex: 1; font-size: 12px; padding: 8px 10px; border-radius: 8px;
  background: var(--bg-3); border: 1px solid var(--line-2); font-family: var(--mono);
}
.pin b { color: var(--text); }
.pin-ref { border-left: 3px solid var(--ref); }
.pin-meas { border-left: 3px solid var(--meas); }

.result-card { border-color: var(--line-2); box-shadow: 0 0 0 1px rgba(56,189,248,.08); }
.result-big { font-size: 34px; font-weight: 700; font-family: var(--mono);
  letter-spacing: -0.02em; margin: 4px 0 14px; color: var(--accent-2); }
.result-meta { list-style: none; padding: 0; margin: 0 0 14px; font-size: 12.5px; }
.result-meta li { display: flex; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px dashed var(--line); font-family: var(--mono); }
.result-meta li span:first-child { color: var(--muted); }
.tag {
  font-size: 11px; font-family: var(--mono); padding: 3px 9px; border-radius: 999px;
  letter-spacing: 0.05em; vertical-align: middle;
}
.tag.Low { background: #3a1d1d; color: #fca5a5; border: 1px solid #5a2a2a; }
.tag.Medium { background: #3a2f12; color: #fcd34d; border: 1px solid #5a4a1a; }
.tag.High { background: #133a28; color: #6ee7b7; border: 1px solid #1f5a3e; }

/* Reconstruction */
.recon-bar { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.recon-canvas-wrap { min-height: 460px; position: relative; padding: 0; }
#reconViewer { width: 100%; height: 460px; }
.recon-hint {
  position: absolute; bottom: 10px; left: 12px; font-size: 11px;
  color: var(--muted); font-family: var(--mono); pointer-events: none;
  background: rgba(7,9,13,.7); padding: 4px 8px; border-radius: 6px;
}
.pt-slot { font-family: var(--mono); font-size: 13px; padding: 8px 10px;
  background: var(--bg-3); border-radius: 8px; margin-bottom: 8px; }
.recon-dist { font-family: var(--mono); font-size: 13px; color: var(--accent-2); margin: 10px 0; }
.scale-state { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 10px; }
.scale-state.set { color: var(--meas); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line-2);
  padding: 12px 18px; border-radius: 10px; font-size: 13.5px; opacity: 0;
  pointer-events: none; transition: opacity .25s, transform .25s; z-index: 50;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: #5a2a2a; color: #fca5a5; }

/* ===== Pole-measurement redesign ===== */
.warn-text { color: #fbbf24; }
.amber { color: var(--ref); }

/* Setup */
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .setup-grid { grid-template-columns: 1fr; } }
.dropzone.small { padding: 26px 18px; }
.dropzone .dz-inner { pointer-events: none; }
.mini-tag { font-family: var(--mono); font-size: 10px; padding: 2px 6px; border-radius: 6px;
  background: var(--bg-3); color: var(--accent-2); border: 1px solid var(--line-2); margin-left: 6px; }
.mini-tag.manual { color: var(--ref); }
.mini-tag.dup { color: var(--danger); border-color: #4a2530; background: #2a1a1f; }
.data-table tr.dup-row td { background: rgba(229, 72, 77, 0.08); }
.data-table tr.dup-row:hover td { background: rgba(229, 72, 77, 0.14); }
.col-thumb { width: 58px; }
.thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--line-2); background: var(--bg-3); display: block; }
.thumb-empty { display: inline-block; border-style: dashed; }
.setup-toolbar { align-items: center; }
.inline-filter { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.inline-filter select { width: auto; min-width: 150px; }

/* Measure layout */
.measure-layout { display: grid; grid-template-columns: 230px 1fr 360px; gap: 18px; align-items: start; }
@media (max-width: 1180px) { .measure-layout { grid-template-columns: 200px 1fr; } .controls-col { grid-column: 1 / -1; } }
@media (max-width: 820px) { .measure-layout { grid-template-columns: 1fr; } }

.pole-rail { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
  overflow: hidden; max-height: 640px; overflow-y: auto; }
.rail-head { padding: 12px 14px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--panel); z-index: 2; }
.pole-item { display: block; width: 100%; text-align: left; background: transparent; border: none;
  border-bottom: 1px solid var(--line); padding: 10px 14px; cursor: pointer; color: var(--text); }
.pole-item:hover { background: var(--bg-2); }
.pole-item.active { background: #15212e; box-shadow: inset 3px 0 0 var(--accent); }
.pi-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pi-name { font-size: 13.5px; font-weight: 600; }
.pi-sub { font-size: 11.5px; margin-top: 2px; }
.dots { display: inline-flex; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bg-3); border: 1px solid var(--line-2); }
.dot.on { background: var(--meas); border-color: var(--meas); }

/* Segmented control */
.seg { display: inline-flex; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { font-family: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: transparent; border: none; padding: 7px 12px; border-radius: 7px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent); color: #04222f; }
.seg button[data-kind]::before { content: ""; display: inline-block; width: 9px; height: 9px;
  border-radius: 50%; margin-right: 6px; vertical-align: middle; border: 1px solid rgba(0,0,0,0.35); }
.seg button[data-kind="tip_x"]::before { background: #60a5fa; }
.seg button[data-kind="tip_y"]::before { background: #fbbf24; }
.seg button[data-kind="crossarm"]::before { background: #c084fc; }

/* Canvas */
.canvas-wrap { position: relative; min-height: 560px; }
#measureCanvas { width: 100%; height: 560px; display: block; cursor: crosshair; }
.zoom-hint { position: absolute; bottom: 10px; left: 12px; font-size: 11px; color: var(--muted);
  font-family: var(--mono); pointer-events: none; background: rgba(7,9,13,.7); padding: 4px 8px; border-radius: 6px; }

/* Map */
.map-card { padding: 12px; }
#map { width: 100%; height: 180px; border-radius: 9px; overflow: hidden; background: #07090d; }
.leaflet-container { background: #07090d; font-family: inherit; }

/* Distance input */
.unit-static { display: inline-flex; align-items: center; padding: 0 10px; font-family: var(--mono);
  font-size: 13px; color: var(--muted); background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; }
.pin { display: flex; justify-content: space-between; align-items: center; }
.result-meta .big { color: var(--accent-2); font-weight: 700; }
.result-meta .warn-row { display: block; color: #fbbf24; border-bottom: none; padding: 6px 0 0;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.45; white-space: normal; }

/* Slots */
.slots { display: flex; flex-direction: column; gap: 8px; }
.result-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.result-strip .slot { padding: 9px 11px; }
.result-strip .slot-val { font-size: 18px; }
.slot { position: relative; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: var(--bg-2); }
.slot-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }
.slot-val { font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--accent-2); margin-top: 4px; }
.slot-val.muted { color: var(--muted); font-size: 13px; font-weight: 400; }
.slot-val .u { font-size: 12px; color: var(--muted); }
.slot-clear { position: absolute; top: 8px; right: 10px; font-family: var(--mono); font-size: 10px;
  background: transparent; border: none; color: var(--danger); cursor: pointer; opacity: 0; }
.slot:hover .slot-clear { opacity: 1; }
