/* ========================================================================
   FRESH PAD - Fresh AV Labs Install Tech Toolkit
   ======================================================================== */

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

:root {
  --font-head: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'Roboto Mono', 'Courier New', monospace;
  --font-body: 'Inter', sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: 150ms ease;
}

/* ---- DARK THEME (default) ---- */
[data-theme="dark"] {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #f0f6fc;
  --text2: #9ba4ae;
  --text3: #5a6370;
  --green: #C4E04F;
  --green-dark: #39B224;
  --blue: #58a6ff;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #8C70F0;
  --shadow: 0 4px 12px rgba(0,0,0,.3);
  color-scheme: dark;
}

/* ---- LIGHT THEME ---- */
[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f6f8fa;
  --bg3: #e8ecf0;
  --border: #d0d7de;
  --text: #1f2328;
  --text2: #59636e;
  --text3: #8b949e;
  --green: #4a7c00;
  --green-dark: #2c6b1a;
  --blue: #0969da;
  --red: #cf222e;
  --yellow: #9a6700;
  --purple: #6639ba;
  --shadow: 0 4px 12px rgba(0,0,0,.08);
  color-scheme: light;
}
[data-theme="light"] .form-select option { background: var(--bg2); color: var(--text); }
[data-theme="light"] .color-swatch { border-color: rgba(0,0,0,.15); }
[data-theme="light"] .btn-primary { background: #4a7c00; color: #fff; }
[data-theme="light"] .tag-green { background: rgba(74,124,0,.1); color: #4a7c00; }
[data-theme="light"] .tag-red { background: rgba(207,34,46,.1); color: #cf222e; }
[data-theme="light"] .tag-yellow { background: rgba(154,103,0,.1); color: #9a6700; }
[data-theme="light"] .tag-blue { background: rgba(9,105,218,.1); color: #0969da; }
[data-theme="light"] .draw-toolbar { background: var(--bg2); }
[data-theme="light"] .timer-display { color: #4a7c00; }
[data-theme="light"] .timer-display.expired { color: #cf222e; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  font-weight: 400;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app { display: flex; height: 100vh; height: 100dvh; }

/* ---- SIDEBAR ---- */
.sidebar {
  width: 56px; background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0; gap: 2px; overflow-y: auto; overflow-x: hidden;
  flex-shrink: 0; scrollbar-width: none; transition: width 200ms ease; z-index: 100;
}
.sidebar::-webkit-scrollbar { display: none; }
.sidebar.expanded { width: 180px; align-items: stretch; padding: 12px 8px; }

.sidebar-logo { width: 32px; height: 32px; margin-bottom: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar.expanded .sidebar-logo { margin-left: 4px; }
.sidebar-logo svg { width: 28px; height: 28px; }

.sidebar-divider { width: 28px; height: 1px; background: var(--border); margin: 4px 0 6px; flex-shrink: 0; }
.sidebar.expanded .sidebar-divider { width: 100%; }

.sidebar-group-label {
  display: none; font-family: var(--font-mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text3);
  padding: 6px 10px 2px; flex-shrink: 0;
}
.sidebar.expanded .sidebar-group-label { display: block; }

.tool-btn {
  width: 40px; height: 40px; border: none; background: transparent; color: var(--text2);
  border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  position: relative; flex-shrink: 0; transition: background var(--transition), color var(--transition); gap: 8px;
}
.tool-btn:hover { background: var(--bg3); color: var(--text); }
.tool-btn.active { background: rgba(196,224,79,.12); color: var(--green); }
.tool-btn svg { width: 20px; height: 20px; pointer-events: none; flex-shrink: 0; }

.tool-btn .btn-label {
  display: none; font-size: 12px; font-family: var(--font-body); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.sidebar.expanded .tool-btn { width: 100%; height: 36px; justify-content: flex-start; padding: 0 8px; }
.sidebar.expanded .tool-btn .btn-label { display: block; }
.sidebar.expanded .tool-btn svg { width: 18px; height: 18px; }

.tool-btn::after {
  content: attr(data-tooltip); position: absolute; left: 52px; background: var(--bg3);
  color: var(--text); padding: 4px 10px; border-radius: 6px; font-size: 12px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 120ms ease;
  border: 1px solid var(--border); z-index: 200;
}
.tool-btn:hover::after { opacity: 1; }
.sidebar.expanded .tool-btn::after { display: none; }

.sidebar-toggle {
  width: 40px; height: 32px; border: none; background: transparent; color: var(--text3);
  border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: auto; transition: color var(--transition), background var(--transition);
}
.sidebar-toggle:hover { color: var(--text); background: var(--bg3); }
.sidebar.expanded .sidebar-toggle { width: 100%; justify-content: flex-start; padding: 0 8px; gap: 8px; }
.sidebar-toggle .toggle-label { display: none; font-size: 11px; font-family: var(--font-mono); color: var(--text3); }
.sidebar.expanded .sidebar-toggle .toggle-label { display: block; }
.sidebar-toggle svg { transition: transform 200ms ease; }
.sidebar.expanded .sidebar-toggle svg { transform: rotate(180deg); }

/* ---- MAIN CONTENT ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.header {
  height: 44px; background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 10px; flex-shrink: 0;
}
.header-title { font-family: var(--font-head); font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
.header-subtitle { font-family: var(--font-mono); font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; }

.content {
  flex: 1; overflow-y: auto; padding: 20px;
  scrollbar-width: thin; scrollbar-color: var(--bg3) transparent;
}
.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

.tool-panel { display: none; height: 100%; }
.tool-panel.active { display: flex; flex-direction: column; }

/* ---- SHARED COMPONENTS ---- */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.card-header { background: var(--bg3); padding: 10px 14px; border-bottom: 1px solid var(--border); font-family: var(--font-mono); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text2); }
.card-body { padding: 14px; }

.form-row { display: flex; gap: 10px; align-items: end; margin-bottom: 12px; flex-wrap: wrap; }
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px; }
.form-label { font-size: 12px; color: var(--text); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.form-input, .form-select {
  width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-family: var(--font-mono);
  font-size: 14px; min-height: 38px; outline: none; transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(196,224,79,.12); }
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px;
}
.form-select option { background: var(--bg2); }

.btn {
  padding: 8px 16px; border: none; border-radius: var(--radius-sm); font-family: var(--font-head);
  font-weight: 600; font-size: 13px; cursor: pointer; min-height: 38px;
  transition: opacity var(--transition), transform 80ms ease;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--green); color: #000; }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 30px; }

.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.result-item { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.result-label { font-size: 11px; color: var(--text); font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; font-weight: 500; }
.result-value { font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--green); word-break: break-all; }
.result-value.warn { color: var(--yellow); }
.result-value.error { color: var(--red); }
.result-value.info { color: var(--blue); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; font-family: var(--font-mono); text-transform: uppercase; }
.tag-green { background: rgba(196,224,79,.15); color: var(--green); }
.tag-red { background: rgba(248,81,73,.15); color: var(--red); }
.tag-yellow { background: rgba(210,153,34,.15); color: var(--yellow); }
.tag-blue { background: rgba(88,166,255,.15); color: var(--blue); }

/* ---- CABLE CALC MODE TOGGLE ---- */
.cable-mode-toggle { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; width: fit-content; }
.cable-mode-btn { padding: 5px 14px; border: none; border-radius: 4px; background: transparent; color: var(--text2); font-family: var(--font-mono); font-size: 12px; font-weight: 500; cursor: pointer; transition: all var(--transition); }
.cable-mode-btn:hover { color: var(--text); }
.cable-mode-btn.active { background: rgba(196,224,79,.12); color: var(--green); font-weight: 600; }
.speaker-type-toggle { margin-top: 4px; }

/* ---- CABLE SIGNAL TABLE ---- */
.cable-signal-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 13px; }
.cable-signal-table th, .cable-signal-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.cable-signal-table th { font-size: 11px; text-transform: uppercase; color: var(--text2); letter-spacing: 0.04em; background: var(--bg3); font-weight: 600; }
.cable-signal-table td { color: var(--text); }
.cable-signal-table tr:last-child td { border-bottom: none; }
.cable-signal-table tr.gauge-chart-active td { background: rgba(196,224,79,.08); color: var(--green); font-weight: 600; }

/* ---- HELP MODAL ---- */
.help-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 1000; align-items: center; justify-content: center; }
.help-overlay.active { display: flex; }
.help-modal { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); width: 380px; max-width: 90vw; box-shadow: 0 16px 48px rgba(0,0,0,.3); }
.help-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); font-family: var(--font-mono); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text2); }
.help-close { background: none; border: none; color: var(--text2); font-size: 22px; cursor: pointer; padding: 0 4px; line-height: 1; }
.help-close:hover { color: var(--text); }
.help-body { padding: 16px 18px; }
.help-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 13px; }
.help-table td { padding: 6px 0; color: var(--text); }
.help-table td:first-child { white-space: nowrap; padding-right: 20px; color: var(--text2); }
kbd { display: inline-block; padding: 2px 6px; background: var(--bg3); border: 1px solid var(--border); border-radius: 4px; font-family: var(--font-mono); font-size: 11px; font-weight: 600; color: var(--text); line-height: 1.4; }
.help-footer { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-family: var(--font-mono); font-size: 11px; color: var(--text2); text-align: center; letter-spacing: 0.04em; }

