:root {
  color-scheme: dark;
  font-size: 16px;
  --font-body: "Manrope", "Noto Sans SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #05070b;
  --bg-soft: #0b1016;
  --surface: rgba(16, 21, 29, 0.92);
  --surface-2: rgba(13, 18, 25, 0.96);
  --surface-elevated: rgba(20, 25, 34, 0.98);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f3f6fb;
  --muted: #aab6c8;
  --soft: #8190a5;
  --accent: #8dc2ff;
  --accent-strong: #dcecff;
  --accent-soft: rgba(141, 194, 255, 0.14);
  --success: #73d4a5;
  --warning: #efc16a;
  --error: #ff9b90;
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.34);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 8px 18px rgba(0, 0, 0, 0.18);
  --radius-xl: 1.25rem;
  --radius-lg: 1rem;
  --radius-md: 0.875rem;
  --radius-sm: 0.75rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --app-height: 100dvh;
  --keyboard-inset: 0px;
  --sidebar-width: clamp(19rem, 18vw, 21.5rem);
  --content-max: 84rem;
  --content-padding: clamp(1.25rem, 2vw, 2rem);
  --font-size-title: clamp(1.15rem, 1.03rem + 0.45vw, 1.5rem);
  --font-size-heading: clamp(1rem, 0.96rem + 0.2vw, 1.15rem);
  --font-size-body: clamp(0.93rem, 0.91rem + 0.12vw, 0.95rem);
  --font-size-meta: 0.8rem;
}

@media (min-width: 1600px) {
  :root {
    --content-max: 88rem;
  }
}

@media (max-width: 768px) {
  :root {
    font-size: 14px;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: var(--font-size-body);
  line-height: 1.6;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(85, 127, 211, 0.22), transparent 32%),
    radial-gradient(circle at top right, rgba(37, 121, 106, 0.16), transparent 24%),
    linear-gradient(180deg, #081018 0%, #06090e 48%, #04070b 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 100%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 100%);
  background-size: 64px 64px;
  mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 0.8), transparent 88%);
}

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

button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

input,
textarea,
select {
  appearance: none;
  outline: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) 50%,
    calc(100% - 11px) 50%;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(141, 194, 255, 0.48);
  box-shadow: 0 0 0 3px rgba(141, 194, 255, 0.14);
}

[hidden],
.hidden {
  display: none !important;
}

.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;
}

h1,
h2 {
  font-size: var(--font-size-title);
  line-height: 1.25;
}

h3,
h4,
h5,
h6 {
  font-size: var(--font-size-heading);
  line-height: 1.3;
}

.app-shell {
  position: relative;
  width: 100%;
  height: var(--app-height);
  min-height: var(--app-height);
  overflow: hidden;
}

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  width: 100%;
  height: 100%;
}

.app-sidebar,
.summary-card,
.message-card,
.composer-frame,
.key-drawer,
.status-chip,
.transport-chip,
.toast {
  backdrop-filter: blur(18px);
}

.app-sidebar {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding:
    calc(var(--safe-top) + 1rem)
    1rem
    calc(var(--safe-bottom) + 1rem)
    calc(var(--safe-left) + 1rem);
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(8, 12, 18, 0.96), rgba(9, 14, 20, 0.94));
}

.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding-right: calc(var(--safe-right) * 0.25);
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-block img {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.875rem;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.brand-copy {
  min-width: 0;
}

.brand-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  margin-top: 0.15rem;
  font-size: var(--font-size-meta);
  color: var(--muted);
}

