/* Web Terminal Design System — Clean, Terminal-Native, Mobile & Desktop Ergonomic */

:root {
  --bg: #0b0e14;
  --bg-elev: #11161f;
  --bg-surface: #161c28;
  --bg-hover: #1e2636;
  --border: #242d3d;
  --border-strong: #323e54;
  --text: #e6edf3;
  --text-dim: #9aa7b8;
  --muted: #6e7a8a;
  --accent: #58a6ff;
  --accent-bg: rgba(88, 166, 255, 0.14);
  --good: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 8px;
  --radius-sm: 6px;
  --header-h: 42px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* === App Shell === */
#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100dvh;
  display: none;
  flex-direction: column;
  background: var(--bg);
  padding-top: var(--safe-top);
}

@media (display-mode: fullscreen) {
  #app { padding-top: 0; }
}

/* === Top Bar === */
.topbar {
  height: var(--header-h);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  user-select: none;
  z-index: 20;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
}
.conn-pill:hover { border-color: var(--border-strong); background: var(--bg-hover); }

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.conn-dot.connected { background: var(--good); box-shadow: 0 0 6px rgba(63, 185, 80, 0.6); }
.conn-dot.connecting, .conn-dot.reconnecting { background: var(--warn); animation: pulse 1.1s infinite; }
.conn-dot.disconnected { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* === Session Tab Strip === */
.tab-strip {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}
.tab-strip::-webkit-scrollbar { display: none; }

.tab-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 6px 0 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  max-width: 190px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.tab-item:hover { background: var(--bg-surface); color: var(--text); }
.tab-item.active {
  background: var(--bg-surface);
  border-color: var(--border-strong);
  color: var(--text);
  font-weight: 500;
}
.tab-item.has-activity { color: var(--accent); }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.b-shell { background: rgba(139, 148, 158, 0.2); color: #c9d1d9; }
.b-claude { background: rgba(217, 119, 87, 0.24); color: #f09574; }
.b-agy { background: rgba(88, 166, 255, 0.22); color: #79c0ff; }
.b-kimi { background: rgba(188, 140, 255, 0.22); color: #d2a8ff; }
.b-codex { background: rgba(63, 185, 80, 0.22); color: #56d364; }
.b-action { background: var(--bg-hover); color: var(--text-dim); }

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-act-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.tab-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
}
.tab-close:hover { opacity: 1; background: rgba(248, 81, 73, 0.18); color: var(--danger); }

.tab-add-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tab-add-btn:hover { background: var(--bg-surface); color: var(--text); border-style: solid; }

/* === Topbar Right Actions === */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  position: relative;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 28px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.icon-btn:hover { background: var(--bg-surface); color: var(--text); }
.icon-btn.active { background: var(--accent-bg); color: var(--accent); border-color: rgba(88, 166, 255, 0.35); }

.kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

.mobile-only { display: none; }

.more-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 170px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  padding: 4px;
  display: none;
  flex-direction: column;
  z-index: 60;
}
.more-menu.open { display: flex; }

.menu-item {
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
}
.menu-item:hover { background: var(--bg-hover); }

/* === Reconnect Banner === */
.conn-banner {
  display: none;
  padding: 6px 12px;
  background: rgba(210, 153, 34, 0.16);
  border-bottom: 1px solid rgba(210, 153, 34, 0.35);
  color: #f0c965;
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  z-index: 15;
}
.conn-banner.show { display: block; }

/* === Main Terminal & VNC === */
#terminal-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--bg);
  overflow: hidden;
  padding: 4px 6px 2px;
}

#terminal {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 2px;
  transition: box-shadow 0.15s;
}
.term-pane {
  display: none;
  width: 100%;
  height: 100%;
  border-radius: 2px;
  transition: box-shadow 0.15s;
}
.term-pane.active {
  display: block;
}
.term-pane.bell-flash,
#terminal.bell-flash { box-shadow: inset 0 0 0 2px var(--warn); }

#vnc-container {
  flex: 1;
  min-height: 0;
  display: none;
  background: #000;
  overflow: hidden;
}
#vnc-container.open { display: flex; align-items: center; justify-content: center; }

/* Screen (noVNC) のキーバー。スマホでソフトキーボードを出す入口 */
#vnc-keys {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  user-select: none;
  flex-shrink: 0;
}
#vnc-keys::-webkit-scrollbar { display: none; }
#vnc-keys.open { display: flex; }
.vnc-kbd-input {
  position: fixed;
  left: -1000px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px; /* iOS がフォーカス時にズームしないように */
}