/* ---- DRAWING PAD ---- */
.draw-swatches { display: flex; gap: 3px; align-items: center; }
.draw-swatch { width: 24px; height: 24px; border: 2px solid var(--border); border-radius: 4px; cursor: pointer; padding: 0; transition: border-color var(--transition); }
.draw-swatch:hover { border-color: var(--text2); }
.draw-swatch.active { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.draw-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-wrap: wrap; flex-shrink: 0; }
.draw-tool-group { display: flex; align-items: center; gap: 4px; }
.draw-tool-btn { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--bg); color: var(--text2); border-radius: var(--radius-sm); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.draw-tool-btn:hover { border-color: var(--text2); color: var(--text); }
.draw-tool-btn.active { border-color: var(--green); color: var(--green); background: rgba(196,224,79,.08); }
.draw-tool-btn svg { width: 18px; height: 18px; }
.draw-color-picker { width: 34px; height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; padding: 2px; }
.draw-color-picker::-webkit-color-swatch-wrapper { padding: 2px; }
.draw-color-picker::-webkit-color-swatch { border: none; border-radius: 3px; }

/* ---- PROGRESS BAR (used by PoE) ---- */
.cl-progress-bar { height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden; margin-bottom: 12px; }
.cl-progress-fill { height: 100%; background: var(--green); border-radius: 2px; transition: width 300ms ease; }

