:root {
  color-scheme: dark;
  --bg: #0b0f17;
  --bg-elev: #111827;
  --bg-hover: #1f2937;
  --border: #1f2937;
  --border-strong: #374151;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --text-muted: #6b7280;
  --accent: #a5b4fc;
  --accent-strong: #6366f1;
  --accent-hover: #4f46e5;
  --danger: #f87171;
  --success: #34d399;
  --warning: #fbbf24;
  --running: #60a5fa;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 52px 1fr;
  grid-template-areas:
    "topbar   topbar"
    "sidebar  main";
  height: 100vh;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  color: var(--accent);
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.broadcast-slot {
  flex: 1;
  display: flex;
  justify-content: flex-end;
}

.menu-btn { display: none; }

.sidebar {
  grid-area: sidebar;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 0.75rem 0.5rem;
}

.terminals {
  grid-area: main;
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  overflow: hidden;
  position: relative;
}

.terminals.split { grid-template-columns: 1fr 1fr; }

/* ---------- sidebar ---------- */
.sidebar-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem 0.75rem;
  align-items: center;
}
.ws-select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.sidebar-actions { padding: 0 0.5rem 0.75rem; }

.sidebar-section {
  padding: 0.5rem 0.25rem;
}
.sidebar-heading {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 0.5rem 0.35rem;
  font-weight: 600;
}

.session-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.session-row:hover { background: var(--bg-hover); }
.session-row.active { background: var(--bg-hover); outline: 1px solid var(--accent-strong); }
.session-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}
.broadcast-select { accent-color: var(--accent-strong); cursor: pointer; }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  background: var(--text-muted);
}
.status-idle    { background: var(--text-muted); }
.status-running { background: var(--running); box-shadow: 0 0 6px var(--running); }
.status-error   { background: var(--danger); }
.status-dead    { background: var(--border-strong); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

.sidebar-footer {
  margin-top: auto;
  padding: 0.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  border-top: 1px solid var(--border);
}

.empty {
  padding: 0.75rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* ---------- buttons ---------- */
.btn {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: white;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-block { width: 100%; }
.btn-small { padding: 0.3rem 0.55rem; font-size: 0.8rem; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ---------- broadcast bar ---------- */
.broadcast-bar {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  width: 100%;
  max-width: 720px;
}
.broadcast-target {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
}
.broadcast-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  min-width: 0;
}
.broadcast-input:focus { outline: none; border-color: var(--accent-strong); }
.voice-btn.recording {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.1);
}

/* ---------- terminals ---------- */
.terminal-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  min-width: 0;
}
.terminal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.pane-title { font-weight: 600; color: var(--text); }
.pane-cwd { color: var(--text-muted); font-family: ui-monospace, monospace; font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.terminal-body {
  flex: 1;
  overflow: hidden;
  padding: 4px;
  background: var(--bg);
}
.terminal-body .xterm { height: 100%; }

/* ---------- drawers ---------- */
.drawer {
  position: fixed;
  top: 52px;
  bottom: 0;
  right: 0;
  width: min(420px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer[hidden] { display: none; }
.drawer-left-of-right { right: 0; }
.drawer-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.drawer-header h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent);
  flex: 1;
}
.activity-search {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}
.activity-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}
.activity-row {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.activity-meta {
  display: flex;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.activity-kind { font-weight: 600; color: var(--accent); }
.activity-prompt .activity-kind { color: var(--accent); }
.activity-response .activity-kind { color: var(--success); }
.activity-error .activity-kind { color: var(--danger); }
.activity-body {
  font-family: ui-monospace, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.4;
}

/* ---------- files ---------- */
.files-crumbs {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.crumb { cursor: pointer; }
.crumb:hover { color: var(--accent); }
.crumb-sep { color: var(--text-muted); margin: 0 0.15rem; }
.files-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}
.file-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}
.file-row:hover { background: var(--bg-hover); }
.file-icon { color: var(--text-muted); width: 1rem; text-align: center; }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; flex: 1; color: var(--accent); font-size: 1rem; }
.modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
}
.modal-body section { margin-bottom: 1.25rem; }
.modal-body h4 { margin: 0.5rem 0 0.5rem; color: var(--text-dim); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.modal-body hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.muted { color: var(--text-muted); font-size: 0.85rem; }

.template-list { display: flex; flex-direction: column; gap: 0.5rem; }
.template-row {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.template-name { font-weight: 600; color: var(--accent); margin-bottom: 0.25rem; }
.template-body {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.5rem;
}
.template-actions { display: flex; gap: 0.5rem; }
.template-form { display: flex; flex-direction: column; gap: 0.5rem; }
.template-form input,
.template-form textarea {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
.template-form textarea {
  min-height: 100px;
  font-family: ui-monospace, monospace;
  resize: vertical;
}

/* ---------- settings modal ---------- */
.settings-field {
  margin-bottom: 0.85rem;
}
.settings-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.settings-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.settings-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
  min-width: 0;
}
.settings-input:focus {
  outline: none;
  border-color: var(--accent-strong);
}
.settings-input[readonly] {
  font-family: ui-monospace, monospace;
  color: var(--text-dim);
}
.settings-input-narrow {
  max-width: 120px;
  flex: 0 0 auto;
}
.settings-input-mono {
  font-family: ui-monospace, Menlo, Monaco, "Cascadia Code", monospace;
  font-size: 0.8rem;
}
.settings-row-end {
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.25rem;
}
.settings-hint-inline {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 0.3rem;
}
.settings-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  min-height: 1em;
}
.settings-status {
  font-size: 0.8rem;
  margin-top: 0.4rem;
  min-height: 1em;
}
.settings-status.success { color: var(--success); }
.settings-status.error { color: var(--danger); }
.settings-details {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}
.settings-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  list-style: none;
}
.settings-details summary::before {
  content: "\25B8  ";
  font-size: 0.7rem;
}
.settings-details[open] summary::before {
  content: "\25BE  ";
}
.settings-steps {
  padding-left: 1.1rem;
  margin: 0.6rem 0 0;
  line-height: 1.55;
}
.settings-steps li {
  margin-bottom: 0.3rem;
}
.settings-steps code {
  background: var(--bg);
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  font-size: 0.78rem;
  color: var(--text);
  font-family: ui-monospace, monospace;
}

