:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #eef2f6;
  --text: #17202a;
  --muted: #5f6f80;
  --border: #d9e0e7;
  --accent: #0f7b6c;
  --accent-2: #b63d2e;
  --shadow: 0 12px 34px rgba(18, 27, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: Geist, Satoshi, "Aptos", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

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

button,
.file-button {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button:disabled {
  cursor: progress;
  opacity: 0.6;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(246, 247, 249, 0.92);
  padding: 18px;
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 22px;
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 4px;
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.auth-actions {
  display: grid;
}

.auth-error {
  min-height: 20px;
  margin: 0;
  color: var(--accent-2);
  font-size: 13px;
}

.auth-success {
  min-height: 20px;
  margin: 0;
  color: var(--accent);
  font-size: 13px;
}

.admin-page {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 18px;
}

.admin-card.blocked {
  opacity: 0.78;
}

.app-shell {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: 100dvh;
}

.app-shell.sidebar-closed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.app-shell.sidebar-closed .sidebar {
  overflow: hidden;
  padding-inline: 0;
  border-right: 0;
}

.app-shell.sidebar-closed .sidebar > * {
  visibility: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--border);
  background: #fbfcfd;
  padding: 22px;
  transition: padding 160ms ease;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.advanced,
.conversation-empty {
  color: var(--muted);
  font-size: 13px;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 6px;
  grid-auto-rows: max-content;
  min-height: 0;
  overflow: auto;
}

.conversation-item {
  width: 100%;
  min-height: 36px;
  overflow: hidden;
  border-color: transparent;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #eaf6f3;
}

.conversation-empty {
  padding: 8px 2px;
}

.advanced {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.advanced summary {
  color: var(--text);
  cursor: pointer;
}

.advanced textarea {
  margin-top: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  padding: 14px 18px;
}

.sidebar-toggle {
  display: inline-grid;
  place-items: center;
  width: 40px;
  padding: 0;
}

.hamburger-lines,
.hamburger-lines::before,
.hamburger-lines::after {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.hamburger-lines {
  position: relative;
}

.hamburger-lines::before,
.hamburger-lines::after {
  content: "";
  position: absolute;
  left: 0;
}

.hamburger-lines::before {
  top: -6px;
}

.hamburger-lines::after {
  top: 6px;
}

.sidebar-toggle-outside {
  display: none;
}

.app-shell.sidebar-closed .sidebar-toggle-outside {
  display: inline-grid;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge {
  max-width: 160px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-link {
  display: inline-grid;
  min-height: 40px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0 14px;
  text-decoration: none;
  white-space: nowrap;
}

.chat-surface {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  gap: 14px;
  padding: 18px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 4px;
}

.message {
  max-width: min(850px, 92%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
}

.message.user {
  align-self: flex-end;
  background: #eaf6f3;
  border-color: #c9e7df;
  box-shadow: none;
}

.message.error {
  border-color: #f0c0b8;
  color: var(--accent-2);
  background: #fff4f1;
}

.message-media {
  display: block;
  width: min(100%, 540px);
  max-height: 520px;
  object-fit: contain;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}

.media-placeholder {
  margin-top: 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 10px 12px;
  font-size: 13px;
}

.composer {
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
  box-shadow: var(--shadow);
}

.input-row {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.plus-wrap {
  position: relative;
}

.plus-button {
  width: 40px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.plus-button[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: #eaf6f3;
}

.tool-menu {
  position: absolute;
  left: 0;
  bottom: 48px;
  z-index: 10;
  display: grid;
  gap: 8px;
  width: 286px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px;
  box-shadow: var(--shadow);
}

.tool-menu-group {
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.tool-menu-title {
  color: var(--muted);
  font-size: 12px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-choice {
  min-height: 34px;
  padding: 0 10px;
  text-align: center;
}

.mode-choice.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #eaf6f3;
}

.task-badge {
  display: inline-grid;
  min-height: 40px;
  min-width: 62px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  padding: 0 10px;
}

.tool-menu-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--text);
  font-size: 13px;
}

.model-menu-item {
  grid-template-columns: 1fr;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

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

.tool-menu-item input[type="file"] {
  display: none;
}

#attachmentName {
  display: block;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

textarea,
input,
select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

textarea {
  width: 100%;
  resize: vertical;
  padding: 10px 12px;
}

input,
select {
  padding: 0 10px;
}

.json-output {
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111820;
  color: #dbe7ef;
  padding: 10px;
  font-size: 12px;
}

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

  .app-shell.sidebar-closed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .app-shell.sidebar-closed .sidebar {
    display: none;
  }

  .topbar,
  .topbar-actions,
  .input-row {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    flex-direction: column;
    align-items: stretch;
  }

  .tool-menu {
    width: min(82vw, 300px);
  }
}

/* Account security: a calm, editorial counterpoint to the dense chat workspace. */
.security-page {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 18%, rgba(15, 123, 108, 0.12), transparent 32rem),
    linear-gradient(135deg, #f7faf9 0%, #eef3f2 100%);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

.security-shell {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 30px 0 64px;
}

.security-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 28px;
  border-bottom: 1px solid rgba(23, 32, 42, 0.12);
}

.security-brand {
  color: inherit;
  text-decoration: none;
}

.security-brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.security-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.security-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(420px, 1.1fr);
  align-items: center;
  gap: clamp(42px, 8vw, 112px);
  min-height: calc(100dvh - 150px);
  padding: 56px 0;
}

.security-kicker {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.security-intro h1 {
  margin: 18px 0 22px;
  font-size: clamp(42px, 6vw, 76px);
  font-weight: 760;
  letter-spacing: -0.065em;
  line-height: 0.98;
  word-break: keep-all;
}

.security-intro > p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
  word-break: keep-all;
}

.security-notes {
  display: grid;
  gap: 0;
  margin: 38px 0 0;
  padding: 0;
  border-top: 1px solid var(--border);
  list-style: none;
}

.security-notes li {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 15px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.security-notes span {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}

.security-card {
  display: grid;
  gap: 18px;
  border: 1px solid rgba(23, 32, 42, 0.13);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  padding: clamp(26px, 4vw, 44px);
  box-shadow: 0 30px 80px rgba(23, 54, 50, 0.12);
  backdrop-filter: blur(16px);
}

.security-card-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 8px;
}

.security-lock {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #e5f3f0;
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
}

.security-card h2 {
  margin: 0 0 5px;
  font-size: 24px;
  letter-spacing: -0.03em;
}

.security-card-head p,
.security-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.security-card label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.security-card input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 0 14px;
  color: var(--text);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.security-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 123, 108, 0.1);
}

.password-meter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-top: -8px;
}

.password-meter span {
  height: 4px;
  border-radius: 999px;
  background: #dfe6e5;
  transition: background-color 180ms ease;
}

.password-meter[data-level="1"] span:nth-child(-n+1),
.password-meter[data-level="2"] span:nth-child(-n+2),
.password-meter[data-level="3"] span:nth-child(-n+3),
.password-meter[data-level="4"] span:nth-child(-n+4) {
  background: var(--accent);
}

.security-submit-row {
  display: grid;
  gap: 12px;
  margin-top: 6px;
}

.security-submit-row button {
  min-height: 50px;
  border-radius: 10px;
  font-weight: 750;
}

@media (max-width: 820px) {
  .security-shell {
    width: min(100% - 28px, 620px);
    padding-top: 18px;
  }

  .security-header,
  .security-nav {
    align-items: flex-start;
  }

  .security-nav {
    flex-direction: column;
  }

  .security-layout {
    grid-template-columns: 1fr;
    gap: 38px;
    padding-top: 42px;
  }

  .security-intro h1 {
    font-size: clamp(42px, 13vw, 62px);
  }
}

@media (max-width: 560px) {
  .input-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .task-badge {
    display: none;
  }
}

/* Design refresh */
:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --panel-2: #eef2ef;
  --surface: rgba(255, 255, 255, 0.82);
  --text: #171c19;
  --muted: #66736c;
  --border: #dce3df;
  --border-strong: #c5d0ca;
  --accent: #23715e;
  --accent-soft: #e5f2ed;
  --accent-ink: #145242;
  --accent-2: #a84535;
  --shadow: 0 18px 45px rgba(33, 45, 40, 0.1);
  --shadow-soft: 0 10px 28px rgba(33, 45, 40, 0.06);
  --ease: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  font-family: Geist, Satoshi, "Aptos", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    linear-gradient(90deg, rgba(23, 28, 25, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23, 28, 25, 0.028) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px, 44px 44px, auto;
}

button,
.topbar-link,
textarea,
input,
select {
  transition: border-color var(--ease), background var(--ease), color var(--ease), box-shadow var(--ease), transform var(--ease);
}

button:hover,
.topbar-link:hover {
  border-color: var(--border-strong);
  background: #f8faf8;
}

button:active,
.topbar-link:active {
  transform: scale(0.98);
}

button:focus-visible,
.topbar-link:focus-visible,
textarea:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(35, 113, 94, 0.22);
  outline-offset: 2px;
  border-color: var(--accent);
}

button[type="submit"],
.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  box-shadow: 0 12px 24px rgba(35, 113, 94, 0.18);
}

button[type="submit"]:hover,
.primary-action:hover {
  border-color: var(--accent-ink);
  background: var(--accent-ink);
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 16px;
  z-index: 30;
  transform: translateY(-140%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  text-decoration: none;
  box-shadow: var(--shadow-soft);
  transition: transform var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  min-height: 100dvh;
  transition: grid-template-columns var(--ease);
}

.sidebar {
  gap: 16px;
  background: rgba(251, 252, 251, 0.94);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.72);
}

.sidebar-head {
  padding-bottom: 4px;
}

.brand-mark {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: #171c19;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 14px 26px rgba(23, 28, 25, 0.16);
  font-variant-numeric: tabular-nums;
}

.brand strong {
  font-weight: 750;
}

.brand span {
  margin-top: 2px;
}

.sidebar-actions {
  display: grid;
}

.sidebar-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  gap: 8px;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

#conversationCount {
  min-width: 24px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  padding: 2px 7px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.conversation-list {
  align-content: start;
  gap: 5px;
  grid-auto-rows: max-content;
  padding-right: 2px;
}

.conversation-row {
  display: flex;
  min-width: 0;
  align-items: stretch;
  gap: 3px;
}

.conversation-item {
  min-height: 40px;
  border-radius: 7px;
  background: transparent;
  color: #2f3834;
  padding-inline: 10px;
  box-shadow: none;
}

.conversation-item:hover {
  background: var(--panel);
}

.conversation-item.active {
  border-color: #b9d9cf;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 650;
}

.conversation-open {
  flex: 1 1 auto;
  min-width: 0;
}

.conversation-delete {
  flex: 0 0 34px;
  min-height: 40px;
  border-color: transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 0;
}

.conversation-delete:hover,
.conversation-delete:focus-visible {
  border-color: #e2b9b0;
  background: #fff3f0;
  color: var(--accent-2);
}

.conversation-empty {
  display: grid;
  min-height: 88px;
  place-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
  text-align: center;
}

.advanced {
  border-top-color: var(--border);
  padding-top: 14px;
}

.advanced summary {
  min-height: 34px;
  border-radius: 7px;
  padding: 7px 4px;
  font-weight: 650;
}

.advanced summary:hover {
  background: rgba(255, 255, 255, 0.64);
}

.workspace {
  background: rgba(244, 246, 244, 0.72);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 68px;
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(18px);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.72);
}

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

.topbar-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.topbar-title strong {
  font-size: 15px;
  font-weight: 750;
}

.topbar-title span {
  max-width: min(56vw, 520px);
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-toggle,
.plus-button {
  border-radius: 8px;
  background: var(--panel);
}

.topbar-actions button,
.topbar-link {
  min-height: 36px;
  border-radius: 7px;
  padding-inline: 12px;
}

.user-badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  color: #3c4842;
  padding: 7px 10px;
}

.chat-surface {
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
  padding: 22px clamp(14px, 2.4vw, 34px);
}

.messages {
  gap: 14px;
  padding: 8px 2px 2px;
}

.message {
  border-color: rgba(220, 227, 223, 0.92);
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.message.assistant {
  align-self: flex-start;
}

.message.user {
  border-color: #c8ddd6;
  background: var(--accent-soft);
  color: #173f35;
}

.message.pending {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  box-shadow: none;
}

.pending-label {
  min-width: 9.5rem;
}

.image-progress-steps {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.image-progress {
  flex: 1 1 180px;
  width: min(240px, 100%);
  height: 7px;
  accent-color: var(--accent);
}

.pending-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  animation: pendingPulse 1.1s ease-in-out infinite;
}

@keyframes pendingPulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.82);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.composer {
  border-color: rgba(197, 208, 202, 0.92);
  border-radius: 12px;
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.input-row {
  align-items: end;
}

.plus-button {
  font-size: 22px;
  font-weight: 450;
}

.plus-button[aria-expanded="true"],
.mode-choice.active,
.task-badge {
  border-color: #b9d9cf;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.tool-menu {
  width: min(420px, 92vw);
  border-color: rgba(197, 208, 202, 0.95);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  padding: 12px;
  box-shadow: 0 28px 60px rgba(33, 45, 40, 0.16);
  animation: menuRise 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes menuRise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tool-menu-group {
  border-bottom-color: var(--border);
}

.tool-menu-title,
.tool-menu-item span {
  font-weight: 650;
}

.mode-choice {
  border-radius: 7px;
  background: #f8faf8;
}

.tool-menu-item {
  min-height: 42px;
}

.tool-menu-item select,
.tool-menu-item input[type="number"] {
  max-width: 176px;
  background: #f8faf8;
}

.model-menu-item select {
  max-width: none;
}

.task-badge {
  font-weight: 650;
}

textarea,
input,
select {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.9);
}

#chatInput {
  min-height: 48px;
  max-height: 180px;
}

#attachmentName:not(:empty) {
  min-height: 26px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.62);
  padding: 5px 8px;
}

