:root {
  color-scheme: light;
  --bg: oklch(96.8% 0.008 248);
  --panel: oklch(99% 0.006 248);
  --panel-2: oklch(94.2% 0.01 248);
  --text: oklch(20% 0.018 248);
  --muted: oklch(49% 0.024 248);
  --line: oklch(86% 0.018 248);
  --accent: oklch(49% 0.14 188);
  --accent-strong: oklch(39% 0.13 188);
  --danger: oklch(51% 0.17 28);
  --shadow: 0 18px 60px oklch(35% 0.02 248 / 0.12);
  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, textarea, input { font: inherit; }
button { cursor: pointer; }

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

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: oklch(98% 0.006 188);
  font-weight: 800;
}

.product-name { font-weight: 760; }
.status { color: var(--muted); font-size: 13px; margin-top: 2px; }
.status.ready { color: var(--accent-strong); }
.status.working { color: oklch(46% 0.13 72); font-weight: 700; }
.status.error { color: var(--danger); }

.secondary-button, .composer button, .login-form button {
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--panel);
  min-height: 42px;
  padding: 0 16px;
  font-weight: 720;
}

.secondary-button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.session-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
}

.session-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 58px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 5px;
}

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

.session-item.active {
  background: oklch(93.5% 0.028 188);
  border-color: oklch(81% 0.05 188);
}

.session-select {
  display: grid;
  gap: 4px;
  min-width: 0;
  min-height: 46px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 5px;
  text-align: left;
}

.session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
}

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

.session-delete {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.session-delete:hover {
  background: oklch(94% 0.025 28);
  color: var(--danger);
}

.side-section h2 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.side-section p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.logout-form { margin-top: auto; }
.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 0;
}

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

.topbar {
  padding: 22px 28px 14px;
  border-bottom: 1px solid var(--line);
  background: oklch(97.8% 0.007 248);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

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

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

.empty-state {
  max-width: 620px;
  margin: auto;
  text-align: center;
  color: var(--muted);
  line-height: 1.55;
}

.message {
  max-width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 24px oklch(35% 0.02 248 / 0.06);
  padding: 14px 16px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: oklch(93.5% 0.028 188);
  border-color: oklch(81% 0.05 188);
}

.message.assistant { align-self: flex-start; }
.message.working {
  display: flex;
  align-items: center;
  gap: 12px;
  border-color: oklch(78% 0.08 72);
  background: oklch(96% 0.035 72);
  color: oklch(34% 0.08 72);
  font-weight: 720;
}

.message.working::before {
  content: "";
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: oklch(54% 0.14 72);
  box-shadow: 0 0 0 0 oklch(54% 0.14 72 / 0.45);
  animation: workPulse 1.05s ease-out infinite;
}

.message.working::after {
  content: "";
  width: 26px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background:
    radial-gradient(circle, oklch(54% 0.14 72) 45%, transparent 48%) 0 50% / 8px 8px no-repeat,
    radial-gradient(circle, oklch(54% 0.14 72) 45%, transparent 48%) 9px 50% / 8px 8px no-repeat,
    radial-gradient(circle, oklch(54% 0.14 72) 45%, transparent 48%) 18px 50% / 8px 8px no-repeat;
  animation: workDots 1.05s steps(3, end) infinite;
}

.message.error { border-color: oklch(75% 0.08 28); color: var(--danger); }

@keyframes workPulse {
  0% { box-shadow: 0 0 0 0 oklch(54% 0.14 72 / 0.45); }
  100% { box-shadow: 0 0 0 12px oklch(54% 0.14 72 / 0); }
}

@keyframes workDots {
  0% { opacity: 0.25; }
  33% { opacity: 0.55; }
  66%, 100% { opacity: 1; }
}

.composer {
  padding: 16px 28px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer textarea {
  resize: none;
  min-height: 46px;
  max-height: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: oklch(98.6% 0.005 248);
  color: var(--text);
  outline: none;
}

.composer textarea:focus, .login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px oklch(49% 0.14 188 / 0.16);
}

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

.login-shell { width: min(390px, 100%); }
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1 {
  margin: 18px 0 4px;
  font-size: 28px;
}

.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

.login-form { display: grid; gap: 10px; }
.login-form label { font-size: 14px; color: var(--muted); }
.login-form input {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: oklch(98.6% 0.005 248);
  outline: none;
}
.form-error { min-height: 20px; color: var(--danger); font-size: 14px; }

@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px 16px;
  }
  .session-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .session-item {
    min-width: 180px;
  }
  .side-section, .logout-form { display: none; }
  .chat-pane { height: calc(100vh - 118px); }
  .topbar { padding: 16px; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px 16px; grid-template-columns: 1fr; }
}
