:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-muted: #f1f4f9;
  --text: #18212f;
  --muted: #657085;
  --border: #dfe4ee;
  --blue: #1a73e8;
  --blue-strong: #1558b0;
  --green: #188038;
  --yellow: #fbbc04;
  --red: #d93025;
  --shadow: 0 12px 30px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(26, 115, 232, 0.10), transparent 32%),
    linear-gradient(315deg, rgba(24, 128, 56, 0.10), transparent 34%),
    var(--bg);
}

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

.auth-brand {
  min-height: 46px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-muted);
}

.auth-tab {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.auth-tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(24, 33, 47, 0.08);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-error {
  display: none;
  padding: 10px 12px;
  border: 1px solid #f2b8b5;
  border-radius: 8px;
  background: #fceeee;
  color: var(--red);
  font-size: 13px;
  line-height: 1.4;
}

.auth-error.visible {
  display: block;
}

.auth-submit {
  min-height: 42px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue);
  color: white;
  font-weight: 800;
}

.auth-submit:hover {
  background: var(--blue-strong);
}

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

.sidebar,
.settings-panel {
  background: var(--panel);
  border-color: var(--border);
  border-style: solid;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-width: 0 1px 0 0;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: conic-gradient(from 140deg, var(--blue), var(--green), var(--yellow), var(--red), var(--blue));
  color: white;
  font-weight: 800;
}

.brand strong,
.panel-heading strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.brand span,
.panel-heading span,
.topbar-title small,
.section-label {
  color: var(--muted);
  font-size: 12px;
}

.primary-action,
.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.primary-action {
  justify-content: flex-start;
  padding: 0 14px;
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(24, 33, 47, 0.06);
}

.primary-action:hover,
.tool-button:hover,
.icon-button:hover {
  background: var(--panel-muted);
}

.sidebar-section {
  min-height: 0;
}

.section-label {
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}

.thread-list {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  max-height: calc(100vh - 150px);
  padding-right: 2px;
}

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

.thread-item:hover,
.thread-item.active {
  border-color: var(--border);
  background: var(--panel-muted);
}

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

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
}

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

.topbar-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

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

.user-chip {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.icon-button,
.send-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.icon-button.danger {
  color: var(--red);
}

.chat-surface {
  overflow-y: auto;
  padding: 26px 24px;
}

.empty-state {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 100%;
  gap: 14px;
  text-align: center;
}

.empty-state.hidden {
  display: none;
}

.spark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 8px;
  background: #e8f0fe;
  color: var(--blue);
}

.empty-state h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.empty-state p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 260px));
  gap: 10px;
  margin-top: 12px;
}

.prompt-card {
  min-height: 84px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.prompt-card:hover {
  border-color: #b7c5da;
  box-shadow: var(--shadow);
}

.message-list {
  width: min(920px, 100%);
  margin: 0 auto;
}

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  padding: 18px 0;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.message.assistant .avatar {
  background: #e6f4ea;
  color: var(--green);
}

.message.user .avatar {
  background: #e8f0fe;
  color: var(--blue);
}

.message-body {
  min-width: 0;
  padding: 7px 0 0;
  line-height: 1.65;
  white-space: normal;
  overflow-wrap: anywhere;
}

.message-body p {
  margin: 0 0 12px;
}

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

.message-body pre {
  overflow-x: auto;
  margin: 12px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #111827;
  color: #f9fafb;
}

.message-body code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--panel-muted);
}

.message-body pre code {
  padding: 0;
  background: transparent;
}

.composer {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto 18px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.composer-tools {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.tool-button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.tool-button:disabled,
.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

.composer textarea {
  display: block;
  width: 100%;
  max-height: 220px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 9px 8px;
  line-height: 1.5;
  color: var(--text);
}

.send-button {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.send-button:hover {
  background: var(--blue-strong);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-width: 0 0 0 1px;
  overflow-y: auto;
}

.panel-heading {
  min-height: 44px;
}

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

.field span,
.slider-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.field select,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.field select,
.field input {
  min-height: 40px;
  padding: 0 10px;
}

.field textarea {
  resize: vertical;
  min-height: 110px;
  padding: 10px;
  line-height: 1.5;
}

.slider-field > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.slider-field output {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.key-state {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.key-state.ok {
  border-color: #b7dfc1;
  background: #edf7ee;
  color: var(--green);
}

.key-state.missing {
  border-color: #f2b8b5;
  background: #fceeee;
  color: var(--red);
}

.mobile-only {
  display: none;
}

.sidebar.open,
.settings-panel.open {
  transform: translateX(0);
}

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

  .settings-panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 10;
    width: min(340px, 92vw);
    transform: translateX(100%);
    box-shadow: var(--shadow);
    transition: transform 180ms ease;
  }

  .mobile-only {
    display: inline-grid;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 11;
    width: min(300px, 90vw);
    transform: translateX(-100%);
    box-shadow: var(--shadow);
    transition: transform 180ms ease;
  }

  .workspace {
    grid-template-rows: 58px minmax(0, 1fr) auto;
  }

  .topbar {
    padding: 9px 12px;
  }

  .chat-surface {
    padding: 18px 16px;
  }

  .prompt-grid {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .composer {
    width: calc(100% - 18px);
    margin-bottom: 9px;
  }

  .composer-tools {
    overflow-x: auto;
  }
}
