/* ══════════════════════════════════════════════════════════════════════════
   TerraformPlatform — AWS Cloudscape-inspired console theme
   Light + dark mode driven entirely by tokens on :root / [data-theme].
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Brand (theme-invariant) */
  --brand-orange: #ec7211;
  --brand-orange-hover: #d55f0a;
  --brand-squid: #232f3e;

  /* ── Light palette ─────────────────────────────────────────────────── */
  --bg-app: #f2f3f3;
  --bg-surface: #ffffff;
  --bg-surface-alt: #fafafa;
  --bg-raised: #ffffff;
  --bg-hover: #f4f6f6;
  --bg-active: #e9f2fb;
  --bg-nav: #ffffff;
  --bg-topbar: #232f3e;
  --bg-input: #ffffff;
  --bg-code: #0f1b2a;

  --text-primary: #16191f;
  --text-secondary: #5f6b7a;
  --text-muted: #879596;
  --text-inverse: #ffffff;
  --text-link: #0972d3;

  --border: #d5dbdb;
  --border-subtle: #eaeded;
  --border-strong: #aab7b8;

  --accent: #0972d3;
  --accent-hover: #033160;
  --accent-soft: #f0f7ff;

  --status-success: #037f0c;
  --status-success-bg: #f2fcf3;
  --status-success-border: #b7e3ba;
  --status-danger: #d91515;
  --status-danger-bg: #fff7f7;
  --status-danger-border: #f5c6c6;
  --status-warning: #b45309;
  --status-warning-bg: #fffaf0;
  --status-warning-border: #f5d9a8;
  --status-info: #0972d3;
  --status-info-bg: #f0f7ff;
  --status-info-border: #b8d9f7;
  --status-neutral: #5f6b7a;
  --status-neutral-bg: #f4f6f6;
  --status-neutral-border: #d5dbdb;
  --status-purple: #6b3fa0;
  --status-purple-bg: #f7f4fd;
  --status-purple-border: #d9cbf0;

  --shadow-sm: 0 1px 1px 0 rgba(0, 28, 36, 0.10);
  --shadow-md: 0 2px 6px 0 rgba(0, 28, 36, 0.14);
  --shadow-lg: 0 6px 20px 0 rgba(0, 28, 36, 0.20);

  /* Metrics */
  --sidebar-w: 232px;
  --topbar-h: 48px;
  --r-sm: 4px;
  --r-md: 8px;
  --r-pill: 999px;
  --gutter: 20px;
}

/* ── Dark palette ────────────────────────────────────────────────────── */
:root[data-theme="dark"] {
  --bg-app: #0f1b2a;
  --bg-surface: #192534;
  --bg-surface-alt: #1b2735;
  --bg-raised: #21303f;
  --bg-hover: #232f3e;
  --bg-active: #123456;
  --bg-nav: #192534;
  --bg-topbar: #0b1520;
  --bg-input: #101d2b;
  --bg-code: #0b1119;

  --text-primary: #e9ebed;
  --text-secondary: #a3aeb9;
  --text-muted: #7d8998;
  --text-inverse: #16191f;
  --text-link: #539fe5;

  --border: #354150;
  --border-subtle: #2a3746;
  --border-strong: #4a5a6b;

  --accent: #539fe5;
  --accent-hover: #75b3ea;
  --accent-soft: #12283d;

  --status-success: #6cc16f;
  --status-success-bg: #172a1c;
  --status-success-border: #2f5233;
  --status-danger: #f87171;
  --status-danger-bg: #2c1618;
  --status-danger-border: #5c2a2c;
  --status-warning: #e8a33d;
  --status-warning-bg: #2b2214;
  --status-warning-border: #574220;
  --status-info: #539fe5;
  --status-info-bg: #12283d;
  --status-info-border: #2b4c6d;
  --status-neutral: #a3aeb9;
  --status-neutral-bg: #232f3e;
  --status-neutral-border: #3b4856;
  --status-purple: #b79ce8;
  --status-purple-bg: #241f38;
  --status-purple-border: #453a63;

  --shadow-sm: 0 1px 1px 0 rgba(0, 0, 0, 0.35);
  --shadow-md: 0 2px 8px 0 rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 8px 24px 0 rgba(0, 0, 0, 0.55);
}

