/* ============================================
   Quill Studio — CSS
   ============================================ */

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

:root {
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --ease-out-expo: cubic-bezier(0.16,1,0.3,1);
  --ease-spring: cubic-bezier(0.34,1.56,0.64,1);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
}

/* ---- Dark Theme ---- */
[data-theme="dark"] {
  --bg-primary: #0a0b0f;
  --bg-secondary: #12131a;
  --bg-tertiary: #1a1b24;
  --bg-elevated: #1e1f2a;
  --bg-glass: rgba(18,19,26,.88);
  --text-primary: #e8e6f0;
  --text-secondary: #9895a8;
  --text-tertiary: #6b6880;
  --border-primary: rgba(255,255,255,.06);
  --border-hover: rgba(255,255,255,.12);
  --accent: #c4a0ff;
  --accent-dim: #8b6cc4;
  --accent-rgb: 196,160,255;
  --accent-surface: rgba(196,160,255,.08);
  --success: #7dd4a0;
  --success-rgb: 125,212,160;
  --warning: #f0c674;
  --error: #e87e7e;
  --gradient-hero: linear-gradient(135deg, #0a0b0f 0%, #16102a 50%, #0f1520 100%);
  --gradient-card: linear-gradient(145deg, rgba(30,31,42,.6), rgba(18,19,26,.8));
  --noise-opacity: .03;
}

/* ---- Light Theme ---- */
[data-theme="light"] {
  --bg-primary: #f5f3f0;
  --bg-secondary: #eceae6;
  --bg-tertiary: #e3e0db;
  --bg-elevated: #ffffff;
  --bg-glass: rgba(255,255,255,.88);
  --text-primary: #1a1520;
  --text-secondary: #5c5768;
  --text-tertiary: #8a8596;
  --border-primary: rgba(0,0,0,.08);
  --border-hover: rgba(0,0,0,.15);
  --accent: #7c4dcc;
  --accent-dim: #9b70d9;
  --accent-rgb: 124,77,204;
  --accent-surface: rgba(124,77,204,.07);
  --success: #3da56e;
  --success-rgb: 61,165,110;
  --warning: #c49a3c;
  --error: #c45858;
  --gradient-hero: linear-gradient(135deg, #f5f3f0 0%, #ebe4f5 50%, #e8eef5 100%);
  --gradient-card: linear-gradient(145deg, rgba(255,255,255,.9), rgba(236,234,230,.7));
  --noise-opacity: .02;
}

/* ---- Base ---- */
html { font-size: 16px; scroll-behavior: smooth }
body {
  font-family: var(--font-body);
  background: var(--gradient-hero);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
  position: relative;
  transition: background .5s var(--ease-out-expo), color .3s;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: var(--noise-opacity);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px }
::-webkit-scrollbar-track { background: transparent }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary) }

/* ---- Shell ---- */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- Header ---- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(1.5);
  border-bottom: 1px solid var(--border-primary);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background .3s;
}
.logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  text-decoration: none;
  color: var(--text-primary);
}
.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 12px rgba(var(--accent-rgb), .3);
}
.logo-text {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -.02em;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ---- Buttons ---- */
.btn {
  font-family: var(--font-body);
  font-size: .85rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1.1rem;
  transition: all .25s var(--ease-out-expo);
  position: relative;
  overflow: hidden;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
}
.btn-ghost:hover {
  background: var(--accent-surface);
  color: var(--text-primary);
  border-color: var(--border-hover);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 16px rgba(var(--accent-rgb), .25);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 24px rgba(var(--accent-rgb), .35);
}
.btn-primary:active { transform: translateY(0) }
.btn-primary:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-sm { padding: .4rem .8rem; font-size: .8rem; border-radius: var(--radius-sm) }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: var(--radius-sm) }
.btn svg { width: 18px; height: 18px; flex-shrink: 0 }

/* ---- Layout ---- */
.main {
  flex: 1;
  padding: 2rem;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  gap: 1.5rem;
}
.panel {
  background: var(--gradient-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: border .3s, background .3s;
}
.panel-left {
  width: 400px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  overflow-y: auto;
  max-height: calc(100vh - 128px);
}
.panel-left::-webkit-scrollbar { width: 4px }
.panel-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---- Section labels ---- */
.section-label {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-tertiary);
  margin-bottom: .5rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.section-label svg { width: 14px; height: 14px; opacity: .6 }

/* ---- Form controls ---- */
.field { display: flex; flex-direction: column; gap: .3rem }
.field label { font-size: .8rem; font-weight: 500; color: var(--text-secondary) }

textarea, .input-text {
  font-family: var(--font-body);
  font-size: .9rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: .75rem 1rem;
  resize: vertical;
  transition: border .2s, box-shadow .2s, background .2s;
  line-height: 1.6;
  width: 100%;
}
textarea:focus, .input-text:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .12);
  background: var(--bg-tertiary);
}
.prompt-area { min-height: 130px }

