* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", system-ui, sans-serif; font-size: 15px; line-height: 1.7; letter-spacing: 0.02em; color: #1a1a1a; background: #fff; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
h1, h2, h3, .brand, .pagetitle { letter-spacing: 0.04em; }
button { cursor: pointer; font: inherit; }
.primary { background: #1a1a1a; color: #fff; border: none; border-radius: 8px; padding: 10px 20px; }
.ghost { background: transparent; border: 1px solid #ccc; border-radius: 8px; padding: 10px 20px; }
.ghost.small { padding: 4px 10px; font-size: 13px; }
.muted { color: #777; font-size: 13px; }

/* login */
#loginView, #nameView { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #f7f7f5; }
.login-card { text-align: center; padding: 40px; }
.login-card h1 { font-size: 40px; font-weight: 700; margin: 0 0 8px; }
.login-card input { display: block; width: 260px; margin: 10px auto; padding: 12px; border: 1px solid #ddd; border-radius: 8px; font: inherit; background: #fff; }
.login-sub { color: #555; margin-bottom: 28px; }
.login-card button { display: block; width: 260px; margin: 10px auto; padding: 12px; }
.login-note { color: #999; font-size: 12px; margin-top: 18px; }

/* app layout */
#appView { display: flex; height: 100vh; }
.sidebar { width: 280px; flex: none; background: #f7f7f5; border-right: 1px solid #e5e5e0; display: flex; flex-direction: column; padding: 14px; gap: 12px; }
.brand { font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; border: 1px solid #ddd; background: #fff; border-radius: 8px; padding: 7px; }
.tab.active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.newchat { width: 100%; padding: 9px; border-radius: 8px; border: 1px solid #ddd; background: #fff; text-align: left; }
#chatList { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.chatitem { display: flex; align-items: center; gap: 6px; padding: 7px 9px; border-radius: 7px; cursor: pointer; }
.chatitem:hover { background: #eee; }
.chatitem.active { background: #e8e8e3; }
.chatitem span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chatitem .del { border: none; background: transparent; color: #999; }
#sideMemory input, #sideMemory select { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 8px; margin-bottom: 8px; }
.sidefoot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* chat */
#chatView { display: flex; flex-direction: column; height: 100%; }
#chatScroll { flex: 1; overflow-y: auto; padding: 24px 16px; }
#chatLog { max-width: 768px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
#chatEmpty { max-width: 768px; margin: 12vh auto 0; text-align: center; }
.greeting { font-size: 28px; font-weight: 700; margin: 0 0 6px; }
.greet-sub { color: #555; font-size: 17px; margin: 0; }
.chips { display: flex; flex-direction: column; gap: 8px; align-items: center; margin-top: 18px; }
.chip { border: 1px solid #ddd; background: #fff; border-radius: 999px; padding: 8px 16px; font-size: 14px; }
.msg { display: flex; flex-direction: column; }
.msg.user { align-self: flex-end; align-items: flex-end; max-width: 85%; }
.msg.assistant { align-self: stretch; align-items: flex-start; }
.msg.assistant .bubble { max-width: 85%; }
.bubble { padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; line-height: 1.75; }
.msg.user .bubble { background: #1a1a1a; color: #fff; }
.msg.assistant .bubble { background: #f1f1ee; }
.provenance { margin-top: 6px; font-size: 12px; color: #888; width: 100%; max-width: 600px; }
.provenance summary { cursor: pointer; list-style: none; }
.provenance > div { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; }
.composer { display: flex; gap: 8px; padding: 14px 16px; border-top: 1px solid #eee; max-width: 800px; width: 100%; margin: 0 auto; }
.composer textarea { flex: 1; resize: none; border: 1px solid #ddd; border-radius: 12px; padding: 11px 14px; font: inherit; max-height: 140px; }

/* memory */
#memoryView { display: flex; flex-direction: column; height: 100%; }
.memtoolbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid #eee; font-weight: 600; }
.memtablewrap { overflow-y: auto; padding: 8px 18px 24px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #eee; vertical-align: top; }
th { color: #666; font-weight: 600; }
td:nth-child(1) { white-space: nowrap; color: #666; }
td:nth-child(2) { white-space: nowrap; }

/* dock */
.dock { width: 68px; flex: none; background: #ececea; border-right: 1px solid #e0e0da; display: flex; flex-direction: column; align-items: stretch; padding: 10px 6px; gap: 4px; }
.dockbtn { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 2px; border: none; background: transparent; border-radius: 10px; color: #555; font-size: 11px; }
.dockbtn:hover { background: #e2e2dd; }
.dockbtn.active { background: #1a1a1a; color: #fff; }
.sidetitle { font-weight: 700; margin-bottom: 8px; }
.sideitem { padding: 7px 9px; border-radius: 7px; font-size: 14px; margin-bottom: 8px; }
.sideitem.active { background: #e8e8e3; }

/* settings / profile */
#settingsView, #profileView { overflow-y: auto; height: 100%; }
.pagewrap { max-width: 720px; margin: 0 auto; padding: 28px 20px 48px; }
.pagetitle { margin: 0 0 18px; font-size: 22px; font-weight: 700; }
.card { border: 1px solid #e5e5e0; border-radius: 12px; padding: 20px; background: #fff; }
.card h3 { margin-top: 0; font-size: 16px; font-weight: 700; }
.keystatus { font-weight: 600; }
.keyrow { display: flex; gap: 8px; margin: 12px 0 4px; }
.keyrow input { flex: 1; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font: inherit; }
.proftable { margin-bottom: 18px; }
.proftable th { width: 150px; }

/* transitions (competitor-level snappiness: 120-200ms ease-out) */
@keyframes viewIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#chatView, #memoryView, #settingsView, #profileView { animation: viewIn .18s ease-out; }
#loginView .login-card, #nameView .login-card { animation: viewIn .22s ease-out; }
.msg { animation: msgIn .16s ease-out; }
button, .chip, .chatitem, .dockbtn, .sideitem, input, select, textarea { transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .1s ease; }
.chip:hover { transform: translateY(-1px); border-color: #bbb; }
.primary:hover { background: #333; }
.ghost:hover { background: #f4f4f1; }
.composer textarea:focus { border-color: #999; box-shadow: 0 0 0 3px rgba(0,0,0,.06); outline: none; }
.keyrow input:focus, .login-card input:focus, #sideMemory input:focus, #sideMemory select:focus { border-color: #999; box-shadow: 0 0 0 3px rgba(0,0,0,.06); outline: none; }
#chatScroll { scroll-behavior: smooth; }
.card h4 { margin: 18px 0 4px; font-size: 14px; font-weight: 700; }

/* dock bottom group + avatar */
.dockspacer { flex: 1; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: #9a9a92; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.dockbtn.active .avatar { background: #fff; color: #1a1a1a; }
#settingsView .card { margin-bottom: 16px; }