/* System preference when the user has made no explicit choice */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-app: #0f1b2a;
    --bg-surface: #192534;
    --bg-surface-alt: #1b2735;
    --bg-raised: #21303f;
    --bg-hover: #232f3e;
    --bg-active: #123456;
    --bg-nav: #192534;
    --bg-topbar: #0b1520;
    --bg-input: #101d2b;
    --bg-code: #0b1119;

    --text-primary: #e9ebed;
    --text-secondary: #a3aeb9;
    --text-muted: #7d8998;
    --text-inverse: #16191f;
    --text-link: #539fe5;

    --border: #354150;
    --border-subtle: #2a3746;
    --border-strong: #4a5a6b;

    --accent: #539fe5;
    --accent-hover: #75b3ea;
    --accent-soft: #12283d;

    --status-success: #6cc16f;
    --status-success-bg: #172a1c;
    --status-success-border: #2f5233;
    --status-danger: #f87171;
    --status-danger-bg: #2c1618;
    --status-danger-border: #5c2a2c;
    --status-warning: #e8a33d;
    --status-warning-bg: #2b2214;
    --status-warning-border: #574220;
    --status-info: #539fe5;
    --status-info-bg: #12283d;
    --status-info-border: #2b4c6d;
    --status-neutral: #a3aeb9;
    --status-neutral-bg: #232f3e;
    --status-neutral-border: #3b4856;
    --status-purple: #b79ce8;
    --status-purple-bg: #241f38;
    --status-purple-border: #453a63;

    --shadow-sm: 0 1px 1px 0 rgba(0, 0, 0, 0.35);
    --shadow-md: 0 2px 8px 0 rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 8px 24px 0 rgba(0, 0, 0, 0.55);
  }
}

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

html, body { height: 100%; }

body {
  font-family: "Inter", "Amazon Ember", "Helvetica Neue", Roboto, Arial, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

svg[data-lucide], [data-lucide] { stroke-width: 1.75; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: content-box; }

/* ── Layout ──────────────────────────────────────────────────────────── */
/* Set before first paint when no token is stored — keeps the console shell
   out of sight until login, so a refresh never leaks the panel. */
html.tf-locked .app-container,
html.tf-locked .toast-container { display: none; }

.app-container {
  display: grid;
  grid-template-areas: "topbar topbar" "sidebar content";
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  background: var(--bg-topbar);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  gap: 12px;
  z-index: 300;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: -0.2px;
  color: #fff;
  white-space: nowrap;
}

.sidebar-toggle {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  padding: 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
  align-items: center;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.12); }

.topbar-actions { display: flex; align-items: center; gap: 4px; }

.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  background: transparent;
  border: none;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s;
}
.topbar-btn:hover { background: rgba(255,255,255,0.12); }

.user-profile {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: #fff;
  transition: background 0.12s;
}
.user-profile:hover { background: rgba(255,255,255,0.12); }
.user-profile span { font-size: 12px; font-weight: 500; }

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-nav);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 200;
}

.sidebar-nav { padding: 8px 0; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--bg-active);
  color: var(--text-link);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-divider { height: 1px; background: var(--border-subtle); margin: 6px 12px; }

.sidebar-label {
  padding: 10px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.7px;
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}
.sidebar-backdrop.open { display: block; }

/* ── Content ─────────────────────────────────────────────────────────── */
.content {
  grid-area: content;
  overflow-y: auto;
  padding: 16px var(--gutter) 40px;
  background: var(--bg-app);
}

/* ── Page header (unified across every section) ──────────────────────── */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.page-head-titles { min-width: 0; }

.breadcrumbs {
  display: flex;
  gap: 4px;
  align-items: center;
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 2px;
}
.breadcrumb-item:not(:last-child)::after { content: "/"; margin-left: 4px; color: var(--border-strong); }

.page-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  line-height: 1.2;
}
.page-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