/* ---------- view switcher ---------- */
.view-switcher {
  display: flex;
  gap: 2px;
  background: var(--bg);
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
}
.view-switcher button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.view-switcher button.active {
  background: var(--accent-strong);
  color: white;
}

/* ---------- kanban view ---------- */
.kanban-view {
  grid-area: main;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.kanban-view[hidden] { display: none; }

body.view-kanban .sidebar { display: none; }
body.view-kanban .terminals { display: none; }
body.view-kanban .layout {
  grid-template-columns: 1fr;
  grid-template-areas:
    "topbar"
    "main";
}

.kanban-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.ws-chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.ws-chip {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  border-left: 3px solid var(--ws-color, var(--accent-strong));
  font-family: inherit;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.ws-chip.active {
  background: var(--bg-hover);
  color: var(--text);
  opacity: 1;
}

.kanban-board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, minmax(260px, 1fr));
  gap: 0.5rem;
  padding: 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
}

.kanban-column {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  transition: border-color 0.15s, background 0.15s;
}
.kanban-column.drop-target {
  border-color: var(--accent-strong);
  background: var(--bg-hover);
}

.kanban-col-header {
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.kanban-col-count {
  background: var(--bg);
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.kanban-col-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.add-card-btn {
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 0.25rem;
  font-family: inherit;
}
.add-card-btn:hover {
  color: var(--text);
  border-color: var(--accent-strong);
}

.kanban-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: grab;
  display: flex;
  overflow: hidden;
  transition: border-color 0.15s;
}
.kanban-card:hover { border-color: var(--border-strong); }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.35; }

.card-color-bar {
  width: 3px;
  flex-shrink: 0;
}
.card-body {
  padding: 0.55rem 0.7rem;
  flex: 1;
  min-width: 0;
}
.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.35;
  margin-bottom: 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.ws-tag { font-weight: 600; }
