/* Lilith — one stylesheet for the chat and the admin panel.
   Dark by default (like the logo); light follows the device or the menu choice. */
:root, .auth {
  color-scheme: dark;
  --bg: #0a0a0a; --panel: #141414; --panel2: #1c1c1c; --line: #2a2a2a; --line2: #3a3a3a;
  --fg: #f2f2f2; --muted: #9a9a9a; --dim: #6b6b6b; --accent: #ffffff; --accent-fg: #0a0a0a;
  --danger: #ff6b6b; --danger-line: #4a2626; --warn: #f5b84a; --ok: #7ee2a8; --focus: #8a8a8a; --focus2: #5a5a5a;
  --shadow: 0 10px 40px rgba(0,0,0,.35); --shadow-menu: 0 16px 48px rgba(0,0,0,.55); --logo-bg: transparent; --logo-pad: 0; --radius: 22px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #fafafa; --panel: #ffffff; --panel2: #f0f0f0; --line: #e6e6e6; --line2: #d2d2d2;
    --fg: #141414; --muted: #636363; --dim: #8e8e8e; --accent: #141414; --accent-fg: #ffffff;
    --danger: #d33a3a; --danger-line: #f0c4c4; --warn: #c98a12; --ok: #1d8a4c; --focus: #9a9a9a; --focus2: #b5b5b5;
    --shadow: 0 6px 24px rgba(0,0,0,.06); --shadow-menu: 0 12px 36px rgba(0,0,0,.14); --logo-bg: #0a0a0a; --logo-pad: 18px 30px;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fafafa; --panel: #ffffff; --panel2: #f0f0f0; --line: #e6e6e6; --line2: #d2d2d2;
  --fg: #141414; --muted: #636363; --dim: #8e8e8e; --accent: #141414; --accent-fg: #ffffff;
  --danger: #d33a3a; --danger-line: #f0c4c4; --warn: #c98a12; --ok: #1d8a4c; --focus: #9a9a9a; --focus2: #b5b5b5;
  --shadow: 0 6px 24px rgba(0,0,0,.06); --shadow-menu: 0 12px 36px rgba(0,0,0,.14); --logo-bg: #0a0a0a; --logo-pad: 18px 30px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
a { color: var(--fg); }

/* ---- sign-in ---------------------------------------------------------------- */
.auth { min-height: 100%; background: var(--bg); color: var(--fg); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 360px; text-align: center; }
/* the logo is white artwork; on the light theme it sits on its own black tile */
.auth-logo { height: 168px; width: auto; display: block; margin: 0 auto 20px; box-sizing: content-box;
  background: var(--logo-bg); padding: var(--logo-pad); border-radius: 30px; }
.brand img { background: var(--logo-bg); border-radius: 8px; padding: 3px 5px; }
.auth h1 { font-size: 28px; font-weight: 650; letter-spacing: .5px; margin: 0 0 6px; }
.auth p { color: var(--muted); margin: 0 0 26px; }
.field { width: 100%; height: 52px; border-radius: 16px; border: 1px solid var(--line2); background: var(--panel);
  padding: 0 16px; outline: none; transition: border-color .15s; }
.field:focus { border-color: var(--focus); }
textarea.field { height: auto; padding: 14px 16px; resize: vertical; line-height: 1.5; }
.btn { height: 50px; border: 0; border-radius: 16px; background: var(--accent); color: var(--accent-fg); font-weight: 600;
  padding: 0 20px; transition: opacity .15s, transform .1s; }
.btn:hover { opacity: .9; } .btn:active { transform: scale(.99); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-ghost { background: transparent; color: var(--fg); border: 1px solid var(--line2); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger-line); }
.btn-sm { height: 36px; border-radius: 12px; padding: 0 14px; font-size: 14px; }
.auth .btn { width: 100%; margin-top: 12px; }
.msg { min-height: 22px; margin-top: 12px; font-size: 14px; color: var(--danger); }
.pw-wrap { position: relative; }
.pw-eye { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; }
.pw-eye svg { width: 18px; height: 18px; }

/* ---- chat layout ------------------------------------------------------------ */
.app { position: relative; height: 100%; display: flex; flex-direction: column; }
.top { height: 60px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid transparent; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .3px; }
.brand img { height: 32px; width: auto; }
.spacer { flex: 1; }
.icon-btn { width: 36px; height: 36px; border-radius: 12px; border: 0; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--panel2); color: var(--fg); }
.icon-btn svg, .tool svg, .pill svg, .send svg, .menu-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.dropdown { position: relative; }
.menu { position: absolute; z-index: 50; min-width: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow-menu); padding: 6px; animation: pop .13s ease-out; }
.menu.down { top: calc(100% + 8px); right: 0; }
.menu.up { bottom: calc(100% + 10px); left: 0; width: 290px; max-width: calc(100vw - 40px); }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }
.menu-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--dim); padding: 8px 10px 4px; }
.menu-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 11px; border: 0; background: transparent; text-align: left; color: var(--fg); }
.menu-item:hover { background: var(--panel2); }
.menu-item b { display: block; font-weight: 600; font-size: 14px; }
.menu-item small { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.menu-item .check { margin-left: auto; opacity: 0; }
.menu-item[aria-checked="true"] .check { opacity: 1; }

.thread { flex: 1; overflow-y: auto; padding: 60px 16px 24px; scroll-behavior: smooth; display: flex; flex-direction: column; }
.thread-in { flex: none; width: 100%; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 16px 16px 40px; }
.empty h2 { color: var(--fg); font-size: 22px; font-weight: 600; margin: 0 0 4px; }
.row-user { align-self: flex-end; max-width: 85%; }
.bubble { background: var(--panel2); border: 1px solid var(--line); border-radius: 20px 20px 6px 20px; padding: 10px 15px; white-space: pre-wrap; word-wrap: break-word; }
.bubble-imgs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.bubble-imgs img { width: 120px; height: 120px; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); }
.row-ai { align-self: stretch; }
.ai-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); margin-bottom: 4px; }
.thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .2s; } .thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.err { color: var(--danger); font-size: 14px; }

