/* style.css — Shared responsive layout and design system for PQRS Visualizations */

:root {
  --pqv-bg: #faf9f6;
  --pqv-surface: #ffffff;
  --pqv-card: #f3f2ee;
  --pqv-ink: #1a1a1f;
  --pqv-muted: #55544e;
  --pqv-faint: #84827a;
  --pqv-hairline: #e2e0d8;
  --pqv-accent: #0f766e;
  --pqv-accent-soft: rgba(15, 118, 110, 0.13);
  --pqv-part-1: #0072B2;
  --pqv-part-2: #D55E00;
  --pqv-part-3: #882E72;
  --pqv-warn: #b45309;
  --pqv-warn-soft: rgba(180, 83, 9, 0.12);
  --pqv-radius: 12px;
  --pqv-tap: 44px;
  --pqv-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pqv-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --pqv-bg: #121216;
    --pqv-surface: #18181e;
    --pqv-card: #212129;
    --pqv-ink: #ececf0;
    --pqv-muted: #b4b4bd;
    --pqv-faint: #7c7c87;
    --pqv-hairline: #2e2e38;
    --pqv-accent: #3cb8ab;
    --pqv-accent-soft: rgba(60, 184, 171, 0.18);
    --pqv-warn: #f59e0b;
    --pqv-warn-soft: rgba(245, 158, 11, 0.16);
  }
}

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

html {
  background: var(--pqv-bg);
  color: var(--pqv-ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--pqv-bg);
  color: var(--pqv-ink);
  font: 15px/1.45 var(--pqv-font);
  overflow-x: hidden;
}

button, input, select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--pqv-accent);
  text-underline-offset: 2px;
}

[hidden] { display: none !important; }

.pqv-app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) 28px max(16px, env(safe-area-inset-left, 0px));
}

/* ---- Top Navigation Bar ---- */
.pqv-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--pqv-hairline);
}

.pqv-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pqv-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--pqv-hairline);
  background: var(--pqv-surface);
  color: var(--pqv-ink);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pqv-back:hover { background: var(--pqv-card); }

.pqv-switcher {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.pqv-navlink {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--pqv-hairline);
  background: var(--pqv-surface);
  color: var(--pqv-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  transition: background-color 0.12s, color 0.12s, border-color 0.12s;
}
.pqv-navlink:hover {
  background: var(--pqv-card);
  color: var(--pqv-ink);
}
.pqv-navlink[aria-current="page"] {
  background: var(--pqv-accent-soft);
  border-color: var(--pqv-accent);
  color: var(--pqv-ink);
  font-weight: 650;
}

/* ---- Page Header ---- */
.pqv-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-bottom: 12px;
}
.pqv-title {
  margin: 0;
  font-size: clamp(20px, 2.6vw, 26px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.pqv-subtitle {
  margin: 0;
  color: var(--pqv-muted);
  font-size: 14.5px;
  font-weight: 500;
}
.pqv-desc {
  flex: 1 1 100%;
  margin: 2px 0 0;
  color: var(--pqv-muted);
  font-size: 14px;
  max-width: 78ch;
}

/* ---- Main Workspace Grid ---- */
.pqv-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 16px;
  align-items: start;
}

/* ---- Canvas Pane ---- */
.pqv-stage-panel {
  min-width: 0;
  background: var(--pqv-surface);
  border: 1px solid var(--pqv-hairline);
  border-radius: var(--pqv-radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pqv-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pqv-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--pqv-ink);
}
.pqv-badge-kind {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--pqv-card);
  color: var(--pqv-muted);
  border: 1px solid var(--pqv-hairline);
}

.pqv-tool-btns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.pqv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--pqv-hairline);
  border-radius: 8px;
  background: var(--pqv-surface);
  color: var(--pqv-ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.pqv-btn:hover { background: var(--pqv-card); }
.pqv-btn[aria-pressed="true"] {
  background: var(--pqv-accent-soft);
  border-color: var(--pqv-accent);
}
.pqv-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.pqv-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: min(72vh, 720px);
  min-height: 280px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--pqv-bg);
  border: 1px solid var(--pqv-hairline);
  cursor: grab;
  touch-action: none;
}
.pqv-stage:active { cursor: grabbing; }

.pqv-stage > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.pqv-overlay-canvas {
  pointer-events: none;
}

.pqv-hint {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--pqv-surface) 88%, transparent);
  border: 1px solid var(--pqv-hairline);
  color: var(--pqv-muted);
  font-size: 12px;
  pointer-events: none;
}

/* ---- Control Sidebar ---- */
.pqv-sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pqv-section {
  background: var(--pqv-surface);
  border: 1px solid var(--pqv-hairline);
  border-radius: var(--pqv-radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pqv-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pqv-sec-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--pqv-muted);
}

