/* ==========================================================================
   DXF Viewer — layout & theme
   Brand colours (--brand, --brand-2) are injected from config.php.
   ========================================================================== */

:root {
  --brand: #ff6a13;
  --brand-2: #ffb020;
  --radius: 14px;
  --topbar-h: 60px;
  --sidebar-w: 312px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --brand-soft: color-mix(in srgb, var(--brand) 15%, transparent);
  --brand-line: color-mix(in srgb, var(--brand) 45%, transparent);
}

:root,
[data-theme="dark"] {
  --bg: #07090e;
  --surface: #0f131c;
  --surface-2: #141925;
  --surface-3: #1c2230;
  --border: rgba(148, 163, 184, .12);
  --border-strong: rgba(148, 163, 184, .22);
  --text: #e7ebf3;
  --text-2: #a3acbf;
  --muted: #6f7a90;
  --canvas: #0b0f17;
  --grid-line: rgba(148, 163, 184, .06);
  --glass: rgba(16, 20, 30, .74);
  --shadow: 0 14px 34px -12px rgba(0, 0, 0, .65), 0 2px 6px rgba(0, 0, 0, .35);
  --tip-bg: #f1f5f9;
  --tip-fg: #0f172a;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --surface-3: #e8ecf2;
  --border: rgba(15, 23, 42, .09);
  --border-strong: rgba(15, 23, 42, .16);
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8391a7;
  --canvas: #ffffff;
  --grid-line: rgba(15, 23, 42, .05);
  --glass: rgba(255, 255, 255, .8);
  --shadow: 0 14px 34px -14px rgba(15, 23, 42, .28), 0 2px 6px rgba(15, 23, 42, .08);
  --tip-bg: #0f172a;
  --tip-fg: #ffffff;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.icon {
  width: 20px; height: 20px; flex: none;
  stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ------------------------------------------------------------- app frame */

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.app-body { flex: 1; display: flex; min-height: 0; position: relative; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  flex: none;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 30;
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--brand-line) 30%, var(--brand-line) 70%, transparent);
  opacity: .55; pointer-events: none;
}

.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  display: grid; place-items: center; position: relative;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  color: #fff; font-weight: 800; font-size: 19px; letter-spacing: -.02em;
  box-shadow: 0 8px 18px -8px var(--brand), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.brand-mark::before {
  content: ''; position: absolute; inset: 5px; border-radius: 7px;
  border: 1.5px solid rgba(255, 255, 255, .28);
}
.brand-mark span { position: relative; text-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.brand-logo { height: 38px; width: auto; display: block; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-name { font-weight: 800; font-size: 17.5px; letter-spacing: -.015em; white-space: nowrap; }
.brand-hl { color: var(--brand); }
.brand-tag {
  margin-top: 3px; font-size: 10.5px; font-weight: 700; color: var(--muted);
  letter-spacing: .12em; text-transform: uppercase; white-space: nowrap;
}

.topbar-file {
  display: flex; align-items: center; gap: 8px; min-width: 0; max-width: min(44vw, 560px);
  margin-left: 14px; height: 36px; padding: 0 14px 0 11px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  animation: rise .35s var(--ease) both;
}
.topbar-file .icon { width: 16px; height: 16px; color: var(--brand); }
.file-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 12px;
  border: 1px solid transparent; background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 14px; white-space: nowrap; cursor: pointer;
  transition: transform .12s var(--ease), background .2s, box-shadow .2s, border-color .2s, filter .2s;
}
.btn .icon { width: 18px; height: 18px; }
.btn:active { transform: translateY(1px) scale(.98); }
.btn-primary {
  color: #fff; background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: 0 8px 22px -10px var(--brand), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.btn-primary:hover { filter: brightness(1.07) saturate(1.05); box-shadow: 0 10px 26px -10px var(--brand), inset 0 1px 0 rgba(255, 255, 255, .25); }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--brand-line); }
.btn-ghost .icon { color: var(--brand); }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; border-radius: 14px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 40px; height: 40px; flex: none; border-radius: 11px;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--text-2);
  transition: background .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn-sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn-sm .icon { width: 16px; height: 16px; }

[data-theme="dark"] .show-light, [data-theme="light"] .show-dark { display: none; }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  width: var(--sidebar-w); flex: none; position: relative; z-index: 20;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  transition: margin-left .3s var(--ease);
}
.app.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-head {
  display: none; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 12px 14px 16px; border-bottom: 1px solid var(--border);
}
.brand-sm .brand-mark { width: 34px; height: 34px; font-size: 17px; border-radius: 10px; }
.brand-sm .brand-name { font-size: 16px; }

