/* =========================================================================
   PrintProof Studio — ISO Neutral Soft-Proofing Interface Styles
   Neutral chromaticity UI (#1c1c1e / #262629 / #808080 canvas surround)
   so observer color adaptation remains unbiased when judging print proofs.
   ========================================================================= */

:root {
  --bg-app: #18181a;
  --bg-panel: #222225;
  --bg-elevated: #2c2c30;
  --bg-input: #161618;
  --border-subtle: #36363b;
  --border-strong: #4a4a52;

  --text-primary: #f2f2f4;
  --text-secondary: #b5b5be;
  --text-muted: #84848f;

  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --status-good: #10b981;
  --status-caution: #f59e0b;
  --status-alert: #ef4444;

  --ink-cyan: #009fe3;
  --ink-magenta: #e6007e;
  --ink-yellow: #ffed00;
  --ink-black: #3a3a3e;

  --surround-color: #777777; /* ISO 12646 mid-neutral gray default */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

html, body {
  height: 100%;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: 'Noto Sans Thai', 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* =========================================================================
   TOP HEADER BAR
   ========================================================================= */
.topbar {
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  z-index: 30;
}

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

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: conic-gradient(from 45deg, #009fe3 0deg 90deg, #e6007e 90deg 180deg, #ffed00 180deg 270deg, #2d2d30 270deg 360deg);
  border: 1px solid rgba(255,255,255,0.18);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

/* Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}

.btn:hover {
  background: #36363c;
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-line {
  background: #06c755;
  border-color: #06c755;
  color: #ffffff;
  font-weight: 600;
}

.btn-line:hover {
  background: #05b04b;
  border-color: #05b04b;
}

.text-input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}

.text-input:focus {
  border-color: var(--accent-primary);
}

.line-grid-2 {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
}

.flex-card-preview {
  background: #ffffff;
  color: #111827;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #d4d4d8;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.flex-prev-header {
  background: #2563eb;
  color: #ffffff;
  padding: 12px 14px;
}

.flex-prev-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flex-prev-footer {
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flex-prev-btn {
  display: block;
  text-align: center;
  padding: 9px 12px;
  border-radius: 7px;
  background: #2563eb;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  font-size: 12.5px;
}

@media (max-width: 820px) {
  .line-grid-2 {
    grid-template-columns: 1fr;
  }
}

.btn-sm {
  height: 28px;
  padding: 0 9px;
  font-size: 11.5px;
}

.btn-block {
  width: 100%;
}

.select-input {
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  cursor: pointer;
}

.select-input:focus {
  border-color: var(--accent-primary);
}

/* =========================================================================
   MAIN 3-COLUMN WORKSPACE
   ========================================================================= */
.workspace {
  display: grid;
  grid-template-columns: 310px 1fr 340px;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.sidebar {
  background: var(--bg-panel);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-left {
  border-right: 1px solid var(--border-subtle);
}

.sidebar-right {
  border-left: 1px solid var(--border-subtle);
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.card-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,255,255,0.08);
  color: var(--text-secondary);
}

.badge-good { background: rgba(16, 185, 129, 0.18); color: #34d399; border: 1px solid rgba(16,185,129,0.35); }
.badge-caution { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245,158,11,0.35); }
.badge-alert { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239,68,68,0.4); }

/* Form fields inside cards */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 11.5px;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  user-select: none;
}

.checkbox-row input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--accent-primary);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

/* Range Sliders */
.slider-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent-primary);
  height: 5px;
  cursor: pointer;
}

/* Segmented Pills (Plates / View Mode / Surround) */
.segmented {
  display: flex;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.seg-btn:hover {
  color: var(--text-primary);
}

.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.seg-btn[data-plate="C"].active { background: var(--ink-cyan); color: #fff; }
.seg-btn[data-plate="M"].active { background: var(--ink-magenta); color: #fff; }
.seg-btn[data-plate="Y"].active { background: var(--ink-yellow); color: #111; }
.seg-btn[data-plate="K"].active { background: #111; color: #fff; border: 1px solid #555; }
.seg-btn[data-plate="TAC"].active { background: var(--status-alert); color: #fff; }

/* =========================================================================
   CENTER VIEWPORT & SPLIT / SIDE-BY-SIDE CANVAS
   ========================================================================= */
.viewport-col {
  display: flex;
  flex-direction: column;
  background: var(--surround-color);
  position: relative;
  overflow: hidden;
  transition: background-color 0.2s ease;
}

.viewport-toolbar {
  background: rgba(28, 28, 31, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 15;
  flex-wrap: wrap;
}

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

.canvas-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: crosshair;
  user-select: none;
}

.canvas-stage.panning {
  cursor: grab;
}
.canvas-stage.panning:active {
  cursor: grabbing;
}

/* Split / Single Container */
.artwork-wrapper {
  position: relative;
  transform-origin: center center;
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.42);
  line-height: 0;
}

.artwork-wrapper canvas {
  display: block;
  image-rendering: auto;
}

#origCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* Split Slider Handle */
.split-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ffffff;
  box-shadow: 0 0 6px rgba(0,0,0,0.75);
  z-index: 10;
  cursor: ew-resize;
}

.split-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(24, 24, 27, 0.92);
  border: 2px solid #ffffff;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.5);
}

.canvas-badge-left,
.canvas-badge-right {
  position: absolute;
  top: 12px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  background: rgba(20, 20, 23, 0.84);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  pointer-events: none;
  z-index: 12;
  backdrop-filter: blur(4px);
}

.canvas-badge-left { left: 14px; }
.canvas-badge-right { right: 14px; }

.hover-pill {
  position: absolute;
  bottom: 12px;
  left: 14px;
  padding: 5px 11px;
  border-radius: 99px;
  font-size: 11.5px;
  background: rgba(20, 20, 23, 0.88);
  color: #e4e4e7;
  border: 1px solid rgba(255, 255, 255, 0.16);
  display: none;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 20;
  backdrop-filter: blur(6px);
}

.hover-pill.visible {
  display: inline-flex;
}

.hover-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.45);
  display: inline-block;
}

/* Side-by-Side Layout */
.side-by-side-grid {
  display: none;
  gap: 20px;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.canvas-stage.mode-side .artwork-wrapper {
  display: none;
}

.canvas-stage.mode-side .side-by-side-grid {
  display: flex;
}

.side-pane {
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  line-height: 0;
}

.side-pane canvas {
  display: block;
  max-width: 44vw;
  max-height: calc(100vh - 190px);
  width: auto;
  height: auto;
}

/* Pin Markers on Artwork */
.pin-marker {
  position: absolute;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  border-radius: 50%;
  background: #18181b;
  border: 2px solid #ffffff;
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.65);
  z-index: 11;
  cursor: pointer;
}

.pin-marker.active {
  border-color: #fbbf24;
  transform: scale(1.15);
}

/* Bottom Metrics Strip */
.metrics-bar {
  background: rgba(24, 24, 27, 0.94);
  border-top: 1px solid var(--border-subtle);
  padding: 7px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  z-index: 15;
  flex-wrap: wrap;
}

.metric-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.metric-item strong {
  color: var(--text-primary);
}

/* Drag & Drop Overlay */
.drop-overlay {
  position: absolute;
  inset: 12px;
  border: 2px dashed #60a5fa;
  border-radius: var(--radius-lg);
  background: rgba(24, 24, 28, 0.86);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  z-index: 40;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.drop-overlay.visible {
  display: flex;
}

/* =========================================================================
   RIGHT INSPECTOR: COLOR PATCHES, CMYK BARS & PREPRESS ADVISOR
   ========================================================================= */
.swatch-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.16);
}

