/* ============================================================
   AI Relief Studio v4 — 3-Column Professional Layout
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #07080f;
  --bg2:       #0d0f1a;
  --bg3:       #12141f;
  --bg4:       #181b28;
  --border:    #1e2235;
  --border2:   #252840;
  --accent:    #6366f1;
  --accent2:   #818cf8;
  --accent-glow: rgba(99,102,241,0.25);
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #f59e0b;
  --text:      #e2e4f0;
  --text2:     #9ca3c0;
  --text3:     #5a6080;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,0.5);
  --font:      'Inter', system-ui, -apple-system, sans-serif;
  --left-w:    270px;
  --right-w:   260px;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- Header ---- */
header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.logo-mark {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 14px var(--accent-glow);
}

.header-text h1 { font-size: 15px; font-weight: 700; letter-spacing: -0.3px; }
.header-text p  { font-size: 10px; color: var(--text3); margin-top: 1px; }

.header-status {
  margin-left: auto;
  font-size: 11px;
  color: var(--text3);
}

/* ---- 3-Column Layout ---- */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: 0; /* forces flex children to respect overflow */
}

/* ---- Shared panel styles ---- */
.panel-left,
.panel-right {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
  flex-shrink: 0;
}
.panel-left::-webkit-scrollbar,
.panel-right::-webkit-scrollbar { width: 3px; }
.panel-left::-webkit-scrollbar-thumb,
.panel-right::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ---- Left Panel ---- */
.panel-left {
  width: var(--left-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  padding-bottom: 16px;
}

/* ---- Centre Panel ---- */
.panel-centre {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.panel-centre::-webkit-scrollbar { width: 4px; }
.panel-centre::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ---- Right Panel ---- */
.panel-right {
  width: var(--right-w);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  padding-bottom: 16px;
}

/* ---- Panel sections ---- */
.panel-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.panel-section:last-child { border-bottom: none; }

.panel-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 10px;
}

/* ---- Field labels ---- */
.field-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 5px;
  margin-top: 9px;
}
.field-label:first-child { margin-top: 0; }

.rc-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 5px;
  margin-top: 9px;
}
.rc-label:first-child { margin-top: 0; }

.unit {
  font-size: 10px;
  color: var(--text3);
  font-weight: 400;
}

.val-badge {
  margin-left: auto;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent2);
  min-width: 32px;
  text-align: center;
}

/* ---- Range sliders ---- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--bg4);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  margin-bottom: 2px;
  border: 1px solid var(--border2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 5px var(--accent-glow);
  transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

/* ---- Segmented controls ---- */
.seg-control {
  display: flex;
  gap: 3px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 2px;
  margin-bottom: 8px;
}

.seg-btn {
  flex: 1;
  padding: 4px 6px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.seg-btn:hover { background: var(--bg3); color: var(--text2); }
.seg-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 6px var(--accent-glow);
}

/* ---- Toggle switches ---- */
.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text2);
  user-select: none;
}
.toggle-label input[type="checkbox"] { display: none; }

.toggle-track {
  width: 28px; height: 16px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: 8px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 10px; height: 10px;
  background: var(--text3);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle-label input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-label input:checked + .toggle-track .toggle-thumb { transform: translateX(12px); background: #fff; }

/* ---- Textarea ---- */
textarea {
  width: 100%;
  min-height: 70px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 11px;
  padding: 7px 9px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
textarea:focus { border-color: var(--accent); }

/* ---- File drop ---- */
.file-drop {
  position: relative;
  border: 1.5px dashed var(--border2);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-size: 11px;
  color: var(--text3);
}
.file-drop:hover, .file-drop.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,0.06);
  color: var(--text2);
}
.file-drop input[type="file"] {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
  width: 100%; height: 100%;
}

/* ---- Generate button ---- */
.generate-wrap {
  padding: 12px 14px;
}

.generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 11px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 18px var(--accent-glow);
  letter-spacing: 0.3px;
}
.generate-btn:hover { opacity: 0.92; box-shadow: 0 6px 24px rgba(99,102,241,0.4); }
.generate-btn:active { transform: scale(0.98); }
.generate-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-icon { font-size: 11px; }

/* ---- Re-generate button ---- */
.rc-apply-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 10px var(--accent-glow);
  white-space: nowrap;
}
.rc-apply-btn:hover { opacity: 0.9; box-shadow: 0 4px 18px rgba(99,102,241,0.4); }
.rc-apply-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- Status bar ---- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  flex-shrink: 0;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text3);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.processing { background: var(--yellow); animation: pulse 1.2s infinite; }
.status-dot.done       { background: var(--green); }
.status-dot.error      { background: var(--red); }
.status-dot.awaiting_selection { background: var(--accent2); animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  flex-shrink: 0;
}