.sidebar-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
  scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent;
}
.sidebar-scroll > * { flex-shrink: 0; } /* keep cards full height; the panel scrolls instead */
.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }

.sidebar-foot {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); font-size: 11.5px; color: var(--muted);
}
.sidebar-foot .dot { opacity: .6; }

.panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-open { background: transparent; border: 0; display: flex; flex-direction: column; gap: 10px; }

details.panel > summary {
  list-style: none; display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer; user-select: none;
  font-weight: 700; font-size: 13px; letter-spacing: .01em;
  border-radius: var(--radius);
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary > .icon { width: 18px; height: 18px; color: var(--brand); }
details.panel > summary > span:first-of-type { flex: 1; }
details.panel > summary::after {
  content: ''; width: 7px; height: 7px; margin: 0 4px 3px 4px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform .2s var(--ease);
}
details.panel:not([open]) > summary::after { transform: rotate(-45deg); margin-bottom: 0; }
details.panel > summary:hover::after { border-color: var(--text-2); }
.panel-body { padding: 0 14px 14px; }

.badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.badge:empty { display: none; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 18px 14px; cursor: pointer; text-align: center;
  border: 1.5px dashed var(--brand-line); border-radius: var(--radius);
  background: var(--brand-soft); color: var(--text);
  transition: background .2s, border-color .2s, transform .12s;
}
.dropzone:hover, .dropzone.is-over { border-style: solid; background: color-mix(in srgb, var(--brand) 22%, transparent); }
.dropzone:active { transform: scale(.99); }
.dropzone-icon {
  width: 44px; height: 44px; border-radius: 12px; margin-bottom: 4px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  box-shadow: 0 8px 18px -8px var(--brand);
}
.dropzone-title { font-weight: 700; font-size: 14px; }
.dropzone-sub { font-size: 12px; color: var(--text-2); }

.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: 13px; }
.info-grid dt { color: var(--muted); white-space: nowrap; }
.info-grid dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; word-break: break-word; }
.info-empty, .list-empty { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.info-warn { grid-column: 1 / -1; display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: var(--text-2); padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, #f59e0b 12%, transparent); }
.info-warn .icon { width: 16px; height: 16px; color: #f59e0b; margin-top: 1px; }

.layer-tools { display: flex; gap: 6px; margin-bottom: 10px; }
.search {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 10px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  transition: border-color .2s, box-shadow .2s;
}
.search .icon { width: 16px; height: 16px; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 13px; }
.search:focus-within { border-color: var(--brand-line); box-shadow: 0 0 0 3px var(--brand-soft); }
.chip-btn {
  width: 36px; height: 36px; flex: none; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border);
}
.chip-btn .icon { width: 17px; height: 17px; }
.chip-btn:hover { color: var(--text); border-color: var(--border-strong); }

.layer-list {
  list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent;
}
.layer-item {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 7px 6px 7px 9px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  transition: background .15s;
}
.layer-item:hover { background: var(--surface-3); }
.layer-swatch { width: 12px; height: 12px; flex: none; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .28), 0 0 0 1px rgba(255, 255, 255, .06); }
.layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; }
.layer-count { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.layer-eye { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 8px; color: var(--text-2); }
.layer-eye .icon { width: 17px; height: 17px; }
.layer-item .i-off { display: none; }
.layer-item.is-off .i-on { display: none; }
.layer-item.is-off .i-off { display: block; }
.layer-item.is-off .layer-name, .layer-item.is-off .layer-swatch, .layer-item.is-off .layer-count { opacity: .38; }
.layer-item.is-off .layer-eye { color: var(--muted); }

.field-label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 8px; }
.seg {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
}
.seg button {
  height: 30px; border: 0; border-radius: 8px; background: transparent; cursor: pointer;
  color: var(--text-2); font-weight: 600; font-size: 12.5px; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .18), inset 0 0 0 1px var(--border); }

.switch { display: flex; align-items: center; gap: 12px; padding: 7px 0; cursor: pointer; font-size: 13.5px; font-weight: 500; position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch-ui {
  width: 38px; height: 22px; flex: none; position: relative; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border-strong); transition: background .2s, border-color .2s;
}
.switch-ui::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); transition: transform .22s var(--ease);
}
.switch input:checked + .switch-ui { background: var(--brand); border-color: var(--brand); }
.switch input:checked + .switch-ui::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-ui { box-shadow: 0 0 0 3px var(--brand-soft); }

