:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e6eaf2;
  background: #0d111a;
  font-synthesis: none;
  --muted: #9caac0;
  --border: #2a3447;
  --accent: #b3a5ff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0 auto;
  max-width: 1600px;
  min-height: 100vh;
  padding: 48px 28px 64px;
  background: radial-gradient(ellipse at 50% 0, #25213e66, transparent 60%);
  line-height: 1.6;
}

.app-header, .brand, .section-header, .composer-actions, .header-controls, .room-heading {
  display: flex;
  align-items: center;
  gap: 16px;
}
.app-header, .section-header { justify-content: space-between; }
.app-header { margin-bottom: 36px; flex-wrap: wrap; }
.header-controls, .room-heading { flex-wrap: wrap; gap: 10px; }
.room-heading label { white-space: nowrap; }
.room-heading #chat-status { margin-left: auto; }
#room-title { overflow-wrap: anywhere; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border: 1px solid #7564b8;
  border-radius: 15px;
  background: linear-gradient(135deg, #514174, #27223e);
  color: #e3daff;
  font-size: 30px;
  box-shadow: 0 6px 24px #0003;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 23px; letter-spacing: -.7px; }
h2 { margin-bottom: 0; font-size: 24px; letter-spacing: -.6px; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }
#connection {
  margin: 0;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 100px;
  background: #171e2b;
  color: #bac7dc;
  font-size: 12px;
  max-width: 100%;
}

