/*
 * Sau Area Measure — Stylesheet
 * Copyright (c) Jon Thomas Stokkeland
 * Licensed under GNU General Public License v3.0
 */

/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg-deep:      #07090f;
  --bg-app:       #0d1117;
  --bg-panel:     #111827;
  --bg-elem:      #1a2234;
  --bg-hover:     #1f2d45;
  --bg-active:    #243352;
  --border:       #1e3a5f;
  --border-light: #2a4a7a;

  --blue-900:     #0d2a4a;
  --blue-700:     #1a5fa0;
  --blue-600:     #2272c3;
  --blue-500:     #3b82f6;
  --blue-400:     #60a5fa;
  --blue-300:     #93c5fd;
  --blue-200:     #bfdbfe;

  --accent:       #3b82f6;
  --accent-bright:#60a5fa;
  --accent-glow:  rgba(59,130,246,0.25);

  --amber:        #f59e0b;
  --green:        #10b981;
  --red:          #ef4444;
  --red-dim:      #7f1d1d;

  --text-1:       #e2e8f0;
  --text-2:       #94a3b8;
  --text-3:       #475569;
  --text-4:       #1e293b;

  --font-ui:      'Exo 2', 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Consolas', monospace;

  --sidebar-w:    240px;
  --header-h:     46px;
  --status-h:     28px;
  --panel-gap:    1px;

  --radius:       4px;
  --radius-md:    6px;
  --transition:   0.15s ease;
}

/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; font-family: var(--font-ui); }
input, select { font-family: var(--font-ui); }
a { color: var(--blue-400); }

/* ── App Shell ──────────────────────────────────────────────────────────────── */
#sam-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
#sam-header {
  height: var(--header-h);
  background: linear-gradient(90deg, #0a1628 0%, #0e1f3d 50%, #0a1628 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px 0 12px;
  gap: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

#sam-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.logo-icon {
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
  text-shadow: 0 0 12px var(--accent-glow);
}
.logo-text {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--blue-300);
  text-shadow: 0 0 20px rgba(93,165,250,0.4);
}
.logo-ver {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#sam-header-info {
  flex: 1;
  min-width: 0;
}
#sam-status-bar {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--blue-300);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.hdr-copy, a.hdr-copy {
  font-size: 10px;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
}
a.hdr-copy:hover {
  color: var(--blue-300);
  text-decoration: underline;
}

/* ── Body Layout ────────────────────────────────────────────────────────────── */
#sam-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
#sam-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--panel-gap);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#sam-sidebar::-webkit-scrollbar { width: 5px; }
#sam-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.s-panel {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.s-panel-title {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: 9px;
}

/* Drop Zone */
#sam-dropzone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  background: var(--bg-elem);
  margin-bottom: 8px;
  user-select: none;
}
#sam-dropzone:hover, #sam-dropzone:focus {
  border-color: var(--accent);
  background: var(--bg-hover);
  outline: none;
}
#sam-dropzone.drag-over {
  border-color: var(--blue-300);
  background: var(--blue-900);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.dz-icon { font-size: 22px; color: var(--accent); margin-bottom: 4px; }
.dz-text { font-size: 12px; color: var(--text-1); line-height: 1.5; }
.dz-text span { color: var(--text-2); font-size: 11px; }
.dz-hint { font-size: 9.5px; color: var(--text-3); margin-top: 4px; font-family: var(--font-mono); }

/* Project Name Input */
.proj-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.proj-name-label {
  font-size: 10px;
  color: var(--text-3);
  white-space: nowrap;
  flex-shrink: 0;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
}
#sam-project-name {
  flex: 1;
  background: var(--bg-elem);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 7px;
  min-width: 0;
}
#sam-project-name:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
#sam-project-name::placeholder { color: var(--text-3); }

/* Session sub-heading inside Export panel */
.s-sub-title {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-3);
  text-transform: uppercase;
  margin: 10px 0 5px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Button Rows */
