/* ============================================================
   QSCad Mini — layout.css
   DOM structure ตาม spec: body > topbar + workspace + statusbar
   Modal/overlay อยู่ body level — ไม่ใช่ใน canvas-wrap
   ============================================================ */

:root {
  --bg:      #0e1117;
  --panel:   #151b27;
  --card:    #1c2333;
  --border:  #263047;
  --accent:  #38bdf8;
  --green:   #4ade80;
  --orange:  #fb923c;
  --red:     #f87171;
  --yellow:  #fbbf24;
  --purple:  #a78bfa;
  --text:    #e2e8f0;
  --muted:   #64748b;
  --mono:    'IBM Plex Mono', monospace;
  --sans:    'Sarabun', sans-serif;

  --toolbar-w:  56px;
  --panel-w:    260px;
  --topbar-h:   48px;
  --statusbar-h:32px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background:  var(--bg);
  color:       var(--text);
  font-family: var(--sans);
  height:      100vh;
  display:     flex;
  flex-direction: column;
  overflow:    hidden;
}

/* ── Top Bar ────────────────────────────────────────────────── */
.topbar {
  height:        var(--topbar-h);
  background:    var(--panel);
  border-bottom: 1px solid var(--border);
  display:       flex;
  align-items:   center;
  padding:       0 16px;
  gap:           12px;
  flex-shrink:   0;
  z-index:       10;
}

.topbar-logo {
  font-family:    var(--mono);
  font-size:      13px;
  font-weight:    600;
  color:          var(--accent);
  letter-spacing: .05em;
  white-space:    nowrap;
}

.topbar-sep {
  width:      1px;
  height:     20px;
  background: var(--border);
  flex-shrink: 0;
}

.topbar-title {
  font-size: 12px;
  color:     var(--muted);
  font-family: var(--mono);
}

.topbar-right {
  margin-left: auto;
  display:     flex;
  gap:         6px;
  align-items: center;
}

/* ── Workspace ───────────────────────────────────────────────── */
.workspace {
  display:  flex;
  flex:     1;
  overflow: hidden;   /* ← critical: ไม่ให้ children overflow ออกไป */
}

/* ── Left Toolbar ───────────────────────────────────────────── */
.toolbar {
  width:          var(--toolbar-w);
  background:     var(--panel);
  border-right:   1px solid var(--border);
  display:        flex;
  flex-direction: column;
  align-items:    center;
  padding:        6px 0;
  gap:            1px;
  flex-shrink:    0;
  overflow-y:     auto;
  overflow-x:     hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Canvas Wrap ─────────────────────────────────────────────── */
.canvas-wrap {
  flex:     1;
  position: relative;
  overflow: hidden;   /* ← critical */
  background: var(--bg);
}

#drawCanvas {
  position: absolute;
  top:      0;
  left:     0;
  cursor:   default;
}

/* Upload zone (overlay inside canvas-wrap — OK ไม่ใช่ modal) */
.upload-zone {
  position:        absolute;
  inset:           0;
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  background:      rgba(14, 17, 23, 0.92);
  border:          2px dashed var(--border);
  cursor:          pointer;
  z-index:         5;
}

.upload-zone.drag {
  border-color: var(--accent);
  background:   rgba(56, 189, 248, 0.05);
}

.upload-zone-icon { font-size: 48px; opacity: .4; margin-bottom: 12px; }
.upload-zone-text {
  font-family: var(--mono);
  font-size:   12px;
  color:       var(--muted);
  text-align:  center;
  line-height: 1.8;
}

/* Tool mode label (inside canvas-wrap — OK) */
.tool-mode-label {
  position:    absolute;
  top:         12px;
  left:        50%;
  transform:   translateX(-50%);
  background:  rgba(21, 27, 39, 0.9);
  border:      1px solid var(--border);
  border-radius: 6px;
  padding:     5px 14px;
  font-family: var(--mono);
  font-size:   11px;
  color:       var(--accent);
  pointer-events: none;
  z-index:     20;
}

/* Edit mode banner (inside canvas-wrap — OK) */
.edit-mode-banner {
  position:    absolute;
  top:         48px;
  left:        50%;
  transform:   translateX(-50%);
  background:  rgba(251, 191, 36, 0.15);
  border:      1px solid var(--yellow);
  border-radius: 6px;
  padding:     5px 14px;
  font-family: var(--mono);
  font-size:   11px;
  color:       var(--yellow);
  z-index:     20;
}

