:root {
  --bg: #0b0f17;
  --panel: #111827;
  --panel-2: #182234;
  --border: #263248;
  --text: #e5edf7;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.topbar {
  height: 54px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.brand-icon { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.3px; }
.brand-badge {
  font-size: 11px;
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.nav-tabs { display: flex; gap: 6px; }
.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.nav-btn:hover:not(:disabled) { color: var(--text); background: var(--panel-2); }
.nav-btn.active { color: var(--text); background: var(--panel-2); border-color: var(--border); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.auth-bar { display: flex; align-items: center; gap: 10px; }
.user-chip {
  font-size: 13px;
  background: var(--panel-2);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

/* Buttons & Inputs */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #223047; }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; border-color: rgba(239, 68, 68, 0.35); }
.full-width { width: 100%; }
.file-btn { cursor: pointer; }

.input, .input-sm, .search-input {
  background: #0d1422;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
.input-sm { padding: 6px 8px; font-size: 12px; }
.input:focus, .input-sm:focus, .search-input:focus { border-color: var(--accent); }

/* Views */
.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; flex-direction: column; }

/* Library */
#libraryView { overflow-y: auto; padding: 28px 24px; }
.library-container { max-width: 1200px; width: 100%; margin: 0 auto; }
.library-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}
.library-header h1 { font-size: 24px; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 13px; }

.library-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.scope-tabs { display: flex; gap: 6px; }
.scope-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
}
.scope-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.search-input { max-width: 380px; }

.boards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.board-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
}
.board-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.board-thumb {
  height: 150px;
  background: #0a1912;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.board-thumb img { width: 100%; height: 100%; object-fit: cover; }
.board-thumb-empty { color: var(--muted); font-size: 12px; }
.board-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
}
.board-badge.public { color: #34d399; border-color: rgba(16, 185, 129, 0.4); }
.board-body { padding: 14px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.board-title { font-weight: 600; font-size: 15px; }
.board-meta { font-size: 12px; color: var(--muted); }
.board-desc { font-size: 12px; color: #cbd5e1; line-height: 1.4; flex: 1; }
.board-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Editor */
.editor-toolbar-top {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.board-meta-bar, .editor-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.board-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  width: 240px;
}
.board-title-input:hover, .board-title-input:focus {
  background: #0d1422;
  border-color: var(--border);
  outline: none;
}

.side-switcher {
  display: flex;
  background: #0d1422;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.side-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.side-btn.active { background: var(--accent); color: #fff; }

.toggle-public {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.save-status { font-size: 12px; color: var(--muted); }
.save-status.dirty { color: var(--warning); }

.editor-workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Tool Rail */
.tool-rail {
  width: 68px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  gap: 6px;
  flex-shrink: 0;
}
.tool-btn {
  width: 54px;
  padding: 7px 4px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  font-size: 16px;
}
.tool-btn small { font-size: 10px; }
.tool-btn:hover { background: var(--panel-2); color: var(--text); }
.tool-btn.active { background: rgba(59, 130, 246, 0.2); border-color: var(--accent); color: #fff; }
.tool-divider { width: 36px; height: 1px; background: var(--border); margin: 4px 0; }

/* Canvas Stage */
.canvas-stage {
  flex: 1;
  position: relative;
  background: #070a10;
  background-image: radial-gradient(#1b2434 1px, transparent 1px);
  background-size: 20px 20px;
  overflow: hidden;
}
#pcbCanvas { width: 100%; height: 100%; display: block; cursor: grab; }
#pcbCanvas.crosshair { cursor: crosshair; }
#pcbCanvas.grabbing { cursor: grabbing; }

.canvas-hud {
  position: absolute;
  bottom: 12px;
  left: 12px;
  display: flex;
  gap: 10px;
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

.empty-photo-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(7, 10, 16, 0.72);
  color: var(--muted);
  font-size: 14px;
}

/* Right Panel */
.right-panel {
  width: 310px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.panel-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 10px 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.panel-tab.active { color: var(--text); border-bottom-color: var(--accent); }

.panel-body {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
  gap: 12px;
}
.panel-body.active { display: flex; }

.marker-filters { display: flex; flex-direction: column; gap: 6px; }
.markers-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.marker-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.marker-item:hover { border-color: #475569; }
.marker-item.selected { border-color: var(--accent); background: rgba(59, 130, 246, 0.14); }
.marker-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.marker-item-main { flex: 1; min-width: 0; }
.marker-item-label { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marker-item-val { font-size: 11px; color: var(--muted); }

.inspector {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.inspector-header { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.btn-icon-danger {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-icon-danger:hover { background: rgba(239, 68, 68, 0.2); }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checkbox-field { flex-direction: row; align-items: center; gap: 6px; padding-top: 16px; color: var(--text); }
.color-input { width: 100%; height: 28px; border: 1px solid var(--border); background: #0d1422; border-radius: 6px; cursor: pointer; }

/* Layers */
.panel-hint { font-size: 12px; color: var(--muted); }
.layers-list { display: flex; flex-direction: column; gap: 8px; }
.layer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
}
.layer-left { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* Attachments */
.section-block { display: flex; flex-direction: column; gap: 8px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--text); }
.upload-att-box { display: flex; gap: 6px; align-items: center; }
.attachments-list { display: flex; flex-direction: column; gap: 6px; }
.att-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.att-name { font-weight: 500; word-break: break-all; }
.att-meta { font-size: 10px; color: var(--muted); }
.att-actions { display: flex; gap: 6px; align-items: center; }
.att-actions a { color: #60a5fa; text-decoration: none; font-size: 12px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 17px; }
.modal-close { background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.auth-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: #0d1422; padding: 4px; border-radius: 8px; }
.tab-pill { background: transparent; border: none; color: var(--muted); padding: 7px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.tab-pill.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
#authForm, #newBoardForm { display: flex; flex-direction: column; gap: 12px; }
.form-error { color: #f87171; font-size: 12px; min-height: 16px; }
.demo-hint { font-size: 12px; color: var(--muted); text-align: center; }
.demo-hint code { background: #0d1422; padding: 2px 5px; border-radius: 4px; color: #93c5fd; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e293b;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; }

/* New features styles */
.library-filters-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.xray-control { display: flex; align-items: center; gap: 6px; padding-left: 6px; border-left: 1px solid var(--border); }

.presets-bar {
  background: #0d1422;
  border-bottom: 1px solid var(--border);
  padding: 5px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  flex-shrink: 0;
}
.presets-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.preset-chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}
.preset-chip:hover { border-color: var(--accent); color: #93c5fd; }
.preset-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.insp-img-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 4px;
}
.insp-img-preview img {
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* Diagnostics table */
.diag-table { display: flex; flex-direction: column; gap: 8px; }
.diag-row {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
}
.diag-row-top { display: flex; justify-content: space-between; align-items: center; }
.diag-inputs { display: flex; gap: 6px; align-items: center; }
.diag-status { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 4px; }
.diag-status.ok { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.diag-status.warn { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.diag-status.bad { background: rgba(239, 68, 68, 0.2); color: #f87171; }

/* Cases & Comments */
.mini-form { display: flex; flex-direction: column; gap: 6px; }
.cases-list, .comments-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.case-card, .comment-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.case-card strong { color: #93c5fd; }
.case-meta { font-size: 10px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }

/* Calculators */
.calc-pane { display: flex; flex-direction: column; gap: 10px; }
.calc-result {
  background: #0d1422;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  color: #34d399;
  text-align: center;
}