.entity-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.entity-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
}
.entity-chip b { color: var(--brand); font-variant-numeric: tabular-nums; }
.entity-chip.is-unsupported { opacity: .6; border-style: dashed; }
.entity-chip.is-unsupported b { color: var(--muted); }

.app-panel { display: grid; gap: 4px; }
.app-row { display: flex; align-items: center; gap: 11px; padding: 6px 0; }
.app-row-icon {
  width: 32px; height: 32px; flex: none; border-radius: 9px;
  display: grid; place-items: center; background: var(--brand-soft); color: var(--brand);
}
.app-row-icon .icon { width: 17px; height: 17px; }
.app-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.app-row-text b { font-size: 13px; font-weight: 600; }
.app-row-text small { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 12.5px; border-radius: 9px; }
.btn:disabled { opacity: .6; cursor: progress; }
.status-dot { width: 9px; height: 9px; flex: none; margin-right: 10px; border-radius: 50%; background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--border-strong); }
.status-dot.is-on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }

.help h4 {
  display: flex; align-items: center; gap: 8px; margin: 14px 0 6px;
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.help h4:first-child { margin-top: 0; }
.help h4 .icon { width: 16px; height: 16px; color: var(--brand); }
.help ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 13px; color: var(--text-2); }
.help b { color: var(--text); font-weight: 600; }
.help .keys li { display: flex; align-items: center; gap: 6px; }
kbd {
  display: inline-block; min-width: 22px; text-align: center;
  font: 600 11px var(--mono); padding: 2px 6px; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--border-strong); border-bottom-width: 2px; color: var(--text);
}

.scrim { display: none; }

/* ----------------------------------------------------------------- viewer */

