:root {
  --bg: #0d0d0f;
  --side: #111114;
  --surface: #17171b;
  --surface2: #211f25;
  --line: #2a2a31;
  --text: #f2f2f4;
  --muted: #8e8e98;
  --red: #e11d2e;
  --red2: #ff4d5e;
  --user: #2a1518;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
body.chat { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--red2); }
#particles { position: fixed; inset: 0; z-index: 0; pointer-events: none; width: 100%; height: 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); text-decoration: none;
}
.btn:hover { border-color: var(--red); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--red2); border-color: var(--red2); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.ico {
  display: flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 9px; border: 1px solid var(--line); background: var(--surface); flex-shrink: 0;
}
.ico:hover { border-color: var(--red); }

/* Chat layout */
.app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }
.side {
  width: 260px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 12px; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 4px 6px; }
.brand b { color: var(--red); }
.newbtn {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); text-align: left;
}
.newbtn:hover { border-color: var(--red); }
.list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; padding: 8px 6px 4px; }
.item {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 8px 10px;
  border-radius: 9px; border: 1px solid transparent; background: none; text-align: left;
}
.item:hover { background: var(--surface); }
.item.active { background: var(--surface2); border-color: var(--line); }
.item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.item .del { opacity: 0; border: 0; background: none; color: var(--muted); padding: 0 4px; font-size: 16px; }
.item:hover .del { opacity: 1; }
@media (hover: none) { .item .del { opacity: 1; } }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.side-foot a, .side-foot button {
  display: block; padding: 8px 10px; border-radius: 9px; border: 0; background: none;
  text-align: left; text-decoration: none; color: var(--text); font-size: 14px;
}
.side-foot a:hover, .side-foot button:hover { background: var(--surface); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: rgba(13, 13, 15, .9);
}
.topbar .title { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.only-m { display: none; }
#scroll { flex: 1; overflow-y: auto; padding: 24px 16px; }
.wrap { max-width: 760px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding-top: 14vh; }
.empty h2 { color: var(--text); font-size: 22px; margin: 12px 0 6px; }

.msg { margin-bottom: 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .body {
  max-width: 85%; background: var(--user); border: 1px solid #3a1d21; border-radius: 16px;
  padding: 10px 14px; white-space: pre-wrap; word-wrap: break-word;
}
.msg.ai .body { padding: 0 4px; }
.msg.error .body { color: #ff8c96; }
.thumb { display: block; max-width: 220px; max-height: 220px; border-radius: 10px; margin-bottom: 6px; }
.md p { margin: .45em 0; }
.md ul, .md ol { padding-left: 1.4em; }
.md :not(pre) > code {
  background: var(--surface2); padding: 1px 6px; border-radius: 6px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em;
}
.codebox { margin: 12px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #0a0a0c; }
.codehead {
  display: flex; justify-content: space-between; align-items: center; padding: 6px 12px;
  background: var(--surface2); font-size: 12px; color: var(--muted);
}
.codebox pre { margin: 0; padding: 12px; overflow-x: auto; font-size: 13.5px; }
.codebox code { font-family: ui-monospace, Menlo, Consolas, monospace; }
.copy {
  font-size: 12px; background: none; border: 1px solid var(--line); border-radius: 7px;
  padding: 3px 9px; color: var(--text);
}
.copy:hover { border-color: var(--red); }
.typing::after { content: ""; display: inline-block; width: 1ch; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

.composer-wrap { padding: 8px 14px 12px; }
.composer {
  max-width: 760px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 10px 10px 8px;
}
.composer:focus-within { border-color: var(--red); }
.composer textarea {
  width: 100%; background: none; border: 0; outline: none; resize: none;
  padding: 6px 6px 4px; min-height: 30px; max-height: 200px; font-size: 15px;
}
.composer textarea::placeholder { color: var(--muted); }
.cbar { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }
.round {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; border: 1px solid var(--line); background: var(--surface2); flex-shrink: 0;
}
.round:hover { border-color: var(--red); }
.send { background: var(--red); border-color: var(--red); color: #fff; font-size: 18px; font-weight: 700; }
.send:disabled { opacity: .4; }
.pill {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface2); font-size: 13px; color: var(--text);
  text-decoration: none; max-width: 220px;
}
.pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill:hover { border-color: var(--red); }
.model-wrap { position: relative; }
.menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; min-width: 260px; max-height: 320px;
  overflow-y: auto; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; box-shadow: 0 14px 36px rgba(0, 0, 0, .5); z-index: 5;
}
.mi {
  display: flex; justify-content: space-between; gap: 8px; width: 100%; padding: 8px 10px;
  border: 0; background: none; border-radius: 8px; text-align: left; font-size: 13px;
}
.mi:hover { background: var(--surface); }
.mi.active { color: var(--red2); }
.mi small { color: var(--muted); }
.preview { max-width: 760px; margin: 0 auto 8px; display: flex; align-items: center; gap: 10px; }
.preview img { height: 52px; border-radius: 8px; border: 1px solid var(--line); }
.hint { text-align: center; color: var(--muted); font-size: 11px; margin: 8px 0 0; }
.overlay { display: none; }
.overlay.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 15; }

@media (max-width: 768px) {
  .only-m { display: flex; }
  .side {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
    transform: translateX(-100%); transition: transform .2s; padding-top: env(safe-area-inset-top, 0px);
  }
  .side.open { transform: none; }
}

/* Login, profil, admin */
.login-page {
  position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px;
}
.card h1 { font-size: 20px; margin: 14px 0 4px; text-align: center; }
.card p.sub { color: var(--muted); text-align: center; margin: 0 0 20px; font-size: 14px; }
.card .btn.primary { width: 100%; padding: 11px; }
.logo-big { display: block; margin: 0 auto; }
.err { color: #ff8c96; font-size: 14px; min-height: 20px; margin: 0 0 8px; }

.page {
  position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh;
  padding: 24px 16px; display: flex; justify-content: center;
}
.box { width: 100%; max-width: 620px; display: flex; flex-direction: column; gap: 14px; }
.box.wide { max-width: 900px; }
.topline { display: flex; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.tablewrap { padding: 0; overflow: auto; }
.profile { display: flex; align-items: center; gap: 14px; }
.name { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); }
.badge.on { color: #7fd69b; border-color: #2c5a3b; }
.badge.off { color: var(--muted); }
.meter { height: 12px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--red); transition: width .4s; }
.meta { display: flex; justify-content: space-between; margin-top: 8px; font-size: 14px; gap: 10px; }
.muted { color: var(--muted); font-size: 13px; }
.feat { margin: 0 0 10px; padding-left: 18px; }
.price { font-size: 18px; font-weight: 600; margin: 6px 0 12px; }
.paybox {
  margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface2); font-size: 14px;
}
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }
.pay-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.pay-row:last-child { border-bottom: 0; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; flex: 1; min-width: 140px; }
.row .field { margin-bottom: 0; }
.field.narrow { flex: 0; min-width: 120px; max-width: 140px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select {
  background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--red); }
