/* ============================================================
   MILP Solver — Design System
   Light theme · Inter + JetBrains Mono
   ============================================================ */

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

:root {
  --bg:          #f5f6f8;
  --surface:     #ffffff;
  --surface-2:   #f9fafb;
  --border:      #e4e7ec;
  --border-2:    #d0d5dd;
  --text-1:      #101828;
  --text-2:      #475467;
  --text-3:      #98a2b3;
  --accent:      #4f46e5;
  --accent-light:#ede9fe;
  --accent-dark: #3730a3;
  --green:       #12b76a;
  --green-light: #d1fadf;
  --red:         #f04438;
  --red-light:   #fee4e2;
  --amber:       #f79009;
  --amber-light: #fef0c7;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow-sm:   0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-md:   0 4px 16px rgba(16,24,40,.08), 0 2px 6px rgba(16,24,40,.04);
  --shadow-lg:   0 12px 40px rgba(16,24,40,.12), 0 4px 12px rgba(16,24,40,.06);
  --font:        'Inter', system-ui, sans-serif;
  --mono:        'JetBrains Mono', 'Fira Code', monospace;
  --header-h:    60px;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  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;
  text-decoration: none;
  color: var(--text-1);
}
.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-1);
}
.logo-accent { color: var(--accent); }
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.header-tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.settings-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.settings-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
  color: var(--text-1);
}

/* ── Main Layout ─────────────────────────────────────────── */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}
.layout {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
}

/* ── Panel ───────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.panel-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 3px;
}
.panel-subtitle {
  font-size: 0.8rem;
  color: var(--text-3);
  line-height: 1.4;
}

/* ── Input Panel ─────────────────────────────────────────── */
.panel-input { padding-bottom: 8px; }

.input-block {
  padding: 18px 24px 0;
}
.input-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.input-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.label-optional {
  font-weight: 400;
  color: var(--text-3);
  text-transform: none;
  letter-spacing: 0;
}
.ghost-btn {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-3);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all .15s;
}
.ghost-btn:hover { color: var(--text-2); background: var(--surface-2); }

.problem-textarea {
  width: 100%;
  min-height: 200px;
  max-height: 340px;
  resize: vertical;
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-1);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.problem-textarea::placeholder { color: var(--text-3); }
.problem-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
  background: var(--surface);
}
.textarea-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}
.char-count {
  font-size: 0.72rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.hint-text {
  font-size: 0.72rem;
  color: var(--text-3);
  text-align: right;
}

/* ── Upload Zone ─────────────────────────────────────────── */
.upload-zone {
  border: 1.5px dashed var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  transition: all .15s;
  overflow: hidden;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-idle {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}
.upload-icon { color: var(--text-3); }
.upload-text {
  font-size: 0.82rem;
  color: var(--text-2);
}
.upload-link {
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}
.upload-hint {
  font-size: 0.72rem;
  color: var(--text-3);
}
.upload-preview {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.file-icon { color: var(--accent); flex-shrink: 0; }
.file-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-1);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.remove-file {
  width: 24px;
  height: 24px;
  border: none;
  background: var(--surface-2);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .15s;
}
.remove-file:hover { background: var(--red-light); color: var(--red); }

/* ── Solve Button ────────────────────────────────────────── */
.solve-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: calc(100% - 48px);
  margin: 20px 24px 0;
  padding: 13px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  box-shadow: 0 1px 3px rgba(79,70,229,.3);
}
.solve-btn:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: 0 4px 12px rgba(79,70,229,.35);
  transform: translateY(-1px);
}
.solve-btn:active:not(:disabled) { transform: translateY(0); }
.solve-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}
.solve-btn-icon { display: flex; align-items: center; }
.solve-btn-icon.spinning svg {
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Status Bar ──────────────────────────────────────────── */
.status-bar {
  margin: 10px 24px 0;
  padding: 10px 14px;
  background: var(--accent-light);
  border: 1px solid rgba(79,70,229,.2);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
}
.status-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(79,70,229,.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.status-text {
  font-size: 0.8rem;
  color: var(--accent-dark);
  font-weight: 500;
  flex: 1;
}
.attempt-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(79,70,229,.12);
  padding: 2px 8px;
  border-radius: 20px;
}

/* ── Examples ────────────────────────────────────────────── */
.examples-block {
  padding: 16px 24px 20px;
}
.examples-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.examples-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.example-chip {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all .15s;
}
.example-chip:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Output Panel ────────────────────────────────────────── */
.panel-output {
  min-height: 600px;
  display: flex;
  flex-direction: column;
}
.panel-output .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* ── Tab Bar ─────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.tab-btn {
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-3);
  background: none;
  border: none;
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text-2); background: var(--surface); }
.tab-btn.active {
  color: var(--text-1);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* ── Tab Content ─────────────────────────────────────────── */
.tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
}
.tab-content.active { display: flex; }

