/* =================================================================
 * Medisana DS Tuner · Control Panel Styles (v2 · Macro-driven)
 * ============================================================== */

:root {
  --ui-bg: #1A1D21;
  --ui-panel: #22262B;
  --ui-panel-2: #2A2F35;
  --ui-card: #2D3239;
  --ui-text: #E8E8E9;
  --ui-text-muted: #999B9F;
  --ui-text-dim: #6B6E72;
  --ui-border: #34383E;
  --ui-border-soft: #2A2E33;
  --ui-accent: #00C45A;
  --ui-accent-dim: #009639;
  --ui-warn: #F8951D;
  --ui-error: #E25C5C;

  --panel-w: 380px;
  --font-ui: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Monaco', 'Menlo', 'Courier New', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  background: var(--ui-bg);
  color: var(--ui-text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

code {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ui-text-muted);
  background: rgba(0,0,0,0.25);
  padding: 1px 4px;
  border-radius: 3px;
}

/* ============= LAYOUT ============= */
.tuner-app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100vh;
  width: 100vw;
}

/* ============= CONTROL PANEL ============= */
.control-panel {
  background: var(--ui-panel);
  border-right: 1px solid var(--ui-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
.panel-header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-header h1 .badge {
  display: inline-block;
  padding: 2px 6px;
  background: var(--ui-accent-dim);
  color: white;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.panel-header .subtitle {
  margin-top: 3px;
  font-size: 11px;
  color: var(--ui-text-muted);
}

.panel-body { flex: 1; padding: 14px 20px 28px; }

/* ============= SECTIONS ============= */
.section { margin-bottom: 22px; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.section-title h2,
.section-title-summary h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ui-text-muted);
}
.section-meta {
  font-size: 10px;
  color: var(--ui-text-dim);
  font-family: var(--font-mono);
}
.section-meta-dim {
  font-size: 10px;
  color: var(--ui-text-dim);
}

/* Collapsible */
details.collapsible { margin-bottom: 22px; }
details.collapsible > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 6px;
}
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 6px;
  transition: transform 150ms;
  font-size: 9px;
  color: var(--ui-text-muted);
  transform: translateY(-1px);
}
details.collapsible[open] > summary::before { transform: rotate(90deg) translateX(-1px); }
.section-title-summary { display: flex; align-items: baseline; flex: 1; }
.section-title-summary h2 { flex: 1; }
.section-body { padding-top: 10px; }

/* ============= PAGE CHIPS ============= */
.page-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.page-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 150ms, color 150ms, background 150ms;
}
.page-chip:hover { color: var(--ui-text); border-color: var(--ui-text-dim); }
.page-chip.active {
  background: rgba(0,196,90,0.10);
  border-color: var(--ui-accent);
  color: var(--ui-text);
}
.page-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ui-text-dim);
  flex-shrink: 0;
}
.page-chip.active .page-chip-dot { background: var(--ui-accent); }
.page-chip-flag {
  font-size: 10px;
  color: var(--ui-accent);
  font-weight: 600;
}

/* ============= MACRO CARDS ============= */
.macro-card {
  background: var(--ui-card);
  border: 1px solid var(--ui-border-soft);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  transition: border-color 200ms;
}
.macro-card:hover { border-color: var(--ui-border); }

.macro-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.macro-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  background: var(--ui-bg);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-accent);
}
.macro-label {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-text);
  letter-spacing: -0.1px;
}
.macro-value {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-accent);
  letter-spacing: -0.3px;
}

.macro-range {
  width: 100%;
  height: 4px;
  background: linear-gradient(to right, var(--ui-bg), var(--ui-accent-dim));
  border-radius: 2px;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: pointer;
  margin: 4px 0 2px;
}
.macro-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  background: var(--ui-accent);
  border: 2px solid var(--ui-card);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--ui-accent);
  transition: transform 100ms;
}
.macro-range::-webkit-slider-thumb:hover { transform: scale(1.12); }
.macro-range::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--ui-accent);
  border: 2px solid var(--ui-card);
  border-radius: 50%;
  cursor: pointer;
}