.swatch-box {
  height: 76px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

.swatch-tag {
  display: inline-block;
  align-self: flex-start;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
}

.swatch-hex {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  align-self: flex-start;
}

/* CMYK Separation Bars */
.cmyk-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cmyk-row {
  display: grid;
  grid-template-columns: 20px 1fr 40px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.cmyk-label {
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

.cmyk-track {
  height: 8px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
}

.cmyk-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.12s ease;
}

.fill-c { background: var(--ink-cyan); }
.fill-m { background: var(--ink-magenta); }
.fill-y { background: var(--ink-yellow); }
.fill-k { background: #8e8e98; }

.cmyk-val {
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-weight: 600;
}

/* Advisor Box */
.advisor-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.advisor-note {
  font-size: 12px;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--accent-primary);
  color: var(--text-secondary);
}

.advisor-note.status-good { border-left-color: var(--status-good); }
.advisor-note.status-caution { border-left-color: var(--status-caution); }
.advisor-note.status-alert { border-left-color: var(--status-alert); background: rgba(239, 68, 68, 0.09); color: #f3f4f6; }

/* Pinned Swatches List */
.pins-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pin-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  font-size: 11.5px;
}

.pin-item:hover, .pin-item.active {
  border-color: var(--accent-primary);
}

.pin-mini-pair {
  display: flex;
  width: 34px;
  height: 20px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}

.pin-mini-pair span {
  flex: 1;
}

/* =========================================================================
   MODALS (MONITOR BRIGHTNESS CHECK & PRINTABLE CMYK SWATCH SHEET)
   ========================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  max-width: 840px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 12px;
}

/* Monitor Calibration Step Wedge */
.step-wedge {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  border: 1px solid #555;
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 68px;
}

.wedge-cell {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  font-size: 10.5px;
  font-family: ui-monospace, monospace;
  font-weight: 700;
}

/* 5x5 Printable CMYK Swatch Grid */
.printable-sheet {
  background: #ffffff;
  color: #18181b;
  padding: 20px;
  border-radius: var(--radius-md);
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #e4e4e7;
  padding-bottom: 10px;
  margin-bottom: 14px;
}

.sheet-title {
  font-size: 16px;
  font-weight: 700;
  color: #111827;
}

.sheet-meta {
  font-size: 11.5px;
  color: #52525b;
}

.swatch-matrix-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.matrix-card {
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.matrix-card.is-center {
  border: 2.5px solid #111827;
  box-shadow: 0 0 0 2px #fbbf24;
}

.matrix-patch {
  height: 58px;
  width: 100%;
}

.matrix-code {
  padding: 5px 6px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 10.5px;
  color: #18181b;
  line-height: 1.35;
  background: #fafafa;
}

/* =========================================================================
   RESPONSIVE & PRINT STYLES (@media print for A4 Test Swatch Chart)
   ========================================================================= */
@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 270px 1fr 300px;
  }
}

@media (max-width: 920px) {
  html, body { overflow: auto; height: auto; }
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }
  .canvas-stage { min-height: 460px; }
}

@media print {
  body * {
    visibility: hidden !important;
  }
  #swatchModal, #swatchModal .printable-sheet, #swatchModal .printable-sheet * {
    visibility: visible !important;
  }
  #swatchModal {
    position: absolute !important;
    inset: 0 !important;
    background: #ffffff !important;
    padding: 0 !important;
    display: block !important;
  }
  .modal-box {
    border: none !important;
    box-shadow: none !important;
    max-height: none !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  .no-print {
    display: none !important;
  }
  .matrix-patch {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