/* ---- PINOUT TABLES ---- */
.pinout-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 14px; }
.pinout-table th, .pinout-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.pinout-table th { font-size: 12px; text-transform: uppercase; color: var(--text); letter-spacing: 0.04em; background: var(--bg3); font-weight: 600; }
.pinout-table td { color: var(--text); }
.color-swatch { display: inline-block; width: 16px; height: 16px; border-radius: 3px; vertical-align: middle; margin-right: 6px; border: 1px solid rgba(255,255,255,.1); }

/* ---- QR CODE ---- */
#qr-canvas { background: #fff; border-radius: var(--radius-sm); max-width: 256px; image-rendering: pixelated; }

/* ---- TIMER ---- */
.timer-display { font-family: var(--font-mono); font-size: 64px; font-weight: 700; text-align: center; letter-spacing: -0.02em; color: var(--green); padding: 32px 0; line-height: 1; }
.timer-display.expired { color: var(--red); }
.timer-label { text-align: center; font-family: var(--font-mono); font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 24px; }

/* ========================================================================
   WIRING DIAGRAMS
   ======================================================================== */
.wiring-layout { display: flex; gap: 0; height: 100%; overflow: hidden; }
.wiring-nav {
  width: 220px; background: var(--bg2); border-right: 1px solid var(--border);
  overflow-y: auto; flex-shrink: 0; scrollbar-width: thin; scrollbar-color: var(--bg3) transparent;
}
.wiring-nav::-webkit-scrollbar { width: 4px; }
.wiring-nav::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 2px; }
.wiring-nav-group-title {
  font-family: var(--font-mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text3); padding: 12px 14px 4px; user-select: none;
}
.wiring-nav-item {
  display: block; width: 100%; padding: 7px 14px; border: none; background: transparent;
  color: var(--text2); font-family: var(--font-body); font-size: 13px; text-align: left;
  cursor: pointer; transition: background var(--transition), color var(--transition);
  border-left: 2px solid transparent;
}
.wiring-nav-item:hover { background: var(--bg3); color: var(--text); }
.wiring-nav-item.active { color: var(--green); background: rgba(196,224,79,.06); border-left-color: var(--green); }

