:root {
  --bg: #f7f7f9;
  --panel: #ffffff;
  --sidebar: #f1f1f5;
  --text: #1c1c22;
  --muted: #6b6b78;
  --line: #e3e3ea;
  --accent: #5d5cde;
  --accent-soft: #ecebfd;
  --user-bubble: #5d5cde;
  --user-text: #ffffff;
  --bot-bubble: #ffffff;
  --code-bg: #f3f3f7;
  --danger: #c4314b;
  --danger-soft: #fdecee;
  --good: #0f8a4b;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --shadow: 0 6px 24px rgba(20, 20, 40, 0.08);
  --radius: 14px;
  font-family: Inter, "Segoe UI", "Noto Sans Myanmar", "Myanmar Text", "Noto Sans Khmer", "Noto Sans Lao", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15151b;
    --panel: #1c1c24;
    --sidebar: #111117;
    --text: #ececf2;
    --muted: #9a9aab;
    --line: #2b2b36;
    --accent: #8a89ff;
    --accent-soft: #26264a;
    --user-bubble: #5d5cde;
    --bot-bubble: #1f1f29;
    --code-bg: #24242f;
    --danger: #ff7a8e;
    --danger-soft: #3a1d24;
    --good: #4cc98a;
    --warn: #f0c060;
    --warn-soft: #3a3020;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.55; }
button { font: inherit; color: inherit; cursor: pointer; }

.app { display: grid; grid-template-columns: 272px 1fr; height: 100dvh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--sidebar); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 10px; overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 16px;
}
.new-chat {
  border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 12px;
  text-align: left; font-weight: 600; display: flex; gap: 8px; align-items: center;
}
.new-chat:hover { border-color: var(--accent); }

.wallet {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.wallet-label { font-size: 12px; color: var(--muted); }
.wallet-balance { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.wallet.low .wallet-balance { color: var(--danger); }
.small-btn {
  border: none; background: var(--accent-soft); color: var(--accent); font-weight: 600;
  border-radius: 8px; padding: 6px 10px; font-size: 13px;
}
.small-btn:hover { filter: brightness(0.97); }

.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px 6px 0; }

.bot-list, .chat-list { display: flex; flex-direction: column; gap: 2px; }
.bot-item, .chat-item {
  display: flex; align-items: center; gap: 10px; border: none; background: transparent;
  text-align: left; padding: 8px; border-radius: 10px; width: 100%;
}
.bot-item:hover, .chat-item:hover { background: var(--panel); }
.bot-item.active, .chat-item.active { background: var(--accent-soft); }
.bot-item .bot-text { min-width: 0; flex: 1; }
.bot-item .bot-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.bot-item .bot-cost { font-size: 12px; color: var(--muted); }
.badge {
  font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.unconfigured { opacity: .5; }

.chat-item { justify-content: space-between; }
.chat-open { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; border: none; background: none; padding: 0; text-align: left; }
.chat-item .chat-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; flex: 1; }
.chat-item .chat-del { opacity: 0; border: none; background: none; color: var(--muted); padding: 0 4px; }
.chat-item:hover .chat-del, .chat-item:focus-within .chat-del { opacity: 1; }
.chat-empty { color: var(--muted); font-size: 13px; padding: 4px 8px; }

.avatar {
  flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px; background: var(--accent);
}
.avatar.lg { width: 44px; height: 44px; border-radius: 12px; font-size: 17px; }

.avatar.sm { width: 26px; height: 26px; border-radius: 8px; font-size: 11px; }
.avatar.xs { width: 20px; height: 20px; border-radius: 6px; font-size: 9px; }

/* ---------- Main ---------- */
.main { position: relative; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; min-height: 52px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.topbar-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 6px; }
.icon-btn { border: none; background: none; font-size: 20px; padding: 6px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--text); }
.icon-btn:hover { background: var(--accent-soft); }

