:root {
  color-scheme: dark;
  --bg-0: #0b1220;
  --bg-1: #132036;
  --ink: #e8eef7;
  --muted: #93a4bc;
  --accent: #3dd6c6;
  --accent-ink: #04241f;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-2: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.12);
  --danger: #ff7b7b;
  --warn: #ffd166;
  --user: rgba(61, 214, 198, 0.14);
  --bot: rgba(255, 255, 255, 0.05);
  --soft: rgba(61, 214, 198, 0.12);
  font: 14px/1.6 "DM Sans", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1000px 600px at 10% -10%, rgba(61, 214, 198, 0.16), transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
}
button, select, textarea { font: inherit; color: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; background: transparent; }
button:disabled { cursor: default; opacity: 0.45; }
a { color: inherit; text-decoration: none; }
button:focus-visible,
a:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: 1.35rem 1.05rem 1rem;
  background: rgba(11, 18, 32, 0.78);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
  overflow: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.55rem;
  height: 2.55rem;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 400;
}
.brand-text {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.28rem;
  line-height: 1.15;
}
.brand-text em {
  font-style: italic;
  color: var(--accent);
}
.brand-text small {
  display: block;
  margin-top: 0.15rem;
  font-family: "DM Sans", sans-serif;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 500;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  font-weight: 650;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.new-chat:hover {
  border-color: rgba(61, 214, 198, 0.45);
  background: rgba(61, 214, 198, 0.08);
}
.new-chat > span:first-child {
  color: var(--accent);
  font-size: 1.15rem;
  line-height: 1;
}

.section-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.navigation {
  display: grid;
  gap: 0.3rem;
  margin-top: -0.35rem;
}
.navigation a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  color: var(--muted);
  border: 1px solid transparent;
}
.navigation a:hover {
  background: var(--panel);
  color: var(--ink);
}
.navigation a[aria-current] {
  background: rgba(61, 214, 198, 0.12);
  border-color: rgba(61, 214, 198, 0.28);
  color: var(--accent);
  font-weight: 650;
}
.nav-ico { width: 1.1rem; text-align: center; }
.nav-badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
}