/* ── Empty State ─────────────────────────────────────────── */
.output-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  gap: 10px;
  color: var(--text-3);
}
.empty-icon { opacity: 0.35; }
.empty-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-3);
}
.empty-sub {
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ── Output Result ───────────────────────────────────────── */
.output-result {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.result-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--green-light);
  color: #027a48;
}
.result-badge.badge-error {
  background: var(--red-light);
  color: #b42318;
}
.result-badge.badge-warn {
  background: var(--amber-light);
  color: #b54708;
}
.lang-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.02em;
}
.copy-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all .15s;
}
.copy-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Output Pre ──────────────────────────────────────────── */
.output-pre {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-1);
  background: var(--surface);
  padding: 20px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  border: none;
  outline: none;
  min-height: 400px;
}
.code-pre {
  background: #fafafa;
  color: #1e293b;
  border-top: none;
}

/* ── Settings Drawer ─────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,24,40,.35);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.overlay.active {
  opacity: 1;
  pointer-events: all;
}
.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
}
.settings-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-1);
}
.drawer-close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.drawer-close:hover { background: var(--surface-2); color: var(--text-1); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setting-group { display: flex; flex-direction: column; gap: 8px; }
.setting-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.setting-select, .setting-input {
  width: 100%;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text-1);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.setting-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.setting-select:focus, .setting-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
  background: var(--surface);
}
.setting-hint {
  font-size: 0.75rem;
  color: var(--text-3);
}
.setting-hint a { color: var(--accent); text-decoration: none; }
.setting-hint a:hover { text-decoration: underline; }

.key-input-row {
  display: flex;
  gap: 8px;
}
.key-input { flex: 1; }
.toggle-key-btn {
  width: 40px;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.toggle-key-btn:hover { border-color: var(--border-2); color: var(--text-2); }

.retry-group {
  display: flex;
  gap: 6px;
}
.retry-btn {
  flex: 1;
  padding: 8px;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all .15s;
}
.retry-btn:hover { border-color: var(--accent); color: var(--accent); }
.retry-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.save-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  margin-top: auto;
}
.save-btn:hover { background: var(--accent-dark); }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-1);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  white-space: nowrap;
  z-index: 9999;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: #027a48; }
.toast.error   { background: #b42318; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
/* ── Pyodide Status ─────────────────────────────────────────────────────────── */
.pyodide-status {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface-2);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.loading {
  background: var(--amber);
  animation: pulse 1.2s ease-in-out infinite;
}
.status-dot.ready  { background: var(--green); }
.status-dot.error  { background: var(--red); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}
.status-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
}

/* ── Result Actions ─────────────────────────────────────────────────────────── */
.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Run Button ─────────────────────────────────────────────────────────────── */
.run-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: var(--green);
  border: none;
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.run-btn:hover:not(:disabled) {
  background: #0da55e;
  box-shadow: 0 2px 8px rgba(18,183,106,.35);
}
.run-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ── Code Editor ────────────────────────────────────────────────────────────── */
.code-editor {
  flex: 1;
  width: 100%;
  min-height: 320px;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.7;
  color: #1e293b;
  background: #fafafa;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  outline: none;
  resize: vertical;
  tab-size: 4;
  white-space: pre;
  overflow-x: auto;
}
.code-editor:focus {
  background: #f8f9ff;
  box-shadow: inset 0 0 0 2px rgba(79,70,229,.12);
}

/* ── Run Output Area ────────────────────────────────────────────────────────── */
.run-output-wrap {
  display: flex;
  flex-direction: column;
  border-top: 2px solid var(--border);
}
.run-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.run-output-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.run-output-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.run-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 9px;
  border-radius: 20px;
}
.run-badge.success {
  background: var(--green-light);
  color: #027a48;
}
.run-badge.error {
  background: var(--red-light);
  color: #b42318;
}
.run-output {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.7;
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px 20px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 120px;
  max-height: 320px;
  overflow-y: auto;
}