.viewer { flex: 1; min-width: 0; position: relative; overflow: hidden; background: var(--canvas); }
.stage {
  position: absolute; inset: 0; touch-action: none; cursor: grab;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.stage.is-dragging { cursor: grabbing; }
.stage.is-measuring { cursor: crosshair; }
.dxf-canvas, .dxf-overlay { position: absolute; left: 0; top: 0; display: block; }
.dxf-overlay { pointer-events: none; }

/* empty state */
.empty {
  position: absolute; inset: 0; z-index: 5; overflow-y: auto;
  display: grid; place-items: center; padding: 28px 20px;
  background:
    radial-gradient(900px 520px at 50% 38%, var(--brand-soft), transparent 62%),
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--canvas);
}
.empty-card { max-width: 540px; text-align: center; animation: rise .55s var(--ease) both; }
.empty-art {
  display: block; width: min(300px, 78%); height: auto; margin: 0 auto 22px;
  filter: drop-shadow(0 18px 34px color-mix(in srgb, var(--brand) 28%, transparent));
}
.ea-part, .ea-slot, .ea-hole { fill: none; stroke: url(#emptyGrad); stroke-width: 2.5; }
.ea-part { fill: color-mix(in srgb, var(--brand) 6%, transparent); stroke-dasharray: 520; stroke-dashoffset: 520; animation: draw 1.4s var(--ease) .1s forwards; }
.ea-slot { stroke-dasharray: 220; stroke-dashoffset: 220; animation: draw 1.1s var(--ease) .5s forwards; }
.ea-hole { stroke-dasharray: 50; stroke-dashoffset: 50; animation: draw .7s var(--ease) .8s forwards; }
.ea-center { fill: none; stroke: var(--muted); stroke-width: 1; stroke-dasharray: 12 4 2 4; opacity: .55; }
.ea-dim { fill: none; stroke: var(--text-2); stroke-width: 1.2; }
.ea-arrow { fill: var(--text-2); }
.ea-dimtext-bg { fill: var(--canvas); }
.ea-dimtext { font: 700 11px var(--mono); fill: var(--text); }
.empty h1 { margin: 0 0 10px; font-size: clamp(23px, 4.2vw, 31px); font-weight: 800; letter-spacing: -.025em; }
.empty p { margin: 0 auto 24px; max-width: 450px; color: var(--text-2); font-size: 15px; line-height: 1.55; }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.empty .empty-hint { display: inline-flex; align-items: center; gap: 8px; margin: 20px 0 0; font-size: 13px; color: var(--muted); }
.empty-hint .icon { width: 16px; height: 16px; }
.empty code { font-family: var(--mono); font-size: 12px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); }

/* HUD */
.hud {
  position: absolute; z-index: 6; display: flex; align-items: center; gap: 8px;
  background: var(--glass); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  font-size: 12px; animation: fade .3s ease both;
}
.hud-tl { top: 14px; left: 14px; height: 36px; padding: 0 12px; font-family: var(--mono); pointer-events: none; }
.hud-k { color: var(--brand); font-weight: 700; }
.hud-v { min-width: 74px; color: var(--text); font-variant-numeric: tabular-nums; }
.hud-u { color: var(--muted); }
.hud-tr { top: 14px; right: 14px; padding: 3px 3px 3px 12px; }
.hud-zoom { min-width: 50px; text-align: right; font-family: var(--mono); color: var(--text-2); font-variant-numeric: tabular-nums; }
.compass {
  display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px 0 5px;
  border: 0; border-radius: 9px; cursor: pointer; background: var(--surface-3);
  font: 600 12px var(--mono); color: var(--text); font-variant-numeric: tabular-nums;
  transition: background .15s;
}
.compass:hover { background: var(--brand-soft); }
.compass-needle { width: 22px; height: 22px; }
.needle-n { fill: var(--brand); }
.needle-s { fill: var(--muted); }

/* measure card */
.measure-card {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 7;
  min-width: 270px; max-width: calc(100% - 28px); padding: 8px 8px 10px 14px;
  background: var(--glass); border: 1px solid var(--brand-line); border-radius: 14px; box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  animation: drop .25s var(--ease) both;
}
.measure-head { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.measure-head > .icon { width: 18px; height: 18px; color: var(--brand); }
#measureTitle { flex: 1; }
.measure-grid { display: grid; grid-template-columns: repeat(4, auto); gap: 4px 20px; margin-top: 6px; padding-right: 8px; }
.measure-grid span { display: block; font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.measure-grid b { font: 600 14px var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* toolbar */
.toolbar {
  position: absolute; z-index: 8; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 6px;
  background: var(--glass); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(1.5); -webkit-backdrop-filter: blur(16px) saturate(1.5);
  animation: rise-c .4s var(--ease) both;
}
.tb-group { display: flex; gap: 2px; }
.tb-sep { width: 1px; height: 24px; margin: 0 5px; flex: none; background: var(--border-strong); }
.tb-btn {
  width: 42px; height: 42px; flex: none; position: relative;
  display: grid; place-items: center; border: 0; border-radius: 12px; cursor: pointer;
  background: transparent; color: var(--text-2);
  transition: background .15s, color .15s, transform .1s;
}
.tb-btn:hover { background: var(--surface-3); color: var(--text); }
.tb-btn:active { transform: scale(.9); }
.tb-btn[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand-line); }
.tb-btn .show-on { display: none; }
.tb-btn[aria-pressed="true"] .show-on { display: block; }
.tb-btn[aria-pressed="true"] .show-off { display: none; }

/* loading */
.loading {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px;
  background: color-mix(in srgb, var(--canvas) 60%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .2s ease both;
}
.loading-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 250px; padding: 26px 30px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
}
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--brand); animation: spin .8s linear infinite; }
.loading-title { font-weight: 700; }
.loading-sub { max-width: 260px; text-align: center; font-size: 12px; color: var(--muted); word-break: break-word; }

/* drag & drop overlay */
.drop-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .15s ease both;
}
.drop-box {
  width: min(520px, 100%); aspect-ratio: 16 / 9; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 2px dashed var(--brand); border-radius: 24px; background: var(--brand-soft);
  animation: pulse 1.6s ease-in-out infinite;
}
.drop-box .icon { width: 46px; height: 46px; color: var(--brand); }
.drop-box strong { font-size: 20px; }
.drop-box span { color: var(--text-2); font-size: 13px; }

