:root {
  color-scheme: light;
  --bg: #f3efe7;
  --surface: rgba(255, 253, 248, .9);
  --text: #25231f;
  --muted: #777168;
  --line: rgba(48, 43, 36, .12);
  --accent: #afbdaf;
  --accent-text: #20241f;
  --assistant: #fffdf8;
  --shadow: 0 18px 60px rgba(49, 42, 31, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171a18;
  --surface: rgba(31, 35, 32, .94);
  --text: #eeeae1;
  --muted: #aaa49a;
  --line: rgba(255, 255, 255, .1);
  --accent: #91a696;
  --accent-text: #101612;
  --assistant: #252a27;
  --shadow: 0 18px 60px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[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: 24px;
  background:
    radial-gradient(circle at 15% 12%, rgba(151, 177, 153, .24), transparent 34%),
    radial-gradient(circle at 88% 86%, rgba(190, 160, 121, .18), transparent 31%), var(--bg);
}
.login-card { width: min(100%, 420px); padding: 42px; border: 1px solid var(--line); border-radius: 28px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-family: Georgia, serif; font-size: 24px; }
.eyebrow { margin: 30px 0 8px; color: var(--muted); font-size: 11px; letter-spacing: .2em; }
.login-card h1 { margin: 0; font-family: Georgia, "Noto Serif SC", serif; font-size: clamp(34px, 9vw, 48px); font-weight: 500; }
.login-copy { margin: 12px 0 34px; color: var(--muted); }
.login-card label { display: block; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.password-row { display: flex; gap: 8px; }
.password-row input { min-width: 0; flex: 1; border: 1px solid var(--line); border-radius: 13px; padding: 13px 14px; background: var(--bg); color: var(--text); outline: none; }
.password-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.password-row button { border: 0; border-radius: 13px; padding: 0 18px; background: var(--accent); color: var(--accent-text); }
.form-error { min-height: 20px; margin: 10px 0 0; color: #b34b42; font-size: 13px; }

.chat-view { position: relative; height: 100dvh; display: grid; grid-template-rows: auto auto 1fr auto auto auto; max-width: 900px; margin: 0 auto; background: var(--bg); }
.topbar { display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; align-items: center; padding: max(14px, env(safe-area-inset-top)) 18px 12px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); z-index: 2; }
.profile-button { grid-column: 2; min-width: 0; max-width: 100%; justify-self: center; padding: 0 8px; border: 0; background: transparent; color: var(--text); text-align: center; }
.profile-button h1 { overflow: hidden; margin: 0; font-family: Georgia, "Noto Serif SC", serif; font-size: 18px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.menu-button { grid-column: 3; display: grid; width: 38px; height: 38px; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--text); font-size: 27px; line-height: 1; }
.menu-button:hover, .menu-button[aria-expanded="true"] { background: color-mix(in srgb, var(--accent) 20%, transparent); }
.app-menu, .profile-panel, .quota-panel { position: absolute; top: calc(max(14px, env(safe-area-inset-top)) + 54px); right: 12px; z-index: 7; width: min(300px, calc(100% - 24px)); padding: 9px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.app-menu { display: grid; gap: 2px; }
.app-menu-item { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; min-height: 42px; padding: 7px 9px; border: 0; border-radius: 11px; background: transparent; color: var(--text); text-align: left; }
.app-menu-item:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.app-menu-item > span:first-child { color: var(--muted); font-size: 19px; text-align: center; }
.app-menu-item small { color: var(--muted); font-size: 11px; }
.profile-panel { padding: 16px; text-align: center; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; text-align: left; }
.panel-head button { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--text); font-size: 22px; }
.profile-panel label { display: block; margin: 4px 0 6px; color: var(--muted); text-align: left; font-size: 12px; }
.profile-panel input[type="text"] { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); color: var(--text); outline: none; }
.profile-panel input[type="text"]:focus { border-color: var(--accent); }
.profile-save { width: 100%; margin-top: 10px; padding: 10px; border: 0; border-radius: 11px; background: var(--accent); color: var(--accent-text); }
.profile-error { min-height: 16px; margin: 7px 0 0; color: #b34b42; font-size: 11px; }
.quota-panel { width: min(330px, calc(100% - 24px)); max-height: calc(100dvh - 90px); overflow-y: auto; padding: 16px; }
.panel-head-actions { display: flex; gap: 3px; }
.quota-cards { display: grid; gap: 9px; }
.quota-card { padding: 11px 12px; border: 1px solid var(--line); border-radius: 13px; background: color-mix(in srgb, var(--bg) 72%, transparent); }
.quota-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.quota-card-head strong { font-size: 13px; font-weight: 600; }
.quota-card-head span { color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.quota-card progress { display: block; width: 100%; height: 6px; margin: 9px 0 7px; overflow: hidden; border: 0; border-radius: 999px; background: color-mix(in srgb, var(--accent) 22%, transparent); appearance: none; }
.quota-card progress::-webkit-progress-bar { border-radius: 999px; background: color-mix(in srgb, var(--accent) 22%, transparent); }
.quota-card progress::-webkit-progress-value { border-radius: 999px; background: var(--accent); }
.quota-card progress::-moz-progress-bar { border-radius: 999px; background: var(--accent); }
.quota-card small, .quota-updated { color: var(--muted); font-size: 10px; }
.quota-empty { padding: 22px 8px; color: var(--muted); text-align: center; font-size: 12px; }
.quota-updated { min-height: 14px; margin: 9px 2px 0; text-align: right; }
.messages { min-height: 0; overflow-y: auto; padding: 16px max(16px, calc((100% - 760px)/2)) 12px; scroll-behavior: smooth; }
.scroll-latest-button { position: absolute; right: max(18px, calc((100% - 760px)/2 + 18px)); z-index: 5; display: grid; width: 40px; height: 40px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: color-mix(in srgb, var(--surface) 96%, transparent); color: var(--text); box-shadow: var(--shadow); backdrop-filter: blur(12px); transition: transform .16s ease; }
.scroll-latest-button[hidden] { display: none; }
.scroll-latest-button:hover { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.scroll-latest-button:active { transform: translateY(1px); }
.scroll-latest-button svg { width: 19px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.date-separator { width: fit-content; margin: 2px auto 10px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--muted); font-size: 11px; }
.history-panel { position: absolute; top: calc(max(14px, env(safe-area-inset-top)) + 54px); right: 12px; z-index: 6; width: min(360px, calc(100% - 24px)); max-height: calc(100dvh - 130px); overflow-y: auto; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.history-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.history-panel-head button { width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent; color: var(--text); font-size: 22px; }
.history-panel label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.history-panel input { min-width: 0; padding: 10px 11px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); color: var(--text); outline: none; }
.history-search-form { display: flex; gap: 7px; margin-top: 12px; }
.history-search-form input { flex: 1; }
.history-search-form button, .history-mode-bar button { border: 0; border-radius: 11px; padding: 0 13px; background: var(--accent); color: var(--accent-text); }
.history-results { display: grid; gap: 8px; margin-top: 12px; }
.history-result { padding: 10px 11px; border: 1px solid var(--line); border-radius: 12px; background: transparent; color: var(--text); text-align: left; }
.history-result small { display: block; margin-bottom: 4px; color: var(--muted); }
.history-result span { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.history-empty { padding: 18px 4px; color: var(--muted); text-align: center; font-size: 13px; }
.history-mode-bar { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 38px; padding: 5px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.history-mode-bar button { min-height: 28px; }
.message.target-highlight .bubble, .message.target-highlight .message-image { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }
.empty { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty span { display: block; margin-bottom: 8px; font-family: Georgia, serif; color: var(--text); font-size: 28px; }
.message { display: flex; flex-direction: column; align-items: flex-start; margin: 0 0 8px; animation: rise .25s ease-out; }
.message.user { align-items: flex-end; }
.message.assistant + .message.assistant, .message.user + .message.user { margin-top: -6px; }
.bubble { position: relative; display: flow-root; max-width: min(82%, 620px); padding: 6px 10px 5px; border: 0; border-radius: 5px 18px 18px 18px; background: var(--assistant); line-height: 1.48; overflow-wrap: anywhere; box-shadow: 0 3px 14px rgba(40,35,29,.035); }
.user .bubble { padding: 6px 10px 5px; border-radius: 18px 5px 18px 18px; background: var(--accent); color: var(--accent-text); }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p, .bubble ul, .bubble ol, .bubble pre { margin: .28em 0; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.bubble pre { overflow-x: auto; padding: 12px; border-radius: 10px; background: rgba(0,0,0,.12); }
.message-image-shell { position: relative; width: fit-content; max-width: 100%; margin-bottom: 4px; }
.image-only .message-image-shell { margin-bottom: 0; }
.message-image { display: block; width: auto; max-width: min(100%, 120px); max-height: 150px; margin: 0; border-radius: 10px; object-fit: contain; background: rgba(0,0,0,.08); cursor: zoom-in; }
.expired-image { display: grid; width: 120px; min-height: 82px; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--surface) 78%, transparent); color: var(--muted); font-size: 11px; }
.message .time.image-time { position: absolute; right: 5px; bottom: 5px; float: none; margin: 0; padding: 2px 5px; border-radius: 999px; background: rgba(20, 20, 19, .5); color: #fff; font-size: 9px; line-height: 1.1; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.message-image:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.image-lightbox { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: max(46px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); background: rgba(15, 16, 15, .88); backdrop-filter: blur(8px); }
.image-lightbox img { display: block; max-width: 100%; max-height: 100%; border-radius: 10px; object-fit: contain; box-shadow: 0 18px 70px rgba(0,0,0,.35); }
.image-lightbox button { position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px; display: grid; width: 38px; height: 38px; place-items: center; padding: 0; border: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 27px; line-height: 1; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.bubble a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.tool-module { margin: 0 0 11px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; background: color-mix(in srgb, var(--accent) 7%, transparent); font-size: 12px; }
.tool-module summary { color: var(--muted); cursor: pointer; list-style: none; user-select: none; }
.tool-module summary::-webkit-details-marker { display: none; }
.tool-module summary::after { content: '⌄'; float: right; margin-left: 12px; }
.tool-module[open] summary::after { transform: rotate(180deg); }
.tool-module ul { margin: 8px 0 0; padding-left: 18px; }
.tool-module li + li { margin-top: 5px; }
.tool-module p { margin: 8px 0 0; color: var(--muted); }
.thinking-module { width: min(82%, 620px); box-sizing: border-box; margin: 0 0 5px; padding: 2px 10px 4px; border: 0; background: transparent; border-radius: 0; font-size: 12px; color: var(--muted); }
.thinking-module summary { display: flex; width: fit-content; align-items: center; gap: 7px; cursor: pointer; list-style: none; user-select: none; }
.thinking-module summary::-webkit-details-marker { display: none; }
.thinking-module summary::after { content: '›'; font-size: 18px; line-height: .8; transform: translateY(-1px); }
.thinking-module[open] summary::after { content: '⌄'; font-size: 14px; transform: translateY(-1px); }
.thinking-content { margin: 8px 0 2px 5px; padding-left: 11px; border-left: 2px solid color-mix(in srgb, var(--muted) 32%, transparent); line-height: 1.55; }
.thinking-content > :first-child { margin-top: 0; }
.thinking-content > :last-child { margin-bottom: 0; }
.bubble :not(pre) > code { padding: .12em .35em; border-radius: 5px; background: rgba(0,0,0,.09); }
.time { float: right; margin: .45em 0 0 .8em; color: var(--muted); font-size: 10px; line-height: 1; white-space: nowrap; }
.user .time { color: color-mix(in srgb, var(--accent-text) 55%, transparent); }
.message.pending .bubble { border-style: dashed; }
.message.pending .bubble, .message.pending .message-image-shell { -webkit-touch-callout: none; user-select: none; }
.pending-message-menu { position: fixed; z-index: 30; display: flex; overflow: hidden; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.pending-message-menu[hidden] { display: none; }
.pending-message-menu button { min-width: 58px; padding: 8px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 13px; }
.pending-message-menu button + button { border-left: 1px solid var(--line); border-radius: 0 8px 8px 0; color: #a84e47; }
.pending-message-menu button:hover, .pending-message-menu button:focus-visible { background: color-mix(in srgb, var(--accent) 12%, transparent); outline: none; }
.typing::after { content: ""; display: inline-block; width: 6px; height: 1em; margin-left: 3px; vertical-align: -.15em; background: var(--accent); animation: blink .8s steps(1) infinite; }
.status { min-height: 22px; padding: 0 18px; color: var(--muted); text-align: center; font-size: 12px; }
.status:empty { min-height: 0; padding: 0; }
.pending-bar { padding: 7px 18px; background: color-mix(in srgb, var(--accent) 9%, var(--surface)); color: var(--muted); text-align: center; font-size: 12px; }
.system-notice { width: fit-content; max-width: 90%; margin: 6px auto 18px; padding: 7px 12px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--muted); text-align: center; font-size: 12px; }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 10px max(14px, calc((100% - 760px)/2)) max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.composer .attach-button { flex: 0 0 42px; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--text); font-size: 25px; font-weight: 300; }
.message.uploading .message-image { opacity: .68; }
.image-upload-state { position: absolute; inset: 0; display: grid; place-items: center; padding: 8px; border: 0; border-radius: 10px; background: rgba(24, 25, 23, .32); color: #fff; text-align: center; font-size: 10px; line-height: 1.25; }
button.image-upload-state { width: 100%; cursor: pointer; }
.composer textarea { flex: 1; max-height: 150px; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 11px 16px; background: var(--bg); color: var(--text); outline: none; line-height: 1.45; }
.composer textarea:focus { border-color: var(--accent); }
.composer > #send-button { flex: 0 0 44px; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-text); }
.composer button:disabled { opacity: .45; cursor: default; }
.composer svg { width: 21px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }
@keyframes blink { 50% { opacity: 0; } }
@media (min-width: 900px) { .chat-view { height: min(92dvh, 900px); margin-top: 4dvh; border: 1px solid var(--line); border-radius: 24px; overflow: hidden; box-shadow: var(--shadow); } }
@media (max-width: 480px) { .login-card { padding: 30px 24px; } .bubble { max-width: 88%; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; } }
