:root {
  color-scheme: dark;
  --bg: #12141a;
  --panel: #1a1d26;
  --panel-2: #20232e;
  --border: #2a2e3a;
  --text: #e6e8ee;
  --muted: #8a90a2;
  --accent: #5b8cff;
  --claude: #d97757;
  --codex: #34c37e;
  --moi: #5b8cff;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

/* Several elements below are shown/hidden by toggling the `hidden` attribute from JS,
   but also carry an unconditional `display: flex` class rule (e.g. .modal-overlay,
   .conv-active). An author-stylesheet `display` declaration beats the browser's
   default `[hidden] { display: none }` rule regardless of selector specificity, so
   without this it silently stays visible. Force it, unconditionally. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.login-body {
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: min(320px, 90vw);
}

.login-card h1 { margin: 0; }
.muted { color: var(--muted); }
.login-card .muted { margin: 0 0 0.5rem; font-size: 0.9rem; }

input, textarea, select, button {
  font-family: inherit;
  font-size: 1rem;
  background: #22252f;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
}

button {
  cursor: pointer;
  background: var(--accent);
  border: none;
  color: white;
  font-weight: 600;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.ghost-btn {
  background: #22252f;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
}
.ghost-btn:hover { color: var(--text); }
.ghost-btn.danger:hover { color: #ff8a8a; border-color: var(--danger); }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.topbar h1 { font-size: 1.1rem; margin: 0; flex-shrink: 0; }
.tabs { display: flex; gap: 0.5rem; flex: 1; }
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}
.tab-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 0.6rem; }
.whoami { color: var(--muted); font-size: 0.85rem; }
.logout-btn { background: #3a2c2c; }

main { min-height: 0; min-width: 0; flex: 1; overflow: hidden; display: flex; }
.tab-panel { min-width: 0; min-height: 0; display: none; flex: 1; overflow: hidden; }
.tab-panel.active { display: flex; }
#tab-terminal.tab-panel.active { flex-direction: column; padding: 1rem; }

/* --- Conversations layout --- */
.conv-sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  gap: 0.75rem;
  overflow-y: auto;
}
.conv-new-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.new-conv-btn {
  flex: 1;
  min-width: 70px;
  font-size: 0.8rem;
  padding: 0.5rem 0.4rem;
  color: white;
  border: none;
}
.new-conv-btn.claude { background: var(--claude); }
.new-conv-btn.codex { background: var(--codex); }
.new-conv-btn.note { background: #444a5c; }

.conv-list { display: flex; flex-direction: column; gap: 0.9rem; overflow-y: auto; }
.conv-group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.conv-item {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 0.3rem;
  border-left: 3px solid transparent;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-2); border-color: var(--border); }
.conv-item.claude.active, .conv-item.claude:hover { border-left-color: var(--claude); }
.conv-item.codex.active, .conv-item.codex:hover { border-left-color: var(--codex); }
.conv-item.note.active, .conv-item.note:hover { border-left-color: var(--muted); }
.conv-item-title { font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item-meta { font-size: 0.72rem; color: var(--muted); margin-top: 0.15rem; }

.conv-main { min-height: 0; min-width: 0; flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 1rem; }
.conv-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  max-width: 420px;
  margin: 0 auto;
}
.conv-active { min-height: 0; flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.conv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.6rem;
  margin-bottom: 0.6rem;
}
.conv-title { font-weight: 700; display: block; }
.conv-header-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-bottom: 1rem;
}

