:root {
  color-scheme: light;
  --bg: #f3f0e8;
  --surface: #fffdf8;
  --surface-2: #f8f4ec;
  --ink: #1d2421;
  --muted: #6e7771;
  --soft: #edf3ee;
  --line: #ded7c9;
  --line-strong: #cfc5b4;
  --accent: #176b5b;
  --accent-2: #9b5b35;
  --accent-ink: #ffffff;
  --danger: #9a3f2f;
  --shadow: 0 22px 60px rgba(50, 42, 29, 0.16);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(23, 107, 91, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(155, 91, 53, 0.08), transparent 38%),
    var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: wait;
  opacity: 0.58;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  outline: none;
  padding: 11px 12px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(23, 107, 91, 0.7);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.13);
  background: #ffffff;
}

textarea {
  resize: vertical;
}

[hidden] {
  display: none !important;
}

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

.login-panel {
  width: min(100%, 460px);
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(222, 215, 201, 0.88);
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
  padding: 30px;
}

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

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

.login-panel h1,
.app-header h1,
.memory-toolbar h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 {
  margin-top: 18px;
  font-size: clamp(28px, 5vw, 40px);
}

.login-copy {
  margin: 14px 0 22px;
  color: var(--muted);
  line-height: 1.75;
  overflow-wrap: anywhere;
}

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

.login-form label {
  color: var(--muted);
  font-size: 13px;
}

.token-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
}

.icon-button,
.ghost-button,
.primary-action,
.send-button,
.memory-form button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-action,
.send-button,
.memory-form button {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 24px rgba(23, 107, 91, 0.22);
  font-weight: 700;
}

.primary-action:hover,
.send-button:hover,
.memory-form button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(23, 107, 91, 0.24);
}

.icon-button,
.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

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

.login-message {
  min-height: 22px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.login-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.login-foot span,
.chip,
.memory-kind {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid rgba(222, 215, 201, 0.82);
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: 0 14px 40px rgba(50, 42, 29, 0.08);
  padding: 16px 18px;
}

.app-header h1 {
  font-size: clamp(22px, 3vw, 30px);
}

.health-text {
  margin: 6px 0 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mobile-tabs {
  display: none;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 390px);
  gap: 12px;
}

.chat-pane,
.memory-pane {
  min-height: 0;
  border: 1px solid rgba(222, 215, 201, 0.82);
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 14px 40px rgba(50, 42, 29, 0.08);
}

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

.chat-log {
  overflow: auto;
  padding: 22px;
}

.message {
  display: grid;
  gap: 8px;
  max-width: 860px;
  margin: 0 0 16px;
}

.message.user {
  justify-items: end;
  margin-left: auto;
}

.message-bubble {
  width: fit-content;
  max-width: min(100%, 860px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  padding: 13px 15px;
  white-space: pre-wrap;
  line-height: 1.72;
}

.message.user .message-bubble {
  border-color: rgba(23, 107, 91, 0.18);
  background: #eaf3ef;
}

.message.assistant .message-bubble {
  border-left: 4px solid var(--accent);
}

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

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 14px;
}

.composer textarea {
  min-height: 70px;
  max-height: 180px;
}

.memory-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.memory-toolbar {
  display: grid;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.memory-toolbar h2 {
  font-size: 22px;
}

.manual-memory {
  border-bottom: 1px solid var(--line);
  padding: 0;
}

.manual-memory summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
  padding: 14px 16px;
}

.memory-form {
  display: grid;
  gap: 10px;
  padding: 0 16px 16px;
}

.memory-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.memory-list {
  overflow: auto;
  padding: 12px;
}

.memory-item {
  position: relative;
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 13px;
  margin-bottom: 10px;
}

.memory-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.memory-title h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
}

.memory-item p {
  margin: 0;
  color: var(--ink);
  line-height: 1.62;
}

.memory-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.delete {
  justify-self: start;
  min-height: 30px;
  border-radius: 6px;
  background: transparent;
  color: var(--danger);
  padding: 0 2px;
}

.empty-state {
  display: grid;
  gap: 6px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
}

.empty-state strong {
  color: var(--ink);
}

@media (max-width: 980px) {
  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    padding: 10px;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: stretch;
  }

  .header-actions button {
    flex: 1;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .tab-button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
    color: var(--ink);
    font-weight: 700;
  }

  .tab-button.active {
    background: var(--accent);
    color: #fff;
  }

  .workspace {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .chat-pane,
  .memory-pane {
    height: 100%;
    min-height: 0;
  }

  .mobile-hidden {
    display: none;
  }
}

@media (max-width: 560px) {
  .login-view {
    padding: 12px;
    place-items: center;
    overflow-x: hidden;
  }

  .login-panel {
    width: min(100%, 360px);
    max-width: calc(100vw - 24px);
    padding: 22px;
  }

  .login-panel * {
    min-width: 0;
  }

  .login-panel h1 {
    font-size: 28px;
  }

  .token-row {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 6px;
  }

  .token-row input {
    min-width: 0;
  }

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

  .chat-log {
    padding: 14px;
  }

  .message-bubble {
    width: 100%;
  }
}