.auth-screen,
.admin-page {
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(23, 28, 25, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23, 28, 25, 0.028) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px, 44px 44px, auto;
}

.auth-card {
  border-color: rgba(197, 208, 202, 0.95);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.auth-card label {
  color: #3e4a44;
  font-weight: 650;
}

.auth-card input {
  width: 100%;
}

.auth-actions {
  margin-top: 2px;
}

.admin-console {
  min-height: 100dvh;
  padding: clamp(14px, 2vw, 28px);
  background:
    linear-gradient(90deg, rgba(23, 28, 25, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23, 28, 25, 0.028) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px, 44px 44px, auto;
}

.admin-console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: 1320px;
  margin: 0 auto 18px;
  border: 1px solid rgba(197, 208, 202, 0.95);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.admin-console-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.92fr) minmax(520px, 1.4fr);
  gap: 16px;
  max-width: 1320px;
  margin: 0 auto;
}

.admin-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  border: 1px solid rgba(197, 208, 202, 0.95);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.admin-span-all {
  grid-column: 1 / -1;
}

.admin-panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.admin-panel h1,
.admin-panel h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.admin-panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.admin-form-grid label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: #3e4a44;
  font-size: 13px;
  font-weight: 650;
}

.admin-form-grid input,
.admin-form-grid select {
  width: 100%;
}

