/* Minimal, responsive styles tuned for clarity and contrast */
:root {
  --bg: #0e0f12;
  --panel: #171921;
  --text: #e9ecf1;
  --muted: #aab3c2;
  --accent: #6aa6ff;
  --danger: #ff5f6a;
  --good: #3ecf8e;
  --border: #2a2e3a;
  --badge: #222533;
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; height:100%; }
body {
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* Top overlay banner for CORS warning */
#corsWarning {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: 10px 36px 10px 12px;
  border-bottom: 1px solid #e9b34f;
  background: #fff8e6;
  color: #8a6100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}
#corsWarning .banner-close {
  position: absolute;
  right: 8px;
  top: 8px;
  background: transparent;
  border: none;
  color: #8a6100;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}
#corsWarning .banner-close:hover {
  background: rgba(0,0,0,0.06);
}

.app-header, .app-footer {
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: #12141a;
}
.app-footer { border-top:1px solid var(--border); border-bottom:none; }

h1 { font-size: 18px; margin:0; font-weight:600; }
h2 { font-size:16px; margin:0; }

.badge {
  background: var(--badge); color: var(--muted);
  padding: 4px 8px; border-radius: 6px; border:1px solid var(--border);
  font-size:12px;
}

.layout {
  display:grid;
  grid-template-columns: 360px 1fr;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 112px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow:auto;
}

.inputs .section-block { margin-bottom: 12px; }
.inputs .section-inline { display:flex; align-items:flex-end; gap:10px; margin-bottom: 12px; }
.inputs label { display:block; margin-bottom:6px; color: var(--muted); }
.inputs input[type="file"],
.inputs input[type="number"],
.inputs input[type="text"],
.inputs textarea,
.inputs select {
  width:100%; padding:8px; border-radius:8px; border:1px solid var(--border);
  background:#10121a; color:var(--text);
}
.inputs textarea { resize: vertical; }

.actions { display:flex; gap:8px; margin-left:auto; }