.card-has-session {
  color: var(--running);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kanban-card.card-flag-error {
  border-color: var(--danger);
}
.kanban-card.card-flag-error .card-color-bar {
  background: var(--danger) !important;
}

/* ---------- polished modal system ---------- */
.modal-backdrop {
  background: rgba(4, 7, 18, 0.72);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  animation: modal-backdrop-in 180ms ease-out;
}
@keyframes modal-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  border-color: rgba(148, 163, 184, 0.12);
  border-radius: 16px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 30px 60px -20px rgba(3, 7, 18, 0.7),
    0 18px 36px -18px rgba(3, 7, 18, 0.55),
    0 0 0 1px rgba(99, 102, 241, 0.04);
  animation: modal-in 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-sm { width: min(420px, 100%); }

.modal-header {
  padding: 1.1rem 1.4rem;
  border-bottom-color: rgba(148, 163, 184, 0.08);
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.05), transparent);
}
.modal-header h3 {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.modal-body {
  padding: 1.25rem 1.4rem 1.5rem;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.9rem 1.4rem 1.15rem;
  border-top: 1px solid rgba(148, 163, 184, 0.06);
  background: linear-gradient(0deg, rgba(148, 163, 184, 0.02), transparent);
}

/* ---------- polished buttons ---------- */
.btn {
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-weight: 500;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease,
    color 140ms ease;
}
.btn:hover {
  border-color: #4b5568;
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0) scale(0.98);
}
.btn:focus-visible {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.28);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-primary {
  background: linear-gradient(180deg, #6b6dff, #5457e7);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 6px 16px -6px rgba(99, 102, 241, 0.55);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #7b7dff, #4f52e0);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 10px 22px -6px rgba(99, 102, 241, 0.62);
}
.btn-primary:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 4px 12px -4px rgba(99, 102, 241, 0.45);
}
.btn-danger {
  background: linear-gradient(180deg, #ef5757, #dc2626);
  border-color: transparent;
  color: white;
  font-weight: 600;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 6px 16px -6px rgba(220, 38, 38, 0.55);
}
.btn-danger:hover {
  background: linear-gradient(180deg, #f56363, #c81e1e);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 10px 22px -6px rgba(220, 38, 38, 0.62);
}
.btn-ghost:hover {
  transform: none;
  border-color: transparent;
}

.icon-btn {
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.icon-btn:focus-visible {
  outline: none;
  background: var(--bg-hover);
  color: var(--text);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

/* ---------- polished inputs ---------- */
.settings-input:focus,
.template-form input:focus,
.template-form textarea:focus {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22);
}
.settings-input,
.template-form input,
.template-form textarea {
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
  border-radius: 8px;
}

/* ---------- dialog content (confirm/prompt/form) ---------- */
.dialog-body {
  padding: 1.25rem 1.4rem 0.5rem;
}
.dialog-title {
  margin: 0 0 0.4rem;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.dialog-message {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.55;
  text-wrap: pretty;
}
.dialog-field {
  margin-top: 1rem;
}
.dialog-field-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}
.dialog-field-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  line-height: 1.45;
}
.dialog-field-error {
  font-size: 0.76rem;
  color: var(--danger);
  margin-top: 0.35rem;
  min-height: 1em;
}
.dialog-input,
.dialog-select,
.dialog-textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.58rem 0.85rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.dialog-input:focus,
.dialog-select:focus,
.dialog-textarea:focus {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22);
}
.dialog-textarea {
  min-height: 92px;
  resize: vertical;
  font-family: ui-monospace, Menlo, Monaco, "Cascadia Code", monospace;
  font-size: 0.83rem;
  line-height: 1.5;
}
.dialog-select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% - 2px),
    calc(100% - 11px) calc(50% - 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

/* ---------- toast system ---------- */
.toast-container {
  position: fixed;
  top: 72px;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 400;
  pointer-events: none;
  max-width: calc(100% - 2rem);
}
.toast {
  pointer-events: auto;
  min-width: 260px;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-left: 3px solid var(--accent-strong);
  border-radius: 10px;
  padding: 0.7rem 0.85rem 0.7rem 0.8rem;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.45;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 18px 36px -18px rgba(3, 7, 18, 0.6);
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  cursor: pointer;
  animation: toast-in 220ms cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast.toast-leaving {
  animation: toast-out 160ms ease-in forwards;
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-10px); }
}
.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  margin-top: 1px;
}
.toast-message {
  flex: 1;
  word-wrap: break-word;
}
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon {
  background: rgba(52, 211, 153, 0.18);
  color: var(--success);
}
.toast-error { border-left-color: var(--danger); }
.toast-error .toast-icon {
  background: rgba(248, 113, 113, 0.18);
  color: var(--danger);
}
.toast-info { border-left-color: var(--accent-strong); }
.toast-info .toast-icon {
  background: rgba(99, 102, 241, 0.2);
  color: var(--accent);
}
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon {
  background: rgba(251, 191, 36, 0.18);
  color: var(--warning);
}

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr 56px;
    grid-template-areas:
      "topbar"
      "main"
      "broadcast-bottom";
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 80;
    border-right: 1px solid var(--border);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 52px 0 0 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 70;
  }
  .menu-btn { display: inline-block; }
  .menu-btn .bars {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text);
    position: relative;
  }
  .menu-btn .bars::before,
  .menu-btn .bars::after {
    content: "";
    position: absolute;
    left: 0;
    width: 18px;
    height: 2px;
    background: var(--text);
  }
  .menu-btn .bars::before { top: -6px; }
  .menu-btn .bars::after { top: 6px; }

  .broadcast-slot {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 56px;
    padding: 8px;
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
    z-index: 60;
  }
  .broadcast-bar { max-width: none; }
  .broadcast-target { display: none; }

  .terminals.split { grid-template-columns: 1fr; }
  .drawer { top: 52px; width: 100vw; bottom: 56px; }

  .view-switcher button { padding: 0.3rem 0.55rem; font-size: 0.75rem; }
  .kanban-board {
    grid-template-columns: 1fr;
    grid-auto-rows: min-content;
    overflow-x: hidden;
    overflow-y: auto;
  }
  .kanban-column { min-height: 40vh; }
  body.view-kanban .broadcast-slot { display: none; }
  body.view-kanban .layout { grid-template-rows: 52px 1fr; }
}

