:root {
  --bg: #f6f5f1;
  --ink: #20231f;
  --muted: #687069;
  --panel: #ffffff;
  --panel-soft: #eef1ec;
  --glass: rgba(255, 255, 255, 0.66);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --line: #dadfd6;
  --brand: #176b5d;
  --brand-strong: #0f4d43;
  --brand-soft: #dcefe7;
  --accent: #b94735;
  --gold: #8c6416;
  --danger: #b42318;
  --dark: #1f2823;
  --dark-soft: #2d3932;
  --shadow: 0 18px 48px rgba(31, 40, 35, 0.14);
  --glass-shadow: 0 18px 48px rgba(31, 40, 35, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.62);
}

:root[data-theme="dark"] {
  --bg: #141816;
  --ink: #f2f4ef;
  --muted: #a9b2aa;
  --panel: #1e2420;
  --panel-soft: #2a322d;
  --glass: rgba(30, 36, 32, 0.68);
  --glass-strong: rgba(30, 36, 32, 0.84);
  --line: #3a453f;
  --brand: #65c7ac;
  --brand-strong: #8bd9c4;
  --brand-soft: #223b34;
  --dark: #101311;
  --dark-soft: #202720;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
  --glass-shadow: 0 18px 48px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

:root[data-theme="light"] {
  --bg: #fafafa;
  --panel-soft: #f1f1f1;
  --brand: #2459a6;
  --brand-strong: #163f7a;
  --brand-soft: #e7effc;
  --dark: #20252d;
  --dark-soft: #303845;
}

:root[data-theme="contrast"] {
  --bg: #fffdf7;
  --ink: #171717;
  --muted: #4b5563;
  --brand: #7a2d12;
  --brand-strong: #4b1b0a;
  --brand-soft: #ffe6d6;
  --dark: #171717;
  --dark-soft: #2b2b2b;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 8%, rgba(23, 107, 93, 0.14), transparent 30%),
    radial-gradient(circle at 86% 92%, rgba(185, 71, 53, 0.12), transparent 28%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar,
.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: linear-gradient(180deg, rgba(31, 40, 35, 0.94), rgba(31, 40, 35, 0.86));
  color: #f5f7f2;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(18px) saturate(1.24);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.32) transparent;
}

.sidebar::-webkit-scrollbar,
.admin-nav::-webkit-scrollbar,
.conversations::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-thumb,
.admin-nav::-webkit-scrollbar-thumb,
.conversations::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 800;
}

.brand-large {
  min-height: 52px;
  font-size: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 900;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.sidebar-search {
  display: grid;
}

.sidebar-search .input {
  min-height: 36px;
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: #f5f7f2;
}

.sidebar-search .input::placeholder {
  color: rgba(255, 255, 255, 0.58);
}

.sidebar-section-title {
  color: rgba(255, 255, 255, 0.56);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.side-button,
.ghost-button,
.primary-button,
.danger-button,
.icon-button,
.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.side-button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.08);
  color: #f5f7f2;
}

.side-button:hover,
.conversation-item:hover {
  background: #3a473f;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--glass);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.48);
  backdrop-filter: blur(16px) saturate(1.2);
}

.ghost-button:hover {
  background: #e4e9e1;
}

.danger-button {
  background: #fee4df;
  color: var(--danger);
}

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 20px;
}

.icon-button:hover {
  background: rgba(0, 0, 0, 0.08);
}

.conversations {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  min-height: 120px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.32) transparent;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 8px 8px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #edf1ed;
  text-align: left;
}