.sidebar-close {
  display: none;
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  padding-top: 1rem;
  padding-right: 0.125rem;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.sidebar-title {
  margin: 0;
}

.panel-kicker,
.summary-card span,
.message-meta,
.composer-meta-line,
.hint,
.key-meta,
.badge,
.transport-chip,
.status-chip {
  font-size: var(--font-size-meta);
  color: var(--muted);
}

.panel-kicker {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-section-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.summary-grid {
  display: grid;
  gap: 0.75rem;
}

.summary-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.85rem 0.9rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

.summary-card strong {
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--text);
}

.status-cluster {
  display: grid;
  gap: 0.5rem;
}

.status-chip,
.transport-chip {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0 0.875rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
}

.status-chip[data-tone="success"],
.transport-chip[data-tone="success"] {
  color: #e9fff3;
  border-color: rgba(115, 212, 165, 0.34);
  background: rgba(115, 212, 165, 0.14);
}

.status-chip[data-tone="warn"],
.transport-chip[data-tone="warn"] {
  color: #fff1cf;
  border-color: rgba(239, 193, 106, 0.34);
  background: rgba(239, 193, 106, 0.14);
}

.status-chip[data-tone="busy"],
.transport-chip[data-tone="busy"] {
  color: #e7f1ff;
  border-color: rgba(141, 194, 255, 0.34);
  background: rgba(141, 194, 255, 0.14);
}

.status-chip[data-tone="error"],
.transport-chip[data-tone="error"] {
  color: #ffe5df;
  border-color: rgba(255, 155, 144, 0.32);
  background: rgba(255, 155, 144, 0.14);
}

.form-field,
.panel-control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.panel-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-control label,
.form-field span,
.toggle-row span {
  font-size: var(--font-size-meta);
  color: var(--muted);
}

.panel-control input[type="number"],
.panel-control input[type="text"],
.panel-control select,
.form-field input,
.form-field select {
  width: 100%;
  height: 36px;
  min-height: 36px;
  padding: 0 0.75rem;
  font-size: 0.9rem;
}

.panel-control textarea {
  width: 100%;
  min-height: 8rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.9rem;
  resize: vertical;
}

.panel-control input[type="range"] {
  width: 100%;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(141, 194, 255, 0.9), rgba(141, 194, 255, 0.9)) no-repeat, rgba(255, 255, 255, 0.12);
  background-size: 50% 100%, 100% 100%;
}

.panel-control input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 0;
  background: #fff;
}

.panel-control input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 0;
  background: #fff;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2.5rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
}

.toggle-row input[type="checkbox"] {
  width: 2.75rem;
  height: 1.5rem;
  border-radius: 999px;
  position: relative;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: none;
}

.toggle-row input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 50%;
  background: #fff;
  transition: transform 180ms ease;
}

.toggle-row input[type="checkbox"]:checked {
  background: rgba(141, 194, 255, 0.42);
}

.toggle-row input[type="checkbox"]:checked::before {
  transform: translateX(1.25rem);
}

.hint {
  line-height: 1.6;
}

.section-note {
  color: var(--muted);
  font-size: var(--font-size-meta);
  line-height: 1.6;
}