/* Select */
.select-wrap { position: relative }
.select-wrap select {
  font-family: var(--font-body);
  font-size: .85rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: .55rem 2.5rem .55rem .85rem;
  width: 100%;
  appearance: none;
  cursor: pointer;
  transition: border .2s;
}
.select-wrap::after {
  content: '';
  position: absolute;
  right: .85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--text-tertiary);
  pointer-events: none;
}
.select-wrap select:focus { outline: none; border-color: var(--accent) }

/* Range */
.range-group { display: flex; align-items: center; gap: .75rem }
.range-group input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
}
.range-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(var(--accent-rgb), .3);
  transition: transform .15s var(--ease-spring);
}
.range-group input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2) }
.range-value {
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--accent);
  min-width: 56px;
  text-align: right;
  font-weight: 500;
}

/* Chips */
.chip-group { display: flex; flex-wrap: wrap; gap: .4rem }
.chip {
  font-size: .78rem;
  padding: .3rem .7rem;
  border-radius: 20px;
  cursor: pointer;
  border: 1px solid var(--border-primary);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  transition: all .2s;
  user-select: none;
}
.chip:hover { border-color: var(--border-hover); color: var(--text-primary) }
.chip.active {
  background: var(--accent-surface);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px rgba(var(--accent-rgb), .1);
}

/* Toggle */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem }
.toggle-row span { font-size: .85rem; color: var(--text-secondary) }
.toggle {
  width: 42px;
  height: 24px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background .25s;
  flex-shrink: 0;
  border: 1px solid var(--border-primary);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-tertiary);
  transition: all .25s var(--ease-spring);
}
.toggle.active { background: var(--accent-surface); border-color: var(--accent) }
.toggle.active::after { left: calc(100% - 19px); background: var(--accent) }

/* Divider */
.divider { height: 1px; background: var(--border-primary); margin: .2rem 0 }

/* Collapsible */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: .4rem 0;
}
.collapsible-header h3 { font-size: .85rem; font-weight: 600; color: var(--text-primary) }
.collapsible-chevron {
  width: 20px;
  height: 20px;
  color: var(--text-tertiary);
  transition: transform .3s var(--ease-out-expo);
}
.collapsible-header.open .collapsible-chevron { transform: rotate(180deg) }
.collapsible-body { overflow: hidden; max-height: 0; transition: max-height .4s var(--ease-out-expo); opacity: 0 }
.collapsible-body.open { opacity: 1 }

/* ---- Provider tabs ---- */
.provider-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 2px;
  margin-bottom: .6rem;
}
.provider-tab {
  flex: 1;
  text-align: center;
  padding: .4rem .5rem;
  font-size: .75rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all .2s;
  border: none;
  background: none;
  font-family: var(--font-body);
}
.provider-tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.provider-tab:hover:not(.active) { color: var(--text-secondary) }
.provider-section { display: none; flex-direction: column; gap: .4rem }
.provider-section.show { display: flex }
.api-key-row { display: flex; gap: .5rem; align-items: center }
.api-key-row input { flex: 1; font-size: .82rem; padding: .5rem .75rem }
.api-status { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0 }
.api-status.connected { background: var(--success); box-shadow: 0 0 8px rgba(var(--success-rgb), .4) }
.api-status.disconnected { background: var(--error) }
.hint { font-size: .7rem; color: var(--text-tertiary); line-height: 1.4 }

/* ---- Output ---- */
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
  flex-wrap: wrap;
  gap: .5rem;
}
.output-header h2 { font-family: var(--font-display); font-size: 1.4rem; font-weight: 400 }
.output-meta { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap }

