:root {
    color-scheme: dark;
    --bg: #0a0d12;
    --panel: #11161f;
    --panel-2: #171d28;
    --panel-3: #1e2633;
    --border: #293244;
    --border-strong: #3b4860;
    --text: #f3f6fb;
    --muted: #9aa7ba;
    --accent: #7c9cff;
    --accent-2: #8c7bff;
    --success: #58d6a1;
    --warning: #f4bf64;
    --danger: #ff7c8b;
    --shadow: 0 22px 70px rgba(0, 0, 0, .34);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background:
    radial-gradient(circle at 12% 4%, rgba(89, 112, 255, .11), transparent 30rem),
    radial-gradient(circle at 92% 20%, rgba(139, 91, 255, .08), transparent 34rem),
    var(--bg); }

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
textarea { resize: vertical; }

.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.primary-button, .ghost-button, .icon-button {
    border: 1px solid transparent;
    border-radius: 11px;
    color: var(--text);
    transition: .18s ease;
}

.primary-button {
    min-height: 43px;
    padding: 0 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 10px 30px rgba(114, 111, 255, .22);
    font-weight: 750;
}
.primary-button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.07); }
.primary-button:active:not(:disabled) { transform: translateY(0); }

.ghost-button {
    min-height: 39px;
    padding: 0 14px;
    border-color: var(--border);
    background: rgba(255,255,255,.025);
}
.ghost-button:hover { border-color: var(--border-strong); background: rgba(255,255,255,.05); }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border-color: var(--border);
    background: var(--panel-2);
    font-size: 21px;
}
.icon-button:hover { border-color: var(--accent); }

.brand-mark {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 20px 50px rgba(108, 96, 255, .3);
    font-size: 24px;
    font-weight: 900;
    letter-spacing: -.06em;
}
.brand-mark.small { width: 42px; height: 42px; margin: 0; border-radius: 13px; font-size: 16px; }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-card {
    width: min(100%, 430px);
    padding: 38px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: rgba(17, 22, 31, .94);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}
.login-card h1 { margin: 0; text-align: center; font-size: 30px; letter-spacing: -.04em; }
.login-card > p { margin: 10px 0 28px; text-align: center; color: var(--muted); }
.login-card form { display: grid; gap: 10px; }
.login-card label, .dialog-body label { color: var(--muted); font-size: 13px; font-weight: 700; }
.login-card input, .dialog-body input {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 11px;
    outline: none;
    color: var(--text);
    background: var(--panel-2);
}
.login-card input:focus, .dialog-body input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,.13); }
.login-card .primary-button { margin-top: 8px; }
.login-error { margin-bottom: 18px; padding: 11px 13px; border: 1px solid rgba(255,124,139,.35); border-radius: 10px; color: #ffdce1; background: rgba(255,124,139,.09); text-align: center; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 70px;
    padding: 12px 22px;
    border-bottom: 1px solid rgba(41,50,68,.88);
    background: rgba(10,13,18,.86);
    backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand > div:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.topbar-actions form { margin: 0; }
.all-time-cost { display: grid; justify-items: end; margin-right: 8px; }
.all-time-cost span { color: var(--muted); font-size: 11px; }
.all-time-cost strong { font-variant-numeric: tabular-nums; }

.workspace {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 18px;
    width: min(100%, 2400px);
    min-height: calc(100vh - 70px);
    margin: 0 auto;
    padding: 18px;
}

.sidebar {
    position: sticky;
    top: 88px;
    align-self: start;
    display: grid;
    grid-template-rows: auto minmax(150px, .75fr) minmax(250px, 1fr);
    max-height: calc(100vh - 106px);
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(17,22,31,.88);
    box-shadow: 0 18px 50px rgba(0,0,0,.18);
}
.panel-section { min-width: 0; padding: 16px; border-bottom: 1px solid var(--border); }
.panel-section:last-child { border-bottom: 0; }
.panel-section.grow {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
}
.sidebar > .panel-section:last-child {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
}
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-title h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.count-badge { min-width: 26px; padding: 3px 8px; border-radius: 999px; background: var(--panel-3); color: var(--text); text-align: center; font-size: 12px; font-weight: 800; }
.hint { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.danger-link { padding: 8px 0 0; border: 0; color: var(--danger); background: none; font-size: 12px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border: 1px solid var(--border); border-radius: 11px; background: var(--bg); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 8px 7px; border-radius: 8px; color: var(--muted); text-align: center; font-size: 12px; font-weight: 750; cursor: pointer; }
.segmented input:checked + span { color: var(--text); background: var(--panel-3); box-shadow: 0 4px 12px rgba(0,0,0,.2); }

.selection-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.selection-actions button { padding: 4px 7px; border: 0; color: var(--accent); background: transparent; font-size: 11px; }
.selection-actions button:hover { text-decoration: underline; }
.model-picker { display: grid; gap: 7px; min-height: 0; overflow: auto; padding-right: 3px; align-content: start; }
.model-choice { display: flex; align-items: center; gap: 9px; padding: 9px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; transition: .15s ease; }
.model-choice:hover { border-color: var(--border); background: rgba(255,255,255,.02); }
.model-choice.disabled { opacity: .45; cursor: not-allowed; }
.model-choice input { width: 16px; height: 16px; accent-color: var(--accent); }
.model-choice span { min-width: 0; display: grid; gap: 2px; }
.model-choice strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.model-choice small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }

.prompt-list { display: grid; gap: 6px; min-height: 0; overflow: auto; padding-right: 3px; align-content: start; }
.prompt-item { display: grid; grid-template-columns: minmax(0, 1fr) 28px 28px; gap: 5px; }
.prompt-load, .prompt-edit, .prompt-remove { border: 0; border-radius: 8px; color: var(--text); background: transparent; }
.prompt-load { min-width: 0; overflow: hidden; padding: 8px; text-align: left; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.prompt-load:hover { background: var(--panel-3); }
.prompt-edit, .prompt-remove { display: grid; place-items: center; color: var(--muted); font-size: 17px; }
.prompt-edit:hover { color: var(--accent); background: rgba(124,156,255,.09); }
.prompt-remove { font-size: 18px; }
.prompt-remove:hover { color: var(--danger); background: rgba(255,124,139,.08); }
.empty-text { margin: 8px 0; color: var(--muted); font-size: 12px; }

.main-panel { min-width: 0; }
.notice { margin-bottom: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); font-size: 13px; }
.notice.error { border-color: rgba(255,124,139,.4); color: #ffdce1; background: rgba(255,124,139,.08); }
.notice.warning { border-color: rgba(244,191,100,.4); color: #ffebc7; background: rgba(244,191,100,.08); }
.notice.success { border-color: rgba(88,214,161,.35); color: #d7ffed; background: rgba(88,214,161,.07); }

.composer-card { border: 1px solid var(--border); border-radius: 18px; background: rgba(17,22,31,.9); box-shadow: 0 18px 50px rgba(0,0,0,.16); overflow: hidden; }
.system-prompt { border-bottom: 1px solid var(--border); }
.system-prompt summary { padding: 12px 16px; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; user-select: none; }
.system-prompt textarea { width: 100%; min-height: 100px; padding: 4px 16px 16px; border: 0; outline: none; color: var(--text); background: transparent; line-height: 1.55; }
.main-input { display: block; width: 100%; min-height: 170px; padding: 18px; border: 0; outline: none; color: var(--text); background: transparent; font-size: 16px; line-height: 1.58; }
.main-input::placeholder, .system-prompt textarea::placeholder { color: #647085; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 12px 14px; border-top: 1px solid var(--border); background: rgba(255,255,255,.012); }
.composer-meta { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 11px; }
.run-button { display: flex; align-items: center; gap: 13px; }
.run-button kbd { padding: 2px 5px; border: 1px solid rgba(255,255,255,.22); border-radius: 5px; color: rgba(255,255,255,.7); background: rgba(0,0,0,.13); font-size: 10px; font-family: inherit; }
.run-button.busy span::after { content: "…"; animation: dots 1s infinite; }
@keyframes dots { 0%, 20% { opacity: .2; } 50% { opacity: 1; } 100% { opacity: .2; } }

.request-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 13px 0; }
.request-summary span { padding: 7px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); background: rgba(17,22,31,.7); font-size: 11px; }
.request-summary strong { color: var(--text); font-variant-numeric: tabular-nums; }

.results-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; align-items: start; }
.result-card { min-width: 0; border: 1px solid var(--border); border-radius: 16px; background: rgba(17,22,31,.9); overflow: hidden; box-shadow: 0 14px 38px rgba(0,0,0,.12); }
.result-card > header { display: flex; justify-content: space-between; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--border); }
.result-card > header > div { min-width: 0; display: grid; gap: 3px; }
.result-card h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.result-card code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 10px; }
.status-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--border-strong); box-shadow: 0 0 0 4px rgba(255,255,255,.025); }
.result-card.success .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(88,214,161,.09); }
.result-card.error .status-dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(255,124,139,.09); }
.result-card.loading .status-dot { background: var(--warning); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
.result-body { min-height: 190px; max-height: 560px; overflow: auto; padding: 15px; color: #e5eaf2; line-height: 1.58; font-size: 13px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.placeholder-text { color: var(--muted); }
.answer-text, .answer-error, .message div { white-space: pre-wrap; overflow-wrap: anywhere; }
.answer-error { color: #ffd9de; }
.result-meta { display: flex; flex-wrap: wrap; gap: 7px; min-height: 40px; padding: 10px 13px; border-top: 1px solid var(--border); color: var(--muted); font-size: 10px; }
.result-meta span { padding: 3px 6px; border-radius: 6px; background: var(--panel-3); font-variant-numeric: tabular-nums; }
.loader { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; color: var(--muted); }
.loader span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1s infinite alternate; }
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
.loader em { width: 100%; margin-top: 7px; font-style: normal; font-size: 12px; }
@keyframes bounce { to { opacity: .25; transform: translateY(-5px); } }
.conversation { display: grid; gap: 10px; }
.message { max-width: 94%; padding: 10px 11px; border-radius: 12px; }
.message strong { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.user-message { justify-self: end; background: rgba(124,156,255,.12); border: 1px solid rgba(124,156,255,.18); }
.assistant-message { justify-self: start; background: var(--panel-2); border: 1px solid var(--border); }
.results-empty { grid-column: 1 / -1; display: grid; place-items: center; min-height: 220px; padding: 30px; border: 1px dashed var(--border); border-radius: 16px; color: var(--muted); text-align: center; }
.results-empty strong { color: var(--text); font-size: 18px; }
.results-empty span { margin-top: -70px; }

.settings-dialog, .small-dialog { width: min(96vw, 1180px); max-height: 92vh; padding: 0; border: 1px solid var(--border-strong); border-radius: 19px; color: var(--text); background: var(--panel); box-shadow: var(--shadow); }
.small-dialog { width: min(92vw, 480px); }
dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
.dialog-shell { display: grid; grid-template-rows: auto minmax(0,1fr) auto; max-height: 92vh; }
.dialog-shell > header, .dialog-shell > footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; }
.dialog-shell > header { border-bottom: 1px solid var(--border); }
.dialog-shell > footer { border-top: 1px solid var(--border); }
.dialog-shell > footer > div { display: flex; gap: 8px; }
.dialog-shell h2 { margin: 0; font-size: 20px; }
.dialog-shell header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.settings-scroll { overflow: auto; padding: 14px; }
.model-settings { display: grid; gap: 11px; }
.model-setting-card { padding: 13px; border: 1px solid var(--border); border-radius: 13px; background: var(--panel-2); }
.model-setting-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.model-setting-heading > strong { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--panel-3); font-size: 12px; }
.switch-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.switch-label input { accent-color: var(--accent); }
.settings-grid { display: grid; grid-template-columns: minmax(130px, .8fr) minmax(220px, 1.6fr) repeat(5, minmax(90px, .6fr)); gap: 9px; }
.settings-grid.compact { grid-template-columns: repeat(3, minmax(130px, 1fr)); margin-top: 10px; }
.settings-grid label { display: grid; gap: 5px; min-width: 0; }
.settings-grid label span { color: var(--muted); font-size: 10px; }
.settings-grid input, .settings-grid select {
    width: 100%; min-width: 0; height: 36px; padding: 0 9px; border: 1px solid var(--border); border-radius: 8px; outline: none; color: var(--text); background: var(--bg); font-size: 11px;
}
.settings-grid input:focus, .settings-grid select:focus { border-color: var(--accent); }
.advanced-pricing { margin-top: 10px; }
.advanced-pricing summary { color: var(--muted); font-size: 10px; cursor: pointer; }
.dialog-body { display: grid; gap: 7px; padding: 20px; }
.prompt-dialog { width: min(94vw, 760px); }
.prompt-editor { overflow: auto; gap: 9px; }
.prompt-editor-toolbar { display: flex; justify-content: flex-end; margin: 2px 0 4px; }
.prompt-editor-toolbar .ghost-button { min-height: 34px; font-size: 12px; }
.dialog-body textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 11px;
    outline: none;
    color: var(--text);
    background: var(--panel-2);
    line-height: 1.5;
    resize: vertical;
}
.dialog-body textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,.13); }

