/* ============================================================
   OptimAI — Design System
   Palette: Alpine Frost meets clean tool aesthetic
   Fonts: Bricolage Grotesque + JetBrains Mono
   ============================================================ */

:root {
  --bg:           #F0F4FA;
  --surface:      #FFFFFF;
  --surface-2:    #F7F9FC;
  --surface-3:    #EEF2F8;
  --border:       #DDE3EE;
  --border-light: #EEF2F8;

  --text-primary:   #0D1B2E;
  --text-secondary: #4A5568;
  --text-muted:     #8A96A8;
  --text-inverse:   #FFFFFF;

  --blue:         #2563EB;
  --blue-light:   #DBEAFE;
  --blue-mid:     #93C5FD;
  --blue-dark:    #1D4ED8;
  --blue-hover:   #1E50C8;

  --green:        #059669;
  --green-light:  #D1FAE5;
  --red:          #DC2626;
  --red-light:    #FEE2E2;
  --amber:        #D97706;
  --amber-light:  #FEF3C7;
  --purple:       #7C3AED;
  --purple-light: #EDE9FE;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;

  --shadow-sm:  0 1px 3px rgba(13,27,46,0.06), 0 1px 2px rgba(13,27,46,0.04);
  --shadow-md:  0 4px 12px rgba(13,27,46,0.08), 0 2px 4px rgba(13,27,46,0.04);
  --shadow-lg:  0 12px 32px rgba(13,27,46,0.10), 0 4px 8px rgba(13,27,46,0.06);
  --shadow-blue: 0 4px 20px rgba(37,99,235,0.25);

  --font-sans: 'Bricolage Grotesque', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --header-h: 60px;
  --settings-h: 0px;
  --transition: 0.18s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ============================================================
   HEADER
   ============================================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
}
.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.logo-badge {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--blue);
  background: var(--blue-light);
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--blue-mid);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.settings-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 14px;
  cursor: pointer;
  transition: all var(--transition);
}
.settings-btn:hover {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--blue-mid);
  box-shadow: var(--shadow-sm);
}
.settings-btn.active {
  background: var(--blue-light);
  color: var(--blue);
  border-color: var(--blue-mid);
}

/* ============================================================
   SETTINGS PANEL
   ============================================================ */
.settings-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s cubic-bezier(0.4,0,0.2,1), box-shadow 0.3s ease;
}
.settings-panel.open {
  max-height: 260px;
  box-shadow: var(--shadow-md);
}
.settings-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 24px;
}
.settings-title {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  align-items: end;
}
.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings-field--full {
  grid-column: span 1;
}
.settings-field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}
.select-wrapper {
  position: relative;
}
.select-wrapper select {
  width: 100%;
  appearance: none;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 36px 9px 12px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.select-wrapper select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
}
.api-key-wrapper {
  position: relative;
}
.api-key-wrapper input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 40px 9px 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.api-key-wrapper input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.toggle-key-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px;
  display: flex;
  align-items: center;
  transition: color var(--transition);
}
.toggle-key-btn:hover { color: var(--text-primary); }
.retry-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.retry-row input[type="range"] {
  flex: 1;
  accent-color: var(--blue);
  cursor: pointer;
}
.retry-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--blue);
  min-width: 20px;
  text-align: center;
}
.save-settings-btn {
  margin-top: 16px;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-light);
  border: 1px solid var(--blue-mid);
  border-radius: var(--radius-md);
  padding: 8px 20px;
  cursor: pointer;
  transition: all var(--transition);
}
.save-settings-btn:hover {
  background: var(--blue);
  color: white;
}

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}
.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  height: calc(100vh - var(--header-h) - 48px);
  min-height: 600px;
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.panel-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.panel-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.panel-icon--green {
  background: var(--green-light);
  color: var(--green);
}
.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.panel-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: 36px;
}

/* Output tabs */
.output-tabs {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  background: var(--surface-3);
  border-radius: var(--radius-md);
  padding: 3px;
  width: fit-content;
}
.tab-btn {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-md) - 2px);
  padding: 5px 14px;
  cursor: pointer;
  transition: all var(--transition);
}
.tab-btn--active, .tab-btn:hover {
  color: var(--text-primary);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.tab-btn--active { font-weight: 600; }

/* ============================================================
   INPUT AREA
   ============================================================ */
.input-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.input-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.input-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}
.clear-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.clear-btn:hover {
  color: var(--red);
  background: var(--red-light);
}
.problem-textarea {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  resize: vertical;
  min-height: 220px;
  max-height: 380px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.problem-textarea::placeholder { color: var(--text-muted); font-size: 0.82rem; }
.problem-textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
  background: var(--surface);
}