.conversation-item.active {
  background: var(--brand-soft);
  color: #123a32;
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.delete-conversation {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

.delete-conversation:hover {
  background: rgba(0, 0, 0, 0.12);
}

.sidebar-empty {
  padding: 14px 10px;
  color: rgba(255, 255, 255, 0.56);
  font-size: 13px;
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.user-chip {
  display: grid;
  gap: 2px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.user-chip strong {
  font-size: 14px;
}

.user-chip span {
  color: #cbd2ca;
  font-size: 12px;
}

.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.topbar,
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(1.25);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.45);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-left {
  flex: 0 1 auto;
}

.topbar-right {
  flex: 1 1 520px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1 1 180px;
  min-width: 160px;
  max-width: 280px;
}

.search-box .input {
  min-height: 36px;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  display: grid;
  gap: 6px;
  width: min(420px, 88vw);
  max-height: min(460px, 70vh);
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(22px) saturate(1.25);
}

.search-result-item {
  display: grid;
  gap: 2px;
  padding: 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.search-result-item:hover {
  background: var(--panel-soft);
}

.search-result-item span,
.search-result-item small {
  color: var(--muted);
  font-size: 12px;
}

.search-empty {
  padding: 14px;
  color: var(--muted);
  text-align: center;
}

.mobile-menu {
  display: none;
}

.mode-tabs {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(1.2);
}

.tab-button {
  min-height: 34px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
}

.tab-button.active {
  background: var(--glass-strong);
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(20, 25, 20, 0.08);
}

.model-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 0 1 auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.model-select,
.input,
.textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.model-select {
  width: min(260px, 26vw);
  min-width: 0;
  max-width: 360px;
  padding: 0 34px 0 12px;
}

.model-select.full {
  width: 100%;
  max-width: none;
}

.input {
  width: 100%;
  padding: 0 12px;
}

.textarea {
  width: 100%;
  min-height: 118px;
  padding: 12px;
  resize: vertical;
}

.balance-pill {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  max-width: 100%;
  white-space: nowrap;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: #fff4d8;
  color: #68460f;
  font-size: 13px;
  font-weight: 800;
}

.chat-view,
.image-view,
.codex-view {
  display: none;
  min-height: 0;
  overflow: hidden;
}

.chat-view.active,
.image-view.active,
.codex-view.active {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}

.chat-scroll,
.image-scroll,
.codex-scroll,
.admin-content {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(23, 107, 93, 0.46) rgba(255, 255, 255, 0.18);
}

.chat-scroll {
  padding: 24px 20px 120px;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(23, 107, 93, 0.52) rgba(255, 255, 255, 0.22);
}

.chat-scroll::-webkit-scrollbar {
  width: 10px;
}

.image-scroll::-webkit-scrollbar,
.codex-scroll::-webkit-scrollbar,
.admin-content::-webkit-scrollbar,
.usage-list::-webkit-scrollbar,
.redeem-panel::-webkit-scrollbar,
.profile-panel::-webkit-scrollbar,
.settings-panel::-webkit-scrollbar,
.stats-tree::-webkit-scrollbar {
  width: 10px;
}

.chat-scroll::-webkit-scrollbar-track,
.image-scroll::-webkit-scrollbar-track,
.codex-scroll::-webkit-scrollbar-track,
.admin-content::-webkit-scrollbar-track,
.usage-list::-webkit-scrollbar-track,
.redeem-panel::-webkit-scrollbar-track,
.profile-panel::-webkit-scrollbar-track,
.settings-panel::-webkit-scrollbar-track,
.stats-tree::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.24);
  border-left: 1px solid rgba(23, 107, 93, 0.12);
}

.chat-scroll::-webkit-scrollbar-thumb,
.image-scroll::-webkit-scrollbar-thumb,
.codex-scroll::-webkit-scrollbar-thumb,
.admin-content::-webkit-scrollbar-thumb,
.usage-list::-webkit-scrollbar-thumb,
.redeem-panel::-webkit-scrollbar-thumb,
.profile-panel::-webkit-scrollbar-thumb,
.settings-panel::-webkit-scrollbar-thumb,
.stats-tree::-webkit-scrollbar-thumb {
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(23, 107, 93, 0.56);
}

.chat-scroll::-webkit-scrollbar-thumb:hover,
.image-scroll::-webkit-scrollbar-thumb:hover,
.codex-scroll::-webkit-scrollbar-thumb:hover,
.admin-content::-webkit-scrollbar-thumb:hover,
.usage-list::-webkit-scrollbar-thumb:hover,
.redeem-panel::-webkit-scrollbar-thumb:hover,
.profile-panel::-webkit-scrollbar-thumb:hover,
.settings-panel::-webkit-scrollbar-thumb:hover,
.stats-tree::-webkit-scrollbar-thumb:hover {
  background: rgba(23, 107, 93, 0.78);
}

.message-stack {
  display: grid;
  gap: 18px;
  width: min(920px, 100%);
  margin: 0 auto;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 230px);
  text-align: center;
}

.empty-inner {
  display: grid;
  gap: 16px;
  width: min(740px, 100%);
}

.empty-inner h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 60px);
  line-height: 1.03;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.prompt-card {
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  line-height: 1.45;
}