/* Toolbar: search + filters + icon actions, wraps cleanly on narrow screens */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ── Metric tiles (compact) ──────────────────────────────────────────── */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.metric {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  transition: border-color 0.12s, background 0.12s;
}
.metric.clickable { cursor: pointer; }
.metric.clickable:hover { border-color: var(--accent); background: var(--bg-hover); }

.metric-top {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.metric-top svg { flex-shrink: 0; color: var(--metric-color, var(--accent)); }
.metric-top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.metric-value {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.metric-value .metric-unit { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-left: 2px; }

.metric-sub {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Thin multi-segment status bar */
.metric-bar {
  display: flex;
  gap: 1px;
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--border-subtle);
  margin-top: 3px;
}
.metric-bar-seg { height: 100%; transition: width 0.35s ease; }

/* Usage meter (storage / memory) */
.meter {
  height: 3px;
  border-radius: 2px;
  background: var(--border-subtle);
  overflow: hidden;
  margin-top: 4px;
}
.meter-fill { height: 100%; background: var(--metric-color, var(--accent)); transition: width 0.35s ease; }

/* ── Panel (table container) ─────────────────────────────────────────── */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.panel-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  padding: 1px 8px;
  white-space: nowrap;
}

.panel-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.panel-empty svg { margin: 0 auto 10px; display: block; opacity: 0.35; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 7px 12px;
  background: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  font-size: 12.5px;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

.col-actions { width: 44px; text-align: right; }
.col-tight { width: 1%; white-space: nowrap; }

th[data-sort] { user-select: none; cursor: pointer; }
th[data-sort]:hover { color: var(--text-primary); background: var(--bg-hover); }
th.sort-active { color: var(--text-link); }
th[data-dir="asc"] .sort-indicator::after  { content: " ↑"; }
th[data-dir="desc"] .sort-indicator::after { content: " ↓"; }

/* Cell primitives */
.cell-main { display: flex; align-items: center; gap: 8px; min-width: 0; }

.cell-icon {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--cell-icon-bg, var(--accent-soft));
  color: var(--cell-icon-fg, var(--accent));
  border: 1px solid var(--border-subtle);
}

.cell-text { min-width: 0; }
.td-primary {
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.td-secondary { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.td-mono {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  font-size: 11.5px;
  color: var(--text-primary);
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  padding: 1px 5px;
  border-radius: var(--r-sm);
  display: inline-block;
}

/* Inline resource chips (vCPU / RAM / disk) */
.res-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.res-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 1px 5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.res-chip svg { color: var(--text-muted); }

/* Dimmed rows for stopped / destroyed instances */
tr.row-dimmed td { background: var(--bg-surface-alt); }
tr.row-dimmed td .td-primary { color: var(--text-secondary); }
tr.row-dimmed td .cell-icon { opacity: 0.6; }
tr.row-dimmed:hover td { background: var(--bg-hover); }

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px 1px 6px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1.6;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-plain::before { display: none; }

.badge-success   { background: var(--status-success-bg); color: var(--status-success); border-color: var(--status-success-border); }
.badge-danger    { background: var(--status-danger-bg);  color: var(--status-danger);  border-color: var(--status-danger-border); }
.badge-warning   { background: var(--status-warning-bg); color: var(--status-warning); border-color: var(--status-warning-border); }
.badge-info      { background: var(--status-info-bg);    color: var(--status-info);    border-color: var(--status-info-border); }
.badge-neutral   { background: var(--status-neutral-bg); color: var(--status-neutral); border-color: var(--status-neutral-border); }
.badge-unmanaged { background: var(--status-purple-bg);  color: var(--status-purple);  border-color: var(--status-purple-border); }

.badge-pulse::before { animation: pulse 1.4s ease-in-out infinite; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:active { transform: translateY(0.5px); }
.btn svg { flex-shrink: 0; }

.btn-primary {
  background: var(--brand-orange);
  color: #fff;
  border-color: var(--brand-orange);
}
.btn-primary:hover { background: var(--brand-orange-hover); border-color: var(--brand-orange-hover); }

.btn-secondary {
  background: transparent;
  color: var(--text-link);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent); }

.btn-danger {
  background: transparent;
  color: var(--status-danger);
  border-color: var(--status-danger-border);
}
.btn-danger:hover { background: var(--status-danger-bg); }

.btn:disabled, .btn[disabled] { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* Icon-only button — the default action affordance (rule BTN-1) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-link);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn-icon:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn-icon.is-active { background: var(--bg-active); border-color: var(--accent); }
.btn-icon:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn-icon-ghost {
  border-color: transparent;
  color: var(--text-muted);
  width: 24px;
  height: 24px;
}
.btn-icon-ghost:hover { background: var(--bg-hover); color: var(--text-link); border-color: transparent; }

/* Badge counter on a filter button */
.btn-icon { position: relative; }
.btn-badge {
  position: absolute;
  top: -5px; right: -5px;
  min-width: 15px; height: 15px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--brand-orange);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Search bar ──────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 0 8px;
  height: 30px;
  width: 200px;
  max-width: 100%;
  flex: 0 1 200px;
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.search-bar svg { flex-shrink: 0; color: var(--text-muted); }
.search-bar input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 12.5px;
  width: 100%;
  padding: 0;
  color: var(--text-primary);
}
.search-bar input::placeholder { color: var(--text-muted); }

/* ── Segmented / filter chips ────────────────────────────────────────── */
.chips { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.chip:hover { border-color: var(--accent); color: var(--text-primary); }
.chip.active { background: var(--bg-active); border-color: var(--accent); color: var(--text-link); }
.chip-dismiss { display: inline-flex; opacity: 0.7; }

/* ── Dropdown menus ──────────────────────────────────────────────────── */
.action-dropdown { position: relative; display: inline-flex; }

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 200px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  padding: 4px;
  animation: popIn 0.1s ease;
}
.dropdown-menu.open { display: block; }
.dropdown-menu.align-left { right: auto; left: 0; }

.dropdown-label {
  padding: 6px 10px 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item svg { flex-shrink: 0; color: var(--text-muted); }
.dropdown-item.danger { color: var(--status-danger); }
.dropdown-item.danger svg { color: var(--status-danger); }
.dropdown-item.danger:hover { background: var(--status-danger-bg); }
.dropdown-item[disabled], .dropdown-item-disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* Checkbox rows inside a filter dropdown */
.dropdown-check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text-primary);
}
.dropdown-check:hover { background: var(--bg-hover); }
.dropdown-check input { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
.dropdown-check .count { margin-left: auto; font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

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

/* Topbar dropdowns sit on the dark bar */
.topbar .dropdown-menu { background: var(--bg-raised); border-color: var(--border); }

/* ── Forms ───────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.cols-1 { grid-template-columns: 1fr; }

.form-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-group.full { grid-column: 1 / -1; }

label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-primary);
}

input, select, textarea {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-input);
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
textarea { resize: vertical; min-height: 76px; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 12px center, right 7px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}
.form-hint { font-size: 11px; color: var(--text-muted); }

/* ── Modals ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 21, 32, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.14s ease;
}
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 1000px; }

/* The playbook editor is a dedicated workspace: its YAML canvas gets the
   viewport, while metadata and AI drafting live in a separate tab. */
.playbook-workspace {
  width: min(1440px, calc(100vw - 32px));
  max-width: none;
  height: min(920px, calc(100vh - 32px));
  max-height: none;
}
.playbook-workspace .modal-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.playbook-workspace-tabs { flex: none; }
.playbook-workspace-tabs .tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.playbook-workspace-tab { display: none; min-height: 0; }
.playbook-workspace-tab.active { display: flex; flex: 1; flex-direction: column; }
#playbook-tab-editor { padding-top: 8px; }
#playbook-tab-details { overflow-y: auto; padding-top: 16px; }
.playbook-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex: none;
}
.playbook-editor-toolbar .de-spacer { flex: 1; }
#playbook-editor-host { display: flex; flex: 1; min-height: 0; }
#playbook-editor-host .dual-editor { flex: 1; min-height: 0; }
#playbook-editor-host .de-pane { min-height: 0; }
#playbook-editor-host .de-code { height: auto; flex: 1; }
#playbook-editor-host .de-preview { height: auto; flex: 1; min-height: 0; }

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; }

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px;
  border-radius: var(--r-sm);
  display: flex;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body { padding: 16px; overflow-y: auto; flex: 1; }

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ── Login (AWS sign-in style) ───────────────────────────────────────── */
#loginModal.modal-overlay {
  background: var(--bg-app);
  backdrop-filter: none;
  z-index: 2000;
  align-items: flex-start;
  padding: 0;
  overflow-y: auto;
}