.progress-bar {
  width: 100px; height: 3px;
  background: var(--bg4);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a855f7);
  border-radius: 4px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-pct {
  font-size: 10px;
  color: var(--text3);
  min-width: 28px;
  text-align: right;
}

/* ---- 3D Viewer block ---- */
.viewer-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.viewer-toolbar-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.viewer-btn {
  padding: 4px 10px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.viewer-btn:hover { background: var(--bg3); color: var(--text); border-color: var(--accent); }
.viewer-btn.viewer-btn-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 7px var(--accent-glow);
}

.viewer-stat-inline {
  font-size: 10px;
  color: var(--text3);
  margin-left: 4px;
}

.viewer-canvas-wrap {
  position: relative;
  width: 100%;
  height: calc(100vh - 160px);
  min-height: 400px;
  background: #07080f;
  overflow: hidden;
}
.viewer-canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text3);
  background: rgba(7,8,15,0.85);
  z-index: 10;
}
.viewer-loading-dot {
  width: 9px; height: 9px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1s infinite;
}

/* ---- Fusion panel ---- */
.fusion-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.fusion-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.fusion-title {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.fusion-subtitle {
  display: block;
  font-size: 10px;
  color: var(--text3);
  margin-top: 2px;
}

.fusion-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
}

.fusion-card {
  padding: 10px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.fusion-card:last-child { border-right: none; }
.fusion-card:hover { background: var(--bg3); }
.fusion-card.fusion-selected { background: rgba(99,102,241,0.08); }

.fusion-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.fusion-label { font-size: 15px; font-weight: 800; color: var(--accent2); }
.fusion-blend { font-size: 9px; color: var(--text3); }

.fusion-preview-wrap {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 6px;
}
.fusion-preview-img { width: 100%; height: 100%; object-fit: cover; display: block; }

.fusion-desc { font-size: 9px; color: var(--text3); margin-bottom: 6px; line-height: 1.4; }

.fusion-select-btn {
  width: 100%;
  padding: 4px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.fusion-select-btn:hover { background: var(--bg3); border-color: var(--accent); color: var(--text); }
.fusion-select-btn.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Preview grid ---- */
.preview-grid { display: grid; gap: 10px; flex-shrink: 0; }
.preview-grid-3 { grid-template-columns: repeat(3, 1fr); }

/* ---- Cards ---- */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.card-icon { font-size: 13px; }
.card-header h3 { font-size: 11px; font-weight: 600; color: var(--text2); flex: 1; }

.card-body {
  position: relative;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-body img { width: 100%; height: auto; display: block; opacity: 0; transition: opacity 0.3s; }
.card-body img.loaded { opacity: 1; }
.card-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--text3); text-align: center; padding: 12px;
}

/* ---- Downloads ---- */
.dl-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.dl-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  width: 100%;
  text-align: left;
}
.dl-btn:hover { background: var(--bg4); border-color: var(--accent); color: var(--text); }
.dl-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.dl-btn.dl-downloading { border-color: var(--yellow); }

.dl-btn-primary {
  background: rgba(99,102,241,0.12);
  border-color: var(--accent);
  color: var(--accent2);
}
.dl-btn-primary:hover { background: rgba(99,102,241,0.22); }

.dl-icon { font-size: 13px; flex-shrink: 0; }
.dl-label { flex: 1; }
.dl-ext {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: 1px 4px;
  color: var(--text3);
}

/* ---- Error panel ---- */
.error-panel {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  flex-shrink: 0;
}
.error-icon { font-size: 15px; flex-shrink: 0; }
.error-panel pre {
  font-family: var(--font);
  font-size: 11px;
  color: #fca5a5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Passthrough notice ---- */
#passthroughNotice {
  background: #14532d;
  color: #86efac;
  border: 1px solid #22c55e;
  border-radius: var(--radius);
  padding: 9px 14px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  :root { --left-w: 240px; --right-w: 230px; }
  .viewer-canvas-wrap { height: 340px; }
}

@media (max-width: 860px) {
  .app-layout { flex-direction: column; overflow-y: auto; height: auto; }
  .panel-left, .panel-right {
    width: 100%;
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    overflow-y: visible;
  }
  .panel-centre { overflow-y: visible; }
  .preview-grid-3 { grid-template-columns: 1fr 1fr; }
  .fusion-grid { grid-template-columns: repeat(2, 1fr); }
  .viewer-canvas-wrap { height: 280px; }
}

@media (max-width: 540px) {
  .preview-grid-3 { grid-template-columns: 1fr; }
  .fusion-grid { grid-template-columns: 1fr 1fr; }
}