.prompt-card:hover {
  border-color: #aeb9ad;
  box-shadow: 0 10px 26px rgba(25, 31, 25, 0.09);
}

.starter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 900;
}

.message.user .avatar {
  background: #e4ecf8;
  color: #295b93;
}

.message-panel {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.bubble {
  min-width: 0;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
  line-height: 1.7;
  white-space: normal;
  overflow-wrap: anywhere;
}

.message.assistant .bubble {
  background: var(--glass);
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.message-action-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message-action-button:hover {
  border-color: #b6c2b8;
  background: var(--panel-soft);
  color: var(--ink);
}

.composer {
  position: sticky;
  bottom: 0;
  padding: 14px 20px 18px;
  background: linear-gradient(rgba(246, 245, 241, 0), var(--bg) 22%);
}

.composer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 10px;
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass-strong);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(22px) saturate(1.22);
}

.composer textarea {
  min-height: 48px;
  max-height: 190px;
  padding: 12px;
  border: 0;
  outline: none;
  resize: none;
  line-height: 1.5;
}

.send-button {
  width: 46px;
  min-height: 46px;
  padding: 0;
  font-size: 22px;
  font-weight: 800;
}

.image-scroll {
  padding: 28px 20px;
}

.codex-scroll {
  padding: 28px 20px;
}

.codex-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
  width: min(1100px, 100%);
  margin: 0 auto;
}

.codex-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(20px) saturate(1.2);
}

.codex-panel h2 {
  margin: 0;
}

.codex-result-panel {
  grid-column: 1 / -1;
}

.codex-textarea {
  min-height: 260px;
}

.codex-options {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.codex-step {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.38);
}

.codex-step span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
}

.codex-step div {
  display: grid;
  gap: 2px;
}

.codex-step small {
  color: var(--muted);
}

.codex-preview {
  min-height: 160px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  white-space: pre-wrap;
}

.codex-result {
  min-height: 220px;
  max-height: min(560px, 58vh);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.46);
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.image-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  width: min(1200px, 100%);
  margin: 0 auto;
}

.tool-panel,
.table-panel,
.admin-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px) saturate(1.18);
}

.tool-panel {
  display: grid;
  align-self: start;
  gap: 13px;
  padding: 18px;
}

.tool-panel h2,
.admin-panel h2,
.table-panel h2,
.drawer h2,
.auth-card h2 {
  margin: 0;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.image-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  align-content: start;
}

.generated-image {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.generated-image img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--panel-soft);
}

.image-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.image-meta strong {
  color: var(--brand);
  font-size: 13px;
}

.image-meta span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.image-empty,
.usage-empty {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 220px;
  padding: 20px;
  border: 1px dashed #bac3b8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  text-align: center;
}

.image-empty strong {
  color: var(--ink);
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px;
  background:
    radial-gradient(circle at 10% 8%, rgba(23, 107, 93, 0.16), transparent 28%),
    radial-gradient(circle at 90% 80%, rgba(185, 71, 53, 0.13), transparent 28%),
    var(--bg);
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 28px;
  width: min(1040px, 100%);
  align-items: center;
}