.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 22px 16px 12px; overscroll-behavior: contain; }
.thread { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

/* Your messages: a bubble on the right. Bot replies: plain text across the page. */
.msg { display: flex; flex-direction: column; min-width: 0; }
.msg.user { align-items: flex-end; gap: 6px; }
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-text); border-radius: 18px 18px 6px 18px;
  padding: 9px 14px; max-width: min(620px, 85%); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.bot .who { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.msg.bot .body { overflow-wrap: anywhere; min-width: 0; }
.msg .meta { font-size: 12.5px; color: var(--muted); margin-top: 6px; display: flex; gap: 14px; align-items: center; }
.msg .meta button { border: none; background: none; color: var(--muted); padding: 2px 0; font-size: 12.5px; }
.msg .meta button:hover { color: var(--accent); }
.msg.error .body { color: var(--danger); background: var(--danger-soft); border-radius: 12px; padding: 9px 12px; }

.body p, .bubble p { margin: 0 0 .7em; }
.body p:last-child { margin-bottom: 0; }
.body ul, .body ol { margin: .3em 0 .7em; padding-left: 1.4em; }
.body table { border-collapse: collapse; margin: .5em 0; font-size: 14px; display: block; overflow-x: auto; max-width: 100%; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.body code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; font-size: .9em; font-family: ui-monospace, Consolas, monospace; }
.body pre { position: relative; background: var(--code-bg); padding: 12px; border-radius: 10px; overflow-x: auto; max-width: 100%; }
.body pre code { background: none; padding: 0; }
.body img, .body video { max-width: 100%; height: auto; }
.body svg { max-width: 100%; height: auto; }
.body svg.drawn { display: block; max-height: 70vh; border-radius: 12px; margin: .4em 0; }
.copy-code {
  position: absolute; top: 6px; right: 6px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 6px; font-size: 12px; padding: 2px 8px; color: var(--muted);
}

/* Generated pictures: as wide as the chat allows, never wider than the screen. Tap to open. */
.gen-img { display: block; border: none; padding: 0; background: none; border-radius: 14px; overflow: hidden; width: 100%; max-width: 440px; cursor: zoom-in; }
.gen-img img { display: block; width: 100%; height: auto; max-height: 70vh; object-fit: contain; background: var(--code-bg); }
.img-placeholder {
  width: 100%; max-width: 440px; aspect-ratio: 1; border-radius: 14px; display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); font-size: 14px;
  background: linear-gradient(110deg, var(--code-bg) 30%, var(--panel) 50%, var(--code-bg) 70%); background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Attachments on a sent message */
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: min(620px, 85%); }
.msg-thumb { border: none; padding: 0; background: var(--code-bg); border-radius: 12px; overflow: hidden; width: 120px; height: 120px; cursor: zoom-in; }
.msg-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-chip {
  display: flex; align-items: center; gap: 9px; padding: 8px 12px 8px 8px; border: 1px solid var(--line); background: var(--panel);
  border-radius: 12px; text-decoration: none; color: var(--text); max-width: 260px;
}
.file-chip-text { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 12px; color: var(--muted); }
.file-icon {
  flex: none; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  font-size: 10px; font-weight: 800; color: #fff; background: #6b7280; letter-spacing: .02em;
}
.file-icon.pdf { background: #d93f3f; }

.typing span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 4px; animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Empty chat: a short greeting instead of a big list of bots */
.welcome { max-width: 520px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 8px 6vh; }
.welcome-mark {
  width: 44px; height: 44px; border-radius: 13px; background: var(--accent); color: #fff; display: grid; place-items: center;
  font-size: 24px; margin-bottom: 14px;
}
.welcome h1 { font-size: 23px; margin: 0 0 6px; font-weight: 700; }
.welcome p { color: var(--muted); margin: 0; font-size: 14px; }

/* ---------- Message box ---------- */
.banner {
  max-width: 760px; margin: 0 auto 8px; width: calc(100% - 24px); padding: 9px 12px; border-radius: 12px;
  background: var(--danger-soft); color: var(--danger); font-size: 14px; display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.composer {
  max-width: 760px; width: calc(100% - 24px); margin: 0 auto; display: flex; flex-direction: column; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 8px 8px 6px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
/* 16px stops iPhone from zooming in when the box is tapped. */
.composer textarea {
  border: none; outline: none; resize: none; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.45; max-height: 200px; padding: 6px 8px 4px; width: 100%;
}
.composer-bar { display: flex; align-items: center; gap: 4px; }
.spacer { flex: 1; }
.tool-btn {
  border: none; background: none; color: var(--muted); width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
}
.tool-btn:hover { background: var(--accent-soft); color: var(--text); }
.tool-btn.on { background: var(--danger-soft); color: var(--danger); }
.search-btn { width: auto; min-width: 36px; padding: 0 8px; border-radius: 999px; gap: 5px; display: inline-flex; align-items: center; justify-content: center; }
.search-btn .search-label { display: none; font-size: 13.5px; font-weight: 600; }
.search-btn.on { background: var(--accent-soft); color: var(--accent); }
.search-btn.on .search-label { display: inline; }
.status-line { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 14px; }
.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.sources-label { font-size: 12.5px; color: var(--muted); margin-right: 2px; }
.source-chip {
  font-size: 12.5px; color: var(--text); text-decoration: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.source-chip:hover { border-color: var(--accent); }
.bot-pill {
  display: inline-flex; align-items: center; gap: 6px; border: none; background: none; color: var(--muted);
  border-radius: 999px; padding: 6px 10px; font-size: 13.5px; font-weight: 500; max-width: 55%; min-width: 0;
}
.bot-pill:hover, .bot-pill[aria-expanded="true"] { background: var(--accent-soft); color: var(--text); }
.bot-pill-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.bot-pill-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send-btn {
  border: none; background: var(--text); color: var(--bg); width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
}
.send-btn:disabled { opacity: .25; cursor: default; }
.composer-hint { text-align: center; font-size: 11.5px; color: var(--muted); padding: 6px 16px calc(8px + env(safe-area-inset-bottom)); }

/* Attachments waiting to be sent */
.tray { display: flex; gap: 8px; padding: 4px 4px 6px; overflow-x: auto; }
.tray-item {
  position: relative; flex: none; height: 64px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  display: flex; align-items: center; gap: 8px; padding: 0 28px 0 8px; max-width: 200px;
}
.tray-item.image { width: 64px; padding: 0; overflow: hidden; }
.tray-item.image img { width: 100%; height: 100%; object-fit: cover; }
.tray-item.failed { border-color: var(--danger); }
.tray-name { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray-x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 15px; line-height: 1; display: grid; place-items: center; padding: 0;
}
.tray-busy { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--panel) 60%, transparent); }
.tray-err { position: absolute; left: 4px; bottom: 4px; width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }

/* Voice typing bar */
.rec { display: flex; align-items: center; gap: 10px; padding: 6px 6px 4px 10px; font-size: 14px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s infinite both; }
.rec.working .rec-dot { background: var(--accent); }
.rec-label { flex: 1; color: var(--muted); }
.rec-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.rec.working .rec-time { display: none; }
.rec-cancel, .rec-done { border: none; border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 13.5px; }
.rec-cancel { background: none; color: var(--muted); }
.rec-done { background: var(--accent); color: #fff; }

/* Bot picker: a small menu above the message box (computer) or a sheet from the bottom (phone) */
.menu-scrim { position: fixed; inset: 0; z-index: 39; background: transparent; }
.bot-menu {
  position: absolute; z-index: 40; bottom: 96px; left: max(12px, calc(50% - 380px)); width: min(400px, calc(100% - 24px));
  max-height: min(70vh, 560px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.bot-menu-head { padding: 10px 10px 6px; }
.bot-menu.from-typing .bot-menu-head { display: none; }
.bot-menu-head input {
  width: 100%; font: inherit; font-size: 16px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); outline: none;
}
.bot-menu-list { overflow-y: auto; padding: 0 6px 8px; }
.bot-group { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 8px 4px; }
.bot-row { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: none; text-align: left; padding: 7px 8px; border-radius: 10px; }
.bot-row:hover, .bot-row:focus-visible { background: var(--bg); outline: none; }
.bot-row.active { background: var(--accent-soft); }
.bot-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bot-row-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.bot-row-desc { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-row-check { color: var(--accent); font-weight: 700; }
.badge {
  font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}

/* Full-screen picture viewer */
.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; padding: 16px 16px 72px; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.viewer-bar { position: absolute; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 10px; justify-content: center; }
.viewer-btn { border: none; border-radius: 999px; padding: 10px 22px; font-weight: 600; background: rgba(255,255,255,.16); color: #fff; }
.viewer-btn:first-child { background: #fff; color: #111; }
body.no-scroll { overflow: hidden; }

.only-mobile { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 29; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 86vw; max-width: 320px; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .only-mobile { display: inline-grid; }
  .messages { padding: 16px 14px 10px; }
  .composer { width: calc(100% - 16px); border-radius: 20px; }
  .composer-hint { display: none; }
  .composer { margin-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .msg.user .bubble { max-width: 88%; }
  .msg-thumb { width: 104px; height: 104px; }
  .gen-img, .img-placeholder { max-width: 100%; }
  .menu-scrim { background: rgba(0,0,0,.35); }
  .bot-menu {
    position: fixed; left: 0; right: 0; bottom: 0; width: 100%; max-height: 75dvh;
    border-radius: 18px 18px 0 0; border-bottom: none; padding-bottom: env(safe-area-inset-bottom);
  }
  .bot-menu::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }
  .bot-row { padding: 10px 8px; }
}

/* ---------- Top-up dialog ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 10, 20, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); width: min(460px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 18px 20px 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-head h2 { font-size: 19px; margin: 0; }
.modal .lead { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.sandbox-tag { display: inline-block; font-size: 11px; font-weight: 700; color: #8a5a00; background: #fff2cc; border-radius: 6px; padding: 2px 6px; margin-left: 6px; vertical-align: middle; }
.packs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pack { border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 12px; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.pack:hover, .pack:focus-visible { border-color: var(--accent); }
.pack .pack-label { font-size: 12px; font-weight: 600; color: var(--accent); }
.pack .pack-credits { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pack .pack-price { font-size: 14px; color: var(--muted); }
.pack .pack-bonus { font-size: 12px; color: var(--good); font-weight: 600; }
.pay-qr { text-align: center; }
.pay-qr img { width: 260px; max-width: 100%; border-radius: 12px; background: #fff; padding: 8px; border: 1px solid var(--line); }
.pay-amount { font-size: 22px; font-weight: 700; margin: 10px 0 2px; font-variant-numeric: tabular-nums; }
.pay-status { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 14px; margin: 8px 0 14px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.wallet-logos { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.modal-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; font-weight: 600; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.done-icon { font-size: 44px; text-align: center; }
.test-link { display: block; margin: 14px auto 0; border: none; background: none; color: var(--muted); font-size: 12.5px; text-decoration: underline; }
.form-error { color: var(--danger); font-size: 13.5px; margin-top: 10px; text-align: center; }

/* ---------- Log in / create account ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--sidebar); }
.auth-card {
  width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 26px 24px 20px; display: flex; flex-direction: column; gap: 14px;
}
.auth-card .brand { font-size: 22px; }
.auth-lead { margin: 0; color: var(--muted); font-size: 14px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.auth-tabs button { border: none; background: none; border-radius: 8px; padding: 8px; font-weight: 600; color: var(--muted); }
.auth-tabs button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
#authForm { display: flex; flex-direction: column; gap: 12px; }
.auth-foot { margin: 0; font-size: 12.5px; color: var(--muted); text-align: center; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  font: inherit; font-size: 16px; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field-hint { font-weight: 400; font-size: 12px; }
.btn.block { width: 100%; padding: 11px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.danger { color: var(--danger); }
.btn:focus-visible, .small-btn:focus-visible, .link-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#authForm .form-error { margin: 0; text-align: left; }

/* ---------- Account bar (bottom of sidebar) ---------- */
.account {
  margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px 4px 2px;
  border-top: 1px solid var(--line);
}
.account .avatar { width: 28px; height: 28px; font-size: 12px; }
.me-name { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .icon-btn { font-size: 18px; color: var(--muted); }

/* ---------- Account / admin dialogs ---------- */
.modal.wide { width: min(920px, 100%); }
.modal h3 { font-size: 15px; margin: 20px 0 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sheet-foot { display: flex; justify-content: flex-end; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.note { font-size: 13.5px; border-radius: 10px; padding: 9px 12px; margin-bottom: 10px; overflow-wrap: anywhere; }
.note.ok { background: var(--accent-soft); color: var(--text); }
.note.bad { background: var(--danger-soft); color: var(--danger); }
.muted { color: var(--muted); font-size: 13.5px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }

.inv-form { display: grid; grid-template-columns: 1fr 1fr 1.6fr auto; gap: 10px; align-items: end; }
.share { margin: 12px 0; padding: 12px; border: 1px dashed var(--accent); border-radius: 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.share-code { font-family: ui-monospace, Consolas, monospace; font-size: 18px; font-weight: 700; letter-spacing: .04em; }
.share-text { white-space: pre-wrap; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; margin-top: 12px; }
.admin-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.admin-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table .badge { margin-left: 6px; }
.admin-table tr.dim td { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.row-actions { display: flex; align-items: center; gap: 8px; }
.amt { width: 80px; font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.link-btn { border: none; background: none; color: var(--accent); font-weight: 600; padding: 2px 0; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }

@media (max-width: 820px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .inv-form { grid-template-columns: 1fr 1fr; }
  .inv-form .btn { grid-column: 1 / -1; }
}

/* ---------- Credit history ---------- */
.wallet .link-btn { font-size: 12px; padding: 0; margin-top: 2px; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.sheet-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.usage-bars { display: flex; flex-direction: column; gap: 8px; }
.usage-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; }
.usage-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.usage-val { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.admin-table.history td { white-space: normal; }
.admin-table.history td.when, .admin-table.history td.num { white-space: nowrap; }
.admin-table .sub { font-size: 12px; color: var(--muted); }
.num.plus { color: var(--good); font-weight: 600; }
.muted.small { font-size: 12.5px; margin-top: 12px; }
@media (max-width: 820px) {
  .stats.three { grid-template-columns: 1fr 1fr; }
  .usage-row { grid-template-columns: 1fr auto; }
  .usage-bar { grid-column: 1 / -1; grid-row: 2; }
}

.date-m { display: none; }
@media (max-width: 820px) {
  .admin-table.history th:first-child, .admin-table.history td.when { display: none; }
  .date-m { display: block; }
}