.macro-poles {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--ui-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 2px 2px 8px;
}

/* ============= MACRO VIZ ============= */
.macro-viz {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 32px;
  padding: 4px 4px 0;
  background: var(--ui-bg);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.viz-bar {
  width: 8px;
  background: linear-gradient(to top, var(--ui-accent-dim), var(--ui-accent));
  border-radius: 1px 1px 0 0;
  min-height: 2px;
  transition: height 200ms;
}
.viz-caption {
  position: absolute;
  right: 6px;
  top: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--ui-text-dim);
  pointer-events: none;
}
.viz-space {
  height: 100%;
  background: var(--ui-accent-dim);
  border-radius: 1px;
  transition: width 200ms;
}
/* Text spacing visualizer · 4 dots with 3 inter-dot gaps */
.viz-text-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  height: 100%;
  padding: 0 4px;
}
.viz-text-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ui-accent);
  flex-shrink: 0;
}
.viz-text-gap {
  height: 1px;
  background: var(--ui-text-dim);
  flex-shrink: 0;
  transition: width 200ms;
}
/* Component spacing visualizer · rounded box with 3 items inside */
.viz-comp-box {
  border: 1px solid var(--ui-accent-dim);
  border-radius: 3px;
  background: rgba(0,150,57,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: padding 200ms;
}
.viz-comp-row {
  display: flex;
  align-items: center;
  transition: gap 200ms;
}
.viz-comp-item {
  width: 5px;
  height: 5px;
  background: var(--ui-accent);
  border-radius: 1px;
}
/* Section spacing visualizer · vertical stack with 4 blocks and 3 gaps */
.viz-section-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 2px 0;
}
.viz-section-block {
  width: 80%;
  height: 4px;
  background: var(--ui-accent);
  border-radius: 1px;
  flex-shrink: 0;
}
.viz-section-gap {
  width: 100%;
  flex-shrink: 0;
  transition: height 200ms;
}
.viz-radius {
  width: 22px; height: 22px;
  background: var(--ui-accent);
  margin-bottom: 2px;
  transition: border-radius 200ms;
}
.viz-width-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 2px 0;
  align-items: flex-start;
}
.viz-width {
  height: 5px;
  background: var(--ui-accent);
  border-radius: 1px;
  transition: width 200ms;
}
.viz-width-max { background: var(--ui-accent); }
.viz-width-narrow { background: var(--ui-accent-dim); opacity: 0.7; }
.viz-width-form { background: var(--ui-text-dim); opacity: 0.6; }