.auth-copy {
  display: grid;
  gap: 20px;
}

.auth-copy h1 {
  margin: 0;
  max-width: 680px;
  font-size: clamp(44px, 6vw, 76px);
  line-height: 0.98;
}

.auth-copy p {
  margin: 0;
  max-width: 560px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

.auth-feature-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: min(640px, 100%);
}

.auth-feature-grid span {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 800;
}

.auth-card {
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.auth-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.muted {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: none;
  max-width: min(430px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--dark);
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 30;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(420px, 100vw);
  padding: 18px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.18s ease;
}

.drawer.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.usage-list {
  display: grid;
  gap: 10px;
  align-content: start;
  overflow: auto;
  padding-top: 14px;
}

.usage-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.usage-item div {
  display: grid;
  gap: 3px;
}

.usage-item span {
  color: var(--muted);
  font-size: 12px;
}

.usage-item b {
  color: var(--gold);
}

.admin-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.admin-nav .side-button.active {
  background: var(--brand-soft);
  color: #123a32;
}

.admin-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.admin-content {
  padding: 20px;
  overflow-x: hidden;
}

.admin-section {
  display: none;
  gap: 16px;
  min-height: 0;
}

.admin-section.active {
  display: grid;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 28px;
}

.admin-panel,
.table-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  min-width: 0;
  min-height: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.table-wrap {
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: var(--panel);
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e7f5ed;
  color: #176245;
  font-size: 12px;
  font-weight: 800;
}

.status.off {
  background: #f2f0ec;
  color: #706960;
}

@media (max-width: 980px) {
  .auth-layout {
    grid-template-columns: 1fr;
  }

  .auth-feature-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-right {
    flex-basis: 100%;
    justify-content: stretch;
  }

  .search-box {
    max-width: none;
  }

  .model-select {
    width: 100%;
  }
}

@media (max-width: 860px) {
  .app-shell,
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .admin-nav {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 35;
    width: min(82vw, 310px);
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open,
  .admin-nav.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-flex;
  }

  .topbar,
  .admin-header {
    flex-wrap: wrap;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .search-box,
  .admin-search {
    width: 100%;
    min-width: 0;
  }

  .model-box {
    flex: 1;
  }

  .model-select {
    max-width: 100%;
    min-width: 0;
    width: 100%;
  }

  .prompt-grid,
  .image-layout,
  .codex-layout,
  .metric-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .auth-screen {
    padding: 18px;
  }

  .auth-copy h1 {
    font-size: 42px;
  }
}

@media (max-width: 560px) {
  .prompt-grid,
  .auth-feature-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .topbar-right {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    flex-direction: initial;
  }

  .model-box {
    align-items: stretch;
    flex-direction: column;
    gap: 4px;
  }

  .search-box {
    grid-column: 1 / -1;
  }

  .chat-model-box {
    grid-column: 1 / -1;
  }

  .topbar {
    gap: 10px;
    padding: 10px 12px;
  }

  .tab-button {
    min-height: 32px;
    padding: 0 10px;
  }

  .search-box .input,
  .model-select,
  .mini-input,
  .balance-pill {
    min-height: 34px;
  }

  .temperature-box {
    grid-column: 1;
  }

  .balance-pill {
    grid-column: 2;
    min-height: 40px;
    align-self: end;
    font-size: 12px;
  }

  .mini-input {
    width: 100%;
  }

  .profile-grid {
    grid-template-columns: 1fr;
  }
}

.mini-input {
  width: 74px;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.chat-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(920px, 100%);
  margin: 0 auto 8px;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 0.4em 0;
  line-height: 1.25;
}

.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 0.35em 0;
  line-height: 1.3;
}

.markdown-body p {
  margin: 0.45em 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.5em 0;
  padding-left: 1.35em;
}

.markdown-body li + li {
  margin-top: 0.2em;
}

.markdown-body blockquote {
  margin: 0.65em 0;
  padding: 8px 12px;
  border-left: 4px solid var(--brand);
  border-radius: 0 8px 8px 0;
  background: var(--panel-soft);
  color: var(--muted);
}

.markdown-body a {
  color: var(--brand-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.markdown-body code {
  padding: 0.12em 0.35em;
  border-radius: 6px;
  background: var(--panel-soft);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.92em;
}

.table-scroll {
  max-width: 100%;
  margin: 10px 0;
  overflow-x: auto;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94em;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: var(--panel-soft);
  font-weight: 900;
}

.code-block {
  margin: 10px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151a17;
  color: #edf5ef;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #b8c8bd;
  font-size: 12px;
}

.copy-code {
  min-height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.code-block pre {
  margin: 0;
  padding: 12px;
  overflow: auto;
}

.code-block code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.thinking {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
}

.thinking-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--brand);
  animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(0.75); opacity: 0.45; }
  50% { transform: scale(1.18); opacity: 1; }
}

.redeem-panel {
  display: grid;
  gap: 16px;
  align-content: start;
  overflow: auto;
  padding-top: 14px;
}

.profile-panel,
.settings-panel,
.prompt-library {
  display: grid;
  gap: 14px;
  align-content: start;
  overflow: auto;
  padding-top: 14px;
}

.prompt-category {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--glass-shadow);
}