.login-shell {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 16px 32px;
  gap: 20px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: 22px;
  animation: popIn 0.16s ease;
}

.login-card h2 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 3px;
  color: var(--text-primary);
}
.login-card .login-lede { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 18px; }

.login-fields { display: flex; flex-direction: column; gap: 14px; }
.login-card .btn { width: 100%; height: 34px; }

.login-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  margin-bottom: 16px;
}
.login-identity .identity-text { min-width: 0; flex: 1; }
.login-identity .identity-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 700;
}
.login-identity .identity-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--status-danger-bg);
  border: 1px solid var(--status-danger-border);
  border-left: 3px solid var(--status-danger);
  color: var(--status-danger);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 14px;
}
.login-alert svg { flex-shrink: 0; margin-top: 1px; }

.login-footer {
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Detail grid ─────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.detail-item {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  min-width: 0;
}
.detail-item-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.detail-item-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
}

/* ── Activity feed (human-readable recent activity) ──────────────────── */
.activity-list { display: flex; flex-direction: column; }

.activity-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  min-width: 0;
}
.activity-row:last-child { border-bottom: none; }
.activity-row:hover { background: var(--bg-hover); }

.activity-icon {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--act-bg, var(--status-neutral-bg));
  color: var(--act-fg, var(--status-neutral));
  border: 1px solid var(--act-border, var(--status-neutral-border));
}

