:root { --header-h: 0px; }
* { box-sizing: border-box; }
body { font: 16px/1.4 system-ui, sans-serif; margin: 0; background: #111; color: #eee; }
main { max-width: 40rem; margin: 0 auto; padding: 1rem; }
main.tab[hidden] { display: none !important; }

/* ---- header: title + tabs, then the mic controls (Chat/Dictate only) */
header { position: sticky; top: 0; z-index: 1; background: #111; border-bottom: 1px solid #333; }
.bar { max-width: 40rem; margin: 0 auto; padding: .5rem 1rem; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
h1 { font-size: 1.25rem; margin: 0 auto 0 0; }
#tabs { display: flex; gap: .25rem; }
#tabs a { color: #bbb; text-decoration: none; padding: .35rem .7rem; border-radius: .4rem; }
#tabs a:hover { background: #222; }
#tabs a.active { background: #3a7; color: #fff; }
.controls { padding-top: 0; }
.controls[hidden] { display: none; }
.statusline { margin-left: auto; }
body[data-tab="chat"] .dictate-only, body[data-tab="dictate"] .chat-only { display: none; }

button { font: inherit; padding: .5rem 1rem; border-radius: .4rem; border: 0; background: #3a7; color: #fff; cursor: pointer; }
button.secondary { background: #444; }
button.danger { background: #c33; }
button.link { background: none; color: #8bd; padding: 0 .25rem; font-size: .8rem; text-decoration: underline; }
button:disabled { opacity: .5; cursor: default; }
.toggle { display: inline-flex; align-items: center; gap: .35rem; color: #bbb; font-size: .9rem; }
.toggle.block { display: flex; padding: .3rem 0; font-size: 1rem; color: #eee; }
#status { font-weight: 600; }
#status.talking { color: #fc6; }
#status.speaking { color: #6f6; }
small, .muted { color: #888; }
.small { font-size: .85rem; }

/* ---- chat */
ul { list-style: none; padding: 0; margin: 0; }
li { padding: .5rem .75rem; margin: .4rem 0; border-radius: .5rem; background: #222; }
li.you { background: #1e3a5f; }
li.bot { background: #2a2a2a; white-space: pre-wrap; }
li.error { background: #5f1e1e; }
li.tool { background: none; color: #8a8; font-size: .8rem; padding: .1rem .75rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: block; font-size: .75rem; color: #999; margin-top: .2rem; }

/* ---- chat: conversation list on the left, transcript + composer on the right */
#tab-chat { max-width: 62rem; display: grid; grid-template-columns: 14rem minmax(0, 1fr); gap: 1.2rem; align-items: start; }
#chats { position: sticky; top: 6.5rem; max-height: calc(100vh - 7.5rem); overflow-y: auto; display: flex; flex-direction: column; gap: .4rem; }
#new-chat { width: 100%; text-align: left; }
#chat-list li { display: flex; align-items: center; gap: .2rem; padding: 0; margin: 0; background: none; border-radius: .4rem; }
#chat-list li:hover, #chat-list li.active { background: #222; }
#chat-list li.active a { color: #fff; }
#chat-list a { flex: 1; min-width: 0; padding: .45rem .6rem; color: #bbb; text-decoration: none; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-list .delete { background: none; color: #666; padding: 0 .5rem; font-size: 1.1rem; line-height: 1; visibility: hidden; }
#chat-list li:hover .delete { visibility: visible; }
#chat-list .delete:hover { color: #f88; }
#chat-pane { display: flex; flex-direction: column; min-height: calc(100vh - 7rem); min-width: 0; }
#transcript { flex: 1; }
#toggle-chats { display: none; }
.mic.small { width: 2.2rem; height: 2.2rem; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; }
@media (max-width: 700px) {
  #tab-chat { grid-template-columns: 1fr; }
  #chats { display: none; position: fixed; top: 6.5rem; left: 0; bottom: 0; width: 16rem; max-height: none; background: #161616; border-right: 1px solid #333; padding: .75rem; z-index: 3; }
  #tab-chat.show-chats #chats { display: flex; }
  #chat-list .delete { visibility: visible; }
  #toggle-chats { display: inline-block; }
}
#composer { position: sticky; bottom: 0; background: #111; padding: .6rem 0 max(.6rem, env(safe-area-inset-bottom)); }
.composer-box { display: flex; align-items: flex-end; gap: .4rem; background: #1c1c1c; border: 1px solid #3a3a3a; border-radius: 1.2rem; padding: .35rem .4rem .35rem .9rem; }
.composer-box:focus-within { border-color: #3a7; }
#prompt { flex: 1; resize: none; border: 0; background: none; color: #eee; font: inherit; line-height: 1.4; padding: .45rem 0; max-height: 10rem; outline: none; }
.composer-box button { width: 2.5rem; height: 2.5rem; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.send { background: #3a7; }
.send:disabled { background: #333; color: #777; opacity: 1; }
.mic { background: #333; color: #bbb; position: relative; transition: background .2s, color .2s; }
.mic.listening { background: #3a7; color: #fff; }
.mic.listening::before, .mic.listening::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid #3a7; animation: pulse 2s ease-out infinite; }
.mic.listening::after { animation-delay: 1s; }
.mic.speech { background: #4c6; }
.mic.speech::before, .mic.speech::after { animation-duration: .8s; border-color: #7f9; }
.mic.speech::after { animation-delay: .4s; }
.mic.muted { background: #5a2a2a; color: #f99; }
.mic.muted::after { content: ""; position: absolute; width: 2px; height: 1.7rem; background: #f99; transform: rotate(45deg); border-radius: 1px; }
.mic.talking { background: #765; color: #fc6; }
.mic.busy { background: #333; color: #fc6; }
.mic.busy::before { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px dashed #fc6; animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(1.7); opacity: 0; } }
.composer-foot { display: flex; align-items: center; gap: 1rem; padding: .3rem .9rem 0; }
#composer-hint { margin-left: auto; }
.model-panel .toggle.block { color: #ddd; }
.model-panel .toggle.block small { margin-left: auto; padding-left: .6rem; white-space: nowrap; }
.model-menu summary { list-style: none; cursor: pointer; font-size: .8rem; color: #8a8; user-select: none; }
.model-menu summary::-webkit-details-marker { display: none; }
.model-menu summary:hover { color: #bdb; }
.model-menu { position: relative; }
.model-panel { position: absolute; bottom: 1.6rem; left: 0; z-index: 2; background: #222; border: 1px solid #444; border-radius: .5rem; padding: .6rem .8rem; display: flex; flex-direction: column; gap: .5rem; min-width: 18rem; box-shadow: 0 6px 24px #000a; }
.model-panel label { display: flex; align-items: center; justify-content: space-between; gap: .6rem; font-size: .9rem; color: #bbb; }
.model-panel select { max-width: 12rem; }
#composer-hint { font-size: .75rem; }
.context[hidden] { display: none; }
.context { display: inline-flex; align-items: center; gap: .4rem; font-size: .75rem; color: #888; }
.context .bar { width: 5rem; height: .35rem; background: #2a2a2a; border-radius: .2rem; overflow: hidden; }
.context .bar i { display: block; height: 100%; width: 0; background: #3a7; transition: width .3s; }
.context.warn .bar i { background: #fc6; }
.context.full .bar i { background: #f66; }
.context.full { color: #f99; }
li.you.typed { background: #2a3a4f; }
@media (max-width: 480px) { #composer-hint { display: none; } }

/* ---- dictate: the textarea is the page */
#tab-dictate { max-width: none; height: calc(100vh - 7rem); display: flex; }
#dictation { flex: 1; width: 100%; resize: none; font: 1.1rem/1.6 Georgia, "Times New Roman", serif; padding: 1rem 1.2rem;
             background: #181818; color: #eee; border: 1px solid #333; border-radius: .5rem; outline: none; }
#dictation:focus { border-color: #3a7; }

/* ---- artifacts */
.artifact-link { color: #8bd; margin-left: .4rem; }
.artifact-list { display: flex; flex-direction: column; gap: .4rem; }
.artifact-row { display: flex; align-items: baseline; gap: .75rem; padding: .6rem .9rem; background: #1e1e1e; border: 1px solid #333;
                border-radius: .5rem; color: inherit; text-decoration: none; }
.artifact-row:hover { border-color: #3a7; }
.artifact-row .title { flex: 1; font-weight: 600; }
.artifact-row .kind { font-size: .75rem; color: #8a8; text-transform: uppercase; }
.artifact-row .when { font-size: .8rem; color: #888; white-space: nowrap; }
.artifact-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .6rem; }
.artifact-head h2 { font-size: 1.1rem; margin: 0 auto 0 0; }
.artifact-head a { color: #8bd; }
#tab-artifacts.viewing { max-width: none; height: calc(100vh - 4rem); display: flex; flex-direction: column; }
#tab-artifacts.viewing #artifacts-root { flex: 1; display: flex; flex-direction: column; }
.artifact-frame { flex: 1; width: 100%; border: 1px solid #333; border-radius: .5rem; background: #fff; min-height: 60vh; }

/* ---- config */
fieldset { border: 1px solid #333; border-radius: .5rem; padding: .75rem 1rem 1rem; margin: 1rem 0; }
fieldset:disabled { opacity: .6; }
legend { padding: 0 .4rem; color: #ccc; font-weight: 600; }
.row { display: flex; align-items: center; gap: .6rem; margin: .35rem 0; flex-wrap: wrap; }
.row > span:first-child { flex: 0 0 9rem; color: #bbb; }
.row > input, .row > select, .row > textarea { flex: 1 1 12rem; min-width: 0; }
.row > small { flex: 1 0 100%; padding-left: 9.6rem; }
input, select, textarea { font: inherit; padding: .4rem .5rem; border-radius: .4rem; border: 1px solid #444; background: #000; color: #eee; }
fieldset textarea { width: 100%; font-size: .95rem; line-height: 1.4; }
.actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: .6rem 0 .2rem; }
.actions .row { margin: 0; }
.actions .row > span:first-child { flex: 0 0 auto; }
.notice { padding: .5rem .75rem; border-radius: .4rem; background: #222; margin: .5rem 0; }
.notice.ok { background: #1e3a2a; }
.notice.bad { background: #5f1e1e; }
.notice.warn { background: #4a3a1e; }
.notice.inline { display: flex; align-items: center; gap: .5rem; }
.error { color: #f88; margin: 0; }

.server-row { padding: .3rem 0; border-bottom: 1px solid #2a2a2a; }
.server-row .indent { padding-left: 1.6rem; display: flex; gap: .6rem; align-items: center; }
.add-server { margin-top: .8rem; padding-top: .6rem; border-top: 1px solid #333; }

/* ---- about */
.intro p { margin: .4rem 0; }
.pipeline { font-size: .75rem; color: #8a8; overflow-x: auto; padding: .5rem .75rem; background: #181818; border-radius: .4rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .75rem; margin: 1rem 0; }
.card { display: block; background: #1e1e1e; border: 1px solid #333; border-radius: .5rem; padding: .75rem 1rem; color: inherit; text-decoration: none; }
.card:hover { border-color: #3a7; background: #202a24; }
.card h3 { margin: 0 0 .3rem; font-size: 1rem; }
.card h3 small { font-weight: 400; }
.card p { margin: 0; font-size: .85rem; color: #bbb; }

/* ---- login page */
main.login { max-width: 22rem; padding-top: 4rem; }
main.login form { display: flex; flex-direction: column; gap: .6rem; }

@media (max-width: 480px) {
  .row > span:first-child { flex: 1 0 100%; }
  .row > small { padding-left: 0; }
  #tab-dictate { height: calc(100vh - 8.5rem); }
}
