/* ════════════════════════════════════════════════════════════
   Lightstrip Studio — Figma-style Design System
   ════════════════════════════════════════════════════════════ */

:root {
  --bg-app: #1a1a1a;
  --bg-canvas: #141414;
  --bg-toolbar: #2c2c2c;
  --bg-panel: #252525;
  --bg-section: #2c2c2c;
  --bg-input: #1a1a1a;
  --bg-input-hover: #1e1e1e;
  --bg-elevated: #333;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-active: rgba(13, 153, 255, 0.15);

  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-focus: #0d99ff;

  --text-primary: #e8e8e8;
  --text-secondary: #999;
  --text-tertiary: #666;
  --text-inverse: #1a1a1a;

  --accent: #0d99ff;
  --accent-hover: #38abff;
  --accent-muted: rgba(13, 153, 255, 0.2);
  --danger: #f24822;
  --danger-muted: rgba(242, 72, 34, 0.15);
  --success: #14ae5c;
  --warning: #ffcd29;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --toolbar-h: 48px;
  --statusbar-h: 36px;
  --panel-w: 280px;

  --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}


/* ═══ RESET ═══ */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
input, textarea, button, summary { font: inherit; }


/* ═══ APP LAYOUT ═══ */

.app-layout {
  display: grid;
  grid-template-rows: var(--toolbar-h) 1fr var(--statusbar-h);
  width: 100%;
  height: 100%;
}

.main-area {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  min-height: 0;
  overflow: hidden;
}


/* ═══ TOOLBAR ═══ */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  gap: 4px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 4px;
  flex-shrink: 0;
}

.brand-icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.brand-name {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
}

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}


/* ─── Toolbar Buttons ─── */

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 120ms ease;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
}

.toolbar-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.toolbar-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.toolbar-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.toolbar-btn.active:hover {
  background: var(--accent-hover);
}

.toolbar-btn.icon-only {
  padding: 6px;
}

.toolbar-btn.icon-only span { display: none; }

.toolbar-btn.btn-danger:hover {
  background: var(--danger-muted);
  color: var(--danger);
}




/* ═══ CANVAS / STAGE ═══ */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--bg-canvas);
  overflow: hidden;
}

#drawCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}


/* ═══ RIGHT PANEL ═══ */

.panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elevated) transparent;
}

.panel-scroll::-webkit-scrollbar {
  width: 6px;
}
.panel-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.panel-scroll::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 3px;
}
.panel-scroll::-webkit-scrollbar-thumb:hover {
  background: #444;
}


/* ─── Panel Sections ─── */

.panel-section {
  border-bottom: 1px solid var(--border);
}

.panel-section-last {
  border-bottom: none;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.section-title svg {
  width: 14px;
  height: 14px;
  opacity: 0.6;
}


/* ─── Property Groups (collapsible) ─── */

.prop-group {
  border-top: 1px solid var(--border-subtle);
}

.prop-group:first-of-type {
  border-top: none;
}

.prop-group summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background 100ms ease;
  user-select: none;
}

.prop-group summary::-webkit-details-marker { display: none; }

.prop-group summary::after {
  content: '';
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23999' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M5 6l3 3 3-3'/%3E%3C/svg%3E") center/contain no-repeat;
  transition: transform 150ms var(--ease-out);
}

.prop-group[open] summary::after {
  transform: rotate(180deg);
}

.prop-group summary:hover {
  background: var(--bg-hover);
}

.prop-fields {
  padding: 2px 16px 12px;
}


/* ─── Labels & Inputs ─── */

label {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.prop-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}


/* ─── Tooltip (?) icon ─── */

.prop-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-tertiary);
  font-size: 9px;
  font-weight: 700;
  cursor: help;
  position: relative;
  vertical-align: middle;
  margin-left: 4px;
  flex-shrink: 0;
  line-height: 1;
  transition: background 120ms ease, color 120ms ease;
}

.prop-tip:hover {
  background: var(--accent-muted);
  color: var(--accent);
}

/* Tooltip popup is rendered via JS into body to escape overflow:hidden */
.prop-tip-popup {
  position: fixed;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  white-space: normal;
  width: 210px;
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
  transition: opacity 120ms ease;
}

.prop-tip-popup.visible {
  opacity: 1;
}

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input-with-unit:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
}

.input-with-unit input {
  flex: 1;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 6px 8px;
  min-width: 0;
}

.input-with-unit input:focus {
  outline: none;
  box-shadow: none !important;
}

.unit {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  padding: 0 8px;
  flex-shrink: 0;
  user-select: none;
}

input:not([type="checkbox"]):not([type="range"]),
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-primary);
  padding: 6px 8px;
  font-size: 12px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:not([type="checkbox"]):not([type="range"]):focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-muted);
}

textarea {
  resize: vertical;
  min-height: 56px;
  font-family: var(--font-mono);
  font-size: 11px;
}


/* ─── Range Slider ─── */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border: none;
  border-radius: 2px;
  background: var(--bg-elevated);
  cursor: pointer;
  padding: 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 120ms var(--ease-spring);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-tertiary);
  min-width: 32px;
  text-align: right;
}


/* ─── Checkbox ─── */

.checkbox-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.checkbox-row span {
  font-size: 12px;
  color: var(--text-secondary);
}


/* ─── Panel Buttons ─── */

.panel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-section);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms ease;
  white-space: nowrap;
}

.panel-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.12);
}

.panel-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.panel-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.panel-btn.accent {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.panel-btn.accent:hover {
  background: var(--accent-hover);
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
}

.btn-grid .panel-btn:only-child,
.export-grid .panel-btn:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.hint-text {
  margin: 0 0 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-tertiary);
}


