/* ============================================
   DraftLens — DWG Viewer Stylesheet
   Aesthetic: Industrial Precision / Dark Blueprint
   ============================================ */

:root {
  --bg: #0d0f14;
  --bg2: #131720;
  --bg3: #1a2030;
  --surface: #1e2535;
  --surface2: #252d3d;
  --border: #2a3348;
  --border2: #35405a;
  --text: #e8edf7;
  --text2: #8a95b0;
  --text3: #5a6480;
  --accent: #4d9fff;
  --accent2: #2d7de0;
  --accent-glow: rgba(77, 159, 255, 0.15);
  --green: #3dd68c;
  --orange: #f5a623;
  --red: #ff5c5c;
  --header-h: 52px;
  --sidebar-w: 240px;
  --radius: 6px;
  --font-ui: 'Syne', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg: #f0f2f7;
  --bg2: #e8ebf2;
  --bg3: #dde1ec;
  --surface: #ffffff;
  --surface2: #f5f7fc;
  --border: #d0d5e8;
  --border2: #b8bfd8;
  --text: #1a2035;
  --text2: #4a5470;
  --text3: #8a95b0;
  --accent: #1a6fd4;
  --accent2: #1558b0;
  --accent-glow: rgba(26, 111, 212, 0.12);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

/* ---- HEADER ---- */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text);
}

.nav {
  display: flex;
  gap: 2px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.3px;
}

.nav-btn:hover { color: var(--text); background: var(--surface2); }
.nav-btn.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* ---- MAIN LAYOUT ---- */
.main {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
  overflow: hidden;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  transition: width 0.2s;
}

.sidebar:empty { width: 0; }

.panel {
  padding: 16px;
}

.panel-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 12px;
}

.info-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
  color: var(--text3);
  font-size: 12px;
  text-align: center;
  gap: 8px;
}

.empty-icon { font-size: 28px; opacity: 0.5; }

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text3); font-family: var(--font-mono); font-size: 11px; }
.info-value { color: var(--text); font-weight: 500; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: opacity 0.15s;
}
.layer-item:last-child { border-bottom: none; }
.layer-item.hidden { opacity: 0.4; }

.layer-color {
  width: 10px; height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.layer-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-toggle {
  width: 22px; height: 14px;
  background: var(--surface2);
  border-radius: 7px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}
.layer-toggle::after {
  content: '';
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text3);
  top: 2px; left: 2px;
  transition: transform 0.2s, background 0.2s;
}
.layer-item:not(.hidden) .layer-toggle {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
}
.layer-item:not(.hidden) .layer-toggle::after {
  background: var(--accent);
  transform: translateX(8px);
}

/* ---- CANVAS SECTION ---- */
.canvas-section {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

/* Blueprint grid background */
.canvas-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.3;
  pointer-events: none;
}

/* ---- DROP ZONE ---- */
.dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s;
}

.dropzone.drag-over {
  background: var(--accent-glow);
}
.dropzone.drag-over .dz-graphic svg rect {
  stroke-dashoffset: 0;
  animation: dash-spin 1s linear infinite;
}

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  padding: 48px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.4), 0 0 0 1px var(--border2);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.dropzone-inner::before {
  content: '';
  position: absolute;
  top: -60px; left: -60px;
  width: 200px; height: 200px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  pointer-events: none;
}

.dz-graphic {
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.dz-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text);
}

.dz-sub {
  font-size: 13px;
  color: var(--text2);
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  margin-top: 4px;
}
.upload-btn:hover { background: var(--accent2); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(77, 159, 255, 0.3); }
.upload-btn.small { padding: 7px 16px; font-size: 12px; }

.dz-note {
  font-size: 11px;
  color: var(--text3);
  font-family: var(--font-mono);
}

/* ---- VIEWER ---- */
.viewer-wrap {
  position: absolute;
  inset: 0;
  cursor: grab;
  user-select: none;
}
.viewer-wrap:active { cursor: grabbing; }

#viewer-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.canvas-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ---- MINIMAP ---- */
.minimap {
  position: absolute;
  bottom: 40px;
  right: 16px;
  width: 120px;
  height: 90px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
#minimap-canvas { width: 100%; height: 100%; }
.minimap-viewport {
  position: absolute;
  border: 1.5px solid var(--accent);
  pointer-events: none;
  background: rgba(77, 159, 255, 0.08);
}

/* ---- COORDS BAR ---- */
.coords-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 28px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text3);
}
.coords-bar span { display: flex; align-items: center; gap: 4px; }

/* ---- LOADING ---- */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loader-ring {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text2);
}

.loader-bar-wrap {
  width: 200px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.loader-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ---- ERROR ---- */
.error-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.error-content {
  background: var(--surface);
  border: 1px solid var(--red);
  border-radius: 10px;
  padding: 32px;
  text-align: center;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.error-icon { font-size: 36px; }
.error-content h3 { font-size: 16px; font-weight: 700; }
.error-content p { font-size: 12px; color: var(--text2); font-family: var(--font-mono); }

/* ---- FLOATING TOOLBAR ---- */
.floating-toolbar {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  gap: 2px;
  align-items: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 200;
  backdrop-filter: blur(12px);
}

.tool-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
}
.tool-btn:hover { color: var(--text); background: var(--surface2); }
.tool-btn.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-color: var(--accent);
}
.tool-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ---- ANIMATIONS ---- */
@keyframes dash-spin {
  to { stroke-dashoffset: -20; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel { animation: fadeIn 0.2s ease; }
