:root {
  color-scheme: dark;
  --page: #22282e;
  --surface: #2b3239;
  --surface-raised: #343c45;
  --sidebar: #272e35;
  --line: #424b55;
  --ink: #f0f3f6;
  --muted: #b3bdc7;
  --blue: #315d87;
  --blue-hover: #3b6b98;
  --blue-soft: #2e4358;
  --danger: #e09292;
  font-family: -apple-system, BlinkMacSystemFont, "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--page); }
body { min-height: 100dvh; color: var(--ink); font-size: 14px; }
button, input, textarea, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid #79a7d1; outline-offset: 2px; }
.app[hidden], .login-screen[hidden] { display: none; }

.app { display: grid; width: 100%; min-height: 100dvh; grid-template-columns: 252px minmax(0, 1fr); background: var(--page); }
aside { z-index: 10; display: flex; min-width: 0; min-height: 100dvh; flex-direction: column; gap: 20px; padding: 20px 12px 16px; border-right: 1px solid var(--line); background: var(--sidebar); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 7px; }
.brand { display: flex; min-width: 0; align-items: center; gap: 10px; }
.brand-mark { display: grid; width: 34px; height: 34px; flex: none; place-items: center; border: 1px solid #536273; border-radius: 8px; background: var(--blue); color: #fff; font-weight: 750; }
.brand-name { color: var(--ink); font-size: 15px; font-weight: 700; }
.brand-sub { margin-top: 2px; color: var(--muted); font-size: 10px; }
nav { display: grid; gap: 4px; }
.nav-item { display: flex; width: 100%; min-height: 42px; align-items: center; gap: 12px; padding: 9px 12px; border: 0; border-radius: 7px; background: transparent; color: #d6dde4; text-align: left; transition: background .15s, color .15s; }
.nav-item:hover { background: #343d46; color: #fff; }
.nav-item.active { background: var(--blue-soft); color: #e7f1fb; box-shadow: inset 3px 0 var(--blue-hover); }
.nav-icon { display: inline-grid; width: 20px; flex: none; place-items: center; color: #c6d1dc; font-size: 16px; }
.section-label { margin: 0 10px 7px; color: #d0d7de; font-size: 12px; font-weight: 650; }
.recent-block { display: flex; min-height: 0; flex: 1; flex-direction: column; }
.recent-list { display: flex; min-height: 0; flex-direction: column; gap: 2px; overflow-y: auto; }
.recent-item { width: 100%; min-height: 40px; overflow: hidden; padding: 10px; border: 0; border-radius: 6px; background: transparent; color: #cbd3db; font-size: 12px; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.recent-item:hover { background: #343d46; color: #fff; }
.recent-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; }
.side-bottom { margin-top: auto; }
.privacy { padding: 12px 8px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; line-height: 1.7; }

.workspace { display: flex; min-width: 0; min-height: 100dvh; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 2; display: flex; min-height: 58px; flex: none; align-items: center; gap: 13px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--page); }
.top-title { min-width: 0; margin-right: auto; color: var(--ink); font-size: 14px; font-weight: 650; }
.model-state { display: flex; flex: none; align-items: center; gap: 7px; color: #c5ced7; font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c2a66c; }
.dot.ready { background: #78a9d0; }
.dot.error { background: var(--danger); }
.icon-button, .mobile-menu, .mobile-close { display: inline-grid; width: 38px; height: 38px; flex: none; place-items: center; padding: 0; border: 0; border-radius: 7px; background: transparent; color: #d1d9e0; font-size: 18px; }
.icon-button:hover, .mobile-menu:hover, .mobile-close:hover { background: #3a444e; color: #fff; }
.mobile-menu, .mobile-close, .scrim { display: none; }
.content { display: flex; width: min(100%, 1100px); min-width: 0; min-height: 0; flex: 1; flex-direction: column; margin: 0 auto; padding: 20px 32px max(16px, env(safe-area-inset-bottom)); }
.view { display: none; min-height: 0; flex: 1; }
.view.active { display: flex; flex-direction: column; }

.welcome { width: min(740px, 100%); margin: auto auto 22px; padding: 16px 0 8px; }
.eyebrow { margin-bottom: 10px; color: #a8c4df; font-size: 10px; font-weight: 700; }
.welcome h1 { margin: 0 0 12px; color: var(--ink); font-size: 26px; font-weight: 650; line-height: 1.45; }
.welcome p { max-width: 600px; margin: 0; color: #c1cad3; font-size: 13px; line-height: 1.8; }
.prompt-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 19px 0 4px; }
.chip { min-height: 38px; padding: 8px 12px; border: 1px solid #4c5865; border-radius: 6px; background: #303840; color: #e0e6ec; font-size: 12px; transition: background .15s, border-color .15s; }
.chip:hover { border-color: #6d8aa8; background: #384553; }
.messages { display: flex; width: min(800px, 100%); min-height: 0; flex: 1; flex-direction: column; gap: 20px; overflow-y: auto; overscroll-behavior: contain; margin: 0 auto; padding: 4px 0 20px; scrollbar-color: #5b6671 transparent; }
.message { max-width: 96%; overflow-wrap: anywhere; color: #e7ebef; font-size: 15px; line-height: 1.8; white-space: pre-wrap; }
.message.user { align-self: flex-end; max-width: min(82%, 680px); padding: 11px 15px; border: 1px solid #48627c; border-radius: 9px 9px 3px 9px; background: #30465b; color: #eff5fb; }
.message.assistant { align-self: flex-start; width: 100%; padding: 14px 16px; border: 1px solid #46505a; border-radius: 7px; background: var(--surface); }
.message-label { margin-bottom: 6px; color: #c2ccd5; font-size: 11px; font-weight: 650; }
.message-body { color: #e7ebef; line-height: 1.8; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-body a { color: #9fc3e5; text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; }
.source-details { width: fit-content; max-width: 100%; margin-top: 14px; color: #c2ccd5; font-size: 12px; }
.source-details summary { width: fit-content; max-width: 100%; padding: 7px 11px; border: 1px solid #4c5865; border-radius: 6px; background: #303840; color: #e0e6ec; cursor: pointer; list-style-position: inside; }
.source-details summary:hover { border-color: #6d8aa8; background: #384553; }
.source-list { display: grid; gap: 10px; margin: 9px 0 0; padding: 0 0 0 29px; }
.source-list li { padding-left: 2px; color: var(--muted); }
.source-list .source-title, .source-list .source-url { display: block; width: fit-content; max-width: 100%; }
.source-list .source-title { color: #d9e8f6; font-size: 12px; }
.source-list .source-url { margin-top: 3px; color: #a8c4df; font-size: 10px; }
.composer-wrap { position: sticky; bottom: 0; width: min(800px, 100%); flex: none; margin: 0 auto; padding-top: 8px; background: linear-gradient(180deg, transparent, var(--page) 16%); }
.composer { display: flex; min-height: 64px; align-items: center; gap: 10px; padding: 8px 9px 8px 17px; border: 1px solid #56616d; border-radius: 8px; background: #30373f; transition: border-color .15s, background .15s; }
.composer:focus-within { border-color: #7598ba; background: #343d46; }
.composer textarea { display: block; width: 100%; min-width: 0; min-height: 42px; max-height: 180px; flex: 1; padding: 9px 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; line-height: 1.5; }
.composer textarea::placeholder { color: #b0bbc5; }
.send { display: inline-grid; min-width: 44px; min-height: 44px; flex: none; place-items: center; padding: 8px 13px; border: 0; border-radius: 6px; background: var(--blue); color: #fff; font-size: 14px; font-weight: 650; line-height: 1.2; transition: background .15s, opacity .15s; }
.send:hover { background: var(--blue-hover); }
.send:disabled { cursor: wait; opacity: .58; }
.notice { margin-top: 7px; color: #aeb8c2; font-size: 10px; line-height: 1.5; text-align: center; }

.view-heading { display: flex; width: min(850px, 100%); align-items: flex-start; justify-content: space-between; gap: 16px; margin: 4px auto 18px; }
.view-heading h1 { margin: 0 0 6px; color: var(--ink); font-size: 21px; font-weight: 650; }
.view-heading p { margin: 0; color: #c0c9d2; font-size: 12px; line-height: 1.7; }
.plain-button { min-height: 38px; padding: 8px 13px; border: 1px solid #4b5661; border-radius: 6px; background: #333b44; color: #e5eaf0; font-size: 12px; }
.plain-button:hover { border-color: #7189a1; background: #3a4653; }
.memory-form { display: flex; width: min(850px, 100%); gap: 8px; margin: 0 auto 14px; }
.memory-form input { min-width: 0; min-height: 46px; flex: 1; padding: 10px 13px; border: 1px solid #515d69; border-radius: 6px; background: var(--surface); color: var(--ink); }
.memory-form input::placeholder { color: #aeb8c2; }
.memory-list, .history-list, .settings-list { display: flex; width: min(850px, 100%); min-height: 0; flex-direction: column; gap: 8px; overflow: auto; margin: 0 auto; padding: 2px; }
.memory-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 14px; padding: 14px; border: 1px solid #46515c; border-radius: 6px; background: var(--surface); }
.memory-text { min-width: 0; color: #e8edf1; line-height: 1.7; overflow-wrap: anywhere; }
.memory-date { grid-column: 1; color: #b3bdc7; font-size: 11px; }
.memory-actions { display: flex; grid-row: 1 / span 2; grid-column: 2; align-items: center; gap: 6px; }
.memory-action { min-width: 56px; min-height: 44px; padding: 7px 10px; border: 1px solid #4b5661; border-radius: 6px; background: #333b44; color: #e5eaf0; font-size: 11px; }
.memory-action:hover { background: #3a4653; }
.memory-action.danger-action { color: #efc2c2; }
.memory-action.danger-action:hover { border-color: #986d6d; background: #493b3d; }
.empty-state { padding: 24px 12px; color: #c0c9d2; font-size: 13px; }
.history-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 16px; padding: 14px; border: 1px solid #46515c; border-radius: 6px; background: var(--surface); }
.history-title { width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; color: #edf1f5; font-size: 14px; font-weight: 650; line-height: 1.55; text-align: left; overflow-wrap: anywhere; }
.history-title:hover { color: #b9d3eb; text-decoration: underline; text-underline-offset: 3px; }
.history-time { grid-column: 2; grid-row: 1; align-self: center; color: #b3bdc7; font-size: 11px; white-space: nowrap; }
.history-text { grid-column: 1; color: #c2ccd5; font-size: 12px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.delete-chat { grid-column: 2; grid-row: 2; align-self: end; min-height: 36px; padding: 7px 10px; border: 0; border-radius: 6px; background: transparent; color: #c7d0d8; font-size: 11px; }
.delete-chat:hover { background: #41464b; color: var(--danger); }
.settings-row { display: grid; gap: 9px; padding: 15px; border: 1px solid #46515c; border-radius: 6px; background: var(--surface); }
.settings-row label { color: #eef2f5; font-size: 13px; font-weight: 700; }
.settings-row p { margin: 0; color: #c0c9d2; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.settings-row select { width: min(360px, 100%); min-height: 42px; padding: 8px 12px; border: 1px solid #56616d; border-radius: 6px; background: var(--surface-raised); color: var(--ink); }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.toast { position: fixed; z-index: 30; bottom: max(22px, env(safe-area-inset-bottom)); left: 50%; max-width: calc(100vw - 28px); padding: 10px 15px; transform: translateX(-50%); border: 1px solid #59636d; border-radius: 6px; background: #3a424a; color: #fff; font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .18s; }
.toast.show { opacity: 1; }
.login-screen { display: grid; min-height: 100dvh; place-items: center; padding: 24px; background: var(--page); }
.login-panel { width: min(390px, 100%); padding: 26px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.login-panel h1 { margin: 20px 0 6px; color: var(--ink); font-size: 20px; }
.login-panel p { margin: 0 0 20px; color: #c0c9d2; font-size: 12px; line-height: 1.75; }
.login-panel label { display: block; margin: 13px 0 6px; color: #e3e8ed; font-size: 12px; font-weight: 700; }
.login-panel input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #56616d; border-radius: 6px; background: var(--surface-raised); color: var(--ink); }
.login-panel .send { width: 100%; min-height: 44px; margin-top: 17px; }
.login-error { min-height: 20px; margin-top: 10px; color: var(--danger); font-size: 12px; }

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  aside { position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); min-height: 100dvh; padding: calc(18px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom)); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 12px 0 30px rgba(0, 0, 0, .3); }
  .app.menu-open aside { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; display: block; border: 0; background: rgba(12, 17, 22, .6); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 8; }
  .app.menu-open .scrim { opacity: 1; pointer-events: auto; }
  .mobile-menu, .mobile-close { display: inline-grid; }
  .mobile-menu { width: 40px; height: 40px; margin-left: -7px; font-size: 20px; }
  .mobile-close { width: 38px; height: 38px; }
  .topbar { min-height: calc(56px + env(safe-area-inset-top)); gap: 8px; padding: env(safe-area-inset-top) 14px 0; }
  .top-title { font-size: 13px; }
  .model-state { gap: 6px; font-size: 11px; }
  .content { width: 100%; min-height: calc(100dvh - 56px - env(safe-area-inset-top)); padding: 12px 20px max(14px, env(safe-area-inset-bottom)); }
  .messages { gap: 15px; padding-bottom: 10px; }
  .message { max-width: 98%; font-size: 15px; }
  .message.user { max-width: 90%; }
  .composer-wrap { width: 100%; padding-top: 6px; }
  .composer { min-height: 60px; }
  .composer textarea { min-height: 42px; max-height: min(180px, 30dvh); font-size: 16px; }
  .notice { max-width: 95%; margin: 7px auto 0; font-size: 10px; }
  .view-heading { margin-bottom: 15px; }
}

@media (max-width: 430px) {
  .content { padding-right: 14px; padding-left: 14px; }
  .topbar { gap: 6px; padding-right: 10px; padding-left: 10px; }
  .top-title { font-size: 12px; }
  .model-state { gap: 5px; font-size: 10px; }
  .model-state .dot { width: 7px; height: 7px; }
  .view-heading { gap: 8px; }
  .view-heading h1 { font-size: 19px; }
  .view-heading p { font-size: 11px; }
  .view-heading .settings-actions { justify-content: flex-end; }
  .plain-button { min-height: 38px; padding: 7px 10px; font-size: 11px; }
  .history-row { gap: 5px 8px; padding: 12px; }
  .memory-row { grid-template-columns: minmax(0, 1fr); }
  .memory-actions { grid-row: auto; grid-column: 1; }
  .memory-date { grid-column: 1; }
  .history-time { font-size: 10px; }
}

@media (max-width: 350px) {
  .model-state { font-size: 9px; }
  .content { padding-right: 11px; padding-left: 11px; }
  .composer { gap: 6px; padding-right: 7px; padding-left: 10px; }
  .send { min-width: 42px; padding-right: 9px; padding-left: 9px; }
  .history-row { grid-template-columns: minmax(0, 1fr); }
  .history-time, .history-text, .delete-chat { grid-column: 1; grid-row: auto; }
  .history-time { white-space: normal; }
  .delete-chat { justify-self: start; }
  .view-heading { flex-direction: column; }
}

@media (max-height: 620px) and (max-width: 820px) {
  .welcome { margin: 8px auto 12px; padding-top: 0; }
  .welcome h1 { font-size: 20px; }
  .welcome p { line-height: 1.55; }
  .prompt-chips { display: none; }
}

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