.activity-text { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-primary); }
.activity-text strong { font-weight: 700; }
.activity-text .activity-detail {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── Tabs ────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  overflow-x: auto;
}
.tab-btn {
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--text-link); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Log viewer / code ───────────────────────────────────────────────── */
.log-viewer {
  background: var(--bg-code);
  color: #c9d1d9;
  padding: 14px;
  border-radius: var(--r-sm);
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.6;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
}
.log-line-ok   { color: #3fb950; }
.log-line-err  { color: #f85149; }
.log-line-warn { color: #d29922; }
.log-line-info { color: #58a6ff; }

.playbook-editor {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  min-height: 320px;
  width: 100%;
  background: var(--bg-code);
  color: #c9d1d9;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px;
  resize: vertical;
  tab-size: 2;
}
.playbook-editor:focus { outline: none; border-color: var(--brand-orange); box-shadow: 0 0 0 1px var(--brand-orange); }

/* ── Settings ────────────────────────────────────────────────────────── */
.settings-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 16px;
  padding: 5px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  background: var(--bg-surface-alt);
  overflow-x: auto;
}
.settings-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-secondary);
  font: 600 12.5px/1 inherit;
  white-space: nowrap;
  cursor: pointer;
}
.settings-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.settings-tab.active { background: var(--bg-surface); color: var(--text-link); box-shadow: var(--shadow-sm); }
.settings-tab-panel { display: none; }
.settings-tab-panel.active { display: block; }
.settings-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  margin-bottom: 12px;
  overflow: hidden;
}
.settings-section-header {
  padding: 9px 14px;
  background: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-section-body { padding: 14px; }

/* The header carries a status badge on the right for testable sections. */
.settings-section-header { justify-content: space-between; }
.settings-section-header > span { display: inline-flex; align-items: center; gap: 8px; }

.settings-section-intro {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-secondary);
}
.settings-section-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 11px 14px;
  background: var(--bg-surface-alt);
  border-top: 1px solid var(--border-subtle);
}
.settings-footer-note { font-size: 11.5px; color: var(--text-muted); }

/* Banner for configuration that blocks the whole panel (e.g. no ENCRYPTION_KEY). */
.settings-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  margin-bottom: 12px;
  border-radius: var(--r-md);
  font-size: 12px;
  line-height: 1.55;
  background: var(--status-info-bg);
  border: 1px solid var(--status-info-border);
  color: var(--text-primary);
}
.settings-banner.danger {
  background: var(--status-danger-bg);
  border-color: var(--status-danger-border);
}
.settings-banner code { font-size: 11px; word-break: break-all; }