.wiring-viewer {
  flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column;
  align-items: center; scrollbar-width: thin; scrollbar-color: var(--bg3) transparent;
}
.wiring-title { font-family: var(--font-head); font-weight: 700; font-size: 18px; margin-bottom: 4px; text-align: center; }
.wiring-desc { font-family: var(--font-mono); font-size: 12px; color: var(--text2); text-align: center; margin-bottom: 20px; max-width: 500px; line-height: 1.6; }
.wiring-svg-container {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; display: flex; justify-content: center; align-items: center;
  margin-bottom: 16px; width: 100%; max-width: 600px;
}
.wiring-svg-container svg { width: 100%; height: auto; max-height: 400px; }
.wiring-svg-container--wide { max-width: 700px; }
.wiring-svg-container--wide svg { max-height: 320px; }
.wiring-legend { width: 100%; max-width: 600px; }
.wiring-note {
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px;
  background: rgba(196,224,79,.06); border: 1px solid rgba(196,224,79,.15);
  border-radius: var(--radius-sm); margin-top: 12px; max-width: 600px; width: 100%;
}
.wiring-note svg { width: 16px; height: 16px; color: var(--green); flex-shrink: 0; margin-top: 1px; }
.wiring-note p { font-size: 12px; color: var(--text2); line-height: 1.5; }
.wiring-note--warning { background: rgba(248,81,73,.06); border-color: rgba(248,81,73,.2); }
.wiring-note--warning svg { color: var(--red); }
.wiring-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text3); gap: 12px; text-align: center; padding: 40px;
}
.wiring-empty svg { width: 48px; height: 48px; opacity: 0.3; }
.wiring-empty p { font-family: var(--font-mono); font-size: 13px; }

/* ---- RIGGING REFERENCE ---- */
.rig-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.rig-tabs::-webkit-scrollbar { display: none; }
.rig-tab {
  padding: 5px 12px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text2);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.rig-tab:hover { border-color: var(--text2); color: var(--text); }
.rig-tab.active { background: rgba(196,224,79,.12); border-color: var(--green); color: var(--green); }

@keyframes rigFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---- RESPONSIVE ---- */
@media (max-width: 640px) {
  .sidebar { width: 48px; }
  .sidebar.expanded { width: 160px; }
  .tool-btn { width: 36px; height: 36px; }
  .tool-btn svg { width: 18px; height: 18px; }
  .tool-btn::after { display: none; }
  .sidebar.expanded .tool-btn { width: 100%; height: 34px; }
  .content { padding: 14px; }
  .header { padding: 0 12px; }
  .result-grid { grid-template-columns: 1fr; }
  .timer-display { font-size: 40px; }
  .form-row { flex-direction: column; }
  .wiring-layout { flex-direction: column; }
  .wiring-nav { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 160px; }
  .wiring-viewer { padding: 16px; }
  .wiring-svg-container { padding: 16px; }
  .cable-mode-toggle { width: 100%; }
  .cable-mode-btn { flex: 1; text-align: center; padding: 5px 6px; font-size: 11px; }
  .cable-signal-table { font-size: 12px; }
  .cable-signal-table th:nth-child(2), .cable-signal-table td:nth-child(2) { display: none; }
}
