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

/* Tokyo Night (dark) */
:root, [data-theme="tokyo-night"] {
  --bg: #1a1b26;
  --surface: #24283b;
  --surface2: #292e42;
  --border: #3b4261;
  --text: #c0caf5;
  --text-dim: #565f89;
  --green: #9ece6a;
  --yellow: #e0af68;
  --red: #f7768e;
  --blue: #7aa2f7;
  --cyan: #7dcfff;
  --purple: #bb9af7;
  --orange: #ff9e64;
  --term-bg: #1a1b26;
  --shadow: rgba(0,0,0,0.3);
}

[data-theme="tokyo-light"] {
  --bg: #d5d6db; --surface: #cbccd1; --surface2: #c2c3c8; --border: #b4b5b9;
  --text: #343b58; --text-dim: #6a6f87;
  --green: #485e30; --yellow: #8f5e15; --red: #8c4351; --blue: #34548a;
  --cyan: #0f4b6e; --purple: #5a4a78; --orange: #965027;
  --term-bg: #d5d6db; --shadow: rgba(0,0,0,0.1);
}

[data-theme="catppuccin-latte"] {
  --bg: #eff1f5; --surface: #e6e9ef; --surface2: #dce0e8; --border: #ccd0da;
  --text: #4c4f69; --text-dim: #8c8fa1;
  --green: #40a02b; --yellow: #df8e1d; --red: #d20f39; --blue: #1e66f5;
  --cyan: #04a5e5; --purple: #8839ef; --orange: #fe640b;
  --term-bg: #eff1f5; --shadow: rgba(0,0,0,0.08);
}

[data-theme="catppuccin-mocha"] {
  --bg: #1e1e2e; --surface: #313244; --surface2: #383a4e; --border: #45475a;
  --text: #cdd6f4; --text-dim: #6c7086;
  --green: #a6e3a1; --yellow: #f9e2af; --red: #f38ba8; --blue: #89b4fa;
  --cyan: #89dcfe; --purple: #cba6f7; --orange: #fab387;
  --term-bg: #1e1e2e; --shadow: rgba(0,0,0,0.3);
}

[data-theme="solarized-light"] {
  --bg: #fdf6e3; --surface: #eee8d5; --surface2: #e6dfcb; --border: #d3cbb7;
  --text: #586e75; --text-dim: #93a1a1;
  --green: #859900; --yellow: #b58900; --red: #dc322f; --blue: #268bd2;
  --cyan: #2aa198; --purple: #6c71c4; --orange: #cb4b16;
  --term-bg: #fdf6e3; --shadow: rgba(0,0,0,0.08);
}

[data-theme="solarized-dark"] {
  --bg: #002b36; --surface: #073642; --surface2: #0a4050; --border: #2a5059;
  --text: #839496; --text-dim: #586e75;
  --green: #859900; --yellow: #b58900; --red: #dc322f; --blue: #268bd2;
  --cyan: #2aa198; --purple: #6c71c4; --orange: #cb4b16;
  --term-bg: #002b36; --shadow: rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
  font-size: 13px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Picker ── */
#picker {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 24px;
  overflow: hidden;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  flex-shrink: 0;
  padding-bottom: 10px;
  border-bottom: 2px solid transparent;
  border-image: linear-gradient(90deg, var(--green), var(--blue), var(--purple), var(--orange)) 1;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
  letter-spacing: -0.3px;
}

#stats {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#stats .warn { color: var(--yellow); }
#stats .crit { color: var(--red); }

#theme-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  outline: none;
}

#theme-select:hover { border-color: var(--text); }

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

#search {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 12px;
  width: 180px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#search:focus { border-color: var(--blue); box-shadow: 0 0 0 2px color-mix(in srgb, var(--blue) 20%, transparent); }
#search::placeholder { color: var(--text); }

#new-session-btn {
  background: var(--surface);
  color: var(--green);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

#new-session-btn:hover { background: var(--green); color: var(--bg); border-color: var(--green); }

/* ── Infrastructure bar ── */
#infra-bar {
  display: flex;
  gap: 12px;
  margin: 12px 0;
  flex-shrink: 0;
}

