:root {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface-2: #191d26;
  --surface-3: #202631;
  --border: #2b313d;
  --text: #f6f7f9;
  --muted: #a6afbd;
  --accent: #c7f982;
  --accent-dark: #111a08;
  --danger: #ff7575;
  --success: #7ce2a4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background:
    radial-gradient(circle at 80% 0%, rgba(199, 249, 130, .07), transparent 30rem),
    var(--bg);
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea { font: inherit; }
button, .button-link { cursor: pointer; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(199, 249, 130, .72);
  outline-offset: 2px;
}
.muted, small { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.eyebrow {
  color: var(--accent);
  font-size: .74rem;
  font-weight: 750;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 10px;
  color: #071000;
  display: inline-flex;
  font-weight: 900;
  height: 34px;
  justify-content: center;
  width: 34px;
}
.brand { align-items: center; color: var(--text); display: flex; font-weight: 780; gap: .7rem; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 2rem; }
.auth-shell { align-items: center; display: grid; gap: clamp(3rem, 10vw, 9rem); grid-template-columns: minmax(0, 1.2fr) minmax(320px, 430px); max-width: 1120px; width: 100%; }
.auth-copy h1 { font-size: clamp(2.6rem, 6vw, 5.3rem); letter-spacing: -.055em; line-height: .96; margin: 1rem 0 1.5rem; max-width: 760px; }
.auth-copy p { color: var(--muted); font-size: 1.08rem; line-height: 1.7; max-width: 570px; }
.auth-card { background: rgba(17, 21, 28, .92); border: 1px solid var(--border); border-radius: 22px; box-shadow: 0 24px 80px rgba(0,0,0,.35); padding: 2rem; }
.auth-card h2 { font-size: 1.7rem; margin: 1.25rem 0 .35rem; }
.stack-form { display: grid; gap: 1rem; margin-top: 1.6rem; }
.stack-form label { display: grid; font-size: .9rem; font-weight: 700; gap: .5rem; }
input, textarea { background: #0b0e13; border: 1px solid var(--border); border-radius: 11px; color: var(--text); outline: none; padding: .85rem 1rem; transition: border-color .18s, box-shadow .18s; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(184,255,92,.12); }
button, .button-link { border: 0; border-radius: 10px; font-weight: 750; padding: .78rem 1rem; }
.primary { background: var(--accent); color: #071000; }
.secondary { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.danger { background: rgba(255,117,117,.13); color: var(--danger); }
.full { width: 100%; }
.compact { padding: .55rem .78rem; }
.notice { border-radius: 10px; margin-top: 1rem; padding: .75rem .9rem; }
.notice.error { background: rgba(255,117,117,.12); color: #ffb3b3; }
.notice.success { background: rgba(124,226,164,.12); color: var(--success); }
.notice.hidden { display: none; }
.auth-footer { color: var(--muted); font-size: .9rem; margin: 1.4rem 0 0; text-align: center; }
.single-card { display: block; max-width: 460px; }

.app-page { height: 100%; overflow: hidden; overscroll-behavior: none; }
.app-shell { display: grid; grid-template-columns: 288px minmax(0, 1fr); height: var(--app-height, 100dvh); min-height: 0; overflow: hidden; position: relative; }
.sidebar { background: rgba(15,18,24,.98); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; z-index: 30; }
.sidebar-head { display: grid; gap: 1.25rem; padding: 1.25rem; }
.sidebar-brand-row { align-items: center; display: flex; justify-content: space-between; }
.sidebar-close { display: none; }
.new-chat-button { align-items: center; display: flex; gap: .55rem; justify-content: center; min-height: 46px; }
.new-chat-button span { font-size: 1.25rem; line-height: 1; }
.conversation-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .25rem .65rem 1rem; -webkit-overflow-scrolling: touch; }
.conversation-link { background: transparent; border-radius: 11px; color: var(--muted); display: block; font-weight: 550; min-height: 44px; overflow: hidden; padding: .75rem; text-align: left; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.conversation-link:hover, .conversation-link.active { background: var(--surface-2); color: var(--text); }
.empty-sidebar { color: var(--muted); font-size: .84rem; padding: .7rem; }
.sidebar-user { align-items: flex-start; border-top: 1px solid var(--border); display: flex; gap: 1rem; justify-content: space-between; padding: 1rem 1.25rem max(1rem, env(safe-area-inset-bottom)); }
.sidebar-user strong, .sidebar-user small { display: block; max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user small { font-size: .72rem; margin-top: .15rem; }
.user-actions { align-items: end; display: grid; font-size: .78rem; gap: .15rem; text-align: right; }
.user-actions a, .link-button { align-items: center; background: transparent; color: var(--muted); display: inline-flex; justify-content: flex-end; min-height: 44px; padding: 0; }
.user-actions a:hover, .link-button:hover { color: var(--text); }
.sidebar-scrim { display: none; }
.chat-main { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; overflow: hidden; position: relative; }
.mobile-header { align-items: center; background: rgba(11,13,18,.88); border-bottom: 1px solid rgba(43,49,61,.75); display: none; min-height: 60px; padding: .5rem 1rem; }
.mobile-title { color: var(--text); font-size: .97rem; font-weight: 750; text-align: center; }
.icon-button { align-items: center; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); display: inline-flex; font-size: 1.2rem; height: 44px; justify-content: center; padding: 0; width: 44px; }
.messages { flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; padding: 3rem max(1.25rem, calc((100% - 800px) / 2)) 2rem; scroll-behavior: smooth; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.welcome { margin: min(14vh, 120px) auto 0; max-width: 760px; }
.welcome-mark { align-items: center; background: rgba(199,249,130,.12); border: 1px solid rgba(199,249,130,.28); border-radius: 16px; color: var(--accent); display: flex; font-size: 1.35rem; font-weight: 850; height: 52px; justify-content: center; margin-bottom: 1.25rem; width: 52px; }
.welcome h1 { font-size: clamp(2.2rem, 5vw, 4.25rem); letter-spacing: -.05em; line-height: 1.02; margin: .8rem 0 1rem; }
.welcome > p { color: var(--muted); font-size: 1.06rem; line-height: 1.6; margin: 0; max-width: 650px; }
.suggestion-grid { display: grid; gap: .75rem; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 2rem; }
.prompt-suggestion { background: rgba(18,21,28,.82); border: 1px solid var(--border); color: var(--text); min-height: 80px; padding: .9rem 1rem; text-align: left; transition: background .18s, border-color .18s, transform .18s; }
.prompt-suggestion:hover { background: var(--surface-2); border-color: #465062; transform: translateY(-1px); }
.prompt-suggestion:active { transform: scale(.985); }
.prompt-suggestion strong, .prompt-suggestion span { display: block; }
.prompt-suggestion strong { font-size: .93rem; }
.prompt-suggestion span { color: var(--muted); font-size: .78rem; font-weight: 500; margin-top: .28rem; }
.message { margin: 0 auto 1.6rem; max-width: 800px; width: 100%; }
.message-label { color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .09em; margin-bottom: .45rem; text-transform: uppercase; }
.message-content { font-size: 1rem; line-height: 1.7; overflow-wrap: anywhere; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0 0 .9rem; }
.message-content ul, .message-content ol { margin: .65rem 0 1rem; padding-left: 1.4rem; }
.message-content li { margin: .35rem 0; padding-left: .15rem; }
.message-content h2, .message-content h3 { letter-spacing: -.02em; line-height: 1.25; margin: 1.35rem 0 .6rem; }
.message-content h2 { font-size: 1.22rem; }
.message-content h3 { font-size: 1.08rem; }
.message-content code { background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; padding: .08rem .32rem; }
.message.user { align-items: flex-end; display: flex; flex-direction: column; }
.message.user .message-content { background: var(--surface-2); border: 1px solid var(--border); border-radius: 18px 18px 5px 18px; max-width: min(82%, 620px); padding: .85rem 1rem; white-space: pre-wrap; }
.message.assistant { border-bottom: 1px solid var(--border); padding-bottom: 1.6rem; }
.thinking-message .message-content { align-items: center; color: var(--muted); display: flex; gap: .55rem; }
.thinking-dots { display: inline-flex; gap: .25rem; }
.thinking-dots i { animation: thinking 1.2s infinite ease-in-out; background: var(--muted); border-radius: 50%; display: block; height: 5px; opacity: .35; width: 5px; }
.thinking-dots i:nth-child(2) { animation-delay: .16s; }
.thinking-dots i:nth-child(3) { animation-delay: .32s; }
@keyframes thinking { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.sources { color: var(--muted); font-size: .78rem; margin-top: 1rem; }
.sources summary { cursor: pointer; min-height: 44px; padding: .65rem 0; }
.sources ul { margin-top: .25rem; padding-left: 1.2rem; }
.download-link { align-items: center; background: rgba(184,255,92,.1); border: 1px solid rgba(184,255,92,.3); border-radius: 10px; display: inline-flex; font-size: .84rem; margin-top: 1rem; padding: .6rem .75rem; }
.composer-dock { background: linear-gradient(to bottom, rgba(11,13,18,0), var(--bg) 18%); flex: none; padding: .9rem 1rem max(.65rem, env(safe-area-inset-bottom)); }
.composer { align-items: end; background: #11151c; border: 1px solid #343b48; border-radius: 20px; box-shadow: 0 16px 50px rgba(0,0,0,.25); display: flex; gap: .5rem; margin: 0 auto; max-width: 830px; padding: .45rem .45rem .45rem .65rem; width: 100%; }
.composer:focus-within { border-color: #697689; box-shadow: 0 0 0 3px rgba(199,249,130,.08), 0 16px 50px rgba(0,0,0,.25); }
.composer textarea { background: transparent; border: 0; box-shadow: none; font-size: 1rem; line-height: 1.45; max-height: min(180px, 30dvh); min-height: 46px; padding: .72rem .55rem; resize: none; width: 100%; }
.send-button { align-items: center; background: var(--accent); border-radius: 15px; color: #071000; display: flex; flex: 0 0 46px; font-size: 1.4rem; height: 46px; justify-content: center; padding: 0; transition: opacity .18s, transform .18s; width: 46px; }
.send-button:active { transform: scale(.94); }
.send-button:disabled { cursor: wait; opacity: .55; }
.chat-status { color: var(--muted); font-size: .78rem; margin: 0 auto; max-width: 830px; min-height: 1.25rem; padding: 0 .45rem .25rem; width: 100%; }
.chat-status.error { color: var(--danger); }
.composer-hint { color: #737d8b; font-size: .68rem; margin: .45rem auto 0; max-width: 830px; text-align: center; }

.admin-page { padding: 3rem 1.25rem; }
.admin-shell { margin: 0 auto; max-width: 1050px; }
.admin-header { align-items: end; display: flex; justify-content: space-between; margin-bottom: 2rem; }
.admin-header h1 { font-size: clamp(2.4rem, 6vw, 4.5rem); letter-spacing: -.05em; margin: .5rem 0 0; }
.user-table-wrap { border: 1px solid var(--border); border-radius: 16px; overflow-x: auto; }
.user-table { border-collapse: collapse; min-width: 680px; width: 100%; }
.user-table th, .user-table td { border-bottom: 1px solid var(--border); padding: 1rem; text-align: left; }
.user-table th { color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.user-table td strong, .user-table td small { display: block; }
.status { border: 1px solid var(--border); border-radius: 999px; font-size: .75rem; padding: .25rem .55rem; }
.status-active { color: var(--success); }
.status-pending { color: #f4c86a; }
.status-revoked { color: var(--danger); }

@media (max-width: 780px) {
  .auth-page { min-height: 100dvh; padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom)); }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-copy { display: none; }
  .auth-card { margin: auto; max-width: 460px; padding: 1.5rem; width: 100%; }
  .stack-form input, .stack-form button { font-size: 1rem; min-height: 48px; }
  .app-shell { display: block; height: var(--app-height, 100dvh); }
  .sidebar { bottom: 0; box-shadow: 24px 0 80px rgba(0,0,0,.7); left: 0; padding-top: env(safe-area-inset-top); position: fixed; top: 0; transform: translateX(-105%); transition: transform .22s ease-out; width: min(88vw, 340px); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .sidebar-scrim { background: rgba(0,0,0,.55); border: 0; border-radius: 0; display: block; inset: 0; opacity: 0; padding: 0; pointer-events: none; position: fixed; transition: opacity .2s; width: 100%; z-index: 20; }
  .sidebar-visible .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .chat-main { height: var(--app-height, 100dvh); }
  .mobile-header { display: grid; flex: none; grid-template-columns: 44px minmax(0, 1fr) 44px; padding: max(.5rem, env(safe-area-inset-top)) max(.75rem, env(safe-area-inset-right)) .5rem max(.75rem, env(safe-area-inset-left)); }
  .messages { padding: 1.35rem max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left)); }
  .welcome { margin-top: clamp(1.5rem, 7vh, 4rem); }
  .welcome-mark { border-radius: 13px; height: 44px; margin-bottom: 1rem; width: 44px; }
  .welcome h1 { font-size: clamp(2rem, 9vw, 2.65rem); margin-top: .65rem; }
  .welcome > p { font-size: .98rem; line-height: 1.55; }
  .suggestion-grid { gap: .6rem; margin-top: 1.4rem; }
  .prompt-suggestion { min-height: 76px; padding: .75rem .8rem; }
  .prompt-suggestion strong { font-size: .86rem; }
  .prompt-suggestion span { font-size: .72rem; }
  .message { margin-bottom: 1.25rem; }
  .message-content { font-size: 1rem; line-height: 1.62; }
  .message.user .message-content { max-width: 90%; }
  .composer-dock { padding: .5rem max(.75rem, env(safe-area-inset-right)) max(.45rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left)); }
  .composer-hint { display: none; }
  .chat-status { min-height: .9rem; padding-bottom: .2rem; }
}

@media (max-width: 390px) {
  .suggestion-grid { grid-template-columns: 1fr; }
  .prompt-suggestion { min-height: 68px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .thinking-dots i { animation: none; opacity: .65; }
}