/* ─── Chunk List ─── */

.chunk-list {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.chunk-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 6px 10px;
  background: var(--bg-input);
}

.chunk-item span {
  color: var(--text-secondary);
  font-size: 12px;
}

.chunk-item a {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
}

.chunk-item a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}


/* ─── Diagnostics ─── */

#status {
  margin: 0;
  max-height: 200px;
  overflow: auto;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}


/* ═══ STATUS BAR ═══ */

.statusbar {
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg-toolbar);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.status-items {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
}

.status-item:first-child {
  padding-left: 0;
}

.status-label {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.status-item strong {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

.status-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  flex-shrink: 0;
}

.status-badge,
.length-badge {
  font-size: 11px;
  font-weight: 400;
  line-height: 1;
  color: var(--text-tertiary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0;
}

.status-badge .badge-seg {
  padding: 0 12px;
}

.status-badge .badge-seg:first-child {
  padding-left: 0;
}

.status-badge .badge-seg {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.status-badge .badge-seg .status-label {
  font-size: 11px;
  color: var(--text-tertiary);
}

.status-badge .badge-seg strong {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

.badge-div {
  width: 1px;
  height: 16px;
  background: var(--border);
  flex-shrink: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* ═══ RESPONSIVE ═══ */

@media (max-width: 1000px) {
  :root {
    --panel-w: 240px;
  }
}

@media (max-width: 780px) {
  .main-area {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .panel {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 40dvh;
  }

  .toolbar-btn span {
    display: none;
  }

  .toolbar-btn {
    padding: 6px;
  }

  .toolbar-badge {
    font-size: 10px;
    padding: 3px 8px;
  }
}

@media (max-width: 540px) {
  .toolbar {
    padding: 0 8px;
  }

  .brand-name {
    display: none;
  }

  .status-label {
    display: none;
  }

  .status-item {
    padding: 0 6px;
  }

  .prop-fields {
    padding: 2px 12px 10px;
  }

  .section-title {
    padding: 8px 12px;
  }

  .prop-group summary {
    padding: 8px 12px;
  }
}


/* ═══ ANIMATIONS ═══ */

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

.stage {
  animation: fadeIn 300ms var(--ease-out);
}

.panel {
  animation: panelSlide 300ms var(--ease-out);
}

@keyframes panelSlide {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toolbar {
  animation: toolbarSlide 250ms var(--ease-out);
}

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

.statusbar {
  animation: fadeIn 400ms var(--ease-out) 100ms both;
}


/* ═══ SELECTION COLORS ═══ */

::selection {
  background: var(--accent-muted);
  color: var(--text-primary);
}


/* ═══ STRIP TOP FIELDS (always visible, not in collapsible) ═══ */

.strip-top-fields {
  padding: 2px 16px 12px;
}


/* ═══ DIAGNOSTICS OVERLAY ═══ */

.diag-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 340px;
  max-height: calc(100% - 24px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 20;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: diagFadeIn 150ms var(--ease-out);
}

@keyframes diagFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.diag-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.diag-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
}

.diag-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.diag-overlay #status {
  flex: 1;
  overflow: auto;
  border: none;
  border-radius: 0;
  max-height: none;
}


/* ═══ CLEAR CONFIRM OVERLAY ═══ */

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 100ms ease;
}

.confirm-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  min-width: 280px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.confirm-box p {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.confirm-hint {
  display: block;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.confirm-actions .panel-btn {
  flex: 1;
  padding: 8px 16px;
}

.btn-confirm-danger {
  background: var(--danger) !important;
  border-color: transparent !important;
  color: #fff !important;
  font-weight: 600 !important;
}

.btn-confirm-danger:hover {
  background: #ff5c3a !important;
}


/* ═══ SMART EXPORT ═══ */

.export-stl-main {
  width: 100%;
  padding: 8px 16px;
  font-size: 13px;
}

.mesh-preview-trigger {
  width: 100%;
  margin-top: 8px;
}

.export-options {
  margin-top: 8px;
}

.export-hint {
  margin-bottom: 6px !important;
  color: var(--warning) !important;
  font-weight: 500;
}

.mesh-preview-overlay {
  position: absolute;
  inset: 12px;
  z-index: 18;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  background: rgba(5, 8, 12, 0.34);
  backdrop-filter: blur(2px);
  animation: diagFadeIn 150ms var(--ease-out);
}

.mesh-preview-overlay[hidden] {
  display: none !important;
}

.mesh-preview-shell {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(18, 25, 34, 0.96), rgba(8, 12, 17, 0.96)),
    rgba(10, 14, 18, 0.9);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 16px 46px rgba(0, 0, 0, 0.45);
}

.mesh-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mesh-preview-close {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 20px;
  line-height: 1;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mesh-preview-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.mesh-preview-canvas {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #111922, #090d12);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: grab;
}

.mesh-preview-canvas:active {
  cursor: grabbing;
}

.mesh-preview-help {
  margin: 10px 0 0 !important;
  font-size: 11px;
}

.mesh-preview-meta {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-secondary);
  white-space: pre-wrap;
}


/* ═══ STATUS BAR: EMPTY STATE & COLOR CODING ═══ */

.status-empty-hint {
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
}

.status-content {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
}

.remaining-ok {
  color: var(--success) !important;
}

.remaining-warn {
  color: var(--warning) !important;
}

.remaining-over {
  color: var(--danger) !important;
}


/* ═══ RESPONSIVE ADDITIONS ═══ */

@media (max-width: 780px) {
  .diag-overlay {
    width: calc(100% - 24px);
    right: 12px;
    left: 12px;
  }
}

@media (max-width: 540px) {
  .strip-top-fields {
    padding: 2px 12px 10px;
  }
}
