/* Orchestrator PWA — v3 rebuild (2026-05-18)
 * Dashboard-only layout. Mockup-v2 (Proton Pass-inspired) is the reference.
 * Source: ~/telegram-bot/pwa/mockup-v2.html (frozen prototype)
 */

:root {
  --bg: #15131c;
  --rail: #1b1825;
  --list: #1f1c2a;
  --detail: #181520;
  --card: #232030;
  --card-hover: #2a2638;
  --border: #2a2738;
  --fg: #ece8f7;
  --fg-dim: #a39db8;
  --fg-mute: #6e6885;
  --accent: #9b7cff;
  --accent-soft: rgba(155, 124, 255, 0.14);
  --accent-glow: rgba(155, 124, 255, 0.35);
  --good: #6fcf97;
  --bad: #ff7a7a;
  --warn: #ffc26a;
  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 0;
}

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  border-radius: 6px;
}
.icon-btn:hover { background: rgba(255,255,255,0.06); color: var(--fg); }

/* ─── App shell grid ──────────────────────────────────────────────────────── */

#app {
  display: grid;
  grid-template-columns: 232px 320px 1fr;
  height: 100dvh;
  width: 100vw;
  min-height: 0;
}

/* ─── Left rail ───────────────────────────────────────────────────────────── */

#rail {
  background: var(--rail);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px 10px;
  min-height: 0;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

/* Presence chips — top of the rail. Click toggles via POST /api/presence/toggle/:machine. */
.presence-chips {
  display: flex;
  gap: 6px;
  padding: 0 4px 10px;
}
.presence-chip {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-mute);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.presence-chip:hover { border-color: var(--accent); }
.presence-chip.on { color: var(--fg); border-color: var(--good); }
.presence-chip.on .status-dot { background: var(--good); box-shadow: 0 0 6px var(--good); }
.presence-chip.busy { opacity: 0.6; cursor: progress; }
.presence-label { line-height: 1; }

.rail-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 14px;
}
.brand-dot {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #6f4fcc);
  box-shadow: 0 0 14px var(--accent-glow);
  flex: 0 0 auto;
}
.brand-name { font-weight: 600; font-size: 14px; letter-spacing: 0.2px; }
.brand-sub  { color: var(--fg-mute); font-size: 11px; margin-top: 1px; }

