:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-muted: #f1f3f0;
  --text: #202421;
  --muted: #66706a;
  --border: #dfe4df;
  --accent: #2f6f5e;
  --accent-strong: #245447;
  --accent-soft: #e4f1ec;
  --warning: #9f6b20;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(32, 36, 33, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-body {
  min-height: 100%;
  background: linear-gradient(135deg, #f7f7f4 0%, #eef4f0 52%, #f5efe5 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 430px);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 36px;
}

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

.eyebrow {
  margin: 18px 0 6px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-panel h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0;
}

.login-copy {
  margin: 10px 0 24px;
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 13px;
  color: var(--text);
  background: #fff;
}

.login-form input:focus,
.composer textarea:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

.form-error {
  border: 1px solid #f1c5bf;
  color: var(--danger);
  background: #fff4f2;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}

.primary-button,
.secondary-button,
.new-chat-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 0 18px;
  text-decoration: none;
}

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

.secondary-button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  padding: 0 14px;
}

.secondary-button:hover {
  background: var(--surface-muted);
}

.app-body {
  overflow: hidden;
}

.mobile-topbar {
  display: none;
}

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

.sidebar {
  background: #fbfbf8;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.sidebar-brand h1 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.sidebar-brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.new-chat-button {
  width: 100%;
  color: #fff;
  background: #27302b;
  padding: 0 14px;
}

.new-chat-button:hover {
  background: #111612;
}

.sidebar-section {
  min-height: 0;
  flex: 1;
  margin-top: 22px;
}

.section-label {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 750;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.conversation-list {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  max-height: 100%;
  padding-right: 3px;
}

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

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

.conversation-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item small {
  color: var(--muted);
}

.sidebar-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 16px;
}

.sidebar-footer form,
.sidebar-footer button {
  width: 100%;
}

.chat-shell {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  background: var(--surface);
}

.chat-header {
  min-height: 76px;
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-header .eyebrow {
  margin: 0 0 4px;
}

.chat-header h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 40px;
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.icon-button:hover {
  background: var(--surface-muted);
}

.settings-panel {
  border-bottom: 1px solid var(--border);
  background: #fbfbf8;
  padding: 12px 24px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.settings-panel:not([hidden]) {
  display: grid;
}

.settings-panel div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 0;
  background: #fff;
}

.settings-panel span,
.settings-panel strong {
  display: block;
  overflow-wrap: anywhere;
}

.settings-panel span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.settings-panel strong {
  margin-top: 4px;
  font-size: 0.9rem;
}

.messages {
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  margin: auto;
  width: min(100%, 520px);
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.empty-state h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 1.2rem;
}

.empty-state p {
  margin: 0;
  line-height: 1.5;
}

.message {
  width: min(100%, 880px);
  display: grid;
  gap: 7px;
}

.message.user {
  align-self: flex-end;
  width: min(100%, 720px);
}

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

.message-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
  text-transform: uppercase;
}

.message-bubble {
  border-radius: 8px;
  padding: 13px 15px;
  line-height: 1.55;
  overflow-x: auto;
}

.message.user .message-bubble {
  background: var(--accent);
  color: #fff;
}

.message.assistant .message-bubble {
  background: #f8faf7;
  border: 1px solid var(--border);
}

.message-actions {
  display: flex;
  justify-content: flex-end;
}

.copy-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.8rem;
  font-weight: 700;
}

.markdown p {
  margin: 0 0 12px;
}

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

.markdown table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 0.92rem;
}

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

.markdown th {
  background: #eef4f0;
}

.markdown pre {
  margin: 12px 0;
  background: #202421;
  color: #f7f7f4;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}

.markdown code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.markdown :not(pre) > code {
  background: #e8ece7;
  color: #27302b;
  border-radius: 5px;
  padding: 1px 5px;
}

.tool-status {
  margin: 0 24px 12px;
  color: var(--warning);
  background: #fff8eb;
  border: 1px solid #f0d9a8;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.9rem;
  font-weight: 700;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 16px 24px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  background: #fbfbf8;
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  min-height: 46px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  color: var(--text);
  line-height: 1.4;
}

.composer-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 820px) {
  .app-body {
    overflow: auto;
  }

  .mobile-topbar {
    height: 62px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #fbfbf8;
    border-bottom: 1px solid var(--border);
  }

  .mobile-topbar div {
    display: grid;
  }

  .mobile-topbar span {
    color: var(--muted);
    font-size: 0.8rem;
  }

  .app-shell {
    height: calc(100vh - 62px);
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 10;
    inset: 62px auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .chat-shell {
    height: calc(100vh - 62px);
  }

  .chat-header,
  .messages,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .settings-panel:not([hidden]) {
    grid-template-columns: 1fr;
    padding: 12px 14px;
  }

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

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