/* ---------- project wizard ---------- */

.wizard-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.wizard-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.wizard-card:hover {
  background: var(--bg-elev);
  border-color: var(--accent);
}
.wizard-card-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text);
}
.wizard-card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.wizard-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.connect-steps {
  padding-left: 1.25rem;
}
.connect-steps li {
  margin: 0.625rem 0;
}
.connect-url,
.connect-code {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.375rem;
  flex-wrap: wrap;
}
.connect-code code {
  font-size: 1.3rem;
  letter-spacing: 2px;
  padding: 0.25rem 0.625rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
}
.connect-url code {
  background: var(--bg);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 0.85rem;
  word-break: break-all;
  flex: 1 1 auto;
  min-width: 0;
}

.repo-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.repo-search {
  flex: 1;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}
.repo-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.repo-row {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.repo-row:last-child {
  border-bottom: none;
}
.repo-row:hover {
  background: var(--bg-elev);
}
.repo-name {
  font-weight: 500;
  color: var(--text);
}
.repo-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}
.badge {
  font-size: 0.7rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 0.0625rem 0.375rem;
  border-radius: 3px;
  margin-left: 0.25rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.75rem 0;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.wiz-input {
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
}

.error-banner {
  background: rgba(200, 60, 60, 0.1);
  border: 1px solid rgba(200, 60, 60, 0.4);
  color: #ff8888;
  padding: 0.625rem 0.75rem;
  border-radius: 6px;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

.spinner-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 0;
  color: var(--text-dim);
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: wizard-spin 0.8s linear infinite;
}
@keyframes wizard-spin {
  to { transform: rotate(360deg); }
}
