:root {
  --paper: #f4f1eb;
  --paper-deep: #e9e3d8;
  --ink: #202822;
  --muted: #6f746e;
  --line: rgba(38, 48, 41, 0.14);
  --forest: #244a38;
  --forest-soft: #dce7df;
  --clay: #b9694a;
  --white: #fffdf9;
  --shadow: 0 24px 60px rgba(35, 43, 37, 0.12);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
html, body { height: 100%; min-height: 100%; margin: 0; }
body { overflow: hidden; background: var(--paper); }
button, input, textarea { font: inherit; }
button { color: inherit; }

[hidden] { display: none !important; }
.eyebrow { margin: 0 0 8px; font-size: 11px; letter-spacing: .18em; color: var(--muted); font-weight: 700; }
.muted { color: var(--muted); }

.login-shell {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(circle at 14% 20%, rgba(185, 105, 74, .16), transparent 28%),
    radial-gradient(circle at 86% 78%, rgba(36, 74, 56, .15), transparent 30%),
    var(--paper);
}
.login-card { width: min(440px, 100%); padding: 52px; background: rgba(255, 253, 249, .9); border: 1px solid var(--line); box-shadow: var(--shadow); }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: var(--forest); color: white; font-family: Georgia, serif; font-size: 24px; margin-bottom: 28px; }
.brand-mark.small { width: 38px; height: 38px; margin: 0; font-size: 18px; flex: 0 0 auto; }
.login-card h1 { margin: 0 0 10px; font-family: Georgia, "Songti SC", serif; font-size: clamp(30px, 6vw, 42px); font-weight: 500; }
.login-form { display: grid; gap: 10px; margin-top: 32px; }
label { font-size: 13px; font-weight: 700; }
input, textarea { width: 100%; border: 1px solid var(--line); background: var(--white); color: var(--ink); padding: 13px 14px; outline: none; border-radius: 4px; transition: border .2s, box-shadow .2s; }
input:focus, textarea:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(36, 74, 56, .1); }
textarea { resize: vertical; }