.admin-check {
  align-content: end;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 40px;
}

.admin-check input {
  width: 18px;
  min-height: 18px;
}

.admin-form-actions {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.admin-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.admin-table-wrap.compact {
  max-height: 320px;
}

.admin-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--border);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8faf8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

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

.admin-table td strong,
.admin-table td span,
.admin-table td small {
  display: block;
  max-width: 520px;
  overflow-wrap: anywhere;
}

.admin-table td span,
.admin-table td small {
  color: var(--muted);
}

.status-pill {
  display: inline-grid;
  min-height: 28px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 9px;
  font-weight: 650;
}

.status-pill.on {
  border-color: #b9d9cf;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.status-pill.off {
  background: #f4f1ee;
  color: var(--muted);
}

.row-actions {
  white-space: nowrap;
}

.row-actions button {
  min-height: 32px;
  padding-inline: 10px;
}

.empty-cell {
  color: var(--muted);
  text-align: center !important;
}

.api-key-form {
  display: grid;
  gap: 12px;
}

.api-key-form-grid {
  grid-template-columns: minmax(240px, 1fr) minmax(180px, 0.4fr);
}

.api-key-reveal {
  display: grid;
  gap: 12px;
  border: 1px solid #a9d1c5;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  padding: 14px;
}

.api-key-reveal strong,
.api-key-reveal span {
  display: block;
}

