:root {
  color-scheme: light;
  --bg: #f4f2ee;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --surface-3: #e1ded6;
  --text: #1d1f23;
  --muted: #62686f;
  --line: #d9d4c9;
  --accent: #0b6f67;
  --accent-strong: #07564f;
  --accent-soft: #d9efea;
  --danger: #b3261e;
  --danger-soft: #fde7e4;
  --warning: #8a5a00;
  --shadow: 0 18px 50px rgba(40, 36, 28, 0.16);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
.app {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

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

button {
  border: 0;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: var(--accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.boot-screen {
  display: grid;
  min-height: 100%;
  place-items: center;
  align-content: center;
  gap: 16px;
  color: var(--muted);
}

.boot-mark {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.auth-screen {
  display: grid;
  min-height: 100%;
  grid-template-columns: minmax(320px, 480px) minmax(360px, 1fr);
  background: var(--bg);
}

.auth-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: clamp(28px, 5vw, 64px);
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.auth-side {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: clamp(28px, 5vw, 72px);
}

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

.brand-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: white;
  background: var(--accent);
  border-radius: 8px;
  font-weight: 800;
}

.brand-title {
  margin: 0;
  font-size: 24px;
  font-weight: 760;
}

.brand-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-actions {
  display: grid;
  gap: 10px;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.5;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.code-input {
  font-weight: 760;
  text-transform: uppercase;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 13px;
  color: var(--text);
  background: var(--surface-2);
  border-radius: 8px;
  font-weight: 680;
  line-height: 1.1;
}

.button.primary {
  color: white;
  background: var(--accent);
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.ghost {
  background: transparent;
}

.button.subtle {
  color: var(--muted);
  background: transparent;
}

.button.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.button.icon {
  width: 38px;
  min-width: 38px;
  padding: 0;
}

.button.small {
  min-height: 30px;
  padding: 6px 9px;
  font-size: 13px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-strip {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.shell {
  display: grid;
  height: 100%;
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  display: grid;
  min-width: 0;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

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

.sidebar-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-title span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.search-bar .input {
  min-height: 36px;
}

.conversation-list {
  overflow: auto;
  padding: 8px;
}

.conversation-item {
  display: grid;
  width: 100%;
  gap: 4px;
  padding: 11px 10px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border-radius: 8px;
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--surface-2);
}

.conversation-item strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.conversation-item .running {
  color: var(--accent);
  font-weight: 720;
}

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

.topbar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: rgba(255, 253, 248, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

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

.topbar-title h1 {
  margin: 0;
  overflow: hidden;
  font-size: 18px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-title p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.message-pane {
  overflow: auto;
  padding: 22px;
}

.message-stack {
  display: grid;
  max-width: 920px;
  gap: 16px;
  margin: 0 auto;
}

.empty-state {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 22px;
}

.message {
  display: flex;
}

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

.message.assistant {
  justify-content: flex-start;
}

.bubble {
  width: min(720px, 100%);
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(40, 36, 28, 0.04);
}

.message.user .bubble {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 760;
}

.message.user .message-head {
  color: rgba(255, 255, 255, 0.78);
}

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

.message-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.message.user .message-actions .button {
  color: white;
  background: rgba(255, 255, 255, 0.16);
}

.markdown {
  overflow-wrap: anywhere;
  line-height: 1.62;
}

.markdown > *:first-child {
  margin-top: 0;
}

.markdown > *:last-child {
  margin-bottom: 0;
}

.markdown pre {
  overflow: auto;
  padding: 12px;
  color: #f7f7f7;
  background: #1e252b;
  border-radius: 8px;
}

.markdown code {
  padding: 2px 5px;
  background: rgba(80, 80, 80, 0.12);
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.markdown pre code {
  padding: 0;
  background: transparent;
  border-radius: 0;
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 14px;
}

.markdown th,
.markdown td {
  padding: 8px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown th {
  background: var(--surface-2);
}

.message.user .markdown a,
.message.user .markdown code {
  color: white;
}

.reasoning-summary {
  margin-bottom: 10px;
  padding: 10px 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.attachment-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.image-part {
  display: block;
  max-width: min(360px, 100%);
  max-height: 280px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 8px;
}

.file-part {
  display: grid;
  min-width: min(280px, 100%);
  gap: 3px;
  padding: 10px 12px;
  color: inherit;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 8px;
}

.message.user .file-part {
  background: rgba(255, 255, 255, 0.16);
}

.file-part span {
  color: inherit;
  font-size: 12px;
  opacity: 0.78;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 14px 18px 16px;
  background: rgba(255, 253, 248, 0.9);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.composer-inner {
  display: grid;
  max-width: 920px;
  width: 100%;
  gap: 10px;
  margin: 0 auto;
}

.composer-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 9px;
  align-items: end;
}

.composer-row .textarea {
  min-height: 48px;
  max-height: 180px;
}

.edit-banner,
.attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
}

.attachment-preview {
  justify-content: flex-start;
}

.attachment-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  background: var(--surface-3);
  border-radius: 7px;
}

.attachment-meta {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.attachment-meta strong,
.attachment-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta span {
  color: var(--muted);
  font-size: 12px;
}

.banner {
  padding: 10px 12px;
  color: var(--warning);
  background: #fff4d7;
  border: 1px solid #ead39b;
  border-radius: 8px;
  font-size: 14px;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toast.error {
  color: var(--danger);
  background: var(--danger-soft);
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 22, 24, 0.42);
}

.modal {
  display: grid;
  width: min(560px, 100%);
  max-height: min(820px, calc(100vh - 36px));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal.wide {
  width: min(980px, 100%);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  overflow: auto;
  padding: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
}

.settings-nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.settings-nav button {
  justify-content: flex-start;
}

.settings-nav button.active {
  color: white;
  background: var(--accent);
}

.settings-panel {
  display: grid;
  align-content: start;
  gap: 18px;
}

.section {
  display: grid;
  gap: 12px;
}

.section h3 {
  margin: 0;
  font-size: 15px;
}

.row-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.row-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.row-main {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.row-main strong,
.row-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-main span {
  color: var(--muted);
  font-size: 12px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.share-list {
  display: grid;
  gap: 8px;
}

.share-option {
  justify-content: flex-start;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #171a1c;
    --surface: #202427;
    --surface-2: #2a3034;
    --surface-3: #343b40;
    --text: #f3f1ec;
    --muted: #a9b0b5;
    --line: #373e43;
    --accent: #23a195;
    --accent-strong: #35b9ad;
    --accent-soft: rgba(35, 161, 149, 0.22);
    --danger: #ffb4ab;
    --danger-soft: rgba(179, 38, 30, 0.24);
    --warning: #f4c76b;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  }

  .topbar,
  .composer {
    background: rgba(32, 36, 39, 0.9);
  }

  .banner {
    background: rgba(138, 90, 0, 0.16);
    border-color: rgba(244, 199, 107, 0.24);
  }
}

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

  .auth-side {
    display: none;
  }

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

  .shell {
    height: auto;
    min-height: 100%;
  }

  .main {
    min-height: 620px;
  }

  .settings-nav {
    display: flex;
    overflow: auto;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .composer-row {
    grid-template-columns: 1fr auto auto;
  }

  .composer-row .button[data-action="toggleSpeech"] {
    display: none;
  }

  .message-pane {
    padding: 14px;
  }

  .bubble {
    width: 100%;
  }
}
