:root {
  color-scheme: light;
  --ink: #0b0f19;
  --muted: #566073;
  --line: #d8dde6;
  --soft: #f4f6f8;
  --paper: #ffffff;
  --gold: #e6a900;
  --gold-dark: #805900;
  --gold-soft: #fff4c9;
  --blue-soft: #edf5ff;
  --green: #087a55;
  --red: #b42318;
  --focus: #005fcc;
  --sidebar: 248px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; scroll-behavior: smooth; }
body { min-height: 100%; margin: 0; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { outline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(1.6rem, 2.4vw, 2.25rem); line-height: 1.15; letter-spacing: 0; }
h2 { margin-bottom: .25rem; font-size: 1.1rem; letter-spacing: 0; }
code { font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace; }

.skip-link { position: fixed; z-index: 1000; top: 8px; left: 8px; transform: translateY(-160%); padding: 10px 14px; background: var(--ink); color: white; }
.skip-link:focus { transform: translateY(0); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: .5rem; color: var(--gold-dark); font-weight: 750; font-size: .75rem; text-transform: uppercase; }

.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 800; text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 30px; aspect-ratio: 1; border-radius: 6px; background: var(--ink); color: #ffd538; font-weight: 850; }
.brand-mark.large { width: 46px; font-size: 1.35rem; }

.button, .icon-button, .avatar, .send-button, .text-button, .attach-button { border: 0; }
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 9px 15px; border-radius: 7px; font-weight: 720; text-decoration: none; }
.button.primary { background: var(--gold); color: var(--ink); border: 1px solid #bd8900; }
.button.primary:hover { background: #f5bb08; }
.button.secondary { background: var(--paper); border: 1px solid #bcc4d0; }
.button.secondary:hover { background: var(--soft); }
.button.compact { min-height: 36px; padding: 6px 11px; font-size: .875rem; }
.button.full { width: 100%; margin-top: 14px; }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; background: transparent; border-radius: 6px; font-size: 1.25rem; }
.icon-button:hover { background: var(--soft); }
.text-button { padding: 2px; background: transparent; color: #214d85; font-weight: 700; }
.text-button.danger { color: #a21c2a; }

input, select, textarea { width: 100%; border: 1px solid #aeb7c4; border-radius: 6px; background: var(--paper); }
input, select { min-height: 42px; padding: 8px 10px; }
textarea { resize: none; padding: 13px 14px; }
label { display: block; margin: 14px 0 5px; font-size: .875rem; font-weight: 700; }

.auth-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(380px, .8fr); }
.auth-brand { position: relative; display: flex; flex-direction: column; justify-content: space-between; min-height: 100vh; padding: clamp(28px, 5vw, 76px); overflow: hidden; background: radial-gradient(circle at 85% 25%, #fff1b8 0, transparent 36%), linear-gradient(145deg, #edf5ff, #fff 58%); }
.auth-brand::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .18; background-image: radial-gradient(#556070 1px, transparent 1px); background-size: 18px 18px; }
.auth-brand > * { position: relative; z-index: 1; }
.auth-copy { max-width: 680px; }
.auth-copy h1 { max-width: 620px; font-size: clamp(2.5rem, 5vw, 5rem); }
.auth-copy > p:last-child { max-width: 610px; color: #485166; font-size: clamp(1.05rem, 1.8vw, 1.35rem); }
.auth-code { align-self: flex-start; padding: 14px 18px; border: 1px solid #283144; border-radius: 7px; background: #0d1320; color: #f5f7fb; font: .85rem "Cascadia Code", monospace; }
.auth-code span { color: #ffc21a; font-weight: 800; }
.auth-panel { display: grid; place-items: center; min-height: 100vh; padding: 28px; border-left: 1px solid var(--line); }
.auth-box { width: min(100%, 420px); }
.auth-box h2 { margin-top: 26px; font-size: 1.6rem; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: var(--soft); border: 1px solid var(--line); border-radius: 7px; }
.segment { min-height: 38px; border: 0; border-radius: 5px; background: transparent; font-weight: 720; }
.segment.active { background: var(--paper); box-shadow: 0 1px 3px #12223a24; }
.separator { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: .8rem; }
.separator::before, .separator::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.auth-box .button + .button { margin-top: 10px; }
.otp-form { margin-top: 16px; }
.inline-form { display: flex; align-items: end; gap: 10px; }
.inline-form > input { min-width: 0; }
.status { min-height: 24px; margin-top: 12px; color: var(--red); font-size: .875rem; }

.app-shell { min-height: 100vh; display: grid; grid-template: 64px 1fr / var(--sidebar) 1fr; }
.topbar { position: sticky; z-index: 50; top: 0; grid-column: 1 / -1; display: grid; grid-template-columns: var(--sidebar) minmax(180px, 620px) 1fr; align-items: center; gap: 18px; height: 64px; padding: 0 20px; border-bottom: 1px solid var(--line); background: #ffffffee; backdrop-filter: blur(10px); }
.global-search input { min-height: 38px; padding-left: 14px; background: var(--soft); }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; }
.funding-pill { overflow: hidden; max-width: 220px; padding: 5px 9px; border: 1px solid #bdc7d6; border-radius: 999px; color: #334056; background: var(--blue-soft); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.funding-pill.prepaid { border-color: #cf9700; background: var(--gold-soft); color: #604300; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--ink); color: white; font-weight: 800; }
.mobile-only { display: none; }

.sidebar { position: fixed; z-index: 40; top: 64px; bottom: 0; left: 0; display: flex; flex-direction: column; width: var(--sidebar); padding: 14px 12px; border-right: 1px solid var(--line); background: #f8f9fb; overflow-y: auto; }
.new-chat { width: 100%; margin-bottom: 18px; }
.nav-group { margin-bottom: 18px; }
.nav-label { margin: 0 8px 5px; color: #697386; font-size: .69rem; font-weight: 800; text-transform: uppercase; }
.nav-link { display: block; margin: 2px 0; padding: 8px 10px; border-radius: 6px; color: #374151; font-size: .9rem; font-weight: 650; text-decoration: none; }
.nav-link:hover { background: #e9edf3; }
.nav-link.active { background: var(--ink); color: white; }
.conversation-nav { min-height: 120px; flex: 1; overflow-y: auto; }
.conversation-item { display: block; width: 100%; overflow: hidden; padding: 7px 9px; border: 0; border-radius: 5px; background: transparent; color: #4a5568; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item:hover, .conversation-item.active { background: #e6eaf0; color: var(--ink); }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 2px; border-top: 1px solid var(--line); font-size: .75rem; }
.sidebar-footer span { overflow: hidden; text-overflow: ellipsis; }

.main-content { grid-column: 2; min-width: 0; padding: 0 clamp(20px, 4vw, 56px) 60px; }
.view { width: min(100%, 1180px); margin: 0 auto; padding-top: 34px; }
.chat-view { display: grid; grid-template-rows: auto 1fr auto auto; width: min(100%, 900px); min-height: calc(100vh - 64px); padding-top: 0; }
.chat-header { display: flex; align-items: center; justify-content: space-between; min-height: 78px; border-bottom: 1px solid var(--line); }
.chat-header h1 { margin: 0; font-size: 1rem; }
.chat-header p { margin: 0; font-size: .8rem; }
.mode-control { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: .75rem; }
.mode-control select { width: auto; min-height: 34px; padding: 4px 28px 4px 8px; }
.messages { min-height: 360px; padding: 28px 0 150px; }
.empty-chat { display: grid; justify-items: center; padding: min(18vh, 150px) 20px 40px; text-align: center; }
.empty-chat h2 { margin-top: 18px; font-size: 1.65rem; }
.message { max-width: 86%; margin-bottom: 22px; }
.message.user { margin-left: auto; padding: 11px 14px; border-radius: 8px; background: #eef1f5; }
.message.assistant { margin-right: auto; }
.message .role { display: block; margin-bottom: 6px; color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; }
.asset-chip { margin: 10px 6px 0 0; padding: 6px 9px; border: 1px solid #9ca8b8; border-radius: 5px; background: var(--blue-soft); color: #173f70; font-size: .78rem; font-weight: 700; }
.credit-notice { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 10px; padding: 12px 14px; border: 2px solid #bd8900; border-radius: 7px; background: var(--gold-soft); }
.credit-notice p { margin: 2px 0 0; font-size: .85rem; }
.composer { position: sticky; bottom: 16px; margin-bottom: 16px; border: 1px solid #929dac; border-radius: 8px; background: white; box-shadow: 0 10px 34px #12223a1f; }
.composer textarea { min-height: 54px; max-height: 220px; border: 0; }
.composer textarea:focus-visible { outline-offset: 1px; }
.composer-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px 8px; }
.attach-button { display: grid; place-items: center; width: 34px; height: 34px; margin: 0; border: 1px solid #bac2cd; border-radius: 6px; background: white; font-size: 1.25rem; }
.composer-row .muted { flex: 1; font-size: .72rem; }
.send-button { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 6px; background: var(--ink); color: white; font-size: 1.25rem; }

.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding-bottom: 24px; }
.page-heading h1 { margin: 0; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.metric { min-width: 0; padding: 20px; border-right: 1px solid var(--line); background: var(--paper); }
.metric:last-child { border-right: 0; }
.metric-label { display: block; color: var(--muted); font-size: .75rem; font-weight: 700; }
.metric-value { display: block; overflow-wrap: anywhere; margin-top: 4px; font-size: 1.65rem; font-weight: 800; }
.metric-detail { display: block; margin-top: 4px; color: var(--muted); font-size: .75rem; }
.section-band { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-heading p { margin: 0; color: var(--muted); font-size: .85rem; }
.quota-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.quota-item { padding: 14px; border: 1px solid var(--line); border-radius: 7px; }
.progress { height: 8px; margin-top: 12px; border-radius: 10px; background: #e2e6ec; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--gold); }
.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: var(--soft); color: #3f495b; font-size: .72rem; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.empty-row { padding: 24px; color: var(--muted); text-align: center; }

.recharge-band, .api-callout, .notice-band { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 18px 20px; border: 1px solid #cf9700; border-radius: 7px; background: var(--gold-soft); }
.recharge-band p, .api-callout p, .notice-band p { margin: 0; }
.money-input { display: flex; align-items: center; width: 110px; border: 1px solid #aeb7c4; border-radius: 6px; background: white; }
.money-input span { padding-left: 10px; }
.money-input input { border: 0; }
.plans-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.subscription-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 2px; }
.subscription-actions p { margin: 0; }
.plan { padding: 18px; border: 1px solid var(--line); border-radius: 7px; }
.plan-price { margin: 10px 0; font-size: 1.7rem; font-weight: 800; }
.plan-price small { color: var(--muted); font-size: .75rem; font-weight: 500; }
.audit-list { margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: 7px; }
.audit-list li { display: grid; grid-template-columns: 170px 1fr; gap: 14px; padding: 11px 13px; border-bottom: 1px solid var(--line); font-size: .85rem; }
.audit-list li:last-child { border-bottom: 0; }
.audit-list time { color: var(--muted); }

.api-callout { border-color: #b5c9e5; background: var(--blue-soft); }
.api-callout code { display: block; margin-top: 4px; font-weight: 700; overflow-wrap: anywhere; }
.code-label { display: block; color: var(--muted); font-size: .7rem; font-weight: 800; text-transform: uppercase; }
.stack-list { display: grid; gap: 10px; margin-top: 18px; }
.list-item { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 16px; border: 1px solid var(--line); border-radius: 7px; }
.list-item p { margin: 2px 0 0; color: var(--muted); font-size: .8rem; }
.token-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.sharing-group { border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.sharing-group > .list-item { border: 0; border-radius: 0; background: var(--soft); }
.member-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-top: 1px solid var(--line); }
.member-row p { margin: 3px 0 0; color: var(--muted); font-size: .78rem; }
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.asset { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 7px; }
.asset-name { overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.asset-meta { margin: 5px 0 14px; color: var(--muted); font-size: .75rem; }

dialog { width: min(92vw, 620px); padding: 0; border: 1px solid #9da6b3; border-radius: 8px; box-shadow: 0 24px 80px #0b0f1940; }
dialog::backdrop { background: #0b0f1980; }
.modal-shell { padding: 20px; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-heading h2 { margin: 0; font-size: 1.25rem; }
.toast-region { position: fixed; z-index: 200; right: 18px; bottom: 18px; display: grid; gap: 8px; width: min(360px, calc(100vw - 36px)); }
.toast { padding: 12px 14px; border: 1px solid #263246; border-radius: 6px; background: #111827; color: white; box-shadow: 0 10px 30px #0003; }

@media (max-width: 1000px) {
  .topbar { grid-template-columns: auto minmax(180px, 1fr) auto; }
  .topbar > .brand { display: none; }
  .mobile-only { display: grid; }
  .sidebar { transform: translateX(-102%); box-shadow: 8px 0 28px #12223a26; transition: transform .18s ease; }
  .sidebar.open { transform: translateX(0); }
  .main-content { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-brand { min-height: 280px; padding: 24px; }
  .auth-brand .brand { margin-bottom: 70px; }
  .auth-copy h1 { font-size: 2.35rem; }
  .auth-code { display: none; }
  .auth-panel { min-height: auto; padding: 34px 22px; border: 0; }
  .topbar { gap: 8px; padding: 0 10px; }
  .global-search { display: none; }
  .funding-pill { max-width: 140px; }
  .topbar-actions .button { display: none; }
  .main-content { padding: 0 14px 42px; }
  .view { padding-top: 22px; }
  .chat-view { padding-top: 0; }
  .page-heading { align-items: flex-start; }
  .metric-grid, .quota-grid, .plans-grid { grid-template-columns: 1fr; }
  .metric { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .recharge-band, .api-callout, .notice-band { align-items: stretch; flex-direction: column; }
  .inline-form { width: 100%; }
  .credit-notice { align-items: stretch; flex-direction: column; }
  .audit-list li { grid-template-columns: 1fr; gap: 2px; }
  .list-item { align-items: stretch; flex-direction: column; }
  .member-row, .subscription-actions { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@media (prefers-contrast: more) {
  :root { --line: #737b88; --muted: #343b47; }
  .button.secondary, input, select, textarea, .table-wrap { border-width: 2px; }
}