/* toasts */
.toasts {
  position: absolute; z-index: 30; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100% - 24px); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; max-width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  font-size: 13px; font-weight: 500; pointer-events: auto; animation: toast-in .28s var(--ease) both;
}
.toast .icon { width: 18px; height: 18px; }
.toast.ok .icon { color: #22c55e; }
.toast.err { border-color: rgba(239, 68, 68, .45); }
.toast.err .icon { color: #ef4444; }
.toast.out { animation: toast-out .25s ease forwards; }

/* tooltips (pointer devices only) */
@media (hover: hover) and (pointer: fine) {
  [data-tip]::after {
    content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 10px); z-index: 60;
    transform: translate(-50%, 4px); padding: 6px 9px; border-radius: 8px; white-space: nowrap;
    background: var(--tip-bg); color: var(--tip-fg); font: 600 11.5px var(--font);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .3); opacity: 0; pointer-events: none;
    transition: opacity .15s, transform .15s;
  }
  [data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .25s; }
  .topbar [data-tip], .hud [data-tip] { position: relative; }
  .topbar [data-tip]::after, .hud [data-tip]::after { bottom: auto; top: calc(100% + 10px); }
  .hud [data-tip]::after { left: auto; right: 0; transform: translate(0, -4px); }
  .hud [data-tip]:hover::after { transform: none; }
  .topbar #btnSidebar[data-tip]::after { left: 0; transform: translate(0, -4px); }
  .topbar #btnSidebar[data-tip]:hover::after { transform: none; }
}

/* ---------------------------------------------------------------- install */

.btn-install {
  height: 38px; padding: 0 14px 0 12px; border-radius: 999px;
  color: var(--brand); background: var(--brand-soft); border-color: var(--brand-line);
}
.btn-install:hover { background: color-mix(in srgb, var(--brand) 22%, transparent); }
.btn-install .icon { width: 17px; height: 17px; }

.install-bar {
  flex: none; position: relative; z-index: 25; display: flex; align-items: center; gap: 12px;
  padding: 9px max(12px, env(safe-area-inset-right)) 9px max(14px, env(safe-area-inset-left));
  background: linear-gradient(90deg, color-mix(in srgb, var(--brand) 16%, var(--surface)), var(--surface) 70%);
  border-bottom: 1px solid var(--brand-line);
  animation: fade .3s ease both;
}
.install-bar-icon { width: 36px; height: 36px; flex: none; border-radius: 9px; box-shadow: 0 4px 12px -4px var(--brand); }
.install-bar-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.install-bar-text b { font-size: 13.5px; font-weight: 700; }
.install-bar-text span { font-size: 12px; color: var(--text-2); }
.install-bar .btn { flex: none; min-width: 72px; }