/* ============= FIGMA SYNC ============= */
.fs-block {
  background: var(--ui-card);
  border: 1px solid var(--ui-border-soft);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.fs-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ui-text);
  margin-bottom: 4px;
  letter-spacing: 0.2px;
}
.fs-sub-label {
  margin-top: 8px;
  color: var(--ui-text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.fs-hint {
  font-size: 10px;
  color: var(--ui-text-dim);
  margin-bottom: 8px;
  line-height: 1.4;
}
.fs-hint code {
  font-size: 9px;
  background: var(--ui-bg);
  padding: 1px 3px;
  border-radius: 2px;
  color: var(--ui-accent);
}
.fs-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}
.fs-vp {
  flex: 1;
  font-size: 10px;
  color: var(--ui-text-muted);
  font-family: var(--font-mono);
}
.fs-copy-btn {
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text-muted);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10px;
  cursor: pointer;
  font-family: var(--font-ui);
}
.fs-copy-btn:hover {
  border-color: var(--ui-accent);
  color: var(--ui-text);
}
.fs-pushed {
  font-size: 10px;
  color: var(--ui-text-dim);
  font-family: var(--font-mono);
  margin: 2px 0 6px 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.fs-pushed a {
  color: var(--ui-accent);
}
.fs-time { color: var(--ui-text-dim); }
.fs-clear-btn {
  background: none;
  border: none;
  color: var(--ui-text-dim);
  cursor: pointer;
  font-size: 10px;
  padding: 0 4px;
}
.fs-clear-btn:hover { color: var(--ui-error); }

.fs-paste-row {
  margin-top: 4px;
}
.fs-vp-select {
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  padding: 5px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-family: var(--font-ui);
  outline: none;
}
.fs-input {
  flex: 1;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-family: var(--font-mono);
  outline: none;
  min-width: 0;
}
.fs-input:focus { border-color: var(--ui-accent); }
.fs-status {
  margin-top: 6px;
  font-size: 10px;
  color: var(--ui-text-muted);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.fs-status.ok { color: var(--ui-accent); }
.fs-status.error { color: var(--ui-error); }
.fs-status.loading { color: var(--ui-warn); }
.fs-status a { color: var(--ui-accent); }

/* ============= ADVANCED PANEL ============= */
.adv-group {
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--ui-bg);
  border-radius: 6px;
}
.adv-group-title {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ui-text-dim);
}
.adv-row {
  display: grid;
  grid-template-columns: 56px 1fr 48px 10px;
  gap: 6px;
  align-items: center;
  padding: 4px 0;
}
.adv-label {
  font-size: 10px;
  color: var(--ui-text-muted);
  font-family: var(--font-mono);
}
.adv-row input[type=range] {
  width: 100%;
  height: 3px;
  background: var(--ui-panel-2);
  border-radius: 2px;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  cursor: pointer;
}
.adv-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px; height: 10px;
  background: var(--ui-text-muted);
  border-radius: 50%;
  cursor: pointer;
}
.adv-row.overridden input[type=range]::-webkit-slider-thumb { background: var(--ui-warn); }
.adv-row .adv-value {
  background: var(--ui-panel);
  border: 1px solid var(--ui-border-soft);
  color: var(--ui-text);
  padding: 2px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-align: right;
  width: 100%;
  outline: none;
}
.adv-row .adv-value:focus { border-color: var(--ui-accent); }
.adv-ov-marker {
  font-size: 8px;
  color: transparent;
  text-align: center;
  transition: color 200ms;
}
.adv-row.overridden .adv-ov-marker { color: var(--ui-warn); }
.adv-row.overridden .adv-label { color: var(--ui-warn); }

/* ============= URL INPUTS ============= */
.sub-section {
  margin-bottom: 14px;
}
.sub-section:last-child { margin-bottom: 0; }
.sub-label {
  display: block;
  font-size: 10px;
  color: var(--ui-text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.input-row {
  display: flex;
  gap: 4px;
}
.input-row input[type=url] {
  flex: 1;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  padding: 7px 9px;
  border-radius: 5px;
  font-family: var(--font-ui);
  font-size: 11px;
  outline: none;
  transition: border-color 200ms;
  min-width: 0;
}
.input-row input[type=url]:focus { border-color: var(--ui-accent); }
.input-row input[type=url]::placeholder { color: var(--ui-text-dim); }
.btn-fetch {
  background: var(--ui-accent-dim);
  color: white;
  border: none;
  border-radius: 5px;
  padding: 0 10px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  transition: background 200ms;
  white-space: nowrap;
}
.btn-fetch:hover { background: var(--ui-accent); }
.fetch-status {
  margin-top: 5px;
  font-size: 10px;
  color: var(--ui-text-muted);
  font-family: var(--font-mono);
}
.fetch-status.ok { color: var(--ui-accent); }
.fetch-status.error { color: var(--ui-error); }
.fetch-status.loading { color: var(--ui-warn); }

.link-btn {
  background: none;
  border: none;
  color: var(--ui-accent);
  cursor: pointer;
  font-size: 10px;
  padding: 0;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
}
.link-btn:hover { color: var(--ui-text); }

.hint {
  font-size: 10px;
  color: var(--ui-text-dim);
  margin-top: 6px;
  line-height: 1.5;
}
.hint strong { color: var(--ui-text-muted); }

/* ============= PRESET BUTTONS ============= */
.preset-grid {
  display: grid;
  gap: 6px;
}
.btn-preset {
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
  padding: 8px 12px;
  border-radius: 6px;
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: border-color 200ms, background 200ms;
}
.btn-preset:hover {
  border-color: var(--ui-accent);
  background: var(--ui-panel-2);
}
.btn-preset.active {
  border-color: var(--ui-accent);
  background: rgba(0,196,90,0.08);
}
.btn-preset .preset-name { font-weight: 600; font-size: 12px; }
.btn-preset .preset-desc { font-size: 10px; color: var(--ui-text-muted); }

/* ============= EXPORT BUTTONS ============= */
.export-group {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.btn-export {
  background: var(--ui-accent-dim);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 200ms;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.btn-export:hover { background: var(--ui-accent); }
.btn-export.secondary {
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text);
}
.btn-export.secondary:hover {
  border-color: var(--ui-accent);
  background: var(--ui-panel-2);
}

/* ============= PREVIEW AREA ============= */
.preview-area {
  background: #F0F0F0;
  overflow: auto;
  position: relative;
}
.preview-area.mobile {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.preview-area.mobile .preview-toolbar { width: 100%; }
.preview-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11px;
  color: var(--ui-text-muted);
}
.preview-toolbar .label {
  font-weight: 600;
  color: var(--ui-text);
}
.preview-toolbar .indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  background: var(--ui-bg);
  border-radius: 100px;
  font-family: var(--font-mono);
}
.preview-toolbar .indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ui-text-dim);
  transition: background 200ms;
}
.preview-toolbar .indicator.live .indicator-dot { background: var(--ui-accent); }
.preview-toolbar .spacer { flex: 1; }
.preview-toolbar a {
  color: var(--ui-text-muted);
  text-decoration: none;
}
.preview-toolbar a:hover { color: var(--ui-accent); }