/* Provenance / state chips shown next to a field label. */
.setting-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font: 600 10px/1.6 inherit;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  vertical-align: middle;
  color: var(--text-muted);
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
}
.setting-chip.saved { color: var(--status-info); background: var(--status-info-bg); border-color: var(--status-info-border); }
.setting-chip.warn  { color: var(--status-danger); background: var(--status-danger-bg); border-color: var(--status-danger-border); }
.setting-required { color: var(--status-danger); margin-left: 3px; }

.setting-control input[type="text"],
.setting-control input[type="number"],
.setting-control input[type="password"] { text-align: left; }
.setting-error {
  display: none;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--status-danger);
  text-align: left;
}
.setting-row.invalid .setting-error { display: block; }
.setting-row.invalid input { border-color: var(--status-danger); }

/* Result of a Test connection / Send test email run. */
.settings-test-result {
  padding: 12px 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 12px;
}
.settings-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  line-height: 1.5;
}
.settings-check-mark { flex-shrink: 0; font-weight: 700; }
.settings-check.ok   .settings-check-mark { color: var(--status-success); }
.settings-check.bad  .settings-check-mark { color: var(--status-danger); }
.settings-check.skip .settings-check-mark { color: var(--text-muted); }
.settings-check.skip { color: var(--text-muted); }
.settings-check-name { font-weight: 600; }

.setting-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--border-subtle);
  gap: 20px;
  flex-wrap: wrap;
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; min-width: 200px; }
.setting-label { font-weight: 600; font-size: 13px; }
.setting-desc { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.setting-control { flex-shrink: 0; min-width: 180px; text-align: right; }

.toggle-switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background 0.18s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.18s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Checkbox list / snapshots / file tabs ───────────────────────────── */
.checkbox-list {
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  background: var(--bg-surface);
}
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 400;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}
.checkbox-list label:last-child { border-bottom: none; }
.checkbox-list label:hover { background: var(--bg-hover); }
.checkbox-list input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); }
.checkbox-list .vm-meta { font-size: 11px; color: var(--text-muted); margin-left: auto; }

.snapshot-list { list-style: none; }
.snapshot-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12.5px;
}
.snapshot-list li:last-child { border-bottom: none; }

.file-tab-bar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.file-tab-btn {
  padding: 3px 10px;
  font-size: 11.5px;
  font-family: ui-monospace, Menlo, monospace;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-secondary);
}
.file-tab-btn.active { background: var(--brand-orange); color: #fff; border-color: var(--brand-orange); }
.file-tab-btn:hover:not(.active) { background: var(--bg-hover); }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--status-info);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: slideUp 0.2s ease;
  max-width: 340px;
}
.toast-success { border-left-color: var(--status-success); }
.toast-error   { border-left-color: var(--status-danger); }
.toast-info    { border-left-color: var(--status-info); }

/* ── Spinner ─────────────────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

/* Inline error banner inside a modal form */
.form-alert {
  background: var(--status-danger-bg);
  border: 1px solid var(--status-danger-border);
  border-left: 3px solid var(--status-danger);
  color: var(--status-danger);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 12px;
}

