:root {
  --ink: #203552;
  --muted: #687b94;
  --paper: #f5f7fc;
  --line: #dde5f1;
  --green: #326be7;
  --white: #fff;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.6;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; }
button:disabled { opacity: .5; cursor: wait; }
button:hover:not(:disabled) { background-color: #eaf0ff; }
button:focus-visible, a:focus-visible { outline: 2px solid #5184ef; outline-offset: 3px; }
a { color: var(--ink); }
[hidden] { display: none !important; }
#app { display: grid; grid-template-columns: 176px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  background: #162d4a;
  border-right: 1px solid #25405f;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; color: #f5f8ff; text-decoration: none; font-size: 16px; font-weight: 600; padding: 0 10px; }
nav { margin-top: 28px; }
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  color: #b0c4e0;
  text-align: left;
  border-radius: 10px;
  padding: 11px 10px;
  margin: 4px 0;
}
.nav.active { background: #3159a1; color: #fff; box-shadow: 0 5px 16px #07182b33; }
.nav .nav-label { flex: 1; font-size: 13px; }
#unread:not(:empty) { background: #ffb68e; color: #462312; border-radius: 8px; padding: 0 5px; font-size: 10px; }
.sidebar-bottom { margin-top: auto; padding: 0 10px; font-size: 11px; color: #9cb4d1; }
.status-dot { display: inline-block; height: 6px; width: 6px; background: #5cddbd; border-radius: 50%; margin-right: 6px; }
main { width: 100%; max-width: 1040px; padding: 28px 40px 48px; min-width: 0; }
header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
h1 { font-size: 18px; font-weight: 600; margin: 0; }
h2 { font-weight: 600; font-size: 14px; margin: 0 0 14px; }
h3 { font-size: 14px; margin: 0 0 6px; font-weight: 600; }
.subtle { background: #fff; color: var(--ink); border: 1px solid var(--line); padding: 6px 11px; border-radius: 8px; font-size: 12px; }
.primary { background: #326be7; color: #fff; border-radius: 9px; padding: 8px 15px; font-size: 13px; box-shadow: 0 3px 8px #326be72b; }
.primary:hover:not(:disabled) { background: #245bd1; box-shadow: 0 5px 14px #326be740; }
.muted, .small { color: var(--muted); font-size: 12px; }
.eyebrow { color: var(--muted); font-size: 11px; margin: 0 0 8px; }
.conversation { display: flex; flex-direction: column; gap: 20px; margin: 0 0 24px; }
.conversation:empty { display: none; }
.message { max-width: 94%; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { align-self: flex-end; background: #e3ecff; padding: 12px 16px; border-radius: 14px 14px 4px 14px; }
.message.assistant { align-self: flex-start; padding: 8px 0; }
.message-meta { font-size: 11px; color: var(--muted); display: flex; gap: 12px; margin-bottom: 5px; }
#composer { border: 1px solid #d2dff3; border-radius: 16px; background: #fff; overflow: hidden; box-shadow: 0 8px 30px #254c8e08; }
#composer:focus-within { border-color: #6893ed; box-shadow: 0 0 0 4px #326be712, 0 12px 35px #254c8e0e; }
textarea { width: 100%; resize: vertical; min-height: 100px; border: 0; background: none; padding: 14px 16px 8px; color: var(--ink); outline: 0; }
textarea::placeholder { color: #969ba2; }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; gap: 12px; }
.file-button { font-size: 12px; color: var(--muted); cursor: pointer; margin: 0; display: inline-block; }
#attachment-name { font-size: 11px; margin-left: 8px; overflow-wrap: anywhere; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 12px 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.card-grid .card { margin: 0; }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 6px; background: #edf0f8; color: #617291; margin-bottom: 8px; }
.badge.running { background: #e5edff; color: #345faf; }
.badge.waiting { background: #fff0da; color: #8a5c19; }
.badge.done { background: #dcf5ed; color: #23705b; }
.card p { margin: 4px 0 12px; overflow-wrap: anywhere; }
.card .actions, .attention-card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.section-toolbar { display: flex; gap: 10px; margin: 0 0 16px; }
.section-toolbar input { flex: 1; min-width: 0; }
.section-toolbar select { width: 110px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin: 28px 0 12px; }
.section-heading h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0 0 18px; }
.stat { padding: 10px 14px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: 11px; }
.stat strong { display: block; font-size: 20px; font-weight: 500; color: var(--ink); }
label { display: block; font-size: 12px; margin: 12px 0; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
input, select { width: 100%; padding: 8px 10px; border: 1px solid #d2dff3; border-radius: 8px; background: #fff; color: var(--ink); outline-color: #6893ed; }
select { cursor: pointer; }
.form-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.attention-card { padding: 14px 16px; border: 1px solid #f1d6af; background: #fff7ea; border-radius: 12px; margin-bottom: 12px; }
.attention-card p { margin: 5px 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { padding: 16px 0; color: var(--muted); font-size: 12px; }
.engine { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 10px 0; font-size: 12px; }
.engine span { color: var(--muted); font-size: 11px; }
.login-card { max-width: 360px; margin: 12vh auto; padding: 24px; }
.login-card h1 { margin-bottom: 24px; }
.login-card .primary { width: 100%; margin-top: 12px; }
#login-error { font-size: 12px; color: #a14537; }
dialog { border: 1px solid var(--line); border-radius: 8px; padding: 28px; width: min(720px, 92vw); max-height: 88dvh; color: var(--ink); background: #fff; }
dialog::backdrop { background: #0005; }
.close { position: absolute; right: 12px; top: 8px; font-size: 23px; background: none; color: var(--muted); }
.detail-section { padding: 16px 0; border-top: 1px solid var(--line); }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.7; background: #f6f7f8; padding: 14px; border-radius: 5px; max-height: 45vh; overflow: auto; }
#reply-context { background: #f5f6f7; border-bottom: 1px solid var(--line); padding: 8px 14px; font-size: 12px; display: flex; justify-content: space-between; }
#reply-context button { background: none; color: var(--muted); }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #203f68; color: #fff; padding: 10px 18px; border-radius: 5px; z-index: 100; font-size: 13px; max-width: 90vw; }
#view-library > h2:not(:first-child) { margin-top: 28px; }
@media (max-width: 700px) {
  #app { display: block; }
  .sidebar { position: sticky; height: auto; width: 100%; z-index: 10; padding: 12px 16px 0; background: #162d4a; border-right: 0; border-bottom: 1px solid #25405f; }
  .brand { font-size: 14px; padding: 0; }
  .sidebar-bottom { display: none; }
  nav { display: flex; gap: 4px; margin-top: 12px; }
  .nav { font-size: 13px; justify-content: center; gap: 6px; padding: 10px 5px; border-radius: 9px 9px 0 0; margin: 0; }
  .nav .nav-label { flex: 0; }
  .nav span { margin-left: 5px; }
  main { padding: 20px 16px 32px; }
  header { margin-bottom: 20px; }
  h1 { font-size: 17px; }
  .message { max-width: 96%; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .login-card { margin: 8vh auto; }
  .card-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .stats { gap: 8px; }
  .stat { padding: 10px; }
  dialog { padding: 26px 16px; }
}

.icon { width: 20px; height: 20px; flex-shrink: 0; vertical-align: middle; }
.icon-fill { fill: currentColor; opacity: .14; stroke: none; }
.nav { gap: 10px; transition: background .2s ease, color .2s ease, transform .25s cubic-bezier(.2,.8,.2,1); }
.nav[data-view="inbox"] .icon { color: #87b9ff; }
.nav[data-view="tasks"] .icon { color: #ffc39a; }
.nav[data-view="library"] .icon { color: #79d9c3; }
.nav[data-view="settings"] .icon { color: #bca9ef; }
.nav:hover:not(:disabled) { background: #284463; transform: translateX(2px); }
.nav.active:hover:not(:disabled) { background: #3865b6; }
.brand-symbol { display: inline-flex; gap: 3px; align-items: center; height: 24px; }
.brand-symbol i { display: block; width: 5px; height: 16px; border-radius: 3px; background: #83b4ff; transform: rotate(20deg); }
.brand-symbol i:nth-child(2) { height: 24px; background: #ffba91; }
.brand-symbol i:nth-child(3) { height: 12px; background: #7ed9c6; }
.file-button { display: inline-flex; align-items: center; gap: 5px; transition: color .2s ease; }
.file-button:hover { color: #326be7; }
#send { display: inline-flex; align-items: center; gap: 8px; background: #d76143; box-shadow: 0 3px 9px #c456392b; }
#send:hover:not(:disabled) { background: #c25034; }
#send .icon { width: 17px; height: 17px; transition: transform .25s ease; }
#send:hover:not(:disabled) .icon { transform: translateX(3px) rotate(-8deg); }
button { transition: background .18s ease, box-shadow .18s ease, transform .18s ease; }
button:active:not(:disabled) { transform: scale(.97); }
#composer { transition: border-color .2s ease, box-shadow .2s ease; }
input[type="checkbox"] { accent-color: #326be7; }
.stat:nth-child(1) { background: #eaf0ff; border-color: #d6e1fc; }
.stat:nth-child(2) { background: #fff1e5; border-color: #f2dfcd; }
.stat:nth-child(3) { background: #e3f4ef; border-color: #cde9e1; }
.view:not([hidden]) { animation: view-enter .28s cubic-bezier(.2,.7,.2,1) both; }
dialog[open], #toast:not([hidden]) { animation: surface-enter .2s ease-out both; }
@keyframes view-enter { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes surface-enter { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 700px) {
  .nav { gap: 6px; }
  .nav .icon { width: 18px; height: 18px; }
  .nav:hover:not(:disabled) { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Chat keeps the controls fixed while the conversation scrolls independently. */
#app:has(main[data-view="inbox"]) { height: 100dvh; overflow: hidden; }
main[data-view="inbox"] { display: flex; flex-direction: column; height: 100dvh; padding-bottom: 24px; }
main[data-view="inbox"] header { flex-shrink: 0; margin-bottom: 16px; }
#view-inbox { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px 6px 22px; scrollbar-width: thin; scrollbar-color: #c7d5eb transparent; }
#chat-scroll.is-empty:not(:has(#chat-activity:not([hidden]))) { background: radial-gradient(ellipse at 50% 65%, #e5edfc70, transparent 65%); }
.conversation { gap: 26px; margin-bottom: 20px; }
.message { display: flex; align-items: flex-start; gap: 10px; white-space: normal; max-width: 92%; }
.message.user { align-self: flex-end; flex-direction: row-reverse; background: none; padding: 0; border-radius: 0; }
.message.assistant { padding: 0; }
.message-content { min-width: 0; }
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.85; background: #fff; border: 1px solid #e2e8f2; border-radius: 4px 18px 18px; padding: 15px 18px; box-shadow: 0 3px 12px #24476f04; }
.user .message-body { background: #e1ebff; border-color: #d4e2ff; border-radius: 18px 4px 18px 18px; }
.message-meta { display: block; font-size: 10px; padding: 5px 3px 0; color: #7c8ca3; margin: 0; }
.user .message-meta { text-align: right; }
.chat-avatar { width: 29px; height: 29px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; background: #173658; position: relative; margin-top: 3px; }
.chat-avatar .brand-symbol { transform: scale(.62); }
#composer { flex-shrink: 0; margin-top: 8px; box-shadow: 0 5px 25px #254c8e0c; }
#composer textarea { min-height: 52px; max-height: 180px; resize: none; padding: 16px 18px 5px; font-size: 14px; line-height: 1.6; display: block; }
.composer-bottom { padding: 8px 12px 12px; }
#send { width: 37px; height: 37px; border-radius: 12px; padding: 0; justify-content: center; }
#send .icon { width: 19px; height: 19px; }
.send-label { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#composer.sending #send .icon { display: none; }
#composer.sending #send::after { content: ""; width: 15px; height: 15px; border: 2px solid #ffffff66; border-top-color: #fff; border-radius: 50%; animation: chat-spin .8s linear infinite; }
#chat-presence { display: inline-flex; align-items: center; gap: 7px; border: 1px solid #dce5f4; border-radius: 20px; background: #ffffffb3; padding: 5px 10px; color: #6a7e99; font-size: 11px; }
#chat-presence[data-phase="working"], #chat-presence[data-phase="thinking"] { color: #386bd1; background: #eaf0ff; border-color: #d5e1fb; }
#chat-presence[data-phase="waiting"], #chat-presence[data-phase="error"] { color: #a16734; background: #fff2df; border-color: #f3dfc3; }
#chat-activity { padding: 0 0 0 39px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: #71839d; font-size: 11px; }
.activity-row { display: flex; align-items: center; gap: 9px; padding: 10px 14px; background: #eaf0fc; border-radius: 4px 14px 14px; }
#chat-activity[data-phase="error"] .activity-row, #chat-activity[data-phase="waiting"] .activity-row { background: #fff1df; color: #9a692e; }
.work-pill { display: flex; gap: 8px; align-items: center; min-width: 0; max-width: 100%; padding: 8px 12px; border: 1px solid #d6e3fa; border-radius: 10px; color: #3c66a4; background: #edf3ff; font-size: 11px; }
.work-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #7b8da6; max-width: 230px; }
.activity-icon { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; gap: 3px; position: relative; flex-shrink: 0; }
.activity-icon i { display: none; }
.activity-icon.thinking i { display: block; width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: chat-dot 1.25s ease-in-out infinite; }
.activity-icon.thinking i:nth-child(2) { animation-delay: .15s; }
.activity-icon.thinking i:nth-child(3) { animation-delay: .3s; }
.activity-icon.working i { display: block; width: 3px; height: 12px; border-radius: 3px; background: currentColor; animation: chat-bars .9s ease-in-out infinite alternate; }
.activity-icon.working i:nth-child(2) { animation-delay: -.6s; }
.activity-icon.working i:nth-child(3) { animation-delay: -.3s; }
.activity-icon.sending::after, .activity-icon.queued::after { content: ""; width: 12px; height: 12px; border: 2px solid #95b3ea55; border-top-color: currentColor; border-radius: 50%; animation: chat-spin 1s linear infinite; }
.activity-icon.idle::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #40ae91; box-shadow: 0 0 0 3px #40ae9118; }
.activity-icon.waiting::after { content: "?"; color: #b97c32; font-size: 13px; font-weight: 600; width: 16px; height: 16px; border: 1.5px solid currentColor; border-radius: 50%; line-height: 15px; text-align: center; }
.activity-icon.error::after { content: "!"; font-size: 13px; font-weight: 700; color: #c16a48; border: 1.5px solid currentColor; border-radius: 50%; width: 16px; height: 16px; line-height: 15px; text-align: center; }
.activity-icon.paused::before, .activity-icon.paused::after { content: ""; width: 3px; height: 11px; background: #8494ac; border-radius: 2px; }
.activity-icon.offline::after { content: ""; width: 12px; height: 12px; border: 1.5px dashed #8a99ac; border-radius: 50%; }
.activity-icon.deferred::after { content: ""; width: 12px; height: 12px; border: 1.5px solid currentColor; border-radius: 50%; }
.activity-icon.deferred::before { content: ""; position: absolute; width: 4px; height: 5px; border-left: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; top: 4px; left: 8px; }
.new-message { animation: chat-arrive .24s ease-out; }
@keyframes chat-arrive { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes chat-spin { to { transform: rotate(360deg); } }
@keyframes chat-dot { 0%, 70%, 100% { transform: translateY(0); opacity: .4; } 35% { transform: translateY(-3px); opacity: 1; } }
@keyframes chat-bars { from { transform: scaleY(.35); } to { transform: scaleY(1); } }
@media (max-width: 700px) {
  #app:has(main[data-view="inbox"]) { display: flex; flex-direction: column; }
  #app:has(main[data-view="inbox"]) .sidebar { flex-shrink: 0; }
  main[data-view="inbox"] { flex: 1; min-height: 0; height: auto; padding: 16px 12px max(12px, env(safe-area-inset-bottom)); }
  main[data-view="inbox"] header { padding: 0 4px; margin-bottom: 8px; }
  #chat-scroll { padding: 10px 2px 18px; }
  .message { max-width: 98%; gap: 7px; }
  .chat-avatar { width: 25px; height: 25px; border-radius: 8px; }
  .person-head { top: 4px; }
  .person-body { bottom: 4px; }
  .message-body { padding: 12px 14px; font-size: 13px; }
  #chat-activity { padding-left: 32px; }
  .work-title { max-width: 130px; }
}
@media (prefers-reduced-motion: reduce) {
  .new-message, .activity-icon *, .activity-icon::after, #composer.sending #send::after { animation: none !important; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.activity-row:has(.sr-only) { min-width: 62px; justify-content: center; padding: 13px 16px; }
.decision-card { background: #fff; border-color: #d8e3f4; box-shadow: 0 4px 18px #254c8e08; padding: 16px; }
.decision-heading { display: flex; align-items: flex-start; gap: 10px; }
.decision-heading > .activity-icon { margin-top: 5px; color: #b58745; }
.decision-heading p { margin: 0 0 14px; line-height: 1.8; }
.choice-actions { padding-left: 28px; }
.choice-actions button { min-height: 38px; text-align: left; white-space: normal; }
.choice-actions .subtle:hover { border-color: #9bb8f1; background: #edf3ff; }
.approval-details { margin: -4px 0 12px 28px; font-size: 11px; color: var(--muted); }
.approval-details summary { cursor: pointer; width: fit-content; }
.approval-details pre { margin: 8px 0; max-height: 200px; }
.reply-quote { border-left: 2px solid #95b1df; color: #677f9f; padding: 0 0 0 9px; margin-bottom: 10px; font-size: 11px; line-height: 1.6; white-space: pre-wrap; }
.decision-card[aria-busy="true"] { opacity: .65; }
@media (max-width: 700px) { .choice-actions { padding-left: 0; } .choice-actions button { flex-grow: 1; } }
.choice-actions button { max-width: 100%; overflow-wrap: anywhere; }
.pwa-controls .icon { width: 17px; height: 17px; color: #326be7; margin-right: 3px; }
.pwa-controls #pwa-update { margin-left: 8px; }
.offline-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.offline-card { width: min(360px, 100%); padding: 32px; text-align: center; }
.offline-symbol { width: 64px; height: 64px; color: #6f8cb5; margin-bottom: 20px; }
.offline-card .primary { display: inline-block; text-decoration: none; margin-top: 14px; }
@media (display-mode: standalone) and (max-width: 700px) {
  .sidebar { padding-top: max(12px, env(safe-area-inset-top)); }
}