.preview-stage {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 0;
  width: max-content;
  min-width: 100%;
}
.preview-stage.split { gap: 24px; padding-right: 16px; }
.preview-frame {
  width: 1920px;
  border: none;
  display: block;
  background: white;
  min-height: calc(100vh - 38px);
  transition: width 240ms cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}
iframe.preview-frame.mobile { width: 375px; }

.figma-final-pane {
  display: none;
  flex-direction: column;
  background: white;
  border: 1px solid var(--ui-border);
  min-height: 400px;
  width: 1920px;
  flex-shrink: 0;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
}
.preview-stage.split .figma-final-pane { display: flex; }
.preview-stage.split iframe.preview-frame.mobile ~ .figma-final-pane { width: 375px; }
.figma-final-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-panel-2);
  font-size: 11px;
  color: var(--ui-text);
  font-family: var(--font-mono);
  position: sticky;
  top: 0;
  z-index: 1;
}
.figma-final-header a {
  color: var(--ui-accent);
  text-decoration: none;
  font-size: 12px;
}
.figma-final-pane img {
  width: 100%;
  height: auto;
  display: block;
}

.split-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  color: var(--ui-text-muted);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font-ui);
}
.split-toggle:hover { color: var(--ui-text); border-color: var(--ui-text-dim); }
.split-toggle.active {
  background: var(--ui-accent-dim);
  border-color: var(--ui-accent);
  color: white;
}
.split-icon { font-size: 13px; }

/* Viewport toggle */
.viewport-toggle {
  display: inline-flex;
  background: var(--ui-bg);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}
.vp-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--ui-text-muted);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.vp-btn:hover { color: var(--ui-text); }
.vp-btn.active {
  background: var(--ui-accent-dim);
  color: white;
}
.vp-btn svg { stroke: currentColor; }

/* ============= SCROLLBAR ============= */
.control-panel::-webkit-scrollbar { width: 8px; }
.control-panel::-webkit-scrollbar-track { background: var(--ui-panel); }
.control-panel::-webkit-scrollbar-thumb {
  background: var(--ui-border);
  border-radius: 4px;
}
.control-panel::-webkit-scrollbar-thumb:hover { background: var(--ui-text-dim); }

/* ============= TOAST ============= */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ui-panel-2);
  color: var(--ui-text);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 200ms, transform 200ms;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: var(--ui-accent); }
.toast.error { border-color: var(--ui-error); }