/* === Mobile Virtual Keybar === */
#mobile-keys {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  user-select: none;
  flex-shrink: 0;
}
#mobile-keys::-webkit-scrollbar { display: none; }

.vkey {
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.vkey:active { background: var(--bg-hover); transform: translateY(1px); }
.vkey.armed {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}
.vkey-util {
  color: var(--text-dim);
  min-width: 36px;
}

@media (max-width: 768px) {
  #mobile-keys { display: flex; }
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex; }
  .tab-item { max-width: 135px; }
  .conn-pill { padding: 0 7px; font-size: 10px; }
}

/* === Side Drawer (z-index: 40) === */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
  z-index: 40;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 36px rgba(0, 0, 0, 0.55);
  transform: translateX(100%);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
  z-index: 45;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.side-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.drawer-tabs {
  flex: 1;
  display: flex;
  gap: 2px;
  background: var(--bg);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.drawer-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.drawer-tab.active { background: var(--bg-surface); color: var(--text); }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.drawer-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
}

.drawer-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.drawer-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.drawer-card-head .drawer-card-title { margin-bottom: 0; }

/* === Lists & Stats === */
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
}
.stat-label { color: var(--muted); flex-shrink: 0; }
.stat-val { color: var(--text); font-family: var(--font-mono); font-size: 12px; text-align: right; word-break: break-all; }
.stat-val.good { color: var(--good); }
.stat-val.warn { color: var(--warn); }

.meter {
  height: 5px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 4px;
}
.meter-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.meter-fill.good { background: var(--good); }
.meter-fill.warn { background: var(--warn); }

.item-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--bg-elev);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background 0.12s, border-color 0.12s;
}
.list-row:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.list-row.active { border-color: var(--accent); background: var(--accent-bg); }
.list-row-main { min-width: 0; flex: 1; }
.list-row-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-row-sub {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}
.row-chevron { color: var(--muted); font-size: 12px; flex-shrink: 0; }

.status-dot-sm {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.status-dot-sm.good { background: var(--good); }

.pill-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
}

.seg-group {
  display: flex;
  gap: 3px;
  background: var(--bg);
  padding: 3px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  padding: 5px;
  border-radius: 4px;
  cursor: pointer;
}
.seg-btn.active { background: var(--bg-hover); color: var(--text); font-weight: 600; }

.muted-note { font-size: 11px; color: var(--muted); line-height: 1.45; margin-top: 4px; }
.link-accent { color: var(--accent); text-decoration: none; font-size: 11px; }
.link-accent:hover { text-decoration: underline; }

/* === Buttons & Inputs === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #08101c; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { background: rgba(248, 81, 73, 0.15); border-color: rgba(248, 81, 73, 0.45); color: #ff8e88; }
.btn-danger:hover { background: rgba(248, 81, 73, 0.25); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 5px 9px; font-size: 11px; }
.btn-xs { padding: 3px 7px; font-size: 11px; }

.icon-xs {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.icon-xs:hover { background: var(--bg-hover); color: var(--text); }
.icon-xs.danger:hover { background: rgba(248, 81, 73, 0.2); color: var(--danger); }

.input {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.input:focus { border-color: var(--accent); }

.inline-actions { display: inline-flex; align-items: center; gap: 8px; }

/* === Keybar Editor === */
.key-editor-list { display: flex; flex-wrap: wrap; gap: 5px; }
.key-editor-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 5px 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
}
.key-editor-add { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip-add {
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
}
.chip-add:hover { background: var(--bg-hover); color: var(--text); border-style: solid; }

/* === G2 Glasses UI === */
.g2-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.g2apps-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.g2app-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  cursor: pointer;
  font-size: 11px;
}
.g2app-tile.sel { border-color: var(--accent); background: var(--accent-bg); }
.g2app-tile.off { opacity: 0.65; }
.g2app-tile .dot { position: absolute; top: 6px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.g2app-tile.running .dot { background: var(--good); }
.g2app-tile .ico { font-size: 18px; }

.g2-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
}
.g2-slider input { flex: 1; accent-color: var(--accent); }
.g2-slider .v { min-width: 28px; text-align: right; font-family: var(--font-mono); color: var(--text); }

.g2-space-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.g2-space-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border-radius: 5px;
  background: var(--bg-elev);
  font-size: 11px;
}
.g2-space-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g2-space-pane { color: var(--muted); font-family: var(--font-mono); font-size: 10px; }