.primary-button, .secondary-button { border: 0; padding: 13px 18px; cursor: pointer; font-weight: 700; border-radius: 4px; }
.primary-button { background: var(--forest); color: white; }
.primary-button:hover { background: #193c2c; }
.primary-button.compact { padding-inline: 22px; }
.secondary-button { background: transparent; border: 1px solid var(--line); }
.form-error { min-height: 18px; margin: 2px 0 0; color: #a23e34; font-size: 13px; }

.app-shell { height: 100vh; height: 100dvh; min-height: 0; display: grid; grid-template-columns: 260px 1fr; }
.sidebar { background: #e7e2d8; border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 22px 16px; min-width: 0; z-index: 20; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 24px; }
.sidebar-brand strong { display: block; font-family: Georgia, "Songti SC", serif; font-weight: 600; }
.sidebar-brand span { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.new-chat-button { width: 100%; border: 1px solid var(--forest); background: var(--forest); color: white; padding: 11px 14px; display: flex; align-items: center; gap: 9px; cursor: pointer; border-radius: 4px; font-weight: 700; }
.new-chat-button:hover { background: #193c2c; }
.navigation { margin-top: 22px; overflow-y: auto; overflow-x: hidden; flex: 1 1 0; min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.nav-row { border: 0; background: transparent; width: 100%; min-width: 0; overflow: hidden; padding: 11px 10px; display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer; border-radius: 4px; color: #4f5650; }
.nav-row:hover, .nav-row.selected { background: rgba(255, 253, 249, .68); color: var(--forest); }
.nav-row.selected { font-weight: 700; box-shadow: inset 3px 0 var(--forest); }
.nav-row span:nth-child(2) { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-icon { opacity: .7; width: 18px; text-align: center; }
.nav-count { margin-left: auto; font-size: 11px; opacity: .65; }
.nav-section-title { display: flex; justify-content: space-between; align-items: center; padding: 28px 8px 8px; text-transform: uppercase; letter-spacing: .14em; font-size: 10px; font-weight: 800; color: var(--muted); }
.project-list { min-width: 0; display: grid; gap: 2px; }
.mini-button, .icon-button { border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; }
.mini-button { width: 27px; height: 27px; border-radius: 50%; font-size: 18px; }
.mini-button:hover { background: rgba(36, 74, 56, .1); }
.mini-button.filled { background: var(--forest); color: white; }
.sidebar-footer { border-top: 1px solid var(--line); padding-top: 14px; }
.primary-mode-notice { font-size: 12px; color: var(--forest); background: #e7efe9; border: 1px solid rgba(42, 80, 61, .18); padding: 9px 10px; margin-bottom: 8px; border-radius: 4px; }
.text-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 7px 5px; }
.api-notice { font-size: 12px; color: #8c4d34; background: #f2ddd3; padding: 9px 10px; margin-bottom: 8px; border-radius: 4px; }

.workspace { min-width: 0; min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); height: 100%; overflow: hidden; }
.chat-rail { border-right: 1px solid var(--line); background: rgba(255, 253, 249, .45); padding: 28px 20px; overflow: hidden; display: flex; flex-direction: column; }
.rail-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 5px 18px; }
.rail-actions { display: flex; align-items: center; gap: 7px; }
.mobile-only { display: none; }
.rail-header h2 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 21px; font-weight: 600; }
.chat-list { overflow-y: auto; overflow-x: hidden; display: grid; grid-auto-rows: max-content; align-content: start; gap: 3px; flex: 1 1 0; min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.chat-row { border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 16px 8px; text-align: left; cursor: pointer; }
.chat-row:hover { background: rgba(255, 253, 249, .7); }
.chat-row.selected { background: var(--white); box-shadow: inset 3px 0 var(--clay); padding-left: 13px; }
.chat-row strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.chat-row span { display: block; margin-top: 6px; font-size: 11px; color: var(--muted); }
.empty-rail { margin: auto; text-align: center; color: var(--muted); }
.empty-rail span { font-size: 24px; color: var(--clay); }

.conversation { min-width: 0; min-height: 0; position: relative; background: var(--white); overflow: hidden; }
.welcome-state { height: 100%; display: grid; place-content: center; text-align: center; padding: 24px; }
.welcome-orbit { width: 86px; height: 86px; margin: 0 auto 30px; border: 1px solid var(--forest); border-radius: 50%; display: grid; place-items: center; position: relative; color: var(--clay); font-size: 28px; }
.welcome-orbit::after { content: ""; position: absolute; inset: -12px 22px; border: 1px solid rgba(36, 74, 56, .25); border-radius: 50%; transform: rotate(45deg); }
.welcome-state h1 { font-family: Georgia, "Songti SC", serif; font-size: clamp(36px, 5vw, 64px); font-weight: 500; margin: 4px 0 14px; }
.welcome-state > p:last-child { color: var(--muted); }
.chat-view { height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.conversation-header { min-height: 92px; padding: 22px 32px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.conversation-header h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 25px; font-weight: 600; }
.sync-status { color: var(--muted); font-size: 12px; }
.message-list { min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 32px clamp(24px, 7vw, 100px); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.message { max-width: 780px; margin: 0 auto 30px; display: grid; grid-template-columns: 32px 1fr; gap: 14px; }
.message.user { grid-template-columns: 1fr; }
.message-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--forest); color: white; display: grid; place-items: center; font-size: 12px; }
.message-content { line-height: 1.72; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .message-content { justify-self: end; max-width: min(680px, 88%); background: var(--forest-soft); padding: 13px 16px; border-radius: 14px 14px 3px 14px; }
.message.generating .message-content::after { content: ""; display: inline-block; width: 7px; height: 1.1em; margin-left: 4px; background: var(--clay); vertical-align: text-bottom; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.composer-wrap { padding: 12px clamp(24px, 7vw, 100px) 22px; background: linear-gradient(transparent, var(--white) 22%); }
.composer { max-width: 780px; margin: auto; border: 1px solid var(--line); background: var(--white); display: grid; grid-template-columns: 42px minmax(0, 1fr) 42px; align-items: end; padding: 8px 9px; box-shadow: 0 12px 30px rgba(35, 43, 37, .08); border-radius: 7px; }
.composer:focus-within { border-color: var(--forest); }
.composer textarea { min-height: 42px; max-height: 180px; border: 0; box-shadow: none; resize: none; padding: 10px 4px; background: transparent; }
.attach-button { width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; color: var(--forest); font-size: 25px; line-height: 1; cursor: pointer; }
.attach-button:hover { background: var(--forest-soft); }
.attach-button:disabled { opacity: .4; cursor: not-allowed; }
.attachment-tray { grid-column: 1 / -1; display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; -webkit-overflow-scrolling: touch; }
.attachment-tray[hidden] { display: none; }
.attachment-chip { flex: 0 0 auto; max-width: min(280px, 76vw); display: grid; grid-template-columns: 28px minmax(0, 1fr) 26px; align-items: center; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.attachment-icon { width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; background: var(--forest-soft); color: var(--forest); font-size: 11px; font-weight: 700; }
.attachment-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; }
.attachment-remove { width: 26px; height: 26px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 20px; }
.send-button { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--clay); color: white; cursor: pointer; font-size: 22px; }
.send-button:disabled { opacity: .4; cursor: not-allowed; }
.composer-note { text-align: center; font-size: 10px; color: var(--muted); margin: 7px 0 0; }

.dialog-card { width: min(500px, calc(100% - 28px)); border: 1px solid var(--line); padding: 0; background: var(--white); box-shadow: var(--shadow); border-radius: 6px; }
.dialog-card::backdrop { background: rgba(21, 30, 24, .45); backdrop-filter: blur(3px); }
.dialog-card form { padding: 28px; display: grid; gap: 10px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.dialog-heading h2 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 28px; font-weight: 600; }
.dialog-close { width: 32px; height: 32px; font-size: 24px; color: var(--muted); }
.dialog-card label { margin-top: 7px; }
.dialog-card label span { color: var(--muted); font-weight: 400; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.dialog-hint { color: var(--muted); font-size: 12px; margin: 4px 0; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(400px, calc(100% - 48px)); background: var(--ink); color: white; padding: 13px 16px; border-radius: 4px; box-shadow: var(--shadow); }
.mobile-header { display: none; }
.mobile-actions { display: flex; align-items: center; }
.sidebar-backdrop { display: none; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 230px 1fr; }
  .workspace { grid-template-columns: 260px minmax(0, 1fr); }
}

@media (max-width: 760px) {
  body { overflow: hidden; }
  .app-shell { display: block; padding-top: calc(56px + env(safe-area-inset-top)); height: 100dvh; }
  .mobile-header { position: fixed; inset: 0 0 auto 0; height: calc(56px + env(safe-area-inset-top)); z-index: 15; display: grid; grid-template-columns: 80px minmax(0, 1fr) 80px; align-items: end; padding: env(safe-area-inset-top) 8px 8px; background: var(--paper); border-bottom: 1px solid var(--line); }
  .mobile-header .icon-button { width: 40px; height: 40px; font-size: 22px; }
  .mobile-header > strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; line-height: 40px; }
  .mobile-actions { justify-content: flex-end; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 90vw); padding-top: calc(22px + env(safe-area-inset-top)); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 19; width: 100%; height: 100%; border: 0; background: rgba(21, 30, 24, .4); }
  .workspace { grid-template-columns: 1fr; height: calc(100dvh - 56px - env(safe-area-inset-top)); }
  .chat-rail { position: fixed; z-index: 20; inset: calc(56px + env(safe-area-inset-top)) 0 0 auto; width: min(380px, 94vw); height: auto; display: flex; padding: 22px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--paper); transform: translateX(102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .chat-rail.open { transform: translateX(0); }
  .mobile-only { display: grid; }
  .conversation-header { min-height: 72px; padding: 14px 18px; }
  .conversation-header h1 { font-size: 20px; }
  .message-list { padding: 24px 16px; }
  .composer-wrap { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .composer-note { display: none; }
  .welcome-state h1 { font-size: 40px; }
  .login-card { padding: 36px 26px; }
  .dialog-card { max-height: calc(100dvh - 24px); overflow-y: auto; }
}