.prompt-category button {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  text-align: left;
}

.profile-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px) saturate(1.18);
}

.profile-card strong {
  font-size: 22px;
}

.profile-card span {
  color: var(--muted);
}

.profile-card b {
  color: var(--brand);
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.profile-grid div {
  display: grid;
  gap: 4px;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  backdrop-filter: blur(16px);
}

.profile-grid span {
  color: var(--muted);
  font-size: 12px;
}

.profile-grid strong {
  font-size: 18px;
}

.compact-panel {
  box-shadow: none;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  color: var(--muted);
}

.stats-tree {
  display: grid;
  gap: 8px;
  max-height: min(460px, 54vh);
  overflow: auto;
  padding-right: 4px;
  scrollbar-width: thin;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.checklist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.check-item {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
}

.check-item span {
  justify-self: start;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #e7f5ed;
  color: #176245;
  font-size: 12px;
  font-weight: 900;
}

.check-item.warn span {
  background: #fff4d8;
  color: #7a4c05;
}

.check-item small {
  color: var(--muted);
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(14, 18, 16, 0.42);
  backdrop-filter: blur(10px);
}

.tutorial-card {
  display: grid;
  gap: 14px;
  width: min(520px, 100%);
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  background: var(--glass-strong);
  box-shadow: var(--glass-shadow);
}

.tutorial-card h2,
.tutorial-card p {
  margin: 0;
}

.tutorial-card p {
  color: var(--muted);
  line-height: 1.65;
}

.tutorial-progress,
.tutorial-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tree-node {
  display: grid;
  gap: 8px;
}

.tree-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
}

.tree-node.root > .tree-line {
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 900;
}

.tree-children {
  display: grid;
  gap: 8px;
  margin-left: clamp(8px, 2vw, 18px);
  padding-left: clamp(8px, 2vw, 14px);
  border-left: 2px solid var(--line);
}

:root[data-compact="true"] .message-stack {
  gap: 10px;
}

:root[data-compact="true"] .bubble {
  padding: 10px 12px;
  line-height: 1.55;
}

.announcement {
  padding: 12px;
  border: 1px solid #f1d28f;
  border-radius: 8px;
  background: #fff8e6;
  color: #6a470f;
  line-height: 1.5;
}

.plans-list {
  display: grid;
  gap: 10px;
}

.plan-card {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.plan-card span {
  color: var(--muted);
  font-size: 13px;
}

.plan-card b {
  color: var(--brand);
}

.share-page {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.share-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.share-card {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.share-card h1 {
  margin: 0;
}