.infra-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 12px;
  flex: 1;
  transition: box-shadow 0.2s;
}

.infra-section:hover { box-shadow: 0 2px 12px var(--shadow); }

.infra-section h3 {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text);
  margin-bottom: 8px;
}

.infra-section .stats-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.infra-section .stat {
  display: flex;
  gap: 5px;
  align-items: center;
}

.infra-section .stat .label { color: var(--text); }
.infra-section .stat .value { color: var(--text); font-weight: 600; }
.infra-section .stat .value.warn { color: var(--yellow); }
.infra-section .stat .value.crit { color: var(--red); }
.infra-section .stat .value.good { color: var(--green); }

/* Progress bar */
.progress-bar {
  width: 60px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 4px;
}

.progress-bar .fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-bar .fill.good { background: var(--green); }
.progress-bar .fill.warn { background: var(--yellow); }
.progress-bar .fill.crit { background: var(--red); }

.container-summary {
  display: flex;
  gap: 12px;
  align-items: center;
}

.container-summary .count {
  font-size: 22px;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
}

.container-summary .count.has-unhealthy { color: var(--yellow); }
.container-summary .breakdown { color: var(--text); }

/* ── Grid ── */
#grid {
  display: flex;
  gap: 16px;
  overflow-y: auto;
  padding: 4px 0 8px;
  min-height: 0;
}

.column {
  min-width: 180px;
  flex: 1;
}