#pairing, #sessions, #chat {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #151c29;
  box-shadow: 0 12px 40px #0002;
}
#pairing { padding: 18px 22px; margin-bottom: 22px; }
summary { cursor: pointer; font-weight: 500; overflow-wrap: anywhere; }
summary::marker { color: var(--accent); }
#pairing[open] summary { margin-bottom: 16px; }
#pairing p { font-size: 14px; color: var(--muted); }
#sessions, #chat { padding: 28px; }
.eyebrow {
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.7px;
  text-transform: uppercase;
}
a { color: var(--accent); text-underline-offset: 4px; }
a:hover { color: #d7ceff; }
button, input, textarea { font: inherit; }
button {
  padding: 9px 16px;
  border: 1px solid #3a465e;
  border-radius: 9px;
  background: #232d40;
  color: #e6eaf2;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s, border-color .15s;
}
button:hover:not(:disabled) { background: #303d56; border-color: #63728c; }
button:disabled { opacity: .45; cursor: not-allowed; }
#send, #pair-form button { background: #b3a5ff; color: #1c1538; border-color: #b3a5ff; }
#send:hover:not(:disabled), #pair-form button:hover { background: #c8bdff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
input, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #354158;
  border-radius: 10px;
  background: #0e1521;
  color: #e6eaf2;
  padding: 12px 14px;
}
textarea { display: block; resize: vertical; min-height: 110px; margin: 9px 0 14px; }
textarea::placeholder { color: #8391a8; }
input:focus, textarea:focus { border-color: var(--accent); outline: none; }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
label { color: #bdc8da; font-size: 13px; font-weight: 500; }
#pair-form { display: flex; align-items: flex-end; gap: 12px; }
#pair-form label { flex: 1; min-width: 0; }
#pair-form input { display: block; margin-top: 7px; }
#rooms { list-style: none; padding: 0; margin: 24px 0 0; }
#rooms li + li { margin-top: 10px; }
#rooms a {
  display: block;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #1b2434;
  text-decoration: none;
  overflow-wrap: anywhere;
}
#rooms a:hover { background: #242d42; border-color: #716397; }
#empty { margin: 24px 0 0; padding: 36px 20px; text-align: center; border: 1px dashed #354158; border-radius: 12px; color: var(--muted); }
#empty:empty, #pair-status:empty, #history-note:empty, #chat-status:empty { display: none; }
#pair-status { margin: 14px 0 0; }
#room-title { overflow-wrap: anywhere; }
#chat-status, #history-note { color: var(--muted); font-size: 13px; margin: 8px 0; }
body {
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: 20px;
  padding-bottom: 20px;
}
body .app-header { margin-bottom: 16px; flex-shrink: 0; }
body main { display: flex; flex-direction: column; min-height: 0; flex: 1; }
body #pairing { flex-shrink: 0; max-height: 30dvh; overflow-y: auto; margin-bottom: 12px; }
.workspace { display: flex; gap: 20px; flex: 1; min-height: 0; }
#sessions { --sidebar-padding: 16px; width: 290px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0; padding: 20px var(--sidebar-padding) 0; }
#sessions > .section-header { flex-shrink: 0; }
.session-list { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 20px; }
.account-area { position: relative; flex-shrink: 0; margin: 0 calc(-1 * var(--sidebar-padding)); border-top: 1px solid var(--border); }
#account-toggle { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 18px var(--sidebar-padding); border: 0; border-radius: 0 0 17px 17px; background: transparent; text-align: left; }
.account-identity { display: flex; flex-direction: column; min-width: 0; }
#account-name { font-size: 21px; font-weight: 600; overflow-wrap: anywhere; }
#account-email { font-size: 11px; font-weight: 400; color: var(--muted); overflow-wrap: anywhere; }
.account-area svg { width: 18px; height: 18px; flex-shrink: 0; }
#account-menu { position: absolute; bottom: calc(100% + 8px); left: 8px; right: 8px; z-index: 10; padding: 6px; border: 1px solid var(--border); border-radius: 12px; background: #1b2434; box-shadow: 0 8px 24px #0006; }
#account-menu button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; text-align: left; }
#account-menu button:hover { background: #303d56; }
#settings-dialog, #sharing-dialog, #start-session-dialog { width: min(420px, calc(100vw - 32px)); padding: 28px; border: 1px solid var(--border); border-radius: 18px; background: #151c29; color: #e6eaf2; }
#settings-dialog::backdrop, #sharing-dialog::backdrop, #start-session-dialog::backdrop { background: #0009; }
#settings-title { margin-bottom: 24px; }
#settings-dialog input, #session-directory { margin-top: 8px; }
#settings-error, #start-session-error { color: #ffaaaa; font-size: 13px; margin: 12px 0; }
#settings-error:empty, #admin-error:empty, #start-session-error:empty { display: none; }
#admin-error { color: #ffaaaa; font-size: 13px; margin: 12px 0; }
#authorize-form button { margin-top: 12px; }
#authorized-accounts { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
#authorized-accounts > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
#authorized-accounts span { min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
#authorized-accounts button { flex-shrink: 0; }
.settings-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
#sessions .section-header { gap: 8px; }
#sessions h2 { font-size: 20px; }
.conversations-heading { display: flex; align-items: center; gap: 8px; }
#rooms a { padding: 14px; font-size: 13px; }
#rooms a[aria-current="page"] { background: #302b49; border-color: #a18ce6; color: #ece5ff; }
#welcome { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--muted); }
#welcome h2 { color: #e6eaf2; }
#welcome p { margin-top: 12px; }
.welcome-mark { color: var(--accent); font-size: 64px; }
#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; flex: 1; overflow: hidden; }
#chat > :not(#messages) { flex-shrink: 0; }
#chat > p:first-child { margin-bottom: 8px; }
#messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #46516b transparent;
  margin: 16px 0;
  padding-right: 8px;
}
#messages > * { flex-shrink: 0; }
#messages > section, #messages .tool-group > details {
  min-width: 0;
  padding: 18px 20px;
  background: #1b2434;
  border: 1px solid var(--border);
  border-radius: 12px;
}
#messages > section[data-role="user"] { background: #202c3d; border-color: #35475f; }
#messages > section[data-role="assistant"] { background: #272338; border-color: #423956; }
#messages > section > strong { color: var(--accent); font-size: 12px; letter-spacing: .4px; }
#messages pre { margin: 10px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 14px; }
#messages details { background: #101824; color: #b1bfd4; font-size: 13px; }
#messages > .tool-group { padding: 0; border: 0; border-radius: 0; background: transparent; }
.tool-group > summary { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; list-style: none; }
.tool-group > summary::-webkit-details-marker { display: none; }
.tool-group > summary::before { content: ''; width: 24px; border-top: 1px solid var(--border); }
.tool-group > summary::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.tool-group-arrow { font-size: 18px; line-height: 1; }
.tool-group[open] > summary > .tool-group-arrow { transform: rotate(90deg); }
.tool-group > details { margin-top: 10px; }
#messages details pre, code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .88em; }
code { color: #cec3ff; overflow-wrap: anywhere; }
.markdown { margin-top: 10px; font-size: 14px; overflow-wrap: anywhere; }
#messages > section[data-role] > .markdown { margin-top: 0; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1em 0 .5em; line-height: 1.3; }
.markdown h1 { font-size: 1.6em; }
.markdown h2 { font-size: 1.4em; }
.markdown blockquote { margin: 1em 0; padding-left: 16px; border-left: 3px solid var(--accent); color: var(--muted); }
#messages .markdown pre { padding: 12px; background: #0e1521; border-radius: 8px; overflow-x: auto; white-space: pre; overflow-wrap: normal; }
.markdown pre code { overflow-wrap: normal; }
.markdown table { display: block; overflow-x: auto; border-collapse: collapse; }
.markdown th, .markdown td { padding: 6px 12px; border: 1px solid var(--border); }
.markdown img { max-width: 100%; height: auto; }
#pending { padding: 14px 0; border-top: 1px solid var(--border); }
#sharing-accounts label { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
#sharing-accounts input { width: auto; accent-color: var(--accent); }
#pending-messages { max-height: 220px; overflow-y: auto; }
.pending-message { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; }
.pending-message + .pending-message { border-top: 1px solid var(--border); }
.pending-message > div { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.pending-message > button { flex-shrink: 0; }
#display-name { width: 150px; max-width: 100%; padding: 7px 10px; }
#context-controls { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
#context-meter { position: relative; flex: 1; min-width: 0; overflow: hidden; border: 1px solid var(--border); border-radius: 4px; background: #101824; }
#context-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: #287347; transition: width .4s, background-color .4s; }
#context-meter::after { content: ''; position: absolute; inset: 0; pointer-events: none; background-image: linear-gradient(to right, transparent calc(100% - 1px), #ffffff50 0); background-size: 5% 4px; background-position: left bottom; background-repeat: repeat-x; }
#context-label { position: relative; display: block; text-align: center; padding: 0 6px; color: #fff; font-size: 10px; line-height: 16px; text-shadow: 0 1px 3px #000; }
#refresh, #open-start-session, #compact, #new-conversation, #sync, #open-sharing, #end-conversation { display: grid; place-items: center; flex-shrink: 0; width: 24px; height: 24px; padding: 0; border-radius: 4px; }
#compact[aria-busy="true"] svg { opacity: .5; }
#send-form { display: grid; grid-template-columns: minmax(0, 1fr) 36px; column-gap: 8px; padding-top: 4px; }
#typing-status { grid-column: 1 / -1; }
#typing-status:empty { display: none; }
#message { margin: 0; }
.composer-actions { flex-direction: column; justify-content: flex-end; gap: 8px; }
.composer-actions > button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; }
#stop:not(:disabled) { background: #b93848; border-color: #dc5263; color: #fff; }
#stop:hover:not(:disabled) { background: #d04456; border-color: #ef7180; }
#stop:disabled { background: #232832; border-color: #414650; color: #9298a3; }

@media (max-width: 600px) {
  body { padding: 24px 14px; }
  .app-header { align-items: flex-start; flex-direction: column; gap: 18px; margin-bottom: 24px; }
  #connection { max-width: 100%; }
  .workspace { gap: 10px; }
  #sessions { --sidebar-padding: 8px; width: 125px; padding: 12px 8px 0; }
  #account-name { font-size: 16px; }
  #account-menu { right: auto; min-width: 160px; }
  #sessions .section-header { align-items: flex-start; flex-direction: column; }
  #sessions h2 { font-size: 14px; }
  #sessions .eyebrow { font-size: 9px; }
  #rooms { margin-top: 14px; }
  #rooms a { padding: 10px 8px; font-size: 12px; }
  #empty { padding: 16px 8px; font-size: 12px; }
  #chat { padding: 16px 12px; }
  #chat h2 { font-size: 18px; }
  #pairing { padding: 16px; }
  #pair-form { align-items: stretch; flex-direction: column; }
  #messages > section, #messages .tool-group > details { padding: 14px; }
  #sync { margin-left: 0; }
}

.file-dialog { width: min(1100px, 92vw); max-height: 90dvh; padding: 0; border: 1px solid #444; border-radius: 12px; background: #161b22; color: #e6edf3; }
.file-dialog::backdrop { background: #000a; }
.file-dialog > header { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid #444; }
.file-dialog h2 { flex: 1; min-width: 0; margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.file-dialog button { flex-shrink: 0; }
.file-content { overflow: auto; padding: 20px; max-height: calc(90dvh - 100px); }
.file-content pre { margin: 0; white-space: pre; overflow: auto; }
.file-content iframe { display: block; width: 100%; height: 65dvh; border: 0; background: white; }

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}

#composer-input { position: relative; min-width: 0; }
#attachment-controls { position: absolute; right: 7px; bottom: 7px; display: flex; align-items: flex-end; gap: 5px; max-width: calc(100% - 14px); pointer-events: none; }
#attach-files { width: 28px; height: 28px; padding: 0; flex-shrink: 0; pointer-events: auto; }
#attachment-previews { display: flex; gap: 4px; overflow-x: auto; max-height: 44px; pointer-events: auto; }
.attachment-chip { display: flex; align-items: center; gap: 4px; max-width: 155px; flex-shrink: 0; padding: 3px 5px; font-size: 11px; }
.attachment-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 3px; }
#attachment-drop { position: absolute; inset: 0; display: grid; place-items: center; background: #172334ed; border: 2px dashed var(--accent); border-radius: 8px; pointer-events: none; }
#attachment-drop[hidden], #attachment-picker[hidden] { display: none; }
.message-attachment { display: block; max-width: min(100%, 480px); max-height: 360px; object-fit: contain; margin-top: 8px; }