.edit-mode-banner.hidden { display: none; }

/* Scale bar (inside canvas-wrap — OK) */
.scale-bar {
  position:     absolute;
  bottom:       44px;
  left:         50%;
  transform:    translateX(-50%);
  background:   rgba(21, 27, 39, 0.9);
  border:       1px solid var(--border);
  border-radius: 6px;
  padding:      5px 14px;
  font-family:  var(--mono);
  font-size:    11px;
  color:        var(--muted);
  display:      flex;
  align-items:  center;
  gap:          10px;
  pointer-events: none;
  z-index:      10;
}

.scale-line {
  width: 60px; height: 3px;
  background:    var(--accent);
  border-radius: 2px;
  position:      relative;
}
.scale-line::before, .scale-line::after {
  content: ''; position: absolute;
  width: 1px; height: 8px; background: var(--accent); top: -2.5px;
}
.scale-line::before { left: 0; }
.scale-line::after  { right: 0; }

/* Coords display (inside canvas-wrap — OK) */
.coords {
  position:  absolute;
  bottom:    44px;
  right:     14px;
  font-family: var(--mono);
  font-size:  10px;
  color:      var(--muted);
  pointer-events: none;
}

/* Sheet bar (inside canvas-wrap — OK, position:absolute) */
.sheet-bar {
  position:   absolute;
  bottom:     0;
  left:       0;
  right:      0;
  display:    flex;
  gap:        3px;
  padding:    5px 10px;
  background: rgba(14, 17, 23, 0.93);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  z-index:    30;
}

/* ── Right Panel ─────────────────────────────────────────────── */
.right-panel {
  width:          var(--panel-w);
  background:     var(--panel);
  border-left:    1px solid var(--border);
  display:        flex;
  flex-direction: column;
  flex-shrink:    0;
  overflow:       hidden;
}

.panel-tabs {
  display:       flex;
  border-bottom: 1px solid var(--border);
  flex-shrink:   0;
}

.panel-body {
  flex:       1;
  overflow-y: auto;
  padding:    12px;
}

/* ── Status Bar ──────────────────────────────────────────────── */
.statusbar {
  height:        var(--statusbar-h);
  background:    var(--panel);
  border-top:    1px solid var(--border);
  display:       flex;
  align-items:   center;
  padding:       0 14px;
  gap:           20px;
  flex-shrink:   0;
  font-family:   var(--mono);
  font-size:     10px;
  color:         var(--muted);
}

.status-item { display: flex; gap: 6px; align-items: center; }
.status-val  { color: var(--text); }

/* ── Modals (body level — NEVER inside canvas-wrap) ─────────────
   ทุก modal ต้องเป็น direct child ของ body
   position: fixed, z-index > 100
   ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position:        fixed;
  inset:           0;
  background:      rgba(0, 0, 0, 0.75);
  display:         none;
  align-items:     center;
  justify-content: center;
  z-index:         200;   /* สูงกว่า everything */
}

.modal {
  background:    var(--card);
  border:        1px solid var(--border);
  border-radius: 12px;
  padding:       28px;
  width:         520px;
  max-width:     95vw;
  max-height:    85vh;
  overflow-y:    auto;
}

.modal h2 {
  font-family: var(--mono);
  font-size:   16px;
  color:       var(--accent);
  margin-bottom: 6px;
}

.modal-sub {
  font-size:     12px;
  color:         var(--muted);
  margin-bottom: 22px;
}

.modal-footer {
  display:         flex;
  justify-content: flex-end;
  gap:             10px;
  margin-top:      20px;
}

/* ── Mode Buttons (Snap/Ortho topbar) ───────────────────────── */
.mode-btn {
  padding:       4px 10px;
  border-radius: 5px;
  border:        1px solid var(--border);
  background:    none;
  color:         var(--muted);
  font-family:   var(--mono);
  font-size:     10px;
  font-weight:   600;
  letter-spacing:.05em;
  cursor:        pointer;
  transition:    all .15s;
  white-space:   nowrap;
}
.mode-btn:hover { color: var(--text); }