.meta-badge {
  font-size: .7rem;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.badge-idle { background: var(--bg-tertiary); color: var(--text-tertiary) }
.badge-generating { background: rgba(var(--accent-rgb), .15); color: var(--accent); animation: pulse-badge 1.5s infinite }
.badge-refining { background: rgba(var(--success-rgb), .15); color: var(--success); animation: pulse-badge 1.5s infinite }
.badge-complete { background: rgba(var(--success-rgb), .12); color: var(--success) }
.badge-error { background: rgba(200,60,60,.12); color: var(--error) }
@keyframes pulse-badge { 0%,100% { opacity: 1 } 50% { opacity: .6 } }

.output-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-size: .95rem;
  line-height: 1.85;
  min-height: 300px;
  position: relative;
  transition: border .2s, background .2s;
  white-space: pre-wrap;
}
.output-content:empty::before {
  content: 'Your generated content will appear here...';
  color: var(--text-tertiary);
  font-style: italic;
}
.output-content[contenteditable="true"] { outline: none }
.output-content[contenteditable="true"]:focus { border-color: var(--accent) }

/* Stats */
.stats-bar {
  display: flex;
  gap: 1.5rem;
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border-primary);
  flex-wrap: wrap;
}
.stat { display: flex; flex-direction: column; gap: .1rem }
.stat-label { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-tertiary) }
.stat-value { font-family: var(--font-mono); font-size: .85rem; font-weight: 500; color: var(--text-primary) }

/* Versions */
.version-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .75rem; max-height: 200px; overflow-y: auto }
.version-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .75rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: .8rem;
  cursor: pointer;
  transition: background .15s;
  border: 1px solid transparent;
}
.version-item:hover { background: var(--bg-tertiary); border-color: var(--border-hover) }
.version-item.active { border-color: var(--accent); background: var(--accent-surface) }
.version-item .v-label { color: var(--text-primary); font-weight: 500 }
.version-item .v-time { color: var(--text-tertiary); font-family: var(--font-mono); font-size: .72rem }

/* Actions */
.action-bar { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap }

/* Detection meter */
.detection-meter { margin-top: .6rem }
.meter-bar { height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden }
.meter-fill { height: 100%; border-radius: 4px; transition: width .6s var(--ease-out-expo), background .3s; width: 0 }
.meter-labels { display: flex; justify-content: space-between; margin-top: .25rem }
.meter-labels span { font-size: .66rem; color: var(--text-tertiary) }

/* Progress */
.progress-steps { display: flex; gap: .3rem }
.progress-step { flex: 1; height: 3px; border-radius: 2px; background: var(--bg-tertiary); transition: background .3s }
.progress-step.done { background: var(--success) }
.progress-step.active { background: var(--accent); animation: pulse-badge 1s infinite }

/* Loading */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(var(--accent-rgb), .03);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
  border-radius: var(--radius-md);
  z-index: 10;
  backdrop-filter: blur(2px);
}
.loading-overlay.show { display: flex }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border-primary); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite }
@keyframes spin { to { transform: rotate(360deg) } }
.loading-text { font-size: .85rem; color: var(--text-secondary); text-align: center; max-width: 280px }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.modal-backdrop.show { display: flex }
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 540px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  animation: modal-in .3s var(--ease-out-expo);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(.97) } to { opacity: 1; transform: none } }
.modal h2 { font-family: var(--font-display); font-size: 1.3rem; margin-bottom: .5rem }
.modal p { color: var(--text-secondary); font-size: .9rem; margin-bottom: 1.25rem }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end }

/* Toast */
.toast-container { position: fixed; bottom: 2rem; right: 2rem; z-index: 300; display: flex; flex-direction: column; gap: .5rem }
.toast {
  padding: .7rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: .85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
  animation: toast-in .3s var(--ease-out-expo);
  display: flex;
  align-items: center;
  gap: .5rem;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--success) }
.toast.error { border-left: 3px solid var(--error) }
.toast.info { border-left: 3px solid var(--accent) }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px) } to { opacity: 1; transform: none } }

/* Dropdown */
.dropdown { position: relative; display: inline-block }
.dropdown-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: .4rem;
  min-width: 170px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  display: none;
  z-index: 50;
}
.dropdown-menu.show { display: block; animation: fade-in .2s var(--ease-out-expo) }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  font-size: .83rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all .15s;
  border: none;
  background: none;
  width: 100%;
  font-family: var(--font-body);
}
.dropdown-item:hover { background: var(--accent-surface); color: var(--text-primary) }

/* Responsive */
@media (max-width: 900px) {
  .main { flex-direction: column; padding: 1rem }
  .panel-left { width: 100%; max-height: none; overflow: visible }
  .header { padding: 0 1rem }
}

/* Animations */
.fade-in { animation: fade-in .5s var(--ease-out-expo) both }
@keyframes fade-in { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }
