:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1d2027;
  --line: #2a2e37;
  --text: #e8e9ec;
  --muted: #8b909c;
  --accent: #d4ff5a;
  --accent-ink: #101114;
  --danger: #ff6b6b;
  --radius: 10px;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); margin: 0; }

input, textarea, select {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font: inherit; outline: none; transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12.5px; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #3a3f4b; background: #232731; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: transparent; color: var(--danger); border-color: #5a2a2a; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; font-size: 13px; }
.icon-btn:hover { color: var(--danger); background: var(--panel-2); }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-family: var(--mono);
}

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 18px; padding: 28px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}

/* Layout */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
.sidebar {
  display: flex; flex-direction: column; gap: 14px; padding: 16px 12px;
  background: var(--panel); border-right: 1px solid var(--line); min-height: 0;
}
.sidebar .brand { padding: 2px 6px 6px; }
.nav { display: grid; gap: 2px; }
.nav-item {
  text-align: left; background: none; border: 0; color: var(--muted); font: inherit;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.convs-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 6px 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: grid; align-content: start; gap: 1px; }
.conv-list li {
  display: flex; align-items: center; gap: 4px; padding: 7px 8px 7px 10px; border-radius: 8px;
  cursor: pointer; color: var(--muted);
}
.conv-list li:hover { background: var(--panel-2); color: var(--text); }
.conv-list li.active { background: var(--panel-2); color: var(--text); }
.conv-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list li .icon-btn { visibility: hidden; }
.conv-list li:hover .icon-btn { visibility: visible; }
.sidebar-foot { display: grid; gap: 8px; border-top: 1px solid var(--line); padding: 12px 6px 0; }
.sys-info { font-size: 12px; color: var(--muted); display: grid; gap: 2px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.ok { background: var(--accent); }
.dot.bad { background: var(--danger); }

.main { min-width: 0; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; }
.menu-btn { display: none; }

/* Chat */
.chat { display: flex; flex-direction: column; height: 100%; }
.chat-bar { display: flex; gap: 10px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.model-select { max-width: 420px; }
.settings { display: grid; grid-template-columns: 1fr 240px; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.temp span { color: var(--text); font-family: var(--mono); }
.temp input { padding: 0; accent-color: var(--accent); }
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 12px; }
.msg { max-width: 820px; margin: 0 auto 22px; display: grid; gap: 6px; }
.msg-role { font-size: 12px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.msg-role b { color: var(--text); font-weight: 600; }
.msg.user .msg-body { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; white-space: pre-wrap; }
.msg.assistant .msg-body { padding: 0 2px; }
.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 0 0 10px; padding-left: 22px; }
.msg-body h3, .msg-body h4 { margin: 14px 0 6px; font-size: 15px; }
.msg-body code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.msg-body pre { position: relative; background: #0a0b0d; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; margin: 0 0 10px; }
.msg-body pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.55; }
.copy { position: absolute; top: 6px; right: 6px; font-size: 11px; padding: 3px 8px; opacity: 0; transition: opacity .15s; }
.msg-body pre:hover .copy { opacity: 1; }
.msg-error { color: var(--danger); border: 1px solid #5a2a2a; border-radius: 8px; padding: 8px 12px; background: #1f1416; }
.msg-stats { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.empty { max-width: 520px; margin: 12vh auto 0; text-align: center; color: var(--muted); display: grid; gap: 10px; }
.empty h2 { color: var(--text); font-size: 20px; }
.composer { display: flex; gap: 10px; align-items: flex-end; max-width: 860px; width: 100%; margin: 0 auto; padding: 12px 20px 20px; }
.composer textarea { resize: none; max-height: 240px; padding: 11px 13px; }

/* Models */
.models { overflow-y: auto; padding: 24px clamp(16px, 4vw, 40px) 60px; height: 100%; }
.page-head { display: grid; gap: 4px; margin-bottom: 20px; max-width: 980px; }
.panel { max-width: 980px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 20px; display: grid; gap: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel p { margin: 0; }
.tag { font-size: 11px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: 1px; }
.row { display: flex; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 4px 11px; font: inherit; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip small { color: var(--muted); margin-left: 4px; }
.chip.installed { opacity: .45; cursor: default; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table td:first-child { font-family: var(--mono); font-size: 13px; }
.table td:last-child { text-align: right; }
.pull { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 6px; margin-bottom: 8px; }
.pull-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.pull-top b { font-family: var(--mono); font-weight: 500; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); transition: width .4s; }
.provider-form { display: grid; grid-template-columns: 150px 1fr 1.4fr 1fr auto; gap: 8px; }
.providers { display: grid; gap: 10px; }
.provider { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--panel-2); display: grid; gap: 10px; }
.provider-top { display: flex; align-items: center; gap: 10px; }
.provider-top .grow { flex: 1; min-width: 0; }
.provider-top .url { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.model-tag { display: inline-flex; align-items: center; gap: 2px; font-family: var(--mono); font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px 3px 9px; }

/* Dialog */
.dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(640px, 94vw); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog-inner { display: grid; gap: 12px; padding: 18px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.browser-list { list-style: none; margin: 0; padding: 0; max-height: 55vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.browser-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 10px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12.5px; }
.browser-list li:last-child { border-bottom: 0; }
.browser-list li.on { color: var(--accent); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 10; }
.toast.err { border-color: #5a2a2a; color: var(--danger); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vw rgba(0,0,0,.5); }
  .menu-btn { display: inline-block; }
  .settings { grid-template-columns: 1fr; }
  .provider-form { grid-template-columns: 1fr 1fr; }
  .provider-form .btn { grid-column: 1 / -1; }
  .table th:nth-child(3), .table td:nth-child(3), .table th:nth-child(4), .table td:nth-child(4) { display: none; }
  .page-head { grid-template-columns: auto 1fr; align-items: center; }
  .page-head p { grid-column: 1 / -1; }
}

/* Catalogs */
.narrow { width: auto; flex: none; }
.check { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; color: var(--text); font-size: 13px; }
.check input { width: auto; accent-color: var(--accent); }
.library-box { border-top: 1px solid var(--line); padding-top: 12px; }
.library-box summary { cursor: pointer; font-weight: 500; padding: 4px 0 10px; }
.library-box[open] summary { margin-bottom: 4px; }
.library-box .row { margin-bottom: 8px; }
.library-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 560px; overflow-y: auto; }
.lib-item { border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 12px 14px; display: grid; gap: 6px; }
.lib-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.lib-head b { font-family: var(--mono); font-weight: 600; }
.lib-head a { color: var(--muted); font-size: 12px; text-decoration: none; }
.lib-head a:hover { color: var(--accent); }
.lib-meta { margin-left: auto; font-size: 12px; color: var(--muted); }
.lib-desc { margin: 0; color: var(--muted); font-size: 13px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge { font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; color: var(--muted); }
.badge.free { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 600; }
.size-btn { font-family: var(--mono); font-size: 12px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; cursor: pointer; }
.size-btn:hover { border-color: var(--accent); color: var(--accent); }
.size-btn small { color: var(--muted); margin-left: 4px; }
.size-btn.big { opacity: .45; }
.size-btn.have { border-color: var(--accent); color: var(--accent); cursor: default; }
.tip { display: flex; gap: 14px; align-items: center; justify-content: space-between; background: var(--panel-2); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 14px; font-size: 13px; color: var(--muted); }
.tip b { color: var(--text); }
.tip code, .links code { font-family: var(--mono); font-size: 12px; color: var(--text); }
.links { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.browser-list li { align-items: flex-start; }
.browser-list .bl-main { display: grid; gap: 3px; min-width: 0; }
.browser-list .bl-name { font-family: var(--sans); color: var(--muted); font-size: 12px; }
.browser-list .bl-desc { font-family: var(--sans); color: var(--muted); font-size: 12px; white-space: normal; }
.browser-filters { align-items: center; }
@media (max-width: 860px) { .tip { flex-direction: column; align-items: flex-start; } .library-box .row { flex-wrap: wrap; } }