.btn {
  background:#222632; color:var(--text);
  border:1px solid var(--border);
  padding:8px 10px; border-radius: 8px; cursor:pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn.active, .btn[aria-pressed="true"] {
  background:#273248;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.btn.primary { background: var(--accent); color:#0a0f1a; border-color: transparent; }
.btn.primary.active, .btn.primary[aria-pressed="true"] {
  box-shadow: 0 0 0 2px rgba(106,166,255,0.5);
}
.btn.danger { background: var(--danger); color:#1a0a0c; border-color: transparent; }
.btn.ghost { background: transparent; }

.history { display:flex; gap:8px; align-items:end; width:100%; }
.history-table .table-wrap { max-height: 220px; }
.history-table table { min-width: 0; }
.history-table tr.clickable { cursor: pointer; }
.history-table tr.selected {
  background: #2a3450;
  box-shadow: inset 3px 0 0 var(--accent);
}
.history-table .prompt-cell { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.batch-status .progress {
  height:8px; background:#0e1016; border:1px solid var(--border);
  border-radius:99px; margin-top:6px;
}
.batch-status .bar { height:100%; background: var(--accent); border-radius:inherit; }

.preview .canvas-wrap {
  width:100%; height: calc(100% - 40px);
  background:#0a0c12; border:1px dashed var(--border); border-radius:8px;
  display:flex; align-items:center; justify-content:center;
  overflow:hidden; position:relative;
}
#previewCanvas { display:block; max-width:100%; max-height:100%; }

.legend {
  margin-top:8px; font-size:12px; color:var(--muted);
  display:flex; gap:10px; flex-wrap: wrap;
}
.legend .item { display:flex; align-items:center; gap:6px; }
.legend .swatch { width:12px; height:12px; border-radius:3px; border:1px solid #000; }

.bottom-tabs {
  margin: 8px 12px 12px 12px;
  background: var(--panel); border:1px solid var(--border); border-radius:10px;
}
.tabs-header { display:flex; gap:4px; border-bottom:1px solid var(--border); padding:6px; }
.tab-btn {
  padding:8px 10px; background:#1a1d27; border:1px solid var(--border); border-radius:8px;
  cursor:pointer; color: var(--text);
}
.tab-btn.right { margin-left: auto; }
.tab-btn:hover { filter: brightness(1.08); }
.tab-btn.active {
  background:#273248;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.tab-btn .swatch { width:12px; height:12px; border-radius:3px; border:2px solid #000; display:inline-block; margin-right:6px; vertical-align:middle; cursor:pointer; }
.tab-btn .swatch.running { animation: chipBlink 1.1s ease-in-out infinite; box-shadow: 0 0 0 2px rgba(255,255,255,0.08) inset; }
@keyframes chipBlink {
  0% { filter: brightness(0.8) saturate(0.9); opacity: 0.6; }
  50% { filter: brightness(1.3) saturate(1.1); opacity: 1; }
  100% { filter: brightness(0.8) saturate(0.9); opacity: 0.6; }
}
.tabs-body { padding: 10px; }
.tab-pane { display:none; }
.tab-pane.active { display:block; }

/* Models tab */
.model-card {
  border:0; border-radius:0; padding:4px 0 8px; margin-bottom:10px; background:transparent;
}
.model-card .header { display:flex; align-items:center; gap:8px; margin-bottom:8px; }
.model-card .header .swatch { width:14px; height:14px; border-radius:4px; border:1px solid #000; }
.model-card .header .title { font-weight:600; }
.model-card .two-col { display:grid; grid-template-columns: repeat(auto-fit, minmax(520px, 1fr)); gap: 16px; align-items:start; }
.model-card .two-col .col { min-width: 0; overflow: hidden; }
.model-card .model-section { border-top:0; padding-top:6px; margin-top:6px; }
.model-card .model-section:first-of-type { border-top:none; padding-top:0; margin-top:0; }
.model-card .section-title { display:none; }
.model-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap:8px; }
/* Ultra‑compact, left‑aligned grid for settings */
.model-grid.wide { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 14px; row-gap: 8px; justify-content: start; align-items: end; }
.model-grid.wide > div { max-width: none; }
.model-grid.wide > .full { grid-column: 1 / -1; }
.model-grid.wide > .full input { width: min(100%, 980px); max-width: 100%; }
.model-grid label { color:var(--muted); font-size:11.5px; margin-bottom: 2px; }
.model-card .model-grid input, .model-card .model-grid select, .model-card .model-grid textarea {
  width:auto; max-width: 100%; padding:4px 6px; border-radius:6px; border:1px solid var(--border);
  background:#10121a; color:var(--text); font-size:13px;
}
.model-card input[data-field="model"] { width: 100%; max-width: 220px; }
.model-card input[data-field="color"] { width: 100%; max-width: 110px; }
.model-card input[data-field="apiKey"] { width: 100%; max-width: 320px; }
.model-card input[data-field="apiVersion"] { width: 100%; max-width: 180px; }
.model-card input[data-field="maxTokens"] { width: 100%; max-width: 120px; }
.model-card input[data-field="timeoutMs"] { width: 100%; max-width: 140px; }
.model-card select[data-field="reasoningEffort"] { width: 100%; max-width: 160px; }
.model-card input[data-field="temperature"] { width: 100%; max-width: 100px; }
.model-card textarea[data-field="extraHeaders"] { width: 320px; height: 56px; }
.model-card input[data-field="baseURL"] { width: min(980px, 100%); }
.model-card .model-grid .full textarea[data-field="extraHeaders"] { width: 100%; height: 72px; }
.model-card .row { display:flex; gap:8px; margin-top:6px; }
.model-card .row .btn { flex:0 0 auto; }
/* Right-aligned row */
.model-card .row.right { justify-content: flex-end; }
/* Smaller buttons for dense layouts */
.btn.sm { padding: 4px 8px; font-size: 12px; }

/* Button group for endpoint type */
.btn-group { display:inline-flex; gap:6px; }
.btn-group .btn { border-radius: 6px; padding: 4px 8px; font-size: 12px; }

/* Specifics row: endpoint + inline parameter */
.specifics-row { align-items: end !important; gap: 12px; }
.inline-field { display:flex; flex-direction: column; gap: 2px; }
.inline-field label { color: var(--muted); font-size: 11.5px; }
.inline-field input, .inline-field select { width: auto; }

/* Simple inline switch style */
.switch { display:inline-flex; align-items:center; gap:8px; }
.switch input[type="checkbox"] { accent-color: var(--accent); }

.log-area {
  background:#0c0f16; border:1px solid var(--border); border-radius:6px; padding:8px; white-space:pre-wrap;
  max-height:160px; overflow:auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size:12px;
}
/* Inline log + buttons row */
.model-card .log-row { align-items: center; gap: 8px; }

/* Color popover */
.color-popover {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.color-popover .mini-swatch {
  width: 16px; height: 16px;
  border-radius: 4px; border: 1px solid #000;
  display: inline-block; cursor: pointer;
}

/* Results table */
.table-wrap { overflow:auto; border:1px solid var(--border); border-radius:8px; }
table { width:100%; border-collapse: collapse; min-width: 900px; }
th, td { border-bottom:1px solid var(--border); padding:6px 8px; text-align:left; }
th { position:sticky; top:0; background:#1a1d27; }
.scope-bar { display:flex; gap:8px; align-items:center; margin-bottom:8px; }

/* Dialog */
dialog { width: min(1000px, 95vw); border:1px solid var(--border); border-radius:10px; padding:0; background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialog-header { display:flex; align-items:center; justify-content:space-between; padding:10px; border-bottom:1px solid var(--border); }
.dialog-body { padding:10px; max-height: 60vh; overflow:auto; }
.dialog-body table { min-width: 800px; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; height:auto; }
  .preview .canvas-wrap { height: 60vh; }
}

@media (max-width: 900px) {
  .model-grid.wide { grid-template-columns: repeat(2, auto); }
  .model-grid.wide > div { max-width: none; }
}

@media (max-width: 640px) {
  .model-grid.wide { grid-template-columns: 1fr; }
}

/* auto-fit handles wrap; keep single column on very narrow screens just in case */
@media (max-width: 560px) {
  .model-card .two-col { grid-template-columns: 1fr; }
}