.btn-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.btn-col {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.btn-sm {
  padding: 5px 9px;
  border-radius: var(--radius);
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.btn-sm:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}
.btn-primary {
  background: var(--blue-600);
  border-color: var(--blue-500);
  color: #fff;
}
.btn-primary:hover { background: var(--blue-500); border-color: var(--blue-400); }
.btn-outline {
  background: var(--bg-elem);
  border-color: var(--border-light);
  color: var(--text-2);
}
.btn-outline:hover { background: var(--bg-hover); border-color: var(--blue-500); color: var(--text-1); }
.btn-danger-sm {
  background: transparent;
  border-color: var(--red-dim);
  color: var(--red);
}
.btn-danger-sm:hover { background: rgba(239,68,68,0.1); border-color: var(--red); }
.btn-export {
  background: var(--bg-elem);
  border-color: var(--border-light);
  color: var(--text-2);
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.5px;
}
.btn-export:hover { background: var(--bg-hover); border-color: var(--blue-500); color: var(--blue-300); }

/* Scale Panel */
.scale-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  background: var(--bg-elem);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: var(--radius);
}
.scale-label { font-size: 10px; color: var(--text-3); white-space: nowrap; }
.scale-val { font-family: var(--font-mono); font-size: 11px; color: var(--amber); flex: 1; text-align: right; }
.scale-note {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 7px;
  line-height: 1.5;
}

/* Tool Grid */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 9px;
}
.tool-btn {
  background: var(--bg-elem);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 4px 7px;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all var(--transition);
  cursor: pointer;
}
.tool-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--blue-500);
  color: var(--text-1);
}
.tool-btn.active {
  background: var(--blue-900);
  border-color: var(--accent);
  color: var(--blue-300);
  box-shadow: 0 0 8px var(--accent-glow);
}
.tool-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.tool-icon { font-size: 16px; line-height: 1; }
.tool-label { font-size: 9.5px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; }

.tool-hints {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tool-hints div { font-size: 10px; color: var(--text-3); }
kbd {
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 1px 4px;
  background: var(--bg-elem);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  color: var(--text-2);
}

/* Style Options Grid */
.opt-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 8px;
  align-items: center;
}
.opt-label { font-size: 11px; color: var(--text-2); }
.opt-grid input[type="color"] {
  width: 40px;
  height: 22px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--bg-elem);
  cursor: pointer;
  padding: 1px 2px;
}
.opt-grid select {
  background: var(--bg-elem);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-1);
  font-size: 11px;
  padding: 3px 5px;
  height: 24px;
}
.opt-grid select:focus { outline: none; border-color: var(--accent); }

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 18px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-deep);
  border: 1px solid var(--border-light);
  border-radius: 18px;
  transition: 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 12px; width: 12px;
  left: 2px; bottom: 2px;
  background: var(--text-3);
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--blue-700); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: var(--blue-300); }

/* ── Zoom / View Controls ────────────────────────────────────────────────────── */
#sam-view-controls {
  position: absolute;
  bottom: 52px;   /* sit above the measurements panel */
  right: 12px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(13,17,23,0.88);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 3px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
}
.view-btn {
  width: 28px;
  height: 28px;
  background: var(--bg-elem);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  padding: 0;
  font-family: var(--font-ui);
}
.view-btn:hover {
  background: var(--bg-hover);
  border-color: var(--blue-500);
  color: var(--blue-300);
}
.view-btn:active {
  background: var(--bg-active);
}
.view-sep {
  height: 1px;
  background: var(--border);
  margin: 1px 2px;
}

/* ── Canvas Area ─────────────────────────────────────────────────────────────── */
#sam-canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-deep);
  min-width: 0;
}

#sam-canvas-outer {
  flex: 1;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59,130,246,0.04) 0%, transparent 60%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 24px,
      rgba(255,255,255,0.02) 24px,
      rgba(255,255,255,0.02) 25px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 24px,
      rgba(255,255,255,0.02) 24px,
      rgba(255,255,255,0.02) 25px
    );
  cursor: default;
}

#sam-canvas-wrap {
  position: relative;
  display: inline-block;
  transform-origin: 0 0;
  /* JS will set: transform: translate(panX, panY) scale(zoom) */
}

#sam-no-image {
  width: 600px;
  height: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  user-select: none;
}
.ni-icon { font-size: 48px; color: var(--text-4); opacity: 0.5; }
.ni-text { font-size: 18px; font-weight: 600; color: var(--text-3); letter-spacing: 1px; }
.ni-sub  { font-size: 12px; color: var(--text-4); text-align: center; max-width: 280px; line-height: 1.6; }

#sam-bg {
  display: block;
  max-width: none; /* controlled by container */
  user-select: none;
  pointer-events: none;
}

#sam-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: visible;
  cursor: crosshair;
}
#sam-svg.mode-select { cursor: default; }