.msg {
  max-width: 70%;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  position: relative;
}
.msg.moi { align-self: flex-end; border-color: var(--moi); }
.msg.claude { align-self: flex-start; border-color: var(--claude); }
.msg.codex { align-self: flex-start; border-color: var(--codex); }
.msg .author {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}
.msg.moi .author { color: var(--moi); }
.msg.claude .author { color: var(--claude); }
.msg.codex .author { color: var(--codex); }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.msg.pending .text { color: var(--muted); font-style: italic; animation: blink 1.4s ease-in-out infinite; }
.msg.error { border-color: var(--danger); }
.msg.error .text { color: #ff8a8a; }
.msg.system {
  align-self: center;
  background: transparent;
  border: none;
  padding: 0.2rem;
  max-width: 100%;
}
.msg.system .text { color: var(--muted); font-size: 0.75rem; text-align: center; }
@keyframes blink { 50% { opacity: 0.4; } }
.msg img {
  max-width: 220px;
  max-height: 220px;
  width: auto;
  height: auto;
  object-fit: cover;
  border-radius: 8px;
  margin-top: 0.4rem;
  display: block;
  cursor: zoom-in;
  border: 1px solid var(--border);
}
.msg .copy-btn {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.1rem 0.3rem;
}
.msg .copy-btn:hover { color: var(--text); }
.msg .ts { font-size: 0.7rem; color: var(--muted); margin-top: 0.3rem; }

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}
.chat-actions { display: flex; justify-content: space-between; align-items: center; }
.file-btn {
  cursor: pointer;
  background: #22252f;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}
.image-preview { position: relative; display: inline-block; width: fit-content; }
.image-preview img { max-height: 120px; border-radius: 8px; display: block; }
.image-preview button {
  position: absolute; top: -8px; right: -8px;
  border-radius: 50%; width: 24px; height: 24px; padding: 0;
  line-height: 1; background: var(--danger);
}

.term-output {
  flex: 1;
  overflow-y: auto;
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.term-line { margin-bottom: 0.6rem; position: relative; }
.term-line .prompt { color: var(--accent); }
.term-line .stdout { color: var(--text); }
.term-line .stderr { color: #ff6b6b; }
.term-line .copy-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 0.7rem; float: right;
}
.term-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.term-cwd { color: var(--muted); align-self: center; font-family: monospace; font-size: 0.8rem; }
.term-form input { min-width: 0; flex: 1; font-family: monospace; }

/* --- Resources --- */
.resources-panel { flex-direction: column; gap: 1rem; padding: 1.25rem; overflow-y: auto; }
.resource-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.3rem;
  max-width: 560px;
}
.resource-card h2 { margin: 0 0 0.6rem; font-size: 1rem; }
.disk-bar {
  height: 10px;
  border-radius: 999px;
  background: #22252f;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.disk-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.disk-bar-fill.danger { background: var(--danger); }
.resource-stats { list-style: none; margin: 0.4rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: min(400px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.modal.modal-wide { width: min(680px, 94vw); }
.modal h2 { margin: 0 0 0.25rem; font-size: 1.05rem; }
.modal h3 { margin: 0.5rem 0 0; font-size: 0.9rem; color: var(--muted); }
.modal label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

.admin-users-list { display: flex; flex-direction: column; gap: 0.4rem; }
.admin-user-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.admin-user-name { flex: 1; font-size: 0.88rem; }
.badge {
  background: var(--accent);
  color: white;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  vertical-align: middle;
}
.admin-add-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.admin-field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
.admin-field input { width: 100%; }
.admin-field:nth-child(3) { grid-column: 1 / -1; }
.admin-add-footer {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
}
.admin-checkbox { flex-direction: row !important; align-items: center; gap: 0.4rem !important; color: var(--text) !important; }

/* Compact layouts reuse the same components and color tokens. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 0.65rem; padding: 0.75rem; }
  .topbar-right { margin-left: auto; }
  .tabs { order: 3; flex: 1 0 100%; min-width: 0; }
  .tab-btn { flex: 1; white-space: nowrap; padding: 0.6rem 0.45rem; font-size: 0.85rem; }
}
@media (max-width: 600px) {
  #tab-chat.active { flex-direction: column; }
  .conv-sidebar { width: 100%; max-height: 30%; border-right: 0; border-bottom: 1px solid var(--border); padding: 0.65rem; gap: 0.5rem; }
  .conv-new-row { flex-shrink: 0; }
  .conv-main { padding: 0.75rem; }
  .whoami { max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-right { gap: 0.4rem; }
  .logout-btn { font-size: 0.8rem; padding: 0.5rem; }
  .msg { max-width: 95%; }
  .conv-header-info { min-width: 0; overflow-wrap: anywhere; }
  .term-form { flex-wrap: wrap; }
  .term-cwd { flex-basis: 100%; overflow-wrap: anywhere; }
  .resources-panel { padding: 0.75rem; }
  .admin-add-form { grid-template-columns: minmax(0, 1fr); padding: 0.65rem; }
  .admin-user-row { flex-wrap: wrap; }
  .admin-user-name { min-width: 0; overflow-wrap: anywhere; }
  .modal { padding: 1rem; }
}

/* Projects: shared shell, form and list patterns from the Superdesign direction. */
.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; }
.projects-panel { flex-direction: column; overflow-y: auto; padding: 1.5rem; gap: 1.25rem; }
.projects-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.25rem; }
.projects-header h2 { font-size: 1.2rem; margin: 0; }
.projects-header p { font-size: .9rem; margin: .5rem 0 0; line-height: 1.5; }
.projects-header button { flex-shrink: 0; font-size: .9rem; }
.projects-toolbar { display: flex; align-items: center; gap: 1rem; }
.search-field { flex: 1; max-width: 420px; min-width: 0; }
.search-field input { width: 100%; font-size: .9rem; }
.projects-toolbar > span { font-size: .8rem; white-space: nowrap; }
.project-list { border-top: 1px solid var(--border); }
.project-list:empty { display: none; }
.project-row { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: 1rem 0; border-bottom: 1px solid var(--border); }
.project-info { min-width: 0; }
.project-info h3 { margin: 0 0 .35rem; font-size: .95rem; font-weight: 600; overflow-wrap: anywhere; }
.project-path, .conv-project-dir { display: block; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.project-desc { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; overflow-wrap: anywhere; }
.project-meta { font-size: .75rem; color: var(--muted); margin: .4rem 0 0; }
.project-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.projects-empty { padding: 3rem 1rem; text-align: center; border: 1px dashed var(--border); border-radius: 8px; }
.projects-empty h3 { margin: 0; font-size: 1rem; }
.projects-empty p { max-width: 470px; margin: .75rem auto 1rem; line-height: 1.5; font-size: .9rem; }
.projects-footnote { margin: 0; font-size: .8rem; }
.project-modal { width: min(540px, 94vw); gap: .8rem; }
.project-modal input, .project-modal textarea { width: 100%; min-width: 0; }
.project-modal label { color: var(--text); }
.project-modal label .optional { display: contents; color: var(--muted); }
#project-directory { font-family: monospace; font-size: .9rem; }
.modal-intro, .field-help { font-size: .8rem; line-height: 1.5; margin: 0; }
.form-error { color: #ff8a8a; font-size: .85rem; line-height: 1.5; margin: 0; overflow-wrap: anywhere; }
.project-selector { display: flex; flex-direction: column; gap: .4rem; font-size: .75rem; color: var(--muted); }
.project-selector select { width: 100%; font-size: .85rem; padding: .5rem; }
.text-btn { background: transparent; color: var(--accent); text-align: left; padding: 0; font-size: .8rem; font-weight: 500; }
.conv-project-name { display: block; font-size: .75rem; margin: .3rem 0; color: var(--muted); }
.conv-header-info { min-width: 0; }
@media (max-width: 900px) {
  .project-row { align-items: flex-start; flex-direction: column; gap: .75rem; }
}
@media (max-width: 600px) {
  .projects-panel { padding: 1rem .75rem; }
  .projects-header { flex-direction: column; gap: .75rem; }
  .project-actions { flex-wrap: wrap; gap: .4rem; }
  .tabs { flex-wrap: wrap; }
  .tab-btn { flex: 1 1 40%; }
  .conv-sidebar { max-height: 42%; }
  .projects-empty { padding: 2rem 1rem; }
}

/* Account and administration: shared restrained Superdesign settings pattern. */
.management-panel { flex-direction: column; overflow: auto; padding: 1.5rem; gap: 1rem; }
.page-heading { display:flex; align-items:flex-start; justify-content:space-between; gap:1rem; }
.page-heading h2 { margin:0; font-size:1.25rem; letter-spacing:-.02em; }
.page-heading p { margin:.5rem 0 0; font-size:.9rem; line-height:1.5; }
.page-heading button { flex-shrink:0; font-size:.85rem; }
.settings-sections { border-top:1px solid var(--border); }
.settings-section { display:grid; grid-template-columns:minmax(190px,1fr) minmax(0,2fr); gap:2rem; padding:1.5rem 0; border-bottom:1px solid var(--border); }
.section-summary h3 { font-size:.95rem; margin:0 0 .65rem; }
.section-summary p, .provider-controls > p { font-size:.85rem; line-height:1.6; margin:.5rem 0 1rem; }
.structured-form { display:flex; flex-direction:column; gap:.8rem; max-width:540px; }
.structured-form label, .provider-code-form label { display:flex; flex-direction:column; gap:.4rem; font-size:.85rem; }
.structured-form input { width:100%; }
.structured-form button, .provider-controls button { font-size:.85rem; }
.form-status { font-size:.85rem; line-height:1.5; margin:0; color:var(--muted); }
.form-status:empty { display:none; }
.form-status.is-error { color:#ff9c9c; }
.inline-actions, .row-actions { display:flex; flex-wrap:wrap; gap:.5rem; align-items:center; }
.row-actions button { font-size:.75rem; white-space:nowrap; }
.table-scroll { overflow-x:auto; border:1px solid var(--border); border-radius:8px; }
.data-table { width:100%; border-collapse:collapse; font-size:.85rem; text-align:left; }
.data-table th { color:var(--muted); font-size:.75rem; font-weight:500; background:var(--panel); }
.data-table th, .data-table td { padding:.9rem 1rem; border-bottom:1px solid var(--border); }
.data-table tr:last-child td { border-bottom:0; }
.data-table strong { font-size:.85rem; font-weight:600; }
.cell-secondary { display:block; color:var(--muted); font-size:.75rem; margin-top:.35rem; }
.status-badge { display:inline-flex; align-items:center; border:1px solid var(--border); border-radius:5px; padding:.2rem .5rem; font-size:.72rem; white-space:nowrap; }
.status-badge.positive, .success-text { color:#88d9b4; }
.status-badge.pending { color:#d6bd80; }
.settings-notice { border-left:2px solid var(--accent); padding:.15rem 0 .15rem .8rem; font-size:.85rem; color:var(--muted); line-height:1.6; margin:0; max-width:850px; }
.provider-controls { max-width:650px; min-width:0; }
.provider-flow { margin-top:1rem; }
.provider-flow:empty { display:none; }
.provider-flow p { font-size:.85rem; line-height:1.6; }
.official-link { display:inline-block; color:#97b7ff; font-size:.9rem; margin:.2rem 0 .8rem; text-underline-offset:4px; }
.provider-code-form { display:flex; flex-direction:column; align-items:flex-start; gap:.7rem; margin:.4rem 0 1rem; }
.provider-code-form label { width:100%; }
.provider-code-form input { width:100%; font-size:.85rem; }
.device-code { letter-spacing:.15em; font-size:1rem; padding:.4rem; background:var(--panel-2); border-radius:4px; }
.account-label { overflow-wrap:anywhere; }
.danger-button { background:#963d3d; }
.security-login { height:auto; min-height:100dvh; padding:2rem 1rem; }
.auth-panel { width:min(440px,100%); background:var(--panel); border:1px solid var(--border); border-radius:12px; padding:1.8rem; display:flex; flex-direction:column; gap:1rem; }
.auth-panel h1 { font-size:1.4rem; margin:0; letter-spacing:-.03em; }
.auth-panel h2 { font-size:1.1rem; margin:0; }
.auth-panel p { font-size:.85rem; line-height:1.6; margin:0; }
.eyebrow { color:var(--muted); font-size:.7rem; font-weight:600; letter-spacing:.08em; text-transform:uppercase; }
.stack-form { display:flex; flex-direction:column; gap:.6rem; }
.stack-form label { font-size:.85rem; }
.qr-frame { display:flex; justify-content:center; margin:.4rem 0 1rem; }
.qr-frame img { border-radius:8px; background:white; }
.secret-key { display:block; overflow-wrap:anywhere; letter-spacing:.06em; font-size:.85rem; padding:.6rem 0; user-select:all; }
summary { color:var(--muted); cursor:pointer; font-size:.8rem; margin-bottom:.6rem; }
#factor-enrollment > p { margin:.6rem 0; }
.recovery-codes { resize:none; width:100%; font-family:monospace; font-size:.85rem; line-height:1.8; margin:.5rem 0; }
#factor-recovery { display:flex; flex-direction:column; gap:.8rem; }
#factor-code { text-align:center; font-size:1.2rem; letter-spacing:.15em; }
.topbar .tabs { gap:.25rem; }
.topbar .tab-btn { font-size:.8rem; padding:.6rem .65rem; }
@media(max-width:1100px){.topbar { flex-wrap:wrap; }.topbar .tabs{order:3;flex:1 0 100%;}.topbar-right{margin-left:auto;}.topbar .tab-btn{flex:1;white-space:nowrap;}}
@media(max-width:700px){.management-panel { padding:1rem .75rem; }.settings-section { grid-template-columns:minmax(0,1fr); gap:.75rem; padding:1.25rem 0; }.page-heading { flex-wrap:wrap; }.data-table { min-width:650px; }.topbar .tabs { overflow-x:auto; flex-wrap:nowrap; }.topbar .tab-btn { flex:0 0 auto; }.auth-panel { padding:1.25rem; }.inline-actions { align-items:stretch; }.inline-actions button { flex:1 1 auto; }}
.management-panel > .search-field { flex:0 0 auto; width:100%; }
.management-panel > * { flex-shrink:0; }
.auth-panel { flex:none; overflow:visible; }