/* ---- PQRS Order Steppers & Presets ---- */
.pqv-steppers {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.pqv-stepper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 10px;
  background: var(--pqv-card);
  border: 1px solid var(--pqv-hairline);
}
.pqv-stepper-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--pqv-muted);
}
.pqv-stepper-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
}
.pqv-step-btn {
  width: 28px;
  height: 30px;
  border: 1px solid var(--pqv-hairline);
  border-radius: 6px;
  background: var(--pqv-surface);
  color: var(--pqv-ink);
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pqv-step-btn:hover:not(:disabled) { background: var(--pqv-accent-soft); border-color: var(--pqv-accent); }
.pqv-step-btn:disabled { opacity: 0.35; cursor: default; }

.pqv-step-val {
  min-width: 20px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pqv-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pqv-chip {
  min-height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--pqv-hairline);
  border-radius: 999px;
  background: var(--pqv-surface);
  color: var(--pqv-muted);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.pqv-chip:hover { background: var(--pqv-card); color: var(--pqv-ink); }
.pqv-chip[aria-pressed="true"] {
  background: var(--pqv-accent-soft);
  border-color: var(--pqv-accent);
  color: var(--pqv-ink);
}

/* ---- Partition Cards ---- */
.pqv-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pqv-card {
  --part-col: var(--pqv-part-1);
  border: 1.5px solid var(--pqv-hairline);
  border-radius: 10px;
  background: var(--pqv-surface);
  padding: 6px 10px 8px;
  min-width: 0;
}
.pqv-card[data-part="1"] { --part-col: var(--pqv-part-1); }
.pqv-card[data-part="2"] { --part-col: var(--pqv-part-2); }
.pqv-card[data-part="3"] { --part-col: var(--pqv-part-3); }

.pqv-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  margin-bottom: 2px;
}
.pqv-card-id {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.pqv-swatch {
  width: 18px;
  height: 4px;
  border-radius: 2px;
  background: var(--part-col);
  flex: none;
}
.pqv-sep { color: var(--pqv-faint); font-weight: 500; }

.pqv-card-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pqv-bound-badge {
  font-size: 11px;
  font-weight: 650;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--pqv-warn-soft);
  color: var(--pqv-warn);
  white-space: nowrap;
}
.pqv-active-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--part-col);
  opacity: 0;
  transition: opacity 0.15s;
}
.pqv-card[data-active="true"] .pqv-active-dot {
  opacity: 1;
}

.pqv-srow {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 72px;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin: 0;
}
.pqv-slabel {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--pqv-muted);
}
.pqv-swrap {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  min-width: 0;
}
.pqv-swrap input[type="range"] {
  width: 100%;
  height: 36px;
  margin: 0;
  padding: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: pan-y;
}
.pqv-swrap input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--part-col) 28%, var(--pqv-hairline));
}
.pqv-swrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 2px solid var(--pqv-surface);
  border-radius: 50%;
  background: var(--part-col);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.pqv-swrap input[type="range"]::-moz-range-track {
  height: 4px;
  border: 0;
  border-radius: 2px;
  background: color-mix(in srgb, var(--part-col) 28%, var(--pqv-hairline));
}
.pqv-swrap input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  border: 2px solid var(--pqv-surface);
  border-radius: 50%;
  background: var(--part-col);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.pqv-sval {
  text-align: right;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--pqv-mono);
  white-space: nowrap;
}

/* ---- Artistic Parameters Panel ---- */
.pqv-art-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pqv-art-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pqv-art-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.pqv-art-val {
  font-family: var(--pqv-mono);
  font-size: 12.5px;
  color: var(--pqv-muted);
}

.pqv-art-slider {
  width: 100%;
  height: 32px;
  margin: 0;
  accent-color: var(--pqv-accent);
  cursor: pointer;
  touch-action: pan-y;
}

.pqv-art-select {
  width: 100%;
  min-height: 38px;
  padding: 4px 10px;
  border: 1px solid var(--pqv-hairline);
  border-radius: 8px;
  background: var(--pqv-card);
  font-size: 13.5px;
  cursor: pointer;
}

.pqv-art-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pqv-art-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--pqv-card);
  border: 1px solid var(--pqv-hairline);
  cursor: pointer;
}
.pqv-switch {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--pqv-hairline);
  transition: background-color 0.15s;
  flex: none;
}
.pqv-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--pqv-surface);
  transition: transform 0.15s;
}
.pqv-art-toggle[aria-checked="true"] .pqv-switch {
  background: var(--pqv-accent);
}
.pqv-art-toggle[aria-checked="true"] .pqv-switch::after {
  transform: translateX(18px);
}

/* ---- Responsive Breakpoints (Tablet & Mobile 390x844) ---- */
@media (max-width: 960px) {
  .pqv-workspace {
    grid-template-columns: minmax(0, 1fr);
  }
  .pqv-stage {
    max-height: 62vh;
  }
}

@media (max-width: 640px) {
  .pqv-app {
    padding: 10px 12px 24px;
  }
  .pqv-switcher {
    flex-wrap: nowrap;
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .pqv-switcher::-webkit-scrollbar { display: none; }

  .pqv-back,
  .pqv-navlink,
  .pqv-btn,
  .pqv-chip,
  .pqv-step-btn,
  .pqv-art-select,
  .pqv-art-toggle {
    min-height: var(--pqv-tap);
  }
  .pqv-steppers {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .pqv-step-btn {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
  }
  .pqv-srow {
    min-height: var(--pqv-tap);
    grid-template-columns: 46px minmax(0, 1fr) 70px;
  }
  .pqv-swrap {
    height: var(--pqv-tap);
  }
  .pqv-swrap input[type="range"] {
    height: var(--pqv-tap);
  }
  .pqv-swrap input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -9px;
  }
  .pqv-art-slider {
    height: var(--pqv-tap);
  }
  .pqv-stage {
    max-height: 54vh;
    min-height: 250px;
  }
}