.install-dialog {
  width: min(500px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 0; overflow: auto;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 34px 90px -24px rgba(0, 0, 0, .7);
}
.install-dialog[open] { animation: ad-pop .32s var(--ease) both; }
.install-dialog:focus { outline: none; }
.install-dialog::backdrop { background: rgba(3, 6, 12, .62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.install-dialog .dlg-close { top: 14px; right: 14px; color: var(--text-2); background: var(--surface-2); }
.install-dialog .dlg-close:hover { color: var(--text); background: var(--surface-3); }
.install-head { display: flex; align-items: center; gap: 14px; padding: 22px 56px 6px 22px; }
.install-app-icon { width: 64px; height: 64px; flex: none; border-radius: 15px; box-shadow: 0 10px 24px -10px var(--brand); }
.install-head h2 { margin: 0 0 3px; font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.install-head p { margin: 0; font-size: 13.5px; color: var(--text-2); }
.install-benefits { list-style: none; margin: 12px 22px 0; padding: 12px 14px; display: grid; gap: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; }
.install-benefits li { display: flex; gap: 11px; align-items: flex-start; font-size: 12.5px; color: var(--text-2); line-height: 1.4; }
.install-benefits b { display: block; font-size: 13.5px; color: var(--text); font-weight: 600; }
.ib-icon { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 8px; color: var(--brand); background: var(--brand-soft); }
.ib-icon .icon { width: 16px; height: 16px; }
.install-how { padding: 14px 22px 0; }
.install-lead { margin: 0 0 10px; font-size: 13.5px; font-weight: 600; }
.install-small { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.install-note + .install-lead { margin-top: 14px; }
.install-steps { list-style: none; counter-reset: st; margin: 0; padding: 0; display: grid; gap: 8px; }
.install-steps li { counter-increment: st; display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; line-height: 1.45; }
.install-steps li::before {
  content: counter(st); width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 50%;
  font-size: 12px; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--brand-2), var(--brand));
}
.icon.ii { width: 16px; height: 16px; vertical-align: -3px; color: var(--brand); }
.install-note { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; padding: 11px 12px; border-radius: 12px; font-size: 12.5px; line-height: 1.45; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); }
.install-note:first-child { margin-top: 0; }
.install-note > div > b { display: block; color: var(--text); font-size: 13px; }
.install-note span b { color: var(--text); }
.install-note > .icon { width: 18px; height: 18px; margin-top: 1px; flex: none; }
.install-note.is-warn { background: color-mix(in srgb, #f59e0b 11%, var(--surface)); border-color: color-mix(in srgb, #f59e0b 40%, transparent); }
.install-note.is-warn > .icon { color: #f59e0b; }
.install-note.is-ok > .icon { color: #22c55e; }
.install-note.is-info > .icon { color: var(--brand); }
.install-link { display: flex; gap: 6px; margin-top: 10px; }
.install-link input {
  flex: 1; min-width: 0; height: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); font: 500 12.5px var(--mono);
}
.install-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 18px 22px 22px; }
.install-actions .btn { flex: 1 1 auto; height: 44px; }

.empty .empty-install {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; padding: 8px 14px; border-radius: 999px;
  border: 1px dashed var(--brand-line); background: transparent; color: var(--brand); font-size: 13px; font-weight: 600; cursor: pointer;
}
.empty .empty-install:hover { background: var(--brand-soft); border-style: solid; }
.empty .empty-install .icon { width: 16px; height: 16px; }
.empty-card > .empty-hint { display: flex; justify-content: center; }

@media (min-width: 861px) { .install-bar { display: none !important; } }
@media (max-width: 640px) {
  .btn-install { display: none !important; }
  .install-head { padding: 18px 52px 4px 18px; }
  .install-app-icon { width: 54px; height: 54px; }
  .install-benefits { margin: 10px 18px 0; }
  .install-how { padding: 12px 18px 0; }
  .install-actions { padding: 16px 18px 18px; }
}

/* -------------------------------------------------------------------- ads */
/* Content and on/off switches: advertise.php */

.ad-card {
  position: relative; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.ad-img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-3); }
.ad-body { padding: 12px 14px 4px; }
.ad-h1 { margin: 0 0 4px; font-size: 15px; font-weight: 800; line-height: 1.25; letter-spacing: -.01em; }
.ad-h2 { margin: 0; font-size: 12.5px; font-weight: 500; line-height: 1.45; color: var(--text-2); }
.ad-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 14px; }
.ad-actions .btn { flex: 1 1 auto; text-decoration: none; }
.ad-actions .btn .icon { width: 16px; height: 16px; }
.btn-whatsapp { color: #fff; background: #1fae54; box-shadow: 0 8px 20px -12px #1fae54; }
.btn-whatsapp:hover { filter: brightness(1.08); }
.ad-close {
  position: absolute; top: 8px; right: 8px; z-index: 2; width: 28px; height: 28px;
  display: grid; place-items: center; border: 0; border-radius: 50%; cursor: pointer;
  color: #fff; background: rgba(5, 8, 14, .55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: background .15s, transform .1s;
}
.ad-close:hover { background: rgba(5, 8, 14, .8); }
.ad-close:active { transform: scale(.92); }
.ad-close .icon { width: 15px; height: 15px; }

/* sidebar banner */
.ad-sidebar { border-color: var(--brand-line); box-shadow: 0 12px 28px -20px var(--brand); animation: fade .3s ease both; }
.ad-sidebar.is-closing { animation: ad-out .28s ease forwards; }

/* centre popup */
.ad-modal {
  width: min(560px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 0; overflow: auto;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 34px 90px -24px rgba(0, 0, 0, .7);
}
.ad-modal[open] { animation: ad-pop .38s var(--ease) both; }
.ad-modal:focus { outline: none; }
.ad-modal::backdrop { background: rgba(3, 6, 12, .62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.ad-modal .ad-body { padding: 20px 22px 4px; }
.ad-modal .ad-h1 { margin-bottom: 8px; font-size: clamp(21px, 4.4vw, 27px); letter-spacing: -.025em; }
.ad-modal .ad-h2 { font-size: 15px; }
.ad-modal .ad-actions { gap: 8px; padding: 16px 22px 22px; }
.ad-modal .ad-actions .btn { height: 46px; font-size: 14.5px; border-radius: 13px; }
.ad-modal .ad-close { top: 12px; right: 12px; width: 34px; height: 34px; }
.ad-modal .ad-close .icon { width: 17px; height: 17px; }

/* corner popup: bottom-right on desktop, above the toolbar on phones */
.ad-corner {
  position: fixed; z-index: 50; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); width: 360px;
  display: grid; grid-template-columns: 112px 1fr; grid-template-areas: "img body" "actions actions";
  background: var(--surface); border-color: var(--brand-line); border-radius: 18px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .65), 0 0 0 1px rgba(0, 0, 0, .04);
  opacity: 0; transform: translateY(24px) scale(.98);
  transition: opacity .32s var(--ease), transform .32s var(--ease);
}
.ad-corner.is-in { opacity: 1; transform: none; }
.ad-corner .ad-img { grid-area: img; height: 100%; min-height: 104px; aspect-ratio: auto; }
.ad-corner .ad-body { grid-area: body; padding: 12px 36px 6px 12px; align-self: center; }
.ad-corner .ad-h1 { font-size: 14.5px; }
.ad-corner .ad-h2 { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ad-corner .ad-actions { grid-area: actions; padding: 10px 12px 12px; border-top: 1px solid var(--border); }
.ad-corner .ad-close { top: 6px; right: 6px; width: 26px; height: 26px; color: var(--text-2); background: var(--surface-2); }
.ad-corner .ad-close:hover { color: var(--text); background: var(--surface-3); }
/* without an image the text takes the full width */
.ad-corner:not(:has(.ad-img)) { grid-template-columns: 1fr; grid-template-areas: "body" "actions"; }

@keyframes ad-pop { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes ad-out { to { opacity: 0; transform: scale(.96); } }

/* --------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .topbar-file { max-width: 34vw; }
  .file-meta { display: none; }
}

@media (max-width: 860px) {
  :root { --topbar-h: 58px; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 60; width: min(88vw, 348px);
    margin-left: 0 !important; padding-top: env(safe-area-inset-top);
    transform: translateX(-104%); transition: transform .32s var(--ease); box-shadow: var(--shadow);
  }
  .app.drawer-open .sidebar { transform: none; }
  .sidebar-head { display: flex; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 55; opacity: 0; pointer-events: none;
    background: rgba(2, 6, 12, .52); transition: opacity .3s ease;
  }
  .app.drawer-open .scrim { opacity: 1; pointer-events: auto; }
}

@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .topbar-file { display: none !important; }
  .brand-mark { width: 34px; height: 34px; font-size: 17px; border-radius: 10px; }
  .brand-name { font-size: 16.5px; }
  .measure-card { top: 60px; left: 10px; right: 10px; transform: none; min-width: 0; max-width: none; }
  .measure-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hud-tr { top: 10px; right: 10px; }
  .toolbar { bottom: calc(12px + env(safe-area-inset-bottom)); border-radius: 16px; padding: 5px; max-width: calc(100% - 20px); }
  .tb-btn { width: 42px; height: 44px; }
  .tb-sep { margin: 0 3px; }
  .toasts { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .has-ad-corner .toasts { bottom: calc(92px + var(--ad-corner-h, 0px) + env(safe-area-inset-bottom)); }
  .empty p { font-size: 14px; }
  .ad-corner { left: 10px; right: 10px; width: auto; bottom: calc(82px + env(safe-area-inset-bottom)); grid-template-columns: 92px 1fr; border-radius: 16px; }
  .ad-corner .ad-img { min-height: 92px; }
  .ad-corner .ad-actions { padding: 8px 10px 10px; }
  .ad-modal .ad-body { padding: 16px 18px 2px; }
  .ad-modal .ad-actions { padding: 14px 18px 18px; }
  .ad-modal .ad-actions .btn { flex: 1 1 100%; }
}

@media (max-width: 440px) {
  .btn-label { display: none; }
  #btnOpen { width: 42px; padding: 0; }
  .brand-tag { letter-spacing: .08em; }
  #tbExport, #tbLock { display: none; }
  .empty-actions .btn { flex: 1 1 100%; }
}

@media (hover: none) {
  .hud-tl { display: none !important; }
}

/* ---------------------------------------------------------------- motion */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes rise-c { from { opacity: 0; transform: translate(-50%, 14px); } }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pulse { 50% { transform: scale(1.015); background: color-mix(in srgb, var(--brand) 22%, transparent); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(.97); } }

@media (max-width: 640px) {
  @keyframes drop { from { opacity: 0; transform: translateY(-8px); } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .ea-part, .ea-slot, .ea-hole { stroke-dashoffset: 0; }
}