.sidebar-fold {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.sidebar-fold summary {
  list-style: none;
  cursor: pointer;
  padding: 0.8rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar-fold summary::-webkit-details-marker {
  display: none;
}

.sidebar-fold[open] summary {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.fold-body {
  display: grid;
  gap: 0.75rem;
  padding: 0.85rem 0.9rem 0.9rem;
}

.chat-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.app-topbar {
  display: none;
  grid-row: 1;
}

.chat-surface {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "conversation"
    "composer";
  gap: 1rem;
  grid-row: 1;
  padding:
    calc(var(--safe-top) + 1.25rem)
    calc(var(--safe-right) + var(--content-padding))
    0
    calc(var(--safe-left) + var(--content-padding));
}

.conversation-scroll {
  grid-area: conversation;
  min-height: 0;
  overflow-y: auto;
  padding: 0 0 1rem;
  scrollbar-gutter: stable both-edges;
}

.conversation-stack {
  width: min(var(--content-max), 100%);
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.service-banner {
  position: absolute;
  top: calc(var(--safe-top) + 0.9rem);
  right: calc(var(--safe-right) + var(--content-padding));
  z-index: 5;
  max-width: min(28rem, calc(100% - var(--content-padding) * 2));
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.35rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid rgba(141, 194, 255, 0.18);
  border-radius: 999px;
  background: rgba(17, 23, 31, 0.94);
  box-shadow: var(--shadow-sm);
  color: #e7f1ff;
  font-size: 0.84rem;
  line-height: 1.35;
}

.service-banner::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
}

.service-banner[data-tone="success"] {
  color: #ddffeb;
  border-color: rgba(115, 212, 165, 0.3);
  background: rgba(18, 31, 24, 0.84);
}

.service-banner[data-tone="warn"] {
  color: #fff0cc;
  border-color: rgba(239, 193, 106, 0.3);
  background: rgba(45, 34, 15, 0.84);
}

.service-banner[data-tone="error"] {
  color: #ffe1db;
  border-color: rgba(255, 155, 144, 0.28);
  background: rgba(51, 22, 18, 0.84);
}

.service-banner[data-tone="busy"] {
  color: #e7f1ff;
  border-color: rgba(141, 194, 255, 0.3);
  background: rgba(16, 27, 41, 0.84);
}

.empty-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
}

.empty-panel {
  width: min(42rem, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.65rem 1.75rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  background: rgba(13, 18, 25, 0.84);
  box-shadow: var(--shadow-md);
}

.empty-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2rem;
  padding: 0 0.875rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: var(--font-size-meta);
}

.provider-dot {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(141, 194, 255, 0.12);
}

.provider-dot.nvidia {
  background: #78d46d;
  box-shadow: 0 0 0 4px rgba(120, 212, 109, 0.12);
}

.provider-dot.gemini_vertex {
  background: #78d2ff;
  box-shadow: 0 0 0 4px rgba(120, 210, 255, 0.12);
}

.provider-dot.deepseek {
  background: #aa9dff;
  box-shadow: 0 0 0 4px rgba(170, 157, 255, 0.12);
}

.empty-panel h1 {
  margin: 0;
  font-size: var(--font-size-title);
}

.empty-panel p {
  margin: 0;
  font-size: var(--font-size-body);
  line-height: 1.6;
  color: var(--muted);
  max-width: 34rem;
  overflow-wrap: anywhere;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.625rem;
}

.chip-btn,
.message-action,
.btn,
.icon-btn {
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

.chip-btn:hover,
.message-action:hover,
.btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0 0.875rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
}

.message.user {
  justify-content: flex-end;
}

.message-avatar {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.875rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    radial-gradient(circle at 30% 30%, rgba(141, 194, 255, 0.2), transparent 62%),
    rgba(18, 23, 31, 0.96);
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 800;
}

.message.user .message-avatar {
  display: none;
}

.message-card {
  min-width: 0;
  max-width: min(82%, 60rem);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: linear-gradient(180deg, rgba(16, 22, 31, 0.96), rgba(13, 18, 25, 0.96));
  box-shadow: var(--shadow-sm);
}

.message.user .message-card {
  max-width: min(70%, 36rem);
  background: linear-gradient(180deg, rgba(34, 43, 58, 0.94), rgba(25, 33, 46, 0.96));
  border-color: rgba(141, 194, 255, 0.22);
}

.message.pending .message-card {
  border-color: rgba(141, 194, 255, 0.3);
}

.message.error .message-card {
  border-color: rgba(255, 155, 144, 0.24);
}

.message.stopped .message-card {
  border-color: rgba(239, 193, 106, 0.26);
}

.message-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.message-author {
  font-size: 0.92rem;
  font-weight: 700;
}

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

.message-state {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  min-height: 1.625rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(141, 194, 255, 0.18);
  background: rgba(141, 194, 255, 0.1);
  color: #e7f1ff;
  font-size: var(--font-size-meta);
}

.message-state.warn {
  color: #fff1cf;
  border-color: rgba(239, 193, 106, 0.26);
  background: rgba(239, 193, 106, 0.1);
}

.message-state.error {
  color: #ffe2dd;
  border-color: rgba(255, 155, 144, 0.24);
  background: rgba(255, 155, 144, 0.1);
}

.reasoning-block {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
}

.reasoning-block summary {
  cursor: pointer;
  color: var(--muted);
  font-size: var(--font-size-meta);
  font-weight: 600;
}

.reasoning-block pre {
  margin: 0.625rem 0 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #d6dce7;
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}

.message-content {
  margin-top: 0.75rem;
  min-width: 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
}

.message-content > :first-child {
  margin-top: 0;
}

.message-content > :last-child {
  margin-bottom: 0;
}

.message-content p,
.message-content ul,
.message-content ol,
.message-content blockquote,
.message-content pre,
.message-content table,
.message-content hr {
  margin: 0 0 1em;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  margin: 1em 0 0.6em;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.message-content h1,
.message-content h2 {
  font-size: var(--font-size-title);
}

.message-content h3 {
  font-size: var(--font-size-heading);
}

.message-content ul,
.message-content ol {
  padding-left: 1.25em;
}

.message-content li + li {
  margin-top: 0.25em;
}

.message-content code {
  padding: 0.1em 0.35em;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  color: #f7f0ce;
  font-family: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
  word-break: break-word;
}

.message-content pre {
  overflow-x: auto;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: #0b1016;
}

.message-content pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  white-space: pre;
}

.message-content blockquote {
  padding: 0.75rem 0.875rem;
  border-left: 3px solid rgba(141, 194, 255, 0.52);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  background: rgba(141, 194, 255, 0.08);
  color: #dceaff;
}

.message-content a {
  color: #a8d3ff;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  overflow-wrap: anywhere;
}

.message-content img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

.message-content table {
  display: block;
  width: max-content;
  min-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  border-spacing: 0;
}

.message-content th,
.message-content td {
  padding: 0.625rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  text-align: left;
}

.message-content th {
  background: rgba(255, 255, 255, 0.06);
}

.message-content hr {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.stream-cursor {
  display: inline-block;
  margin-left: 0.25rem;
  color: var(--accent-strong);
  animation: blink 900ms steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.attachment-row,
.draft-attachments,
.composer-actions,
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-row {
  margin-top: 0.75rem;
}

.attachment-chip,
.draft-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
  max-width: 100%;
  padding: 0 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: var(--font-size-meta);
}

.attachment-chip i,
.draft-chip i {
  width: 16px;
  height: 16px;
}

.draft-chip button {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
}

.message-actions {
  margin-top: 0.75rem;
}

.message-action {
  display: inline-flex;
  align-items: center;
  min-height: 2.125rem;
  padding: 0 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
}

.message-action i {
  width: 18px;
  height: 18px;
}

.composer {
  grid-area: composer;
  width: min(var(--content-max), 100%);
  margin: 0 auto;
  padding: 0 0 calc(0.75rem + var(--safe-bottom));
}

.draft-attachments {
  margin-bottom: 0.625rem;
}

.composer-frame {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.875rem;
  background:
    linear-gradient(180deg, rgba(20, 26, 35, 0.98), rgba(16, 21, 29, 0.98));
  box-shadow: var(--shadow-md);
}

.file-input {
  display: none;
}

.composer-textarea {
  min-width: 0;
  display: block;
}

.composer-textarea textarea {
  width: 100%;
  min-height: 2.75rem;
  max-height: 200px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  resize: none;
  box-shadow: none;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
}

.composer-textarea textarea::placeholder {
  color: rgba(255, 255, 255, 0.42);
}

.composer-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.composer-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.composer-meta-line {
  color: var(--muted);
}

.composer-actions {
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.icon-btn,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  color: var(--text);
}

.icon-btn {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  flex: 0 0 auto;
}

.app-sidebar .sidebar-close {
  display: none;
}

.icon-btn-soft {
  background: rgba(255, 255, 255, 0.06);
}

.icon-btn i,
.btn i {
  width: 18px;
  height: 18px;
}

.icon-btn:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn {
  min-height: 2.25rem;
  padding: 0 0.875rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.88rem;
  font-weight: 700;
}

.btn-primary {
  color: #0d1218;
  border-color: rgba(255, 255, 255, 0.3);
  background: linear-gradient(135deg, #ffffff, #dcecff);
}

.btn-danger {
  color: #ffd8d2;
  border-color: rgba(255, 155, 144, 0.28);
  background: rgba(122, 36, 28, 0.56);
}

.btn-secondary {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
}

.overlay-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(2, 6, 10, 0.58);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.overlay-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.key-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  width: min(24rem, calc(100vw - 1rem));
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding:
    calc(var(--safe-top) + 1rem)
    calc(var(--safe-right) + 1rem)
    calc(var(--safe-bottom) + 1rem)
    1rem;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 14, 20, 0.98);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.key-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.drawer-head h2 {
  margin: 0.2rem 0 0;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.key-form,
.key-list {
  display: grid;
  gap: 0.75rem;
}

.key-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.04);
}

.key-main {
  min-width: 0;
}

.key-line {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.75rem;
  padding: 0 0.625rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  white-space: nowrap;
  font-weight: 700;
}

.badge.active {
  border-color: rgba(141, 194, 255, 0.24);
  background: rgba(141, 194, 255, 0.12);
}

.key-mask {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.notes-details {
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.notes-details summary {
  padding: 0.875rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
}

.notes-body {
  padding: 0 1rem 1rem;
  color: var(--soft);
  font-size: 0.9rem;
  line-height: 1.6;
}

.notes-body p {
  margin: 0 0 0.75em;
}

.notes-body p:last-child {
  margin-bottom: 0;
}

.drawer-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.625rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 1rem);
  z-index: 60;
  transform: translate(-50%, 12px);
  min-width: 220px;
  max-width: min(92vw, 520px);
  padding: 0.75rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(12, 16, 23, 0.96);
  text-align: center;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 900px) {
  .chat-surface {
    padding-left: calc(var(--safe-left) + 1rem);
    padding-right: calc(var(--safe-right) + 1rem);
  }

  .message-card {
    max-width: min(88%, 40rem);
  }

  .message.user .message-card {
    max-width: min(78%, 30rem);
  }

  .composer-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  input,
  textarea,
  select {
    font-size: 16px;
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-width), calc(100vw - 3rem));
    max-width: calc(100vw - 3rem);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
  }

  .app-shell.drawer-open .app-sidebar {
    transform: translateX(0);
  }

  .sidebar-close {
    display: inline-flex;
  }

  .chat-stage {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .app-topbar {
    position: relative;
    z-index: 15;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    padding:
      calc(var(--safe-top) + 0.75rem)
      calc(var(--safe-right) + 1rem)
      0.75rem
      calc(var(--safe-left) + 1rem);
    border-bottom: 1px solid var(--border);
    background: rgba(7, 11, 16, 0.92);
    backdrop-filter: blur(18px);
  }

  .chat-surface {
    grid-row: 2;
  }

  .topbar-copy {
    min-width: 0;
  }

  .topbar-label {
    font-size: var(--font-size-meta);
    color: var(--muted);
  }

  .topbar-model {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
    font-weight: 700;
  }

  .chat-surface {
    padding:
      0.875rem
      calc(var(--safe-right) + 0.75rem)
      0
      calc(var(--safe-left) + 0.75rem);
    gap: 0.875rem;
  }

  .service-banner {
    top: calc(var(--safe-top) + 0.5rem);
    right: calc(var(--safe-right) + 0.75rem);
    left: calc(var(--safe-left) + 0.75rem);
    max-width: none;
    padding: 0.55rem 0.7rem;
    font-size: 0.82rem;
  }

  .conversation-scroll {
    padding-bottom: 0.75rem;
    scrollbar-gutter: auto;
  }

  .conversation-stack {
    gap: 0.875rem;
  }

  .message {
    gap: 0.5rem;
  }

  .message-avatar {
    display: none;
  }

  .message-card {
    max-width: 90%;
  }

  .message.user .message-card {
    max-width: 90%;
  }

  .composer {
    width: 100%;
    padding-bottom: calc(0.875rem + var(--safe-bottom));
  }

  .composer-textarea textarea {
    font-size: 16px;
    line-height: 1.55;
  }

  .drawer-foot {
    flex-wrap: wrap;
  }

  .drawer-foot .btn {
    flex: 1 1 140px;
  }
}

@media (max-width: 480px) {
  .empty-panel {
    padding: 1.2rem 1.1rem;
    border-radius: 1.25rem;
  }

  .quick-row {
    justify-content: flex-start;
  }

  .message-card {
    max-width: 100%;
  }

  .message.user .message-card {
    max-width: 100%;
  }

  .key-drawer {
    width: 100%;
    max-width: 100%;
  }
}