.column h2 {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

.column h2 .icon { font-size: 13px; }

.col-count {
  font-size: 9px;
  font-weight: 600;
  background: var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 1px 6px;
  margin-left: auto;
}

.session {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  margin-bottom: 2px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.session:hover, .session.focused {
  background: var(--surface);
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 60;
}

.session.focused { outline: 2px solid var(--blue); outline-offset: -2px; }
.session.dragging { opacity: 0.4; }
.session.drag-over { border-top: 2px solid var(--blue); }

.session-main { flex: 1; min-width: 0; }
.session-top { display: flex; align-items: center; gap: 4px; }

.session .idx {
  color: var(--text);
  font-size: 10px;
  min-width: 22px;
  font-weight: 500;
}

.session .name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.session-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
}

.session-note {
  font-size: 10px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

/* ── Context Menu ── */
.context-menu {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
  min-width: 180px;
  box-shadow: 0 8px 24px var(--shadow);
}

.ctx-item {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
}

.ctx-item:hover { background: var(--bg); }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger:hover { background: color-mix(in srgb, var(--red) 10%, transparent); }

.preview-popup {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.preview-popup pre {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  font-size: 12px;
  line-height: 1.5;
  max-width: 600px;
  width: 100%;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.preview-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  padding: 10px 16px;
  border-radius: 10px 10px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  max-width: 600px;
  width: 100%;
  color: var(--green);
}

.preview-popup-header button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.ctx-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.session .recent-badge {
  font-size: 9px;
  white-space: nowrap;
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 600;
}

/* Sparkline */
.sparkline {
  display: inline-flex;
  align-items: flex-end;
  gap: 1px;
  height: 10px;
  flex-shrink: 0;
}

.spark-bar {
  width: 2px;
  background: var(--green);
  border-radius: 1px;
  opacity: 0.5;
  min-height: 0;
}

.recent-badge.recent-now { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.recent-badge.recent-min { background: color-mix(in srgb, var(--green) 10%, transparent); color: var(--green); }
.recent-badge.recent-hour { background: color-mix(in srgb, var(--yellow) 10%, transparent); color: var(--yellow); }
.recent-badge.recent-day { color: var(--text); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  display: inline-block;
  flex-shrink: 0;
}

.dot.alive {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s ease-in-out infinite;
}

.dot.recent-now {
  background: var(--cyan);
  box-shadow: none;
  animation: none;
}

.dot.recent-hour {
  background: var(--blue);
  box-shadow: none;
  animation: none;
}

.dot.recent-day {
  background: var(--purple);
  box-shadow: none;
  animation: none;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 4px var(--green); }
  50% { box-shadow: 0 0 10px var(--green), 0 0 20px color-mix(in srgb, var(--green) 30%, transparent); }
}

.session .kill-btn {
  display: none;
  background: none;
  border: 1px solid var(--red);
  border-radius: 4px;
  color: var(--red);
  cursor: pointer;
  font-size: 14px;
  padding: 1px 6px;
  line-height: 1;
  transition: all 0.15s;
}

.session .kill-btn:hover {
  background: var(--red);
  color: var(--bg);
}

.session:hover .kill-btn.show { display: block; }

.session .preview {
  display: none;
  position: absolute;
  left: calc(100% + 150px);
  top: 0;
  z-index: 20;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 600px;
  min-width: 320px;
  max-height: 300px;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0,0,0,0.6);
  pointer-events: auto;
  z-index: 50;
  isolation: isolate;
}

.session:hover .preview,
.session .preview:hover { display: block; }

/* Column colors */
.col-infrastructure h2 { color: var(--green); border-color: var(--green); }
.col-dashboards h2 { color: var(--orange); border-color: var(--orange); }
.col-projects h2 { color: var(--blue); border-color: var(--blue); }
.col-media h2 { color: var(--cyan); border-color: var(--cyan); }
.col-work h2 { color: var(--purple); border-color: var(--purple); }
.col-ai h2 { color: var(--red); border-color: var(--red); }

footer {
  flex-shrink: 0;
  padding: 10px 0 4px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 24px;
  color: var(--text);
  font-size: 14px;
}

.touch-only { display: none; }

@media (pointer: coarse) {
  .desktop-only { display: none; }
  .touch-only { display: inline; }
}

.legend { display: flex; align-items: center; gap: 6px; }

/* ── Modal ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 16px 48px var(--shadow);
}

.modal-content h2 { font-size: 16px; color: var(--green); }

.modal-content input,
.modal-content select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.modal-content input:focus { border-color: var(--blue); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.modal-actions button {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 16px; font-family: inherit; font-size: 12px;
  cursor: pointer; transition: all 0.15s;
}

.modal-actions button.primary { background: var(--green); color: var(--bg); border-color: var(--green); }
.modal-actions button:hover { opacity: 0.85; }

/* ── Terminal ── */
#terminal-view { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#terminal-view.hidden { display: none; }
#picker.hidden { display: none; }

#terminal-bar {
  display: flex; align-items: center; gap: 0; padding: 0;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}

#terminal-bar #back-btn {
  background: var(--bg); color: var(--text);
  border: none; border-right: 1px solid var(--border);
  padding: 8px 14px; border-radius: 0;
  cursor: pointer; font-family: inherit; font-size: 12px; flex-shrink: 0;
  transition: background 0.15s;
}

#terminal-bar #back-btn:hover { background: var(--border); }

#tabs { display: flex; flex: 1; overflow-x: auto; gap: 0; }

.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-right: 1px solid var(--border);
  cursor: pointer; font-size: 12px; color: var(--text);
  white-space: nowrap; flex-shrink: 0; transition: all 0.15s;
}

.tab.active { background: var(--bg); color: var(--green); }
.tab:hover { background: var(--bg); }
.tab-name { cursor: pointer; }

.tab-close {
  background: none; border: none; color: var(--text);
  cursor: pointer; font-size: 14px; padding: 0 2px; line-height: 1;
}

.tab-close:hover { color: var(--red); }

#terminals { flex: 1; position: relative; overflow: hidden; }

.term-pane {
  position: absolute; inset: 0; padding: 4px;
  background: var(--term-bg, #000); display: none;
  -webkit-overflow-scrolling: touch;
}

.term-pane canvas { touch-action: pan-y; }
.xterm { touch-action: pan-y; }

.term-pane.active { display: block; }


/* ── Container Panel ── */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 420px; max-width: 90vw;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px var(--shadow);
  z-index: 80;
  display: flex; flex-direction: column;
  overflow: hidden;
}

