:root {
  color-scheme: dark;
  --bg: #0a0d12;
  --panel: #11161e;
  --panel-raised: #171e28;
  --panel-soft: #1c2531;
  --border: #273241;
  --text: #edf3f8;
  --muted: #91a0b1;
  --accent: #8be0c2;
  --accent-strong: #4dc49a;
  --danger: #ff9c9c;
  --user: #19382f;
  --assistant: #1a2430;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% -10%, rgba(77, 196, 154, .12), transparent 38rem),
    var(--bg);
  color: var(--text);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }

.shell { width: min(1440px, 100%); margin: 0 auto; padding: 16px; }

.eyebrow {
  color: var(--accent);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }
h1 { margin-top: 5px; font-size: clamp(1.35rem, 2vw, 1.75rem); letter-spacing: -.025em; }
h2 { margin-top: 5px; font-size: 1.08rem; letter-spacing: -.015em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .78rem; line-height: 1.5; }
code { color: var(--accent); }

.login-card {
  width: min(430px, 100%);
  margin: 10vh auto 0;
  padding: 24px;
  background: rgba(17, 22, 30, .92);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
}
.login-card > .muted { margin-top: 10px; line-height: 1.5; }
.stack { display: grid; gap: 7px; margin-top: 20px; }
label { font-size: .82rem; font-weight: 700; }
input, textarea {
  width: 100%;
  padding: 9px 11px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
textarea { min-height: 40px; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(77, 196, 154, .15); }
.login-card .hint { margin-top: 20px; }

.primary, .button, .icon-button {
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 750;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.primary {
  margin-top: 6px;
  padding: 9px 12px;
  color: #07130f;
  background: var(--accent);
}
.primary:hover { background: #a0edd4; }
.button { padding: 6px 9px; color: var(--text); background: transparent; }
.button.secondary { border-color: var(--border); background: var(--panel-raised); }
.button.secondary:hover { border-color: var(--accent-strong); }
.button.ghost { color: var(--muted); }
.button.ghost:hover { color: var(--text); }
.button.danger { color: var(--danger); border-color: rgba(255, 156, 156, .45); }
.button.danger:hover { color: #ffd1d1; border-color: var(--danger); }
.icon-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  color: var(--muted);
  background: var(--panel-raised);
  border-color: var(--border);
}
.icon-button:hover { color: var(--accent); border-color: var(--accent-strong); }
.icon-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.record-message-button { width: 34px; min-width: 34px; padding: 0; }
.record-message-button .recording-button-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.icon-button.recording { color: #fff; background: #a53e4a; border-color: #ff9c9c; }
.composer-actions .turn-control {
  display: inline-flex;
  align-items: center;
  width: auto;
  height: 34px;
  padding: 0 10px;
  font-size: 0.82rem;
}
.composer-actions .turn-control.danger { color: var(--danger); border-color: rgba(255, 156, 156, .45); }
.composer-actions .turn-control.danger:hover { color: #ffd1d1; border-color: var(--danger); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 14px;
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.mobile-menu-button, .mobile-menu-close, .mobile-menu-backdrop { display: none; }
.workspace {
  display: grid;
  grid-template-columns: minmax(220px, 290px) minmax(0, 1fr);
  height: calc(100vh - 92px);
  min-height: 480px;
  overflow: hidden;
  background: rgba(17, 22, 30, .88);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.threads-panel { position: relative; overflow-y: auto; border-right: 1px solid var(--border); }
.panel-heading, .conversation-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.count {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  color: var(--accent);
  background: rgba(139, 224, 194, .1);
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 800;
}
.panel-heading-actions { display: flex; align-items: center; gap: 4px; }
.threads-panel-toggle { display: none; }
.thread-search { padding: 8px 8px 0; }
.thread-search input { padding: 7px 9px; font-size: .8rem; }
.threads-list { padding: 6px; }
.thread-button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
}
.thread-button:hover { background: var(--panel-raised); }
.thread-button.active { background: var(--panel-soft); border-color: var(--border); }
.thread-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 750; }
.thread-title-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-status-indicator { display: inline-grid; place-items: center; flex: 0 0 auto; width: 20px; height: 20px; margin-left: auto; border-radius: 50%; font-size: .76rem; font-weight: 900; line-height: 1; }
.thread-status-indicator.processing { display: inline-flex; align-items: center; justify-content: center; gap: 5px; width: auto; height: 20px; border-radius: 0; color: #8fb3ce; background: transparent; }
.thread-status-indicator.processing .processing-dot { width: 3px; height: 3px; flex: 0 0 3px; border-radius: 50%; background: currentColor; animation: processing-dot-blink 1.6s ease-in-out infinite; }
.thread-status-indicator.processing .processing-dot:nth-child(2) { animation-delay: .2s; }
.thread-status-indicator.processing .processing-dot:nth-child(3) { animation-delay: .4s; }
.thread-status-indicator.completed { color: #10231d; background: var(--accent); }
.thread-status-indicator.failed { color: #fff5f5; background: var(--danger); }
.thread-status-indicator.success { color: #10231d; background: var(--accent); }
.thread-status-indicator.warning { color: #3a2b00; background: #f6c343; }
.thread-status-indicator.error { color: #fff5f5; background: var(--danger); }
.waiting-icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.thread-status-indicator.queued { color: #f0c674; background: transparent; }
.thread-status-indicator .waiting-icon { width: 17px; height: 17px; }
@keyframes processing-dot-blink { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.processing-dots { display: inline-flex; align-items: center; gap: 5px; min-height: 20px; color: #8fb3ce; }
.processing-dots .processing-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: processing-dot-blink 1.4s ease-in-out infinite; }
.processing-dots .processing-dot:nth-child(2) { animation-delay: .18s; }
.processing-dots .processing-dot:nth-child(3) { animation-delay: .36s; }
.thread-unread-badge { display: inline-grid; place-items: center; flex: 0 0 auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: #1976d2; color: #fff; font-size: .72rem; font-weight: 800; line-height: 1; }
.thread-draft-indicator {
  display: inline-grid;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  place-items: center;
  color: #f0c674;
}
.thread-draft-indicator svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}
.thread-details { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 3px; color: var(--muted); font-size: .7rem; }
.thread-status { display: flex; min-width: 0; align-items: center; gap: 5px; }
.thread-status-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-status.delegated {
  color: #f4c98a;
  border-left: 1px solid #f4a64a;
  padding-left: 5px;
}
.thread-status-elapsed { flex: 0 0 auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.thread-turn-elapsed { color: var(--muted); font-size: .7rem; font-variant-numeric: tabular-nums; font-weight: 700; }
.thread-status-elapsed:empty { display: none; }
.thread-timestamp { flex: 0 0 auto; white-space: nowrap; }
.empty { padding: 20px 16px; color: var(--muted); font-size: .8rem; line-height: 1.45; }

.conversation-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; overflow: hidden; }
.conversation-view { display: flex; min-width: 0; min-height: 0; flex: 1; flex-direction: column; }
.conversation-header { position: relative; min-width: 0; width: 100%; align-items: flex-start; }
.conversation-heading { min-width: 0; width: 100%; }
.conversation-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; margin-top: 3px; }
.conversation-title-row h2 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-details { position: relative; flex: 0 0 auto; color: var(--muted); font-size: .78rem; }
.conversation-details summary { display: inline-grid; width: 26px; height: 26px; padding: 4px; place-items: center; color: var(--accent); cursor: pointer; list-style: none; border-radius: 6px; }
.conversation-details summary::-webkit-details-marker { display: none; }
.conversation-details summary:hover, .conversation-details summary:focus-visible { background: var(--panel-raised); }
.conversation-details summary svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; transition: transform .15s ease; }
.conversation-details[open] summary svg { transform: rotate(180deg); }
.conversation-details-content { position: absolute; z-index: 2; top: 30px; left: 0; width: min(440px, calc(100vw - 48px)); margin-top: 0; padding: 10px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; box-shadow: 0 12px 28px rgba(0, 0, 0, .3); }
.conversation-details-content > :first-child { margin-top: 0; }
.conversation-session-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.conversation-session-row .icon-button { width: 26px; height: 26px; padding: 5px; }
.conversation-session-row .icon-button svg { width: 14px; height: 14px; }
.conversation-outcome { margin-top: 10px; color: var(--muted); font-size: .78rem; }
.conversation-outcome summary { width: fit-content; color: var(--muted); cursor: pointer; font-weight: 700; }
.conversation-outcome summary:hover { color: var(--text); }
.conversation-outcome p { margin-top: 6px; line-height: 1.5; overflow-wrap: anywhere; }
.conversation-actions { display: flex; min-width: 0; flex: 0 0 auto; align-items: center; gap: 4px; margin-left: auto; }
.conversation-actions .icon-button { width: 28px; height: 28px; }
.conversation-actions .icon-button.danger { color: var(--danger); }
.conversation-actions .icon-button.danger:hover { color: #ffd1d1; border-color: var(--danger); }
.conversation-empty { display: grid; min-height: 50vh; padding: 24px; place-items: center; text-align: center; }
.conversation-empty .muted { max-width: 330px; margin-top: 8px; line-height: 1.45; }
.empty-mark { color: var(--accent); font-size: 2.5rem; line-height: 1; }
.messages-list { display: grid; min-width: 0; min-height: 0; flex: 1; gap: 8px; padding: 14px clamp(12px, 3vw, 36px) 18px; overflow-x: hidden; overflow-y: auto; align-content: start; }
.message { position: relative; width: min(760px, 100%); min-width: 0; max-width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 11px; }
.message.user { justify-self: end; background: var(--user); border-color: #285443; }
.message.assistant { justify-self: start; background: var(--assistant); }
.message.agent-status {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: min(760px, 100%);
  min-width: 0;
  max-width: 100%;
  padding: 4px 2px;
  border: 0;
  color: #8fd0e6;
  background: transparent;
  font-size: .78rem;
}
.message.agent-status.current { color: #a9e0f2; }
.message.agent-status.historical { color: #6a9cb1; opacity: .75; }
.agent-status-marker { color: #6fb7d0; font-weight: 900; }
.agent-status-body {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}
.agent-status-elapsed { white-space: nowrap; }
.message.agent-status.delegated {
  color: #f4c98a;
  border-left: 1px solid #f4a64a;
  padding-left: 8px;
}
.message.agent-status.delegated.current { color: #ffd08d; }
.message.agent-status.delegated.historical { color: #c8924c; }
.message.agent-status.delegated .agent-status-marker { color: #f4a64a; }
.message.agent-status.delegated .processing-dots { color: #f4a64a; }
.agent-status-group {
  width: min(760px, 100%);
  min-width: 0;
  max-width: 100%;
  color: #7fb8cc;
  font-size: .74rem;
}
.agent-status-group > summary {
  width: max-content;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #7fb8cc;
  cursor: pointer;
  list-style-position: inside;
}
.agent-status-group > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.agent-status-group-items {
  display: grid;
  gap: 1px;
  margin-top: 4px;
}
.agent-status-group-items .message.agent-status {
  max-width: 100%;
}
.pending-response {
  display: flex;
  align-items: center;
  justify-self: start;
  width: max-content;
  min-width: 48px;
  min-height: 32px;
  padding: 6px 10px;
  background: var(--assistant);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.pending-response.queued { color: #f0c674; }
.pending-response .waiting-icon { width: 19px; height: 19px; }
.message-head { display: contents; }
.message-actions {
  float: right;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  overflow: visible;
  pointer-events: auto;
  white-space: nowrap;
}
.message-actions > :not(.message-time-button) {
  opacity: 1;
  pointer-events: auto;
}
.message-actions .message-time-button { order: 10; }
.message-actions .icon-button { flex: 0 0 27px; width: 27px; height: 27px; }
.message-actions .message-time-button { flex: 0 0 auto; width: auto; }
.message-actions > :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.message-role { font-size: .73rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.important-message-marker { color: #ffd166; font-size: .95rem; font-weight: 900; line-height: 1; }
.message-time-button { position: relative; display: inline-flex; flex: 0 0 auto; width: auto; min-width: 27px; gap: 4px; margin-left: 0; overflow: visible; color: var(--muted); }
.message-time-button > svg { display: block; flex: 0 0 17px; width: 17px; height: 17px; }
.message-time-button .message-time { display: block; max-width: 0; overflow: hidden; opacity: 0; white-space: nowrap; transition: max-width .15s ease, opacity .15s ease; }
.message-time-button:hover .message-time, .message-time-button:focus-visible .message-time, .message-time-button[aria-expanded="true"] .message-time { max-width: 180px; opacity: 1; }
.message-time-button[aria-expanded="true"] .message-time {
  position: absolute;
  z-index: 2;
  top: calc(100% + 4px);
  right: 0;
  width: max-content;
  max-width: min(180px, calc(100vw - 32px));
  padding: 4px 6px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .3);
}
.message-time { color: inherit; font-size: .68rem; }
.message-status-indicator { color: var(--accent); }
.message-body { color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; min-width: 0; }
.message-body > p { margin: 0; white-space: pre-wrap; }
.message-body > p + p,
.message-body > h1 + p,
.message-body > h2 + p,
.message-body > h3 + p,
.message-body > h4 + p,
.message-body > h5 + p,
.message-body > h6 + p,
.message-body > ul + p,
.message-body > ol + p,
.message-body > blockquote + p,
.message-body > pre + p,
.message-body > .markdown-table-wrapper + p { margin-top: 10px; }
.message-body > h1,
.message-body > h2,
.message-body > h3,
.message-body > h4,
.message-body > h5,
.message-body > h6 { margin: 0; line-height: 1.25; }
.message-body > ul,
.message-body > ol { margin: 0; padding-left: 22px; }
.message-body > blockquote { margin: 0; padding-left: 10px; border-left: 3px solid var(--accent); color: var(--muted); }
.message-body > pre {
  max-width: 100%;
  margin: 0;
  padding: 8px 10px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(0, 0, 0, .2);
  white-space: pre;
}
.message-body > pre > code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.message-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.markdown-table-wrapper {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.markdown-table-wrapper:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.markdown-table { min-width: max-content; border-collapse: collapse; }
.markdown-table th,
.markdown-table td {
  max-width: 22rem;
  padding: 5px 8px;
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
  vertical-align: top;
}
.markdown-table th { background: rgba(255, 255, 255, .08); font-weight: 800; }
.message-status { margin-top: 7px; color: var(--muted); font-size: .73rem; }
.message-status.failed { color: var(--danger); }
.transcription-progress { display: grid; gap: 4px; margin-top: 6px; color: var(--muted); font-size: .72rem; }
.transcription-progress progress {
  width: 100%;
  height: 7px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  border: none;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(255, 255, 255, .12);
}
.transcription-progress progress::-webkit-progress-bar { background: rgba(255, 255, 255, .12); border-radius: 99px; }
.transcription-progress progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; transition: width .2s ease; }
.transcription-progress progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; transition: width .2s ease; }
.audio-box { display: grid; gap: 6px; margin-top: 10px; }
.audio-box[hidden] { display: none; }
.audio-box audio { width: min(460px, 100%); height: 34px; }
.audio-duration { color: var(--muted); font-size: .72rem; }
.audio-error { color: var(--danger); font-size: .74rem; }
.message-diagnostics { margin-top: 10px; font-size: .76rem; }
.message-diagnostics summary { width: fit-content; color: var(--muted); cursor: pointer; font-weight: 700; }
.message-diagnostics summary:hover { color: var(--text); }
.message-diagnostics-content { display: grid; gap: 4px; margin-top: 6px; color: var(--danger); overflow-wrap: anywhere; }
.message-diagnostics-content p { margin: 0; }
.message-image-link { display: block; margin-top: 10px; max-width: min(720px, 100%); }
.message-image { display: block; width: auto; max-width: 100%; max-height: 520px; border: 1px solid var(--border); border-radius: 10px; object-fit: contain; background: #08111e; }
.message-composer {
  min-width: 0;
  width: 100%;
  padding: 10px clamp(12px, 3vw, 36px) 12px;
  background: linear-gradient(to bottom, rgba(17, 22, 30, .92), var(--panel) 24%);
  border-top: 1px solid var(--border);
}
.message-composer-row { display: grid; min-width: 0; width: 100%; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 7px; }
.message-composer textarea { min-height: 38px; max-height: 140px; padding: 8px 10px; }
.message-composer textarea { min-width: 0; }
.attachment-preview { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
.attachment-preview .icon-button { width: 26px; height: 26px; padding: 5px; }
.attachment-preview .icon-button svg { width: 14px; height: 14px; }
.attachment-preview-name { min-width: 0; overflow: hidden; color: var(--muted); font-size: .74rem; text-overflow: ellipsis; white-space: nowrap; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.recording-control { display: flex; align-items: center; gap: 6px; min-width: 0; }
.recording-status { overflow: hidden; color: var(--muted); font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.send-button { min-width: 72px; margin: 0; padding: 8px 11px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.app-error { margin: 14px 4px 0; }
.error { color: var(--danger); margin-top: 14px; font-size: .82rem; line-height: 1.5; }

.tag-manager { padding: 0; }
.tag-manager-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tag-manager .button { padding: 6px 9px; }
.tag-filters { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
.tag-filter { padding: 4px 7px !important; font-size: .72rem !important; }
.tag-filter.active { color: var(--text); border-color: var(--accent-strong); background: var(--panel-soft); }
.tags-list { display: grid; gap: 6px; margin-top: 12px; }
.tag-manager-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.tag-manager-actions { display: flex; flex: 0 0 auto; gap: 2px; }
.tag-manager-actions .button { color: var(--muted); }
.tag-manager .hint { margin: 8px 0 4px; }
.settings-sidebar { display: none; flex-direction: column; padding: 14px; }
#threads-panel.settings-open .panel-heading,
#threads-panel.settings-open .thread-search,
#threads-panel.settings-open #threads-list,
#threads-panel.settings-open #threads-empty { display: none; }
#threads-panel.settings-open .settings-sidebar { display: flex; }
.settings-sidebar .settings-heading { position: sticky; top: 0; z-index: 2; padding-bottom: 10px; background: var(--panel); }
.settings-sidebar .settings-heading h2 { margin: 0; }
.settings-panel { display: block; flex: 1; min-width: 0; overflow-y: auto; padding: 18px clamp(16px, 3vw, 38px) 30px; }
.settings-detail-heading { padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.settings-detail-heading h2 { margin-top: 5px; }
.conversation-panel:not(.settings-open) .settings-panel { display: none; }
.settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.settings-heading h2 { margin: 0; }
.settings-heading .hint { max-width: 720px; margin-top: 6px; }
.settings-sections { display: grid; gap: 6px; margin-top: 10px; }
.settings-sections button { padding: 9px 10px; color: var(--muted); text-align: left; background: transparent; border: 1px solid transparent; border-radius: 8px; font-size: .8rem; font-weight: 750; }
.settings-sections button:hover, .settings-sections button.active { color: var(--text); border-color: var(--accent-strong); background: var(--panel-soft); }
.settings-section { margin-top: 4px; }
.settings-resource { margin-top: 0; }
.settings-resource-list { display: grid; gap: 7px; margin-top: 18px; }
.settings-resource-row { display: flex; align-items: center; gap: 10px; padding: 10px 11px; border: 1px solid var(--border); border-radius: 8px; }
.settings-resource-main { display: grid; min-width: 0; gap: 2px; }
.settings-resource-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-resource-main .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-resource-actions { display: inline-flex; gap: 4px; margin-left: auto; }
.profile-color-swatch { width: 14px; height: 14px; flex: 0 0 auto; border-radius: 50%; border: 1px solid rgba(255,255,255,.55); }
.settings-form { display: grid; gap: 12px; max-width: 860px; margin-top: 18px; padding: 14px; background: rgba(23, 30, 40, .55); border: 1px solid var(--border); border-radius: 12px; }
.form-field { display: grid; grid-template-columns: minmax(150px, 190px) minmax(0, 1fr); align-items: center; gap: 10px; }
.form-field .hint { grid-column: 2; margin-top: -5px; }
.form-field-wide { align-items: start; }
.form-field-wide textarea { min-height: 170px; line-height: 1.45; }
.form-field-wide .hint { margin-top: -2px; }
.form-field-checkbox input { width: 18px; height: 18px; justify-self: start; accent-color: var(--accent-strong); }
.checkbox-list { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; }
.checkbox-list input { width: 18px; height: 18px; accent-color: var(--accent-strong); }
.form-actions { display: flex; justify-content: flex-end; gap: 6px; padding-top: 4px; }
.settings-resource + .settings-resource { margin-top: 24px; }
.conversation-profile { display: block; flex: 0 1 180px; min-width: 110px; }
.conversation-profile select { width: 100%; padding: 5px 7px; font-size: .76rem; }
.conversation-panel.settings-open .conversation-view,
.conversation-panel.settings-open .conversation-empty { display: none; }
.tag-badge {

  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 22px;
  padding: 3px 8px;
  overflow: hidden;
  color: var(--accent);
  background: rgba(139, 224, 194, .1);
  border: 1px solid rgba(139, 224, 194, .2);
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.conversation-tags:empty { display: none; }
.conversation-tags { margin-top: 10px; }
.conversation-tags .tag-badge { font-size: .74rem; }
.tag-dialog {
  width: min(420px, calc(100vw - 28px));
  padding: 0;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .5);
}
.tag-dialog::backdrop { background: rgba(0, 0, 0, .65); }
.tag-dialog form { display: grid; gap: 14px; padding: 22px; }
.tag-dialog .muted { font-size: .84rem; line-height: 1.45; }
.thread-tag-options { display: grid; gap: 7px; max-height: 42vh; overflow-y: auto; }
.thread-tag-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  color: var(--text);
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-weight: 600;
}
.thread-tag-option input { width: auto; padding: 0; accent-color: var(--accent-strong); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 6px; }
.dialog-actions .primary { margin: 0; padding: 8px 12px; }


@media (min-width: 1280px) {
  .threads-panel-toggle { display: inline-grid; }
  .workspace.threads-collapsed { grid-template-columns: 0 minmax(0, 1fr); }
  .threads-panel.is-collapsed { overflow: visible; border-right: 0; }
  .threads-panel.is-collapsed > :not(.panel-heading) { display: none; }
  .threads-panel.is-collapsed .panel-heading {
    position: absolute;
    top: 10px;
    right: -42px;
    width: 34px;
    padding: 0;
    border-bottom: 0;
  }
  .threads-panel.is-collapsed .panel-heading > div:first-child,
  .threads-panel.is-collapsed .panel-heading-actions > :not(#threads-panel-toggle) { display: none; }
  .threads-panel.is-collapsed .panel-heading-actions { display: block; }
  #threads-panel-toggle[aria-expanded="false"] svg { transform: rotate(180deg); }
}

@media (max-width: 720px) {
  .shell { padding: 10px; }
  .topbar { align-items: flex-start; padding-bottom: 10px; padding-left: 52px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
  .topbar { position: relative; z-index: 4; }
  body.mobile-menu-open { overflow: hidden; }
  .mobile-menu-button {
    position: fixed;
    z-index: 7;
    left: calc(14px + env(safe-area-inset-left, 0px));
    top: calc(14px + env(safe-area-inset-top, 0px));
    display: inline-grid;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  }
  .workspace { position: relative; grid-template-columns: 1fr; height: auto; min-height: calc(100dvh - 90px); overflow: visible; }
  .conversation-panel { min-height: calc(100dvh - 90px); }
  .conversation-view { display: block; min-height: calc(100dvh - 90px); }
  .messages-list { min-height: 0; overflow: visible; }
  .message-composer { position: sticky; bottom: 0; z-index: 3; }
  .threads-panel {
    position: fixed;
    z-index: 6;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(88vw, 360px);
    height: 100vh;
    border-right: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 0 14px 14px 0;
    background: var(--panel);
    box-shadow: 18px 0 50px rgba(0, 0, 0, .38);
    transform: translateX(-105%);
    transition: transform .2s ease;
  }
  .threads-panel.is-open { transform: translateX(0); }
  .mobile-menu-close { display: inline-grid; font-size: 1.2rem; line-height: 1; }
  .mobile-menu-backdrop {
    position: fixed;
    z-index: 5;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(0, 0, 0, .58);
  }
  .mobile-menu-backdrop.is-visible { display: block; }
  .thread-search { padding: 0 8px 8px; }
  .threads-list { display: grid; gap: 4px; padding: 6px; }
  .thread-button { min-width: 0; }
  .conversation-empty { min-height: 40vh; }
  .conversation-header { min-height: 64px; padding: 12px; }
  .conversation-title-row { flex-wrap: wrap; }
  .conversation-actions { margin-left: auto; }
  .messages-list { padding: 12px 8px 16px; }
  .message-composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .message-composer textarea { min-height: 78px; max-height: 140px; overflow-y: auto; }
  .message { max-width: 96%; }
.settings-panel { padding: 14px 10px 24px; }
.settings-form { padding: 11px; }
.form-field { grid-template-columns: 1fr; gap: 6px; }
.form-field .hint, .form-field-wide .hint { grid-column: 1; margin-top: -1px; }
.form-field-checkbox { grid-template-columns: 1fr auto; align-items: center; }
.form-field-checkbox input { grid-column: 2; grid-row: 1; }
.conversation-profile { flex: 1 1 180px; }
}

@media (max-width: 420px) {
  .message-composer-row { grid-template-columns: 1fr; }
  .composer-actions { justify-content: flex-end; }
  .conversation-title-row { align-items: flex-start; }
}
