:root {
  --ink: #1f2430;
  --muted: #6c7382;
  --line: #dfe3ea;
  --canvas: #f4f1ec;
  --panel: #ffffff;
  --accent: #d96b5f;
  --accent-dark: #bf574d;
  --navy: #1f2b3f;
  --navy-soft: #27354d;
  --mist: #f1ece6;
  --gold: #b88a56;
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); }
button, input, textarea { font: inherit; }
button { cursor: pointer; border-radius: 8px; }
textarea { resize: vertical; }
.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: 244px; min-height: 100vh; padding: 24px 14px; background: linear-gradient(180deg, #1f2b3f 0%, #172033 100%); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; }
.brand { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; padding: 0 10px 28px; }
.brand-mark { width: 32px; height: 32px; display: grid; place-items: center; background: var(--accent); color: #fff; font-family: Georgia, serif; border-radius: 9px; }
.nav { display: grid; gap: 8px; }
.nav-item { width: 100%; border: 0; padding: 12px 13px; color: #b8c2d1; background: transparent; text-align: left; border-radius: 8px; font-size: 14px; transition: background .18s, color .18s, transform .18s; }
.nav-item span { display: inline-block; width: 26px; color: #aebbd0; font-size: 17px; vertical-align: -1px; }
.nav-item:hover, .nav-item.active { background: var(--navy-soft); color: #fff; transform: translateX(1px); }
.nav-item.active span { color: #f3a58c; }
.sidebar-bottom { margin-top: auto; }
.ai-note { margin: 16px 10px 0; padding: 15px 0 0; border-top: 1px solid #34435c; color: #aeb8c7; font-size: 12px; line-height: 1.6; }
.ai-note small { color: #8592a7; }
.main-content { flex: 1; min-width: 0; }
.view { display: none; max-width: 1180px; margin: 0 auto; padding: 40px 56px 64px; }
.view.active { display: block; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.eyebrow, .hero-kicker { color: var(--gold); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.topbar h1 { margin: 0; font-size: 30px; line-height: 1.1; }
.hero-panel, .section, .card, .chat-window, .notice { background: var(--panel); border: 1px solid var(--line); box-shadow: 0 10px 28px rgba(18, 26, 40, .06); }
.hero-panel { border-radius: 16px; padding: 28px; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, .8fr); gap: 20px; margin-bottom: 20px; }
.hero-copy h2 { margin: 0 0 12px; font-size: 30px; line-height: 1.15; max-width: 12ch; }
.hero-copy p { margin: 0; color: var(--muted); line-height: 1.7; max-width: 58ch; }
.hero-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.hero-side { padding: 18px; border-radius: 14px; display: grid; align-content: start; gap: 10px; }
.hero-side small { color: var(--muted); }
.hero-side strong { font-size: 22px; }
.hero-side p { margin: 0; color: var(--muted); line-height: 1.6; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 20px; }
.card { border-radius: 14px; padding: 18px; }
.card small { color: var(--muted); display: block; margin-bottom: 8px; }
.stat-number { font-size: 30px; font-weight: 700; }
.section { border-radius: 16px; padding: 22px; }
.section-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; }
.section-head h2 { margin: 0 0 4px; font-size: 22px; }
.section-head p { margin: 0; color: var(--muted); }
.memory-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.memory-card { display: grid; gap: 12px; min-height: 150px; }
.memory-date { color: var(--gold); font-size: 12px; }
.memory-card h3 { margin: 0 0 6px; font-size: 16px; }
.memory-card p { margin: 0; color: var(--muted); line-height: 1.65; }
.primary, .secondary { border: 1px solid transparent; padding: 11px 15px; border-radius: 8px; font-weight: 600; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-dark); }
.secondary { background: #f7f8fb; color: var(--ink); border-color: var(--line); }
.secondary:hover { background: #eef1f6; }
.notice { border-radius: 14px; padding: 16px 18px; color: var(--muted); margin-bottom: 16px; }
.chat-layout { display: grid; grid-template-columns: minmax(0, 1fr); }
.chat-window { border-radius: 16px; overflow: hidden; display: grid; min-height: 72vh; }
.chat-head { padding: 16px 18px; border-bottom: 1px solid var(--line); background: #fbfcfe; }
.chat-head h3 { margin: 0 0 4px; font-size: 18px; }
.status { color: #4e8a63; font-size: 13px; }
.messages { padding: 20px 18px; overflow-y: auto; display: grid; gap: 16px; background: linear-gradient(180deg, #fff 0%, #fcfbf8 100%); }
.message { max-width: min(640px, 88%); }
.message.user { justify-self: end; }
.message.ai { justify-self: start; }
.message-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.bubble { padding: 14px 16px; border-radius: 14px; line-height: 1.7; }
.message.user .bubble { background: #e8efff; color: var(--ink); }
.message.ai .bubble { background: #fff7ef; color: var(--ink); border: 1px solid #f0dfcf; }
.composer { padding: 16px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 12px; background: #fff; }
.composer textarea { min-height: 72px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.privacy-card { color: var(--muted); line-height: 1.8; }
.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(24, 31, 45, .48); }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: 0 22px 60px rgba(18, 26, 40, .22); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 22px; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); background: #f7f8fb; color: var(--muted); font-size: 22px; line-height: 1; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.memory-form, .profile-form { display: grid; gap: 14px; }
.profile-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.memory-form label, .profile-form label { display: grid; gap: 7px; color: var(--ink); font-size: 14px; font-weight: 600; }
.memory-form input, .memory-form textarea, .profile-form input, .profile-form textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; color: var(--ink); background: #fff; }
.memory-form textarea { min-height: 130px; line-height: 1.6; }
.profile-form textarea { min-height: 90px; line-height: 1.6; }
.profile-form .form-wide { grid-column: 1 / -1; }
.form-error { margin: -4px 0 0; color: #b43f36; font-size: 13px; line-height: 1.5; }
.memory-form input:focus, .memory-form textarea:focus, .profile-form input:focus, .profile-form textarea:focus { outline: 2px solid rgba(217, 107, 95, .22); border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
@media (max-width: 1080px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; min-height: auto; position: static; padding: 16px; }
  .brand { padding-bottom: 16px; }
  .nav, .sidebar-bottom { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; overflow: visible; }
  .nav-item { width: 100%; min-width: 0; white-space: normal; }
  .ai-note { display: none; }
  .sidebar-bottom { margin-top: 8px; padding-top: 8px; border-top: 1px solid #34435c; }
  .main-content { width: 100%; }
  .view { padding: 24px 20px 40px; }
  .hero-panel, .stats, .memory-list, .profile-grid { grid-template-columns: 1fr; }
  .topbar, .section-head { flex-direction: column; align-items: stretch; }
  .profile-form { grid-template-columns: 1fr; }
  .profile-form .form-wide { grid-column: auto; }
  .composer { grid-template-columns: 1fr; }
  .message { max-width: 100%; }
}

[hidden] { display: none !important; }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef1f4; }
.auth-panel { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 32px; box-shadow: 0 18px 50px rgba(18, 26, 40, .12); }
.auth-brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 20px; font-weight: 700; margin-bottom: 32px; }
.auth-panel h1 { margin: 0 0 8px; font-size: 28px; }
.auth-copy { margin: 0 0 24px; color: var(--muted); line-height: 1.6; }
.stack-form { display: grid; gap: 15px; }
.stack-form label { display: grid; gap: 7px; font-size: 14px; font-weight: 600; }
.stack-form input, .stack-form textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; color: var(--ink); background: #fff; }
.stack-form textarea { min-height: 100px; line-height: 1.6; }
.stack-form input:focus, .stack-form textarea:focus { outline: 2px solid rgba(217, 107, 95, .22); border-color: var(--accent); }
.stack-form button[type="submit"] { justify-self: start; }
.auth-switch { width: 100%; border: 0; background: transparent; color: var(--accent-dark); padding: 16px 0 0; }
.form-success { margin: 0; color: #31734b; font-size: 13px; }
.settings-section { max-width: 600px; }
.status-label { font-size: 20px; font-weight: 700; color: #31734b; }
.danger { border: 1px solid #d8aaa6; background: #fff; color: #a13e36; padding: 10px 14px; font-weight: 600; }
.danger:hover { background: #fff3f2; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 13px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-size: 12px; }
td small { display: block; color: var(--muted); margin-top: 4px; }
.compact { padding: 7px 9px; font-size: 12px; }
.audit-list { display: grid; gap: 12px; }
.audit-list .message { max-width: 100%; width: 100%; }
button:disabled { cursor: wait; opacity: .65; }
@media (max-width: 560px) { .auth-panel { padding: 24px 20px; } }