/* ---- markdown --------------------------------------------------------------- */
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3 { font-size: 17px; margin: 18px 0 8px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.md pre { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; overflow-x: auto; margin: 0 0 12px; }
.md pre code { background: none; border: 0; padding: 0; }
.md blockquote { margin: 0 0 12px; padding-left: 12px; border-left: 3px solid var(--line2); color: var(--muted); }
.md a { text-decoration: underline; text-underline-offset: 2px; }
.md table { border-collapse: collapse; margin: 0 0 12px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }

/* ---- composer (Grok / Claude style) ---------------------------------------- */
.dock { flex: none; padding: 8px 16px 18px; }
.composer { max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line2); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color .15s; }
.composer:focus-within { border-color: var(--focus2); }
.composer.locked .input, .composer.locked .tools { opacity: .5; }
.attached { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px 0; }
.attached:empty { display: none; }
.thumb { position: relative; width: 64px; height: 64px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 14px; border: 1px solid var(--line2); }
.thumb button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line2);
  background: var(--panel2); color: var(--fg); font-size: 13px; line-height: 1; padding: 0; }
.input { display: block; width: 100%; min-height: 56px; max-height: 220px; resize: none; border: 0; outline: none; background: transparent;
  padding: 16px 18px 6px; line-height: 1.5; }
.input::placeholder { color: var(--dim); }
.tools { display: flex; align-items: center; gap: 6px; padding: 6px 10px 10px; }
.tool { width: 36px; height: 36px; border-radius: 12px; border: 0; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.tool:hover:not(:disabled) { background: var(--panel2); color: var(--fg); }
.tool:disabled { opacity: .3; cursor: not-allowed; }
.pill { height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 11px; border-radius: 999px; border: 1px solid var(--line2);
  background: transparent; color: var(--fg); font-size: 13px; white-space: nowrap; }
.pill:hover, .pill[aria-expanded="true"] { background: var(--panel2); }
.pill .sub { color: var(--muted); }
.pill .chev { width: 13px; height: 13px; opacity: .55; }
.send { margin-left: auto; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-fg);
  display: inline-flex; align-items: center; justify-content: center; transition: opacity .15s; }
.send:disabled { opacity: .25; cursor: default; }
.send.stop { background: var(--fg); }
.foot { text-align: center; font-size: 12px; color: var(--dim); margin-top: 8px; min-height: 18px; }
.foot.warn { color: var(--danger); }
.toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line2);
  border-radius: 12px; padding: 10px 14px; font-size: 14px; z-index: 100; animation: pop .15s ease-out; max-width: calc(100vw - 32px); }
@media (max-width: 420px) { .pill .sub { display: none; } }

/* daily usage, inside the composer: the divider line fills with the share of
   the limit used; text shows the percent and the time to reset */