/* ── Measurements Panel ─────────────────────────────────────────────────────── */
#sam-meas-panel {
  height: 160px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.meas-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
  flex-shrink: 0;
}
.meas-count {
  background: var(--blue-700);
  color: #fff;
  font-size: 10px;
  padding: 0px 6px;
  border-radius: 10px;
  font-weight: 700;
}
#sam-meas-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-content: flex-start;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#sam-meas-list::-webkit-scrollbar { height: 4px; width: 4px; }
#sam-meas-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.meas-empty {
  font-size: 11px;
  color: var(--text-3);
  padding: 12px;
  width: 100%;
  text-align: center;
}

.meas-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px 4px 6px;
  background: var(--bg-elem);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  height: 28px;
  max-width: 320px;
}
.meas-item:hover { border-color: var(--blue-500); background: var(--bg-hover); }
.meas-item.meas-selected {
  border-color: var(--accent);
  background: var(--bg-active);
  box-shadow: 0 0 0 1px var(--accent-glow);
}
.meas-color {
  width: 10px; height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.meas-icon { font-size: 11px; color: var(--text-2); flex-shrink: 0; }
.meas-name {
  font-size: 11px;
  color: var(--text-1);
  min-width: 60px;
  max-width: 100px;
  outline: none;
  border-radius: 2px;
  padding: 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meas-name:focus {
  background: var(--bg-deep);
  box-shadow: 0 0 0 1px var(--accent);
  color: var(--text-1);
  white-space: normal;
}
.meas-val {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--blue-300);
  white-space: nowrap;
  flex-shrink: 0;
}
.meas-del {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 11px;
  padding: 1px 3px;
  border-radius: 3px;
  line-height: 1;
  margin-left: 2px;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition);
}
.meas-del:hover { color: var(--red); background: rgba(239,68,68,0.12); }

/* ── Hint Bar (action instructions) ─────────────────────────────────────────── */
#sam-hint-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  background: linear-gradient(90deg, rgba(15,30,60,0.97) 0%, rgba(30,50,20,0.0) 100%),
              linear-gradient(90deg, rgba(245,158,11,0.12), rgba(59,130,246,0.10));
  border-bottom: 1px solid rgba(245,158,11,0.55);
  flex-shrink: 0;
  z-index: 40;
  animation: hint-glow 2.2s ease-in-out infinite;
}
.hint-icon {
  font-size: 15px;
  color: var(--amber);
  flex-shrink: 0;
  line-height: 1;
}
#sam-hint-text {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sam-hint-step {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  flex-shrink: 0;
  white-space: nowrap;
}
@keyframes hint-glow {
  0%, 100% { border-bottom-color: rgba(245,158,11,0.55); box-shadow: none; }
  50%       { border-bottom-color: rgba(96,165,250,0.7);  box-shadow: 0 2px 12px rgba(245,158,11,0.15); }
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
#sam-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  display: none;     /* hidden by default; JS sets display:flex when showing */
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
#sam-modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 0 1px rgba(59,130,246,0.15);
  overflow: hidden;
}
#sam-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, var(--blue-900), var(--bg-panel));
}
#sam-modal-title {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--blue-300);
}
#sam-modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  transition: color var(--transition);
}
#sam-modal-close:hover { color: var(--text-1); }
#sam-modal-body {
  padding: 16px 14px;
  font-size: 12.5px;
  color: var(--text-1);
  line-height: 1.6;
}
#sam-modal-body p { margin-bottom: 10px; }
#sam-modal-body p:last-child { margin-bottom: 0; }
#sam-modal-footer {
  padding: 10px 14px 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* Modal form elements */
.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.form-row label { font-size: 11.5px; color: var(--text-2); flex-shrink: 0; }
.form-row input[type="number"] {
  background: var(--bg-elem);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 5px 8px;
  width: 100px;
}
.form-row input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.form-row select {
  background: var(--bg-elem);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-1);
  font-size: 12px;
  padding: 5px 8px;
  height: 30px;
}
.form-row select:focus { outline: none; border-color: var(--accent); }

.form-px-dist {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--amber);
  display: inline-block;
  margin-bottom: 2px;
}

/* ── Scrollbar global ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── SVG measurement styling (set via JS, these are fallbacks) ──────────────── */
.measurement { cursor: pointer; }
.measurement .meas-seg { stroke-linecap: round; stroke-linejoin: round; }
.selected-ring {
  fill: none;
  stroke: rgba(255,255,255,0.6);
  stroke-dasharray: 3,2;
}

/* ── Zoom / pan cursor states ─────────────────────────────────────────────── */
#sam-canvas-outer.panning { cursor: grabbing !important; }
#sam-canvas-outer.panning * { cursor: grabbing !important; }

