:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --bg-accent: radial-gradient(circle at top, rgba(236, 197, 145, 0.24), transparent 28%),
    linear-gradient(180deg, #fbf8f2 0%, #f2ede3 100%);
  --panel: rgba(255, 251, 245, 0.84);
  --panel-strong: #fffdf9;
  --panel-border: rgba(89, 66, 33, 0.1);
  --sidebar: #1f1d18;
  --sidebar-alt: #2a271f;
  --sidebar-text: rgba(255, 247, 236, 0.92);
  --sidebar-muted: rgba(255, 239, 219, 0.62);
  --text: #1d1a16;
  --muted: #706558;
  --accent: #b16a21;
  --accent-strong: #8e5315;
  --accent-soft: rgba(177, 106, 33, 0.14);
  --assistant: #fffaf2;
  --user: #f0e2ce;
  --shadow: 0 20px 60px rgba(55, 36, 13, 0.12);
  --font-ui: "IBM Plex Sans", "Noto Sans SC", "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
}

body {
  background-image: var(--bg-accent);
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr;
}

.sidebar {
  background:
    radial-gradient(circle at top, rgba(239, 183, 102, 0.14), transparent 24%),
    linear-gradient(180deg, var(--sidebar) 0%, #171511 100%);
  color: var(--sidebar-text);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-top {
  display: flex;
  flex-direction: column;
}

.brand-button {
  width: 100%;
  padding: 16px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(239, 183, 102, 0.15));
  color: inherit;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  transition: transform 160ms ease, background 160ms ease;
}

.brand-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(239, 183, 102, 0.22));
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 700;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand-copy small,
.sidebar-note,
.history-button time {
  color: var(--sidebar-muted);
}

.history-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: var(--sidebar-muted);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.history-button {
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 18px;
  background: transparent;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid transparent;
}

.history-button:hover,
.history-button.is-active {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
}

.history-button strong {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

.history-button time {
  font-size: 12px;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-badge {
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-badge span {
  color: var(--sidebar-muted);
}

.main-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
}

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

.topbar-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid var(--panel-border);
  font-size: 13px;
}

.chat-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 28px 28px;
}

.empty-state {
  min-height: calc(100vh - 240px);
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
}

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

.empty-state h2 {
  margin: 0;
  color: var(--text);
  font-size: clamp(28px, 3vw, 40px);
}

.empty-state p {
  margin: 0;
  font-size: 15px;
}

.empty-orb {
  width: 74px;
  height: 74px;
  margin: 0 auto 8px;
  border-radius: 24px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.85), transparent 38%),
    linear-gradient(135deg, #e9bc82, #8f5420);
  box-shadow: 0 20px 40px rgba(177, 106, 33, 0.28);
  animation: orb-float 3.2s ease-in-out infinite;
}

@keyframes orb-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.messages {
  width: min(920px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 16px;
  align-items: start;
  animation: message-in 220ms ease;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.message[data-role='assistant'] .avatar {
  background: linear-gradient(135deg, #d58e3f, #8b4a18);
  color: #fffaf2;
}

.message[data-role='user'] .avatar {
  background: linear-gradient(135deg, #efdfc9, #cfb28b);
  color: #5f4324;
}

.message-card {
  border-radius: 24px;
  padding: 18px 20px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.message[data-role='user'] .message-card {
  background: var(--user);
}

.message[data-role='assistant'] .message-card {
  background: var(--assistant);
}

.message-role {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

.message-content {
  font-size: 15px;
  line-height: 1.75;
}

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

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

.message-content pre {
  margin: 12px 0;
  padding: 14px 16px;
  border-radius: 16px;
  overflow: auto;
  background: #1d1a16;
  color: #f8efe2;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}

.message-content code {
  font-family: var(--font-mono);
}

.message-content .inline-code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(29, 26, 22, 0.08);
}

.message-content .cursor {
  display: inline-block;
  width: 8px;
  height: 1.15em;
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 999px;
  background: var(--accent);
  animation: blink 0.9s steps(2, start) infinite;
}

@keyframes blink {
  to {
    opacity: 0;
  }
}

.composer-wrap {
  padding: 0 28px 28px;
}

.composer {
  width: min(920px, 100%);
  margin: 0 auto;
  border-radius: 28px;
  border: 1px solid rgba(89, 66, 33, 0.12);
  background: rgba(255, 250, 244, 0.88);
  box-shadow: 0 18px 50px rgba(58, 38, 14, 0.12);
  backdrop-filter: blur(18px);
  padding: 14px 16px 14px 20px;
}

.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  min-height: 28px;
  max-height: 220px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}

.composer textarea::placeholder {
  color: #998b7b;
}

.composer-actions {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

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

.composer-buttons {
  display: flex;
  gap: 10px;
}

.primary-button,
.ghost-button {
  padding: 10px 14px;
  border-radius: 14px;
  transition: transform 160ms ease, opacity 160ms ease, background 160ms ease;
}

.primary-button {
  color: #fffaf2;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.ghost-button {
  color: var(--text);
  background: rgba(17, 15, 11, 0.06);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.mobile-only {
  display: none;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 320px);
    transform: translateX(-100%);
    transition: transform 220ms ease;
    z-index: 20;
  }

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

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .topbar,
  .chat-stage,
  .composer-wrap {
    padding-left: 18px;
    padding-right: 18px;
  }

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

  .avatar {
    display: none;
  }

  .empty-state {
    min-height: calc(100vh - 220px);
  }
}

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

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