.panel.hidden { display: none; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 { font-size: 14px; color: var(--green); }

.panel-close {
  background: none; border: none; color: var(--text);
  font-size: 20px; cursor: pointer; padding: 0 4px;
}

.panel-close:hover { color: var(--red); }

#container-list {
  flex: 1; overflow-y: auto; padding: 8px;
}

.ct-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px;
  font-size: 12px;
}

.ct-row:hover { background: var(--surface); }

.ct-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}

.ct-dot.good { background: var(--green); }
.ct-dot.warn { background: var(--yellow); }
.ct-dot.crit { background: var(--red); animation: pulse 2s infinite; }

.ct-name { flex: 1; font-weight: 500; color: var(--text); }
.ct-status { color: var(--text); font-size: 14px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ct-restart {
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); cursor: pointer; font-size: 14px; padding: 2px 6px;
  flex-shrink: 0;
}

.ct-restart:hover { color: var(--text); border-color: var(--text); }

.clickable { cursor: pointer; }
.clickable:hover { border-color: var(--text); }

/* ── Alert Badge ── */
.badge {
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  margin-left: 4px;
  vertical-align: top;
}

.badge.hidden { display: none; }

/* ── Touch toolbar (mobile/tablet) ── */
.touch-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.touch-bar.hidden { display: none; }

.touch-key {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.touch-key:active { background: var(--border); }
.touch-key.wide { padding: 10px 20px; }
.touch-key.kbd { background: var(--green); color: var(--bg); border-color: var(--green); }

/* ── Mobile ── */
@media (max-width: 768px) {
  #picker { padding: 10px 12px; }
  header { flex-wrap: wrap; gap: 8px; }
  header h1 { font-size: 16px; width: 100%; }
  #stats {
  font-weight: 600; flex-wrap: wrap; gap: 8px; width: 100%; }
  .header-controls { width: 100%; flex-wrap: wrap; }
  #search { flex: 1; min-width: 120px; }
  #infra-bar { flex-direction: column; gap: 8px; }
  #grid { flex-direction: column; gap: 12px; }
  .column { min-width: unset; }
  footer { flex-wrap: wrap; gap: 12px; }
  .session .preview {
    position: fixed; left: 50%; right: 10px;
    top: auto; bottom: 60px; max-width: 50vw; min-width: unset;
  }
  #tabs { max-width: calc(100vw - 100px); }
  #terminals { padding-bottom: 52px; }
}

.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.stat-pill.sessions { color: var(--green); }
.stat-pill.uptime { color: var(--text-dim); }

.stat-divider {
  color: var(--border);
  font-weight: 300;
  margin: 0 2px;
}
.top-proc {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
}
.top-cpu {
  color: var(--magenta);
  font-weight: 700;
}
.top-mem {
  color: var(--cyan);
  font-weight: 600;
  font-size: 11px;
}

.stats-row-main {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.stats-row-top {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}

.top-inline {
  font-size: 11px;
  font-weight: 700;
  color: var(--magenta);
  margin-left: 2px;
}

.stat-pill.clickable {
  cursor: pointer;
  transition: background 0.15s;
}
.stat-pill.clickable:hover {
  background: var(--border);
}
.stat-popover {
  position: fixed;
  z-index: 1000;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-width: 260px;
  max-width: 400px;
  max-height: 350px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  font-size: 12px;
}
.stat-popover h4 {
  margin: 8px 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.stat-popover h4:first-child { margin-top: 0; }
.sp-table {
  width: 100%;
  border-collapse: collapse;
}
.sp-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 3px 8px 3px 0;
  border-bottom: 1px solid var(--border);
}
.sp-table td {
  padding: 3px 8px 3px 0;
  border-bottom: 1px solid var(--surface);
}
.sp-table .num {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.sp-table .dim { color: var(--text-dim); }
.sp-table .warn { color: var(--yellow); }
.sp-table .crit { color: var(--red); }
.sp-pre {
  font-size: 11px;
  line-height: 1.5;
  margin: 0;
  white-space: pre;
}
.sp-loading {
  color: var(--text-dim);
  text-align: center;
  padding: 16px;
}