.rail-nav { display: flex; flex-direction: column; }
.rail-section { margin-top: 10px; }
.rail-section-label {
  color: var(--fg-mute);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 6px 10px 4px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg-dim);
  font-size: 13.5px;
  text-align: left;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--fg); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--fg);
  box-shadow: inset 0 0 0 1px rgba(155,124,255,0.22);
}
.nav-item .icon {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.9;
}
.nav-item.active .icon { color: var(--accent); }
.nav-item .label { flex: 1; }
.nav-item .badge {
  background: rgba(255,255,255,0.06);
  color: var(--fg-dim);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.nav-item.active .badge { background: var(--accent); color: var(--bg); }
.nav-item .badge.live   { background: var(--good); color: #0c0c0c; }
.nav-item .badge.warn   { background: var(--warn); color: #0c0c0c; }
.nav-item .badge.bad    { background: var(--bad);  color: #0c0c0c; }

.rail-spacer { flex: 1; }

.rail-status {
  border-top: 1px solid var(--border);
  padding: 10px 6px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--fg-dim);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 6px var(--good);
  flex: 0 0 auto;
}
.status-dot.offline { background: var(--fg-mute); box-shadow: none; }
.status-dot.bad     { background: var(--bad);     box-shadow: 0 0 6px var(--bad); }
.status-dot.warn    { background: var(--warn);    box-shadow: 0 0 6px var(--warn); }
.status-name { flex: 1; color: var(--fg); font-weight: 500; }
.status-meta { color: var(--fg-mute); font-size: 11px; }

.rail-settings {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-top: 4px;
  color: var(--fg-dim);
  font-size: 12px;
  border-radius: var(--radius-sm);
  width: 100%;
  text-align: left;
}
.rail-settings:hover { background: rgba(255,255,255,0.04); color: var(--fg); }

/* ─── Middle list column ──────────────────────────────────────────────────── */

#list {
  background: var(--list);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.list-title { font-size: 15px; font-weight: 600; flex: 0 0 auto; }
.list-count { color: var(--fg-mute); font-size: 12px; flex: 1; }

.list-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.list-search input {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 7px 11px;
  border-radius: 7px;
  font-size: 13px;
  outline: none;
}
.list-search input:focus { border-color: var(--accent); }
.list-search.hidden { display: none; }

.list-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  -webkit-overflow-scrolling: touch;
}

.list-empty {
  color: var(--fg-mute);
  font-size: 12px;
  padding: 14px;
  text-align: center;
}

.list-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.list-item:hover { background: var(--card-hover); }
.list-item.active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(155,124,255,0.22);
}
.list-item-row1 {
  display: flex; align-items: center; gap: 8px;
}
.list-item-status {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 6px var(--good);
  flex: 0 0 7px;
}
.list-item-status.idle    { background: var(--fg-mute); box-shadow: none; }
.list-item-status.error   { background: var(--bad);     box-shadow: 0 0 6px var(--bad); }
.list-item-status.queued  { background: var(--warn);    box-shadow: 0 0 6px var(--warn); }
.list-item-status.running { background: var(--good);    box-shadow: 0 0 6px var(--good); }
.list-item-status.grey    { background: var(--fg-mute); box-shadow: none; }
.list-item-status.yellow  { background: var(--warn);    box-shadow: 0 0 6px var(--warn); }
.list-item-status.green   { background: var(--good);    box-shadow: 0 0 6px var(--good); }
.list-item-status.red     { background: var(--bad);     box-shadow: 0 0 6px var(--bad); }
.list-item-name { font-weight: 500; font-size: 13px; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-time { color: var(--fg-mute); font-size: 11px; flex: 0 0 auto; }
.list-item-snippet {
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* File-tree list (Second Brain) */
.tree-node { padding: 4px 8px; border-radius: 4px; cursor: pointer; user-select: none; }
.tree-node:hover { background: var(--card-hover); }
.tree-node.active { background: var(--accent-soft); color: var(--fg); }
.tree-folder {
  font-weight: 600;
  color: var(--fg-dim);
  padding: 6px 4px 2px;
  font-size: 11.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.tree-file { font-size: 13px; color: var(--fg-dim); }
.tree-file.active { color: var(--fg); }
.tree-children { padding-left: 12px; border-left: 1px solid var(--border); margin-left: 6px; }
.tree-toggle { display: inline-block; width: 12px; color: var(--fg-mute); }

/* ─── Detail pane ─────────────────────────────────────────────────────────── */

#detail {
  background: var(--detail);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.detail-back {
  display: none; /* shown on narrow viewports */
}
.detail-titles { flex: 1; min-width: 0; }
.detail-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detail-meta { color: var(--fg-mute); font-size: 12px; margin-top: 1px; }
.detail-actions { display: flex; gap: 8px; }
.detail-empty {
  color: var(--fg-mute);
  padding: 30px 22px;
  font-size: 13px;
}

.btn {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  cursor: pointer;
}
.btn:hover { background: var(--card-hover); }
.btn.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.detail-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px 28px;
  -webkit-overflow-scrolling: touch;
}

.detail-section { margin-bottom: 22px; }
.detail-section h3 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-mute);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat-card .num { font-size: 22px; font-weight: 600; color: var(--fg); line-height: 1.1; }
.stat-card .num.accent { color: var(--accent); }
.stat-card .num.good   { color: var(--good); }
.stat-card .num.bad    { color: var(--bad); }
.stat-card .num.warn   { color: var(--warn); }
.stat-card .lbl { color: var(--fg-mute); font-size: 11px; margin-top: 2px; }

.log-entry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 12.5px;
}
.log-entry .ts {
  color: var(--fg-mute);
  font-size: 11px;
  font-family: var(--mono);
}
.log-entry .body {
  margin-top: 4px;
  color: var(--fg-dim);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-entry.success { border-left: 3px solid var(--good); }
.log-entry.error   { border-left: 3px solid var(--bad); }
.log-entry.info    { border-left: 3px solid var(--accent); }
.log-entry.warn    { border-left: 3px solid var(--warn); }

.screenshot-frame {
  background: #000;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.screenshot-frame img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  background: #000;
}
.screenshot-caption {
  color: var(--fg-mute);
  font-size: 11px;
  font-family: var(--mono);
  padding: 6px 4px 0;
}

/* ─── Markdown rendering (Backlog / Journal / SB / Sessions) ──────────────── */

.markdown-body {
  max-width: 760px;
  margin: 0 auto;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Iowan Old Style", "Georgia",
               "SF Pro Text", "Helvetica Neue", serif;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  color: var(--fg);
  font-weight: 600;
  margin: 1.6em 0 0.6em;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  letter-spacing: -0.01em;
}
.markdown-body h1 { font-size: 1.85em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.4em;  border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
.markdown-body h3 { font-size: 1.15em; color: var(--accent); }
.markdown-body h4 { font-size: 1.05em; color: var(--fg-dim); }
.markdown-body p  { margin: 0 0 1em; color: var(--fg); }
.markdown-body ul, .markdown-body ol { margin: 0 0 1em 1.4em; }
.markdown-body li { margin: 0.3em 0; }
.markdown-body strong { color: var(--fg); font-weight: 600; }
.markdown-body em { color: var(--fg-dim); }
.markdown-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  padding: 1px 5px;
  color: #e9d6ff;
}
.markdown-body pre {
  background: #0e0c14;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
}
.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: inherit;
  color: var(--fg);
}
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  margin: 0 0 1em;
  padding: 8px 14px;
  color: var(--fg-dim);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.markdown-body table {
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.markdown-body th { background: var(--card); }
.markdown-body hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.markdown-body a { color: var(--accent); }
.markdown-body img { max-width: 100%; border-radius: var(--radius); }

/* Journal — single entry card */
.journal-entry {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
}
.journal-entry .journal-ts {
  color: var(--fg-mute);
  font-size: 11px;
  font-family: var(--mono);
  margin-bottom: 6px;
}
.journal-entry .journal-role {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-top: 8px;
}
.journal-entry .journal-text {
  color: var(--fg);
  font-size: 13.5px;
  line-height: 1.55;
  margin-top: 2px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.toast.bad { border-color: var(--bad); color: var(--bad); }

/* ─── Settings drawer ─────────────────────────────────────────────────────── */
.settings-drawer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  display: flex;
  justify-content: flex-end;
  backdrop-filter: blur(2px);
}
.settings-drawer[hidden] { display: none; }
.settings-panel {
  width: min(440px, 100%);
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.settings-head {
  display: flex;
  align-items: center;
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--border);
}
.settings-head h2 { margin: 0; flex: 1; font-size: 16px; }
.settings-section { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.settings-section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; color: var(--fg-mute); letter-spacing: 0.5px; }
.settings-note { color: var(--fg-dim); font-size: 13px; margin: 0 0 12px; line-height: 1.5; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.settings-status { color: var(--fg-dim); font-size: 12px; margin-top: 10px; }
.settings-health {
  background: #0e0c14;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--fg-dim);
  overflow-x: auto;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
}

/* ─── Mobile / narrow viewport ────────────────────────────────────────────── */

@media (max-width: 1000px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  #rail {
    flex-direction: row;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    min-height: 0;
    gap: 6px;
    align-items: center;
  }
  .rail-brand { display: none; }
  .rail-nav  { flex-direction: row; flex: 1; gap: 4px; }
  .rail-section { margin: 0; display: flex; align-items: center; gap: 2px; }
  .rail-section-label { display: none; }
  .nav-item {
    padding: 6px 10px;
    white-space: nowrap;
    font-size: 12.5px;
  }
  .nav-item .label { display: none; }
  .nav-item .icon { font-size: 16px; }
  .rail-spacer { display: none; }
  .rail-status { border-top: 0; padding: 0; flex-direction: row; }
  .status-row { padding: 4px 8px; }
  .status-name, .status-meta { display: none; }
  .rail-settings { padding: 6px 8px; }
  .rail-settings span:nth-child(2) { display: none; }

  /* On narrow, list/detail swap via a state class on #app. */
  #list, #detail { display: none; }
  #app.show-list   #list   { display: flex; }
  #app.show-detail #detail { display: flex; }
  .detail-back { display: inline-flex; }
}

/* Default behavior on wide viewports — both list and detail are visible. */
@media (min-width: 1001px) {
  .detail-back { display: none; }
}

/* ─── SFX unzip — Transmission-style progress bars ──────────────────────── */
.progress-bar {
  margin-top: 8px;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.progress-bar.big {
  height: 14px;
  border-radius: 4px;
}
.progress-bar.empty .progress-fill {
  background: transparent;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease-out, background 0.3s;
}
.progress-fill.good {
  background: var(--good);
}
.progress-fill.bad {
  background: var(--bad);
}
.progress-label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--fg-dim);
  font-family: var(--mono);
}