.api-key-reveal span {
  margin-top: 3px;
  font-size: 13px;
}

.api-key-copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.api-key-copy-row input,
.api-endpoint-note code,
.api-key-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.api-key-copy-row input {
  width: 100%;
  border-color: #a9d1c5;
  background: #fff;
}

.api-endpoint-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8faf8;
  padding: 12px;
  font-size: 13px;
}

.api-endpoint-note span {
  color: var(--muted);
  font-weight: 650;
}

.api-endpoint-note > code {
  overflow-wrap: anywhere;
  color: var(--text);
}

.api-endpoint-note small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.api-client-config {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8faf8;
  padding: 12px;
}

.api-client-config summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 750;
}

.api-client-config p {
  margin: 10px 0;
  line-height: 1.5;
}

.api-client-config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.api-client-config-head button {
  min-height: 32px;
}

.api-client-config pre {
  max-height: 420px;
  margin: 0;
  overflow: auto;
  border: 1px solid #27352f;
  border-radius: 8px;
  background: #17201c;
  color: #dceae3;
  padding: 12px;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

.api-key-table .row-actions button {
  border-color: #e2b9b0;
  color: var(--accent-2);
}

@media (max-width: 900px) {
  body {
    overflow-x: hidden;
  }

  .app-shell,
  .app-shell.sidebar-closed {
    display: block;
    grid-template-columns: none;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(86vw, 320px);
    overflow: auto;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    padding: 18px;
    transform: translateX(0);
    transition: transform var(--ease), box-shadow var(--ease);
    box-shadow: 28px 0 70px rgba(23, 28, 25, 0.18);
    overscroll-behavior: contain;
  }

  .app-shell.sidebar-closed .sidebar {
    display: flex;
    padding: 18px;
    border-right: 1px solid var(--border);
    transform: translateX(calc(-100% - 18px));
    box-shadow: none;
    visibility: hidden;
  }

  .workspace {
    min-height: 100dvh;
  }

  .topbar {
    z-index: 40;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
  }

  .topbar-actions {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
  }

  .chat-surface {
    min-height: calc(100dvh - 68px);
    padding: 14px;
  }

  .message {
    max-width: 100%;
  }

  .composer {
    position: relative;
    z-index: 45;
  }

  .tool-menu {
    position: fixed;
    left: 14px;
    right: 14px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    z-index: 60;
    width: auto;
    max-height: calc(100dvh - 170px);
    overflow: auto;
    overscroll-behavior: contain;
  }

  .admin-console-head,
  .admin-console-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .admin-span-all {
    grid-column: auto;
  }

  .api-key-form-grid,
  .api-key-copy-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 10px;
    padding: 10px;
  }

  .topbar-title span {
    max-width: 44vw;
  }

  .topbar-actions {
    gap: 6px;
  }

  .topbar-actions button,
  .topbar-link,
  .user-badge {
    min-height: 34px;
    padding-inline: 9px;
    font-size: 12px;
  }

  .input-row {
    gap: 8px;
  }

  .composer {
    padding: 8px;
  }

  #chatInput {
    min-height: 44px;
  }
}

/* Keep the sidebar and chat history as separate scroll containers. */
html,
body {
  height: 100%;
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.workspace,
.chat-surface {
  min-height: 0;
}

.sidebar {
  overflow: hidden;
}

.workspace {
  height: 100%;
  overflow: hidden;
}

.chat-surface {
  height: 100%;
  overflow: hidden;
}

.messages {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

@media (max-width: 900px) {
  .app-shell,
  .app-shell.sidebar-closed {
    height: 100dvh;
  }

  .sidebar {
    overflow: auto;
  }

  .workspace {
    height: 100dvh;
  }

  .chat-surface {
    height: 100%;
    min-height: 0;
  }
}