.quota-panel {
  border-top: 1px solid var(--line);
  padding-top: 0.9rem;
  margin-top: 0.2rem;
}
.quota-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}
.icon-button {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
}
.icon-button:hover {
  background: var(--panel);
  color: var(--accent);
}
#plan {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}
.cards {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.85rem;
}
.card {
  padding: 0.85rem 0.9rem;
  background: #151a22;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
}
.muted { font-size: 0.75rem; color: var(--muted); }
.big {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0.2rem 0 0.35rem;
  font-variant-numeric: tabular-nums;
}
.card .muted { font-size: 0.68rem; overflow-wrap: anywhere; }
.card progress {
  display: block;
  width: 100%;
  height: 6px;
  margin: 0.55rem 0 0.65rem;
  appearance: none;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  accent-color: var(--accent);
}
progress::-webkit-progress-bar { background: rgba(255, 255, 255, 0.08); }
progress::-webkit-progress-value {
  background: linear-gradient(90deg, #3dd6c6, #ffd166);
  border-radius: 999px;
}
progress::-moz-progress-bar {
  background: linear-gradient(90deg, #3dd6c6, #ffd166);
}
.low progress { accent-color: var(--warn); }
.low progress::-webkit-progress-value,
.low progress::-moz-progress-bar {
  background: linear-gradient(90deg, #ffd166, #ff9f43);
}
.low .big { color: var(--warn); }
.critical progress::-webkit-progress-value,
.critical progress::-moz-progress-bar {
  background: linear-gradient(90deg, #ff9f43, #ff7b7b);
}
.critical .big { color: var(--danger); }
#updated { font-size: 0.68rem; margin-top: 0.7rem; }
.quota-note {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.65rem;
}
.quota-note summary { cursor: pointer; }
.quota-note p { margin: 0.45rem 0 0; line-height: 1.45; }

.sidebar-footer {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  margin-top: auto;
  padding-top: 1rem;
  font-size: 0.78rem;
}
.avatar {
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  background: var(--soft);
  color: var(--accent);
  border: 1px solid rgba(61, 214, 198, 0.25);
  font-family: "Instrument Serif", Georgia, serif;
}
.sidebar-footer small {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
}
.sidebar-footer a {
  margin-left: auto;
  font-size: 1.05rem;
  color: var(--muted);
}
.sidebar-footer a:hover { color: var(--accent); }

.workspace {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(14, 17, 22, 0.35);
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 4.2rem;
  padding: 0 1.6rem;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.55);
  backdrop-filter: blur(10px);
}
.page-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.25rem;
}
.tag {
  font-family: "DM Sans", sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.local-badge {
  color: var(--muted);
  font-size: 0.75rem;
}
.local-badge:before {
  content: "";
  display: inline-block;
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 0.4rem;
  vertical-align: middle;
}
.mobile-quota { display: none; }

.chat-heading {
  width: min(880px, 100%);
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.6rem 0.55rem;
}
.eyebrow {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
h1 {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 400;
  margin: 0.2rem 0 0;
}
.session-badge {
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.7rem max(1.4rem, calc((100% - 800px) / 2));
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.messages.is-empty {
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome {
  width: 100%;
  max-width: 640px;
  text-align: center;
  padding: 1.4rem 0 2rem;
}
.welcome-mark {
  margin: 0 auto 1.1rem;
  display: grid;
  place-items: center;
  width: 3.6rem;
  height: 3.6rem;
  border-radius: 1.1rem;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.8rem;
  color: var(--accent-ink);
  background: var(--accent);
  box-shadow: 0 0 0 8px rgba(61, 214, 198, 0.12);
}
.welcome-title {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(1.5rem, 2.4vw, 2.1rem);
  font-weight: 400;
  letter-spacing: -0.02em;
}
.welcome-subtitle {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0.7rem 0 1.4rem;
}
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  text-align: left;
}
.suggestion {
  display: grid;
  grid-template-columns: 1.6rem 1fr;
  column-gap: 0.55rem;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem;
  background: var(--panel-2);
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.suggestion:hover {
  background: rgba(61, 214, 198, 0.08);
  border-color: rgba(61, 214, 198, 0.4);
  transform: translateY(-1px);
}
.suggestion-icon {
  grid-row: span 2;
  font-size: 1.05rem;
  color: var(--accent);
}
.suggestion strong {
  font-size: 0.88rem;
  font-weight: 650;
}
.suggestion .muted {
  font-size: 0.74rem;
  margin-top: 0.2rem;
}

.message { margin: 0.9rem 0 1.35rem; }
.message-head {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  font-size: 0.78rem;
  margin-bottom: 0.55rem;
}
.message-head strong { font-weight: 650; }
.message-avatar {
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 0.55rem;
  background: var(--soft);
  color: var(--accent);
  font-size: 0.85rem;
  font-family: "Instrument Serif", Georgia, serif;
}
.user .message-avatar {
  font-family: "DM Sans", sans-serif;
  font-size: 0.7rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
}
.copy-button {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
}
.copy-button:hover {
  background: var(--panel);
  color: var(--accent);
}
.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.7;
  padding-left: 2.25rem;
}
.user .message-content {
  margin-left: 2.25rem;
  padding: 0.8rem 1rem;
  background: var(--user);
  border: 1px solid rgba(61, 214, 198, 0.18);
  border-radius: 0 14px 14px 14px;
}
.message pre {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 0.85rem 0.95rem;
  overflow: auto;
  white-space: pre;
  max-width: 100%;
  font: 0.8rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.composer-area {
  width: min(880px, 100%);
  align-self: center;
  padding: 0.35rem 1.6rem 1rem;
}
.composer {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.35rem 0.85rem 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.composer:focus-within {
  border-color: rgba(61, 214, 198, 0.45);
  box-shadow: 0 12px 36px rgba(61, 214, 198, 0.08);
}
.composer textarea {
  display: block;
  width: 100%;
  min-height: 4.4rem;
  max-height: 12rem;
  resize: none;
  border: 0;
  background: transparent;
  padding: 0.85rem 0.25rem 0.55rem;
  outline: none;
  font-size: 0.95rem;
  line-height: 1.6;
}
.composer textarea::placeholder { color: #738197; }
.composer-toolbar,
.send-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.composer-toolbar { justify-content: space-between; }
.mode-control {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(118, 118, 128, 0.14);
  padding: 0.25rem 0.55rem;
  color: var(--muted);
  font-size: 0.75rem;
}
.mode-control select {
  border: 0;
  background: transparent;
  max-width: 10.5rem;
  cursor: pointer;
  color: var(--ink);
}
.primary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.5rem 0.95rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.82rem;
  font-weight: 700;
}
.primary:hover { filter: brightness(1.05); }
.primary span { font-size: 1rem; line-height: 1; }
.stop-button {
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}
.stop-button:disabled { display: none; }
.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.6rem 0.15rem 0;
  color: var(--muted);
  font-size: 0.72rem;
}
.composer-meta > span:first-child { max-width: 65%; }
.page-foot {
  text-align: center;
  color: #738197;
  font-size: 0.68rem;
  margin-top: 0.85rem;
}
.page-foot span { display: block; }
#status {
  font-size: 0.8rem;
  min-height: 1.4rem;
  padding: 0 0.2rem 0.35rem;
  overflow-wrap: anywhere;
}
#status.error { color: var(--danger); }
.is-busy { border-color: rgba(61, 214, 198, 0.4); }
.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;
}

@media (min-width: 1500px) {
  .app { grid-template-columns: 310px minmax(0, 1fr); }
  .sidebar { padding-left: 1.25rem; padding-right: 1.25rem; }
}
@media (max-width: 1000px) {
  .app { grid-template-columns: 245px minmax(0, 1fr); }
  .sidebar { padding: 1.1rem 0.85rem; }
  .topbar { padding: 0 1.1rem; }
  .chat-heading { padding: 1rem 1.1rem 0.4rem; }
  .composer-area { padding: 0.3rem 1.1rem 0.9rem; }
  .messages { padding-left: 1.1rem; padding-right: 1.1rem; }
  .keyboard-hint { display: none; }
  .composer-meta > span:first-child { max-width: 100%; }
}
@media (max-width: 700px) {
  .app { display: block; }
  .sidebar {
    display: none;
    position: fixed;
    top: 3.9rem;
    bottom: 0;
    left: 0;
    width: min(320px, 90vw);
    z-index: 5;
    box-shadow: 16px 0 48px rgba(0, 0, 0, 0.45);
  }
  .show-quota .sidebar { display: flex; }
  .workspace { height: 100%; width: 100%; }
  .topbar { min-height: 3.9rem; padding: 0 1rem; }
  .mobile-quota {
    display: inline-block;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--ink);
    background: var(--panel);
  }
  .local-badge { display: none; }
  .chat-heading { padding: 0.9rem 1rem 0.25rem; }
  .messages { padding: 0.5rem 1rem; }
  .welcome { padding: 1.2rem 0; }
  .suggestions { gap: 0.55rem; }
  .suggestion {
    grid-template-columns: 1fr;
    padding: 0.85rem;
  }
  .suggestion-icon {
    grid-row: auto;
    margin-bottom: 0.3rem;
  }
  .composer-area { padding: 0 0.85rem max(0.75rem, env(safe-area-inset-bottom)); }
  .composer { border-radius: 14px; }
  .composer textarea { min-height: 4rem; font-size: 16px; }
  .message-content { padding-left: 0; }
  .user .message-content { margin-left: 0; }
  .page-foot span { display: none; }
  #charCount { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