.quota { position: relative; display: flex; align-items: center; gap: 7px; padding: 8px 16px 9px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.qbar { position: absolute; left: 0; top: -1px; height: 2px; width: 0; background: var(--fg); border-radius: 0 2px 2px 0; transition: width .5s ease, background-color .3s; }
.quota.high .qbar { background: var(--warn); }
.quota.full .qbar { background: var(--danger); border-radius: 0; }
.quota.full #qPct { color: var(--danger); font-weight: 600; }

/* ---- admin ------------------------------------------------------------------ */
.admin { max-width: 860px; margin: 0 auto; padding: 0 16px 60px; }
.tabs { display: flex; gap: 6px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: max-content; margin: 8px 0 22px; }
.tab { height: 36px; padding: 0 16px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); font-weight: 500; }
.tab[aria-selected="true"] { background: var(--panel2); color: var(--fg); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 4px; font-size: 16px; } .card .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.grid { display: grid; grid-template-columns: 1fr 160px auto; gap: 10px; align-items: end; }
@media (max-width: 640px) { .grid { grid-template-columns: 1fr; } }
label.lb { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.secret { margin-top: 14px; padding: 14px; border-radius: 14px; border: 1px dashed var(--line2); background: var(--panel2); }
.secret code { font: 600 20px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; word-break: break-all; }
.secret .row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.users { display: flex; flex-direction: column; gap: 10px; }
.user { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); }
.user .nm { font-weight: 600; } .user .sub { color: var(--muted); font-size: 13px; }
.user .meter { grid-column: 1 / -1; height: 6px; border-radius: 6px; background: var(--line2); overflow: hidden; }
.user .meter i { display: block; height: 100%; background: var(--fg); }
.user .meter.full i { background: var(--danger); }
.user .acts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.user .acts input { width: 96px; height: 36px; border-radius: 12px; padding: 0 10px; }
.none { color: var(--muted); text-align: center; padding: 24px 0; }
.ok-msg { color: var(--ok); font-size: 14px; min-height: 20px; margin-top: 10px; }

.mb10 { margin-bottom: 10px; } .mt6 { margin-top: 6px; } .mt8 { margin-top: 8px; } .mt10 { margin-top: 10px; } .mt14 { margin-top: 14px; }
.grid.grid2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .grid.grid2 { grid-template-columns: 1fr; } }
.secret-for { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.grid.grid3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) { .grid.grid3 { grid-template-columns: 1fr; } }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.link { display: block; margin-top: 16px; color: var(--muted); font-size: 14px; text-decoration: none; }
.link:hover { color: var(--fg); }
.tag { display: inline-block; margin-left: 8px; padding: 1px 8px; border: 1px solid var(--line2); border-radius: 99px; font-size: 11px; font-weight: 600; color: var(--muted); vertical-align: 2px; }
body:has(.auth:not(.hidden)) { background: #0a0a0a; }

/* ---- chat: menu button (no bar), drawer, settings ---------------------------- */
.app > .top { position: absolute; top: 0; left: 0; z-index: 20; height: auto; padding: 12px; border: 0; }
.icon-btn.float { width: 40px; height: 40px; border-radius: 12px; background: var(--bg); color: var(--fg); }
.icon-btn.float svg { width: 20px; height: 20px; }
.scrim { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); animation: fade .15s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer { position: fixed; z-index: 61; top: 0; bottom: 0; left: 0; width: min(300px, 84vw); display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); transform: translateX(-102%); transition: transform .22s ease;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
.drawer.open { transform: none; box-shadow: var(--shadow-menu); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px 10px; }
.drawer-title { font-weight: 650; letter-spacing: .3px; }
.d-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 12px; border: 0; border-radius: 12px; background: transparent; color: var(--fg); text-align: left; font-size: 15px; }
.d-item:hover { background: var(--panel2); }
.d-item svg, .h-del svg, .sheet-head svg, .drawer-head svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.d-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--dim); padding: 16px 12px 6px; }
.d-history { flex: 1; overflow-y: auto; min-height: 0; }
.d-empty { color: var(--dim); font-size: 14px; padding: 6px 12px; }
.h-item { display: flex; align-items: center; border-radius: 12px; }
.h-item:hover, .h-item.on { background: var(--panel2); }
.h-open { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 9px 12px; border: 0; background: transparent; color: var(--fg); text-align: left; }
.h-title { width: 100%; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-when { font-size: 11.5px; color: var(--dim); }
.h-del { width: 34px; height: 34px; margin-right: 4px; border: 0; border-radius: 10px; background: transparent; color: var(--dim); display: inline-flex; align-items: center; justify-content: center; opacity: .7; }
.h-del:hover { color: var(--danger); opacity: 1; }
.drawer-foot { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 6px; }
.modal { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s ease-out; }
.sheet { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 16px 18px 20px; box-shadow: var(--shadow-menu); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.set-row:first-of-type { border-top: 0; }
.set-lb { font-weight: 500; } .set-sub { font-size: 12.5px; color: var(--muted); }
.seg { display: flex; padding: 3px; gap: 2px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; }
.seg button { height: 32px; padding: 0 11px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.18); }
@media (max-width: 380px) { .set-row { flex-direction: column; align-items: flex-start; } }
:root[data-font="small"] body { font-size: 14px; }
:root[data-font="large"] body { font-size: 17px; }