@media (min-width: 1550px) {
    .workspace { grid-template-columns: 320px minmax(0, 1fr); }
    .results-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 2200px) {
    .results-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
    .settings-grid { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
    .settings-grid .wide { grid-column: span 2; }
}
@media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; }
    .sidebar { position: static; display: block; max-height: none; overflow: visible; }
    .panel-section.grow, .sidebar > .panel-section:last-child { display: block; min-height: auto; overflow: visible; }
    .prompt-list, .model-picker { overflow: visible; padding-right: 0; }
    .model-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
    .topbar { padding: 10px 12px; }
    .brand small, .all-time-cost span { display: none; }
    .topbar-actions { gap: 5px; }
    .topbar .ghost-button { min-height: 36px; padding: 0 9px; font-size: 12px; }
    .all-time-cost { margin-right: 3px; font-size: 12px; }
    .workspace { padding: 10px; gap: 10px; }
    .results-grid { grid-template-columns: 1fr; }
    .composer-footer { align-items: stretch; flex-direction: column; }
    .run-button { justify-content: center; }
    .model-picker { grid-template-columns: 1fr; }
    .settings-dialog { width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; }
    .dialog-shell { max-height: 100vh; height: 100%; }
    .settings-grid, .settings-grid.compact { grid-template-columns: 1fr 1fr; }
    .settings-grid .wide { grid-column: 1 / -1; }
    .dialog-shell > footer { align-items: stretch; flex-direction: column; }
    .dialog-shell > footer > div { justify-content: flex-end; }
}
@media (max-width: 430px) {
    .login-card { padding: 28px 20px; }
    .brand > div:last-child { display: none; }
    .brand-mark.small { width: 38px; height: 38px; }
    .main-input { min-height: 145px; padding: 14px; font-size: 15px; }
    .panel-section { padding: 13px; }
    .settings-grid, .settings-grid.compact { grid-template-columns: 1fr; }
    .settings-grid .wide { grid-column: auto; }
    .model-setting-heading { flex-wrap: wrap; }
}