.g2-hint-card {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  background: var(--bg-elev);
}
.g2-transcript {
  margin-top: 6px;
  max-height: 70px;
  overflow-y: auto;
  font-size: 10px;
  color: var(--muted);
  white-space: pre-wrap;
}
.g2-preview {
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #000;
  display: none;
  image-rendering: pixelated;
}
.g2-preview.on { display: block; }
.g2-shot-img { width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-top: 6px; image-rendering: pixelated; }
.g2-log-details { margin-top: 8px; font-size: 11px; color: var(--muted); }
.g2-log {
  margin-top: 6px;
  max-height: 160px;
  overflow: auto;
  padding: 6px;
  border-radius: 4px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  white-space: pre-wrap;
}

/* === Full-Screen Overlays: Tiles & Rail (z-index: 50) === */
.fs-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 20, 0.96);
  display: none;
  flex-direction: column;
  z-index: 50;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.fs-overlay.open { display: flex; }

.fs-overlay-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.fs-overlay-title { font-weight: 600; font-size: 13px; }
.fs-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--text-dim); }
.fs-controls label { display: inline-flex; align-items: center; gap: 5px; }

.tile-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 10px;
  align-content: start;
}

.tile-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  height: 220px;
  transition: border-color 0.15s;
}
.tile-card:hover { border-color: var(--accent); }
.tile-card.active { border-color: var(--good); }
.tile-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.tile-card-title { display: flex; align-items: center; gap: 5px; font-weight: 600; flex-shrink: 0; }
.tile-card-sub { flex: 1; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-term-wrap { flex: 1; overflow: hidden; padding: 4px; pointer-events: none; }

/* Rail */
.rail-track {
  flex: 1;
  display: flex;
  gap: 10px;
  padding: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  --rail-w: 460px;
}
.rail-track.snap { scroll-snap-type: x mandatory; }

.rail-strip {
  width: var(--rail-w);
  min-width: var(--rail-w);
  height: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  scroll-snap-align: start;
}
.rail-strip:hover { border-color: var(--accent); }
.rail-strip.active { border-color: var(--good); }
.rail-strip-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.rail-strip-title { display: flex; align-items: center; gap: 5px; font-weight: 600; flex-shrink: 0; }
.rail-strip-sub { flex: 1; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-strip-body { flex: 1; min-height: 0; padding: 4px; overflow: hidden; pointer-events: none; }

.empty-state {
  margin: auto;
  color: var(--muted);
  font-size: 13px;
  padding: 24px;
}

/* === Modals & Command Palette (z-index: 70-80) === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 75;
}

.palette-backdrop { align-items: flex-start; padding-top: min(12vh, 90px); }

.modal-card {
  width: min(440px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.modal-body { font-size: 13px; color: var(--text-dim); line-height: 1.5; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.field-group { margin-bottom: 12px; }
.field-label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 5px; font-weight: 500; }

.tool-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-pill {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}
.tool-pill.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* Command Palette */
.palette-card {
  width: min(540px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}
.palette-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.palette-icon { color: var(--accent); font-size: 15px; }
.palette-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.palette-list { max-height: min(60vh, 420px); overflow-y: auto; padding: 6px; }
.palette-group {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 8px 8px 4px;
}
.palette-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.palette-item.selected { background: var(--accent-bg); }
.palette-item-main { min-width: 0; flex: 1; }
.palette-item-title { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item-sub { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-empty { text-align: center; padding: 24px; color: var(--muted); font-size: 13px; }

/* === Login Screen (z-index: 90 — always above overlays!) === */
#login-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 20%, #151d2e 0%, var(--bg) 65%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 90;
}

.login-card {
  width: min(340px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 26px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-logo { font-family: var(--font-mono); font-size: 18px; font-weight: 700; color: var(--text); }
.login-sub { font-size: 12px; color: var(--muted); margin-top: -6px; }
.login-error { font-size: 12px; color: var(--danger); min-height: 16px; }

/* === Toasts (z-index: 100) === */
.toast-stack {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  padding: 8px 13px;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: auto;
  cursor: pointer;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-good { border-color: rgba(63, 185, 80, 0.5); color: #7ee787; }
.toast-warn { border-color: rgba(210, 153, 34, 0.5); color: #f0c965; }
.toast-error { border-color: rgba(248, 81, 73, 0.55); color: #ff8e88; }

/* === Conductor Overlay === */
.cond-header { justify-content: space-between; }
.cond-header-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cond-header-right { display: flex; align-items: center; gap: 8px; }
.cond-status { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-dim); }
.cond-status-item { display: inline-flex; align-items: center; gap: 5px; }
.cond-status-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.cond-status-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--bg-hover); }
.cond-status-btn:disabled { opacity: 0.55; cursor: default; }

.cond-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.cond-dot.on { background: var(--good); box-shadow: 0 0 6px rgba(63, 185, 80, 0.55); }
.cond-dot.speaking { background: var(--accent); animation: pulse 1s ease-in-out infinite; }

.cond-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
.cond-switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; color: var(--text); }
.cond-switch input { display: none; }
.cond-track {
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--border-strong);
  position: relative;
  transition: background 0.15s;
}
.cond-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.cond-switch input:checked + .cond-track { background: var(--good); }
.cond-switch input:checked + .cond-track::after { transform: translateX(14px); }
.cond-switch.warn input:checked + .cond-track { background: var(--warn); }
.cond-hint { color: var(--warn); font-size: 11px; }
.cond-volume { display: inline-flex; align-items: center; gap: 6px; }
.cond-volume input { width: 110px; accent-color: var(--accent); }
.cond-volume output { min-width: 2.2em; font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--text); }

.cond-mobile-tabs {
  display: none;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  gap: 6px;
}
.cond-mobile-tab {
  flex: 1;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.cond-mobile-tab.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.cond-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 340px) 1fr;
}

.cond-aside {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
}
.cond-aside-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.cond-session {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 11px;
  margin-bottom: 8px;
  transition: border-color 0.12s, background 0.12s;
}
.cond-session.clickable { cursor: pointer; }
.cond-session.clickable:hover { border-color: var(--accent); background: var(--bg-surface); }
.cond-session-top { display: flex; align-items: center; gap: 7px; }
.cond-project { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cond-pane { margin-left: auto; color: var(--muted); font-size: 11px; font-family: var(--font-mono); flex-shrink: 0; }
.cond-busy { font-size: 11px; color: var(--good); font-weight: 600; flex-shrink: 0; }
.cond-last {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.45;
}

.cond-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  color: #fff;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}
.cond-badge.claude { background: #b4562e; }
.cond-badge.codex { background: #3b5bab; }
.cond-badge.agy { background: #1e7e5c; }

.cond-timeline-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}
.cond-timeline {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px;
}
.cond-event { margin: 0 0 12px; max-width: 780px; }
.cond-meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; display: flex; align-items: center; gap: 5px; }
.cond-body { white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.cond-event.report .cond-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
}
.cond-event.report .cond-body { max-height: 7.8em; overflow: hidden; color: var(--text); font-size: 13px; }
.cond-event.report.open .cond-body { max-height: none; }
.cond-more {
  margin-top: 5px;
  padding: 0;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
}
.cond-more:hover { text-decoration: underline; }
.cond-link-btn {
  padding: 0;
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.cond-link-btn:hover { color: var(--accent); text-decoration: underline; }

.cond-event.user { margin-left: auto; text-align: right; }
.cond-event.user .cond-meta { justify-content: flex-end; }
.cond-event.user .cond-body {
  display: inline-block;
  text-align: left;
  background: #234d42;
  color: #e6f5f0;
  padding: 7px 12px;
  border-radius: 12px 12px 2px 12px;
}
.cond-event.conductor .cond-body {
  display: inline-block;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 12px 12px 12px 2px;
}
.cond-event.conductor.silent .cond-body {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  font-size: 12px;
}

.cond-empty { color: var(--muted); text-align: center; margin-top: 40px; font-size: 13px; }
.cond-empty-sm { color: var(--muted); font-size: 12px; padding: 12px 4px; }

.cond-composer-area {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.cond-error { color: var(--danger); font-size: 12px; padding: 6px 14px 0; }
.cond-composer { display: flex; gap: 8px; padding: 10px 14px; align-items: flex-end; }
.cond-composer textarea {
  flex: 1;
  resize: none;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  min-height: 38px;
  max-height: 160px;
  line-height: 1.45;
}
.cond-composer textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

@media (max-width: 768px) {
  .cond-mobile-tabs { display: flex; }
  .cond-main { grid-template-columns: 1fr; }
  .cond-main[data-mobile-tab="timeline"] .cond-aside { display: none; }
  .cond-main[data-mobile-tab="sessions"] .cond-timeline-wrap { display: none; }
  .cond-aside { border-right: none; }
  .cond-timeline { padding: 12px; }
}