/* Power-control button row in the instance detail modal */
.vm-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.vm-actions .btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* ── Utilities ───────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.pt-4 { padding-top: 16px; }
.border-t { border-top: 1px solid var(--border-subtle); }
.col-span-2 { grid-column: 1 / -1; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 11.5px; }
.font-mono { font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
a { color: var(--text-link); }

/* ── Animations ──────────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes popIn   { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: scale(1); } }
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes pulse   { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.fade-in { animation: fadeIn 0.2s ease; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ══ Responsive ═══════════════════════════════════════════════════════ */

/* Tablet — collapse the sidebar to an overlay drawer */
@media (max-width: 900px) {
  :root { --gutter: 12px; }

  .app-container {
    grid-template-areas: "topbar topbar" "content content";
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-toggle { display: inline-flex; }

  .page-head { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; justify-content: flex-start; }
  .search-bar { flex: 1 1 160px; width: auto; }
}

/* Phone — tables reflow into stacked cards */
@media (max-width: 720px) {
  .metrics { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; }
  .metric-value { font-size: 18px; }

  .panel { border-radius: var(--r-md); }
  .panel-head { padding: 8px 10px; }

  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }

  tbody tr {
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-sm);
    margin: 8px;
    padding: 4px 0;
    background: var(--bg-surface);
    position: relative;
  }
  tbody tr:hover td { background: transparent; }

  td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 10px;
    border-bottom: none;
    text-align: right;
  }
  /* Column name from the data-label the renderer stamps on each cell */
  td::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    padding-top: 2px;
  }
  td:empty, td[data-label=""]:empty { display: none; }
  td .cell-main, td .res-chips, td .flex { justify-content: flex-end; }
  td .td-secondary, td .activity-text { text-align: right; }

  /* The name cell reads as the card header */
  td[data-label="Name"], td[data-label="Name / ID"], td[data-label="Job ID"], td[data-label="Playbook"], td[data-label="Username"] {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 7px;
    margin-bottom: 3px;
  }
  td[data-label="Name"]::before, td[data-label="Name / ID"]::before,
  td[data-label="Job ID"]::before, td[data-label="Playbook"]::before,
  td[data-label="Username"]::before { display: none; }
  td[data-label="Name"], td[data-label="Name / ID"], td[data-label="Job ID"],
  td[data-label="Playbook"], td[data-label="Username"] { text-align: left; }
  td[data-label="Name"] .cell-main, td[data-label="Name / ID"] .cell-main { justify-content: flex-start; }

  /* Actions pinned to the card's top-right corner */
  td.col-actions {
    position: absolute;
    top: 6px;
    right: 8px;
    width: auto;
    padding: 0;
  }
  td.col-actions::before { display: none; }

  .modal-footer .btn { flex: 1; }
  .setting-control { min-width: 0; width: 100%; text-align: left; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
}

/* ── Dual editor ──────────────────────────────────────────────────────────
   Left pane: raw source, syntax highlighted. A transparent <textarea> sits
   exactly on top of a highlighted <pre>, so the caret and native editing
   behaviour are the browser's — only the paint underneath is ours. Both layers
   MUST keep identical font metrics, padding and wrapping or the caret drifts.
   Right pane: a structural preview of the same document.
   Used by the playbook editor (editable) and the workspace viewer (read-only).
*/
.dual-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-code);
}
.dual-editor.single-pane { grid-template-columns: 1fr; }
.de-pane { display: flex; flex-direction: column; min-width: 0; }
.de-pane + .de-pane { border-left: 1px solid var(--border); }

.de-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  background: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-secondary);
  flex: none;
}
.de-pane-head .de-head-note {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text-muted);
}

/* Editing surface: gutter + stacked highlight/textarea layers */
.de-code {
  position: relative;
  display: flex;
  background: var(--bg-code);
  overflow: auto;
  height: var(--de-height, 380px);
}
.de-gutter {
  flex: none;
  padding: 10px 8px 10px 10px;
  text-align: right;
  color: #5b6b7f;
  background: var(--bg-code);
  border-right: 1px solid rgba(255, 255, 255, .06);
  user-select: none;
  position: sticky;
  left: 0;
  z-index: 3;
}
.de-layers { position: relative; flex: 1 1 auto; min-width: 0; }

/* The two layers must stay pixel-identical — change one, change the other. */
.de-gutter,
.de-highlight,
.de-input {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  word-break: normal;
}
.de-highlight,
.de-input {
  margin: 0;
  padding: 10px;
  border: 0;
  min-height: 100%;
  box-sizing: border-box;
  overflow: visible;
}
.de-highlight { color: #c9d1d9; pointer-events: none; }
.de-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--brand-orange);
  outline: none;
  overflow: hidden;
}
.de-input::selection { background: rgba(236, 114, 17, .32); color: transparent; }
.de-code:focus-within { box-shadow: inset 0 0 0 1px var(--brand-orange); }
.de-input[readonly] { caret-color: transparent; }