/* File Drop Zone */
.file-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  cursor: pointer;
  transition: all var(--transition);
  overflow: hidden;
}
.file-drop-zone:hover, .file-drop-zone.drag-over {
  border-color: var(--blue);
  background: var(--blue-light);
}
.file-drop-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.file-drop-icon { color: var(--text-muted); }
.file-drop-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.file-drop-link {
  color: var(--blue);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.file-drop-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.file-attached {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--green);
  background: var(--green-light);
}
.file-attached span {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.remove-file-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 4px;
  transition: all var(--transition);
}
.remove-file-btn:hover { color: var(--red); background: var(--red-light); }

/* Solve Button */
.solve-btn {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 24px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow-blue);
  position: relative;
  overflow: hidden;
}
.solve-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 60%);
  pointer-events: none;
}
.solve-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(37,99,235,0.35);
}
.solve-btn:active:not(:disabled) { transform: translateY(0); }
.solve-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}
.solve-btn-content, .solve-btn-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Attempt Indicator */
.attempt-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--amber-light);
  border: 1px solid #FCD34D;
  border-radius: var(--radius-md);
  animation: fadeIn 0.3s ease;
}
.attempt-dots {
  display: flex;
  gap: 5px;
}
.attempt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s ease;
}
.attempt-dot.active { background: var(--amber); }
.attempt-dot.done { background: var(--green); }
.attempt-dot.failed { background: var(--red); }
.attempt-text {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--amber);
}

/* ============================================================
   OUTPUT AREA
   ============================================================ */
.output-empty, .output-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  text-align: center;
  gap: 12px;
}
.empty-illustration { margin-bottom: 8px; }
.empty-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.empty-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 300px;
  line-height: 1.6;
}
.empty-subtitle strong { color: var(--text-secondary); }

.error-icon {
  color: var(--red);
  background: var(--red-light);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.error-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}
.error-message {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 320px;
  line-height: 1.6;
}
.retry-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--red);
  background: var(--red-light);
  border: 1px solid #FCA5A5;
  border-radius: var(--radius-md);
  padding: 8px 18px;
  cursor: pointer;
  margin-top: 4px;
  transition: all var(--transition);
}
.retry-btn:hover {
  background: var(--red);
  color: white;
  border-color: var(--red);
}

/* Output Content */
.output-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.tab-content--active { display: flex; }

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.result-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot--success { background: var(--green); box-shadow: 0 0 0 3px var(--green-light); }
.status-dot--error   { background: var(--red);   box-shadow: 0 0 0 3px var(--red-light); }
.status-dot--warning { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-light); }

.copy-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
  transition: all var(--transition);
}
.copy-btn:hover {
  color: var(--blue);
  border-color: var(--blue-mid);
  background: var(--blue-light);
}
.copy-btn.copied {
  color: var(--green);
  border-color: #6EE7B7;
  background: var(--green-light);
}
.code-lang-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--purple);
  background: var(--purple-light);
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid #C4B5FD;
}

/* Result Output */
.result-output {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Code Block */
.code-block {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--surface-2);
  white-space: pre;
  overflow-x: auto;
  margin: 0;
  border: none;
}

/* Model Output */
.model-output {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--text-primary);
}
.model-output h4 {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 16px 0 8px;
}
.model-output h4:first-child { margin-top: 0; }
.model-output p {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--surface-2);
  border-left: 3px solid var(--blue-mid);
  padding: 6px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 4px;
}

/* Output Meta */
.output-meta {
  padding: 10px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--surface-2);
  flex-shrink: 0;
}
.meta-sep { color: var(--border); }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text-primary);
  color: white;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 99px;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.output-content { animation: fadeIn 0.25s ease; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }
  .panel { min-height: 500px; }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .settings-field--full { grid-column: span 2; }
}
@media (max-width: 600px) {
  .main { padding: 12px; }
  .workspace { gap: 12px; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-field--full { grid-column: span 1; }
  .header-inner { padding: 0 16px; }
  .logo-badge { display: none; }
}