:root {
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: #241b15;
  background: #fffaf5;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --orange: #ff6a00;
  --orange-dark: #d95000;
  --orange-soft: #fff0e4;
  --ink: #241b15;
  --muted: #75665d;
  --line: #eadfd7;
  --surface: #ffffff;
  --surface-soft: #fbf7f3;
  --shadow: 0 20px 70px rgba(72, 40, 18, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 106, 0, 0.12), transparent 30rem),
    #fffaf5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

[hidden] {
  display: none !important;
}

.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-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: min(100%, 460px);
  padding: 32px;
  border: 1px solid rgba(255, 106, 0, 0.18);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

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

.brand img {
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(255, 106, 0, 0.18);
}

.brand-large {
  gap: 14px;
}

.brand-name {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-note {
  color: var(--muted);
  font-size: 12px;
}

.login-copy {
  margin: 40px 0 28px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--orange-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-copy h1,
.conversation-header h1,
.pane-heading h2 {
  margin: 0;
  letter-spacing: -0.035em;
}

.login-copy h1 {
  font-size: clamp(30px, 8vw, 42px);
}

.login-copy > p:last-child {
  color: var(--muted);
  line-height: 1.7;
}

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

.login-form label {
  margin-top: 8px;
  color: #55483f;
  font-size: 13px;
  font-weight: 700;
}

.login-form input,
.composer-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.login-form input {
  min-height: 48px;
  padding: 0 14px;
  border-radius: 13px;
}

.login-form input:focus,
.composer-form textarea:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 4px rgba(255, 106, 0, 0.11);
}

.primary-button,
.send-button,
.new-button {
  border: 0;
  background: var(--orange);
  color: white;
  font-weight: 800;
}

.primary-button {
  min-height: 50px;
  margin-top: 14px;
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(255, 106, 0, 0.24);
}

.primary-button:hover,
.send-button:hover,
.new-button:hover {
  background: var(--orange-dark);
}

.status-line {
  min-height: 22px;
  margin: 14px 0 0;
  color: #a23d00;
  font-size: 13px;
  line-height: 1.5;
}

.security-note {
  display: flex;
  gap: 8px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.app-view {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: calc(64px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 245, 0.92);
  backdrop-filter: blur(18px);
}

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

.account-label {
  max-width: 180px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.text-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 36px;
  font-size: 21px;
}

.text-button {
  padding: 0 12px;
  font-size: 13px;
}

.workspace-grid {
  min-height: calc(100dvh - 64px - env(safe-area-inset-top));
  display: grid;
  grid-template-columns: minmax(230px, 290px) minmax(440px, 1fr) minmax(230px, 300px);
}

.sessions-pane,
.memory-pane,
.conversation-pane {
  min-width: 0;
}

.sessions-pane,
.memory-pane {
  padding: 26px 18px;
  background: rgba(251, 247, 243, 0.84);
}

.sessions-pane {
  border-right: 1px solid var(--line);
}

.memory-pane {
  border-left: 1px solid var(--line);
}

.pane-heading,
.conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pane-heading h2 {
  font-size: 22px;
}

.new-button {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 11px;
  font-size: 13px;
}

.session-list,
.memory-list {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.session-item {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 13px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.session-item:hover,
.session-item.is-active {
  border-color: rgba(255, 106, 0, 0.18);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(57, 35, 19, 0.06);
}

.session-item.is-active {
  border-color: rgba(255, 106, 0, 0.42);
}

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

.session-preview,
.session-time {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-pane {
  min-height: calc(100dvh - 64px - env(safe-area-inset-top));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface);
}

.conversation-header {
  min-height: 82px;
  padding: 17px 24px;
  border-bottom: 1px solid var(--line);
}

.conversation-header h1 {
  max-width: min(64vw, 620px);
  overflow: hidden;
  font-size: 22px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-badge {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 999px;
  background: #eef9f1;
  color: #26723a;
  font-size: 11px;
  font-weight: 800;
}

.sync-badge.is-working {
  background: var(--orange-soft);
  color: var(--orange-dark);
}

.sync-badge.is-error {
  background: #fff0ef;
  color: #a42a22;
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  padding: 24px clamp(18px, 5vw, 64px);
  scroll-behavior: smooth;
}

.message-empty,
.list-empty {
  padding: 28px 18px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
}

.message {
  width: min(88%, 780px);
  margin: 0 0 22px;
}

.message-user {
  margin-left: auto;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}

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

.message-role {
  color: var(--ink);
  font-weight: 800;
}

.message-body {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 5px 17px 17px 17px;
  background: var(--surface-soft);
  font-size: 14px;
  line-height: 1.72;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-user .message-body {
  border-color: rgba(255, 106, 0, 0.25);
  border-radius: 17px 5px 17px 17px;
  background: var(--orange-soft);
}

.composer-form {
  margin: 0 clamp(14px, 4vw, 54px) max(18px, env(safe-area-inset-bottom));
  padding: 10px 10px 9px 14px;
  border: 1px solid rgba(255, 106, 0, 0.48);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(68, 41, 22, 0.1);
}

.composer-form textarea {
  max-height: 220px;
  padding: 4px 3px;
  border: 0;
  resize: vertical;
  line-height: 1.55;
}

.composer-form textarea:focus {
  box-shadow: none;
}

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

.composer-status {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.send-button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 22px;
}

.memory-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.memory-scope {
  display: inline-block;
  margin-bottom: 7px;
  color: var(--orange-dark);
  font-size: 10px;
  font-weight: 800;
}

.memory-body {
  margin: 0;
  color: #4a3e36;
  font-size: 12px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.privacy-copy {
  margin: 22px 3px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.legal-links a {
  color: inherit;
  text-underline-offset: 2px;
}

@media (max-width: 1040px) {
  .workspace-grid {
    grid-template-columns: minmax(220px, 270px) minmax(0, 1fr);
  }

  .memory-pane {
    grid-column: 1 / -1;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .memory-list {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    min-height: calc(60px + env(safe-area-inset-top));
  }

  .account-label {
    display: none;
  }

  .workspace-grid {
    min-height: calc(100dvh - 60px - env(safe-area-inset-top));
    display: block;
  }

  .conversation-pane {
    min-height: calc(100dvh - 60px - env(safe-area-inset-top));
  }

  .sessions-pane {
    padding: 18px 14px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .session-list {
    display: flex;
    gap: 8px;
    margin-top: 13px;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
  }

  .session-item {
    flex: 0 0 190px;
    background: rgba(255, 255, 255, 0.72);
    scroll-snap-align: start;
  }

  .conversation-pane {
    min-height: 68dvh;
  }

  .conversation-header {
    min-height: 72px;
    padding: 14px 16px;
  }

  .conversation-header h1 {
    max-width: 66vw;
    font-size: 19px;
  }

  .message-list {
    min-height: 310px;
    padding: 20px 14px;
  }

  .message {
    width: 94%;
  }

  .composer-form {
    position: sticky;
    z-index: 10;
    bottom: max(8px, env(safe-area-inset-bottom));
    margin: 0 10px max(10px, env(safe-area-inset-bottom));
  }

  .memory-pane {
    padding: 24px 14px max(30px, env(safe-area-inset-bottom));
  }

  .memory-list {
    display: grid;
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 24px 20px;
    border-radius: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