/* Token colours — tuned against --bg-code in both themes */
.tok-key     { color: #79c0ff; }
.tok-str     { color: #a5d6ff; }
.tok-num     { color: #f2cc60; }
.tok-bool    { color: #ffa657; }
.tok-comment { color: #768390; font-style: italic; }
.tok-punct   { color: #8b949e; }
.tok-dash    { color: #ff7b72; }
.tok-anchor  { color: #d2a8ff; }
.tok-doc     { color: #768390; }
.tok-block   { color: #ffa657; }

/* Preview pane */
.de-preview {
  height: var(--de-height, 380px);
  overflow: auto;
  padding: 12px;
  background: var(--bg-surface);
  font-size: 12.5px;
  color: var(--text-primary);
}
.de-preview-empty {
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 10px 2px;
}
.de-preview-error {
  color: var(--status-warning);
  background: var(--status-warning-bg);
  border: 1px solid var(--status-warning-border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
}

.de-play {
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--bg-surface-alt);
}
.de-play:last-child { margin-bottom: 0; }
.de-play-head {
  padding: 7px 10px;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border-subtle);
}
.de-play-title { font-weight: 600; font-size: 12.5px; color: var(--text-primary); }
.de-play-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.de-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-size: 10.5px;
  font-family: ui-monospace, Menlo, monospace;
  background: var(--status-neutral-bg);
  color: var(--status-neutral);
  border: 1px solid var(--status-neutral-border);
}
.de-tag.accent { background: var(--accent-soft); color: var(--accent); border-color: var(--status-info-border); }
.de-tag.warn   { background: var(--status-warning-bg); color: var(--status-warning); border-color: var(--status-warning-border); }

.de-section-label {
  padding: 5px 10px 2px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.de-task {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 5px 10px;
  border-top: 1px solid var(--border-subtle);
}
.de-task-num {
  flex: none;
  min-width: 18px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: ui-monospace, Menlo, monospace;
}
.de-task-body { min-width: 0; flex: 1; }
.de-task-name { color: var(--text-primary); line-height: 1.4; }
.de-task-name.unnamed { color: var(--text-muted); font-style: italic; }
.de-task-mods { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px; }
.de-mod {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: var(--r-sm);
  background: var(--status-purple-bg);
  color: var(--status-purple);
  border: 1px solid var(--status-purple-border);
}

/* Generic key/value preview, used for cloud-init, netplan, tfstate, JSON */
.de-tree { font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.7; }
.de-tree ul { list-style: none; margin: 0; padding-left: 14px; border-left: 1px dotted var(--border); }
.de-tree > ul { padding-left: 2px; border-left: 0; }
.de-tree .k { color: var(--accent); }
.de-tree .v { color: var(--text-primary); }
.de-tree .v.str  { color: var(--status-success); }
.de-tree .v.num  { color: var(--status-warning); }
.de-tree .v.bool { color: var(--status-purple); }
.de-tree .v.null { color: var(--text-muted); font-style: italic; }
.de-tree .idx { color: var(--text-muted); }

.de-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.de-toolbar .de-spacer { flex: 1 1 auto; }
.de-status { font-size: 11.5px; color: var(--text-muted); }
.de-status.ok   { color: var(--status-success); }
.de-status.bad  { color: var(--status-danger); }

/* ── AI generation panel ──────────────────────────────────────────────── */
.ai-panel {
  border: 1px solid var(--status-purple-border);
  background: var(--status-purple-bg);
  border-radius: var(--r-sm);
  padding: 12px;
  margin-bottom: 14px;
}
.ai-panel-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--status-purple);
  margin-bottom: 9px;
}
.ai-panel textarea {
  width: 100%;
  min-height: 62px;
  resize: vertical;
  font-size: 12.5px;
}
.ai-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
}
.ai-panel-row select { min-width: 210px; max-width: 320px; }
.ai-notes {
  margin-top: 9px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 8px 10px;
}
.ai-tools { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }

@media (max-width: 900px) {
  .playbook-workspace {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
  .playbook-workspace .modal-body { padding: 12px; }
  .dual-editor { grid-template-columns: 1fr; }
  .de-pane + .de-pane { border-left: 0; border-top: 1px solid var(--border); }
}
