/* ════════════════════════════════════════════════════════════════════════════
   o9n · COMPONENTS
   Mobile-first. Every value comes from tokens.css. No magic numbers.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── RESET ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  min-height: 100vh;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }
[x-cloak] { display: none !important; }

/* selection */
::selection { background: var(--accent-mid); color: var(--text); }

/* scrollbar (webkit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: var(--r-pill);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--border3); }

/* ── UTILITY · text colors / sizes / weights ─────────────────────────────── */
.text-muted   { color: var(--muted); }
.text-subtle  { color: var(--subtle); }
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error   { color: var(--error); }
.text-mono    { font-family: var(--mono); font-feature-settings: "tnum" 1; }
.text-up      { text-transform: uppercase; letter-spacing: var(--track-wider); }

.text-2xs { font-size: var(--text-2xs); }
.text-xs  { font-size: var(--text-xs); }
.text-sm  { font-size: var(--text-sm); }
.text-md  { font-size: var(--text-md); }
.text-lg  { font-size: var(--text-lg); }
.text-xl  { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.fw-medium   { font-weight: var(--fw-medium); }
.fw-semibold { font-weight: var(--fw-semibold); }
.fw-bold     { font-weight: var(--fw-bold); }

/* ── BRAND MARK ──────────────────────────────────────────────────────────── */
.o9n-mark {
  font-weight: var(--fw-bold);
  letter-spacing: var(--track-widest);
  font-size: var(--text-md);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  user-select: none;
}
.o9n-mark .nine { color: var(--accent); }

/* ── BUTTON ──────────────────────────────────────────────────────────────── */
.btn {
  --_h: 36px;
  --_px: var(--space-4);
  --_bg: var(--surface2);
  --_fg: var(--text);
  --_bd: var(--border);

  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  height: var(--_h);
  padding: 0 var(--_px);
  background: var(--_bg);
  color: var(--_fg);
  border: 1px solid var(--_bd);
  border-radius: var(--r);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  letter-spacing: var(--track-snug);
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), transform var(--t-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover     { background: var(--surface3); border-color: var(--border2); }
.btn:active    { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* sizes */
.btn-sm { --_h: 30px; --_px: var(--space-3); font-size: var(--text-xs); }
.btn-lg { --_h: 44px; --_px: var(--space-5); font-size: var(--text-md); }

/* variants */
.btn-primary {
  --_bg: var(--accent); --_fg: var(--accent-ink); --_bd: transparent;
  font-weight: var(--fw-semibold);
}
.btn-primary:hover { --_bg: var(--accent-hover); }

.btn-ghost { --_bg: transparent; --_bd: transparent; }
.btn-ghost:hover { --_bg: var(--surface2); }

.btn-danger { --_bg: var(--error-s); --_fg: var(--error); --_bd: rgba(239,68,68,.2); }
.btn-danger:hover { --_bg: rgba(239,68,68,.18); }

.btn-icon { --_px: 0; width: var(--_h); }

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

/* ── INPUT / SELECT / TEXTAREA ───────────────────────────────────────────── */
.input, .select, .textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.textarea { height: auto; min-height: 96px; padding: var(--space-3); resize: vertical; line-height: var(--lh-normal); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border2); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent-mid);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--subtle); }

.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field label {
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  color: var(--muted);
  letter-spacing: var(--track-wide);
}
.field .hint  { font-size: var(--text-xs); color: var(--subtle); }
.field .err   { font-size: var(--text-xs); color: var(--error); }

/* search input with icon */
.search {
  position: relative;
  display: flex; align-items: center;
  width: 100%;
}
.search svg {
  position: absolute; left: 12px;
  width: 14px; height: 14px;
  color: var(--muted);
  pointer-events: none;
}
.search .input { padding-left: 36px; }

/* ── CARD ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  position: relative;
}
.card-compact { padding: var(--space-4); }
.card-pad-lg  { padding: var(--space-6); }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card-title {
  font-size: var(--text-md);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--track-snug);
}
.card-subtitle { font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }

.card-divider {
  height: 1px; background: var(--border);
  margin: var(--space-5) calc(var(--space-5) * -1);
}
.card-compact .card-divider { margin: var(--space-4) calc(var(--space-4) * -1); }

/* ── KPI CARD ────────────────────────────────────────────────────────────── */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-3);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  /* subtle dot grid hint */
  content: "";
  position: absolute; inset: 0;
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 16px 16px;
  opacity: 0.4;
  pointer-events: none;
}
.kpi > * { position: relative; }
.kpi-label {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: var(--track-wider);
  font-weight: var(--fw-medium);
}
.kpi-label .ico {
  width: 24px; height: 24px;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
}
.kpi-value {
  font-size: var(--text-3xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--track-tight);
  font-family: var(--mono);
  font-feature-settings: "tnum" 1;
  line-height: 1;
  color: var(--text);
}
.kpi-meta {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--muted);
}
.kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-family: var(--mono);
  font-size: var(--text-2xs);
  font-weight: var(--fw-semibold);
}
.kpi-delta.up   { background: var(--success-s); color: var(--success); }
.kpi-delta.down { background: var(--error-s);   color: var(--error); }
.kpi-delta.flat { background: var(--surface3);  color: var(--muted); }

/* sparkline visual inside KPI */
.kpi-spark {
  height: 32px;
  margin-top: var(--space-2);
}
.kpi-spark path { stroke: var(--accent); stroke-width: 1.5; fill: none; }
.kpi-spark .area { fill: var(--accent-soft); stroke: none; }

/* ── BADGE / CHIP / PILL ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: var(--text-2xs);
  font-weight: var(--fw-medium);
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: var(--track-wide);
}
.badge .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
}
.badge.success { background: var(--success-s); border-color: rgba(16,185,129,.2); color: var(--success); }
.badge.success .dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.badge.warning { background: var(--warning-s); border-color: rgba(245,158,11,.2); color: var(--warning); }
.badge.warning .dot { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.badge.error   { background: var(--error-s);   border-color: rgba(239,68,68,.2);  color: var(--error); }
.badge.error   .dot { background: var(--error); box-shadow: 0 0 8px var(--error); }
.badge.info    { background: var(--info-s);    border-color: rgba(96,165,250,.2); color: var(--info); }
.badge.info    .dot { background: var(--info); box-shadow: 0 0 8px var(--info); }
.badge.accent  { background: var(--accent-soft); border-color: var(--accent-mid); color: var(--accent); }
.badge.accent  .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  transition: background var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
}
.chip:hover { background: var(--surface3); border-color: var(--border2); }
.chip.active { background: var(--accent-soft); border-color: var(--accent-mid); color: var(--accent); }
.chip svg { width: 14px; height: 14px; }

/* ── TABLE ───────────────────────────────────────────────────────────────── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table thead th {
  text-align: left;
  font-size: var(--text-2xs);
  font-weight: var(--fw-medium);
  text-transform: uppercase;
  letter-spacing: var(--track-wider);
  color: var(--muted);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface2); }
.table .num   { font-family: var(--mono); font-feature-settings: "tnum" 1; text-align: right; }
.table .right { text-align: right; }
.table .muted { color: var(--muted); }

/* on small screens, switch to a "card" layout — see [data-card-table] block */
@media (max-width: 767px) {
  .table-responsive[data-card-table] { display: block; }
  .table-responsive[data-card-table] thead { display: none; }
  .table-responsive[data-card-table] tbody,
  .table-responsive[data-card-table] tr { display: block; }
  .table-responsive[data-card-table] tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
  }
  .table-responsive[data-card-table] td {
    display: flex; align-items: center; justify-content: space-between;
    border: none;
    padding: var(--space-2) var(--space-1);
  }
  .table-responsive[data-card-table] td::before {
    content: attr(data-label);
    font-size: var(--text-2xs);
    text-transform: uppercase;
    letter-spacing: var(--track-wider);
    color: var(--muted);
    font-weight: var(--fw-medium);
    margin-right: var(--space-3);
  }
  .table-responsive[data-card-table] td.num,
  .table-responsive[data-card-table] td.right { text-align: left; }
}

/* ── NAV ITEM (sidebar / bottom-nav share this) ─────────────────────────── */
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--r);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-item.active::before {
  content: "";
  position: absolute; left: -10px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 16px;
  background: var(--accent);
  border-radius: var(--r-pill);
  box-shadow: 0 0 12px var(--accent);
}
.nav-item .ico {
  width: 18px; height: 18px;
  flex-shrink: 0;
}
.nav-item .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: var(--text-2xs);
  padding: 1px 6px;
  background: var(--surface3);
  border-radius: var(--r-pill);
  color: var(--muted);
}
.nav-item.active .count { background: var(--accent-mid); color: var(--accent); }

.nav-section {
  font-size: var(--text-2xs);
  font-weight: var(--fw-medium);
  text-transform: uppercase;
  letter-spacing: var(--track-wider);
  color: var(--subtle);
  padding: var(--space-3) var(--space-3) var(--space-2);
}

/* ── STATUS DOT ──────────────────────────────────────────────────────────── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.ok   { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.warn { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.status-dot.err  { background: var(--error);   box-shadow: 0 0 8px var(--error); }
.status-dot.idle { background: var(--muted); }
.status-dot.live { background: var(--success); animation: pulse-dot 2s ease-in-out infinite; }
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,.6); }
  50%      { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
}

/* ── AVATAR ──────────────────────────────────────────────────────────────── */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--success) 60%, var(--warning));
  border: 1.5px solid var(--border2);
  display: grid; place-items: center;
  color: var(--bg);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  font-family: var(--mono);
  flex-shrink: 0;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; border-width: 1px; }
.avatar-lg { width: 44px; height: 44px; font-size: var(--text-sm); }

/* ── PROGRESS ────────────────────────────────────────────────────────────── */
.progress {
  width: 100%; height: 4px;
  background: var(--surface3);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress > div {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width var(--t-slow) var(--ease);
}
.progress.success > div { background: var(--success); }
.progress.warning > div { background: var(--warning); }
.progress.error > div   { background: var(--error); }

/* ── SHEET / MODAL ───────────────────────────────────────────────────────── */
.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
}

/* mobile bottom sheet, desktop centered modal */
.sheet {
  position: fixed;
  z-index: var(--z-modal);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  /* mobile default: bottom sheet */
  inset: auto 0 0 0;
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  max-height: 90dvh;
  overflow-y: auto;
}
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border3);
  border-radius: var(--r-pill);
  margin: var(--space-3) auto var(--space-2);
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.sheet-body { padding: var(--space-5); }

@media (min-width: 768px) {
  /* tablet+: center as modal */
  .sheet {
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(560px, calc(100vw - var(--space-8)));
    max-height: 80dvh;
    border-radius: var(--r-2xl);
  }
  .sheet-handle { display: none; }
}

/* ── TABS ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ── TOAST ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + var(--space-4));
  left: 50%; transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  display: flex; align-items: center; gap: var(--space-3);
  font-size: var(--text-sm);
}
@media (min-width: 768px) {
  .toast {
    bottom: var(--space-6);
    left: auto; right: var(--space-6);
    transform: none;
  }
}

/* ── SKELETON / LOADING ─────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface2) 0%,
    var(--surface3) 50%,
    var(--surface2) 100%);
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request .htmx-indicator-hide { display: none; }

/* spin */
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── LAYOUT PRIMITIVES ───────────────────────────────────────────────────── */
.stack    { display: flex; flex-direction: column; gap: var(--space-3); }
.stack-sm { gap: var(--space-2); }
.stack-lg { gap: var(--space-5); }
.row      { display: flex; align-items: center; gap: var(--space-3); }
.row-sm   { gap: var(--space-2); }
.row-lg   { gap: var(--space-5); }
.spacer   { flex: 1; }
.cluster  { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .grid-2  { grid-template-columns: repeat(2, 1fr); }
  .grid-sm-2 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .grid-md-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-md-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .grid-lg-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-lg-4 { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1280px) {
  .grid-xl-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ════════════════════════════════════════════════════════════════════════════
   APP SHELL — sidebar + topbar + main + (optional) right rail
   Mobile: bottom-nav, no sidebar visible by default (drawer)
   Tablet: collapsed icon sidebar
   Desktop: full sidebar + main + right rail
   ════════════════════════════════════════════════════════════════════════════ */

.app {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar"
    "main";
  min-height: 100dvh;
}

/* ── TOPBAR ──────────────────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--content-pad);
  background: rgba(9,9,11,.75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand-link { display: flex; align-items: center; gap: var(--space-2); }
.topbar .brand-link .orb-mini {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%,
    rgba(255,255,255,.5), var(--accent) 35%, var(--node-bg) 80%);
  box-shadow: 0 0 12px var(--accent-mid);
  flex-shrink: 0;
}
.topbar .breadcrumb {
  display: none;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: var(--text-sm);
}
.topbar .breadcrumb .sep { opacity: 0.4; }
.topbar .breadcrumb .here { color: var(--text); font-weight: var(--fw-medium); }
.topbar .topbar-search { display: none; flex: 1; max-width: 480px; }
.topbar .topbar-actions { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; }

@media (min-width: 768px) {
  .topbar .breadcrumb { display: flex; }
  .topbar .topbar-search { display: flex; }
}
@media (min-width: 1024px) {
  /* sidebar always shows the brand at desktop, so hide the topbar copy */
  .topbar .brand-link { display: none; }
}

.menu-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r);
  color: var(--text);
}
.menu-btn:hover { background: var(--surface2); }

@media (min-width: 1024px) { .menu-btn { display: none; } }

/* ── SIDEBAR ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-h); bottom: 0; left: 0;
  height: calc(100dvh - var(--topbar-h));
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: var(--z-drawer);
  display: flex; flex-direction: column;
  padding: var(--space-4);
  transform: translateX(-100%);
  transition: transform var(--t-base) var(--ease);
}
.sidebar[data-open="true"] { transform: translateX(0); }
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2);
  margin-bottom: var(--space-3);
}
.sidebar-nav {
  flex: 1;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
  padding-right: 2px;
  margin: 0 -2px;
}
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
  margin-top: var(--space-3);
}

@media (min-width: 1024px) {
  .sidebar {
    /* always-visible sticky drawer on desktop, no transform */
    transform: none;
    transition: none;
  }
  .sidebar-scrim { display: none !important; }
}

/* ── RIGHT RAIL (system status, recent alerts) ───────────────────────────── */
.rail {
  display: none;
}
@media (min-width: 1280px) {
  .rail {
    display: block;
    grid-area: rail;
    border-left: 1px solid var(--border);
    background: var(--surface);
    padding: var(--space-5);
    overflow-y: auto;
  }
  .app {
    grid-template-columns: 1fr var(--rail-w);
    grid-template-areas:
      "topbar topbar"
      "main    rail";
  }
}

/* ── MAIN CONTENT ────────────────────────────────────────────────────────── */
.main {
  grid-area: main;
  padding: var(--content-pad);
  padding-bottom: calc(var(--bottomnav-h) + var(--space-6));  /* avoid bottom-nav overlap */
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
}
@media (min-width: 1024px) {
  /* reserve space for the always-visible sidebar */
  .app  { margin-left: var(--sidebar-w); }
  .main { padding-bottom: var(--content-pad); }
}

/* ── BOTTOM NAV (mobile only) ────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: var(--z-sticky);
  height: var(--bottomnav-h);
  background: rgba(17,17,19,.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch; justify-content: space-around;
  padding: 0 var(--space-2);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  font-size: 10px;
  font-weight: var(--fw-medium);
  letter-spacing: var(--track-wide);
  color: var(--muted);
  position: relative;
}
.bottom-nav-item .ico { width: 22px; height: 22px; }
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item.active::after {
  content: "";
  position: absolute; top: 4px; left: 50%;
  transform: translateX(-50%);
  width: 16px; height: 2px;
  background: var(--accent);
  border-radius: var(--r-pill);
}
@media (min-width: 1024px) { .bottom-nav { display: none; } }

/* ── SIDEBAR SCRIM (when drawer is open on mobile/tablet) ────────────────── */
.sidebar-scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: calc(var(--z-drawer) - 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.sidebar-scrim[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

/* ── PAGE HEADER (page title row) ────────────────────────────────────────── */
.page-header {
  display: flex; flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.page-header .head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
}
.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--track-tight);
}
.page-subtitle {
  margin-top: var(--space-1);
  font-size: var(--text-sm);
  color: var(--muted);
}
.page-actions {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
}

/* ── DOT-GRID BACKDROP UTILITY (canvas hint) ─────────────────────────────── */
.dot-grid {
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* ════════════════════════════════════════════════════════════════════════════
   WORKFLOW · CANVAS (desktop/tablet) + FLOW (mobile)
   Two views of the same data — share node colors, status states, type tokens.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── flush main (no padding) for the canvas page ─────────────────────────── */
.main-flush {
  padding: 0;
  padding-bottom: var(--bottomnav-h);
  max-width: none;
}
@media (min-width: 1024px) {
  .main-flush { padding: 0; }
}

/* ── VOICE PROMPT CARD (always visible, hero of the workflow page) ──────── */
.voice-prompt {
  margin: var(--content-pad);
  background: linear-gradient(135deg,
    var(--surface) 0%,
    var(--surface2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-4);
  position: relative;
  overflow: hidden;
}
.voice-prompt::before {
  /* faint dot grid hint */
  content: "";
  position: absolute; inset: 0;
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 16px 16px;
  opacity: 0.5;
  pointer-events: none;
}
.voice-prompt > * { position: relative; }
.voice-prompt-head {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--track-wider);
  color: var(--accent);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--space-2);
}
.voice-prompt-head .mic {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.voice-prompt-text {
  font-size: var(--text-md);
  line-height: var(--lh-snug);
  font-weight: var(--fw-medium);
  color: var(--text);
  font-style: italic;
}
.voice-prompt-text::before { content: "“"; color: var(--accent); margin-right: 2px; }
.voice-prompt-text::after  { content: "”"; color: var(--accent); margin-left: 2px; }
.voice-prompt-meta {
  margin-top: var(--space-3);
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-2xs);
  color: var(--muted);
  font-family: var(--mono);
}
.voice-prompt-actions {
  display: flex; gap: var(--space-2); margin-top: var(--space-3);
  flex-wrap: wrap;
}

/* mini waveform decoration (purely visual) */
.voice-wave {
  display: inline-flex; align-items: center; gap: 2px;
  height: 14px;
}
.voice-wave span {
  display: block;
  width: 2px;
  background: var(--accent);
  border-radius: var(--r-pill);
  opacity: 0.7;
  animation: voice-wave 1.1s ease-in-out infinite;
}
.voice-wave span:nth-child(1) { height: 30%; animation-delay: 0.0s; }
.voice-wave span:nth-child(2) { height: 70%; animation-delay: 0.1s; }
.voice-wave span:nth-child(3) { height: 50%; animation-delay: 0.2s; }
.voice-wave span:nth-child(4) { height: 90%; animation-delay: 0.3s; }
.voice-wave span:nth-child(5) { height: 60%; animation-delay: 0.4s; }
.voice-wave span:nth-child(6) { height: 40%; animation-delay: 0.5s; }
@keyframes voice-wave {
  0%, 100% { transform: scaleY(0.5); }
  50%      { transform: scaleY(1); }
}

/* ── CANVAS (desktop / tablet) ───────────────────────────────────────────── */
.canvas-shell {
  position: relative;
  width: 100%;
  height: calc(100dvh - var(--topbar-h) - 220px);   /* leaves space for voice card */
  min-height: 480px;
  background: var(--canvas-bg);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  touch-action: none;
}
.canvas-shell::before {
  /* dot grid */
  content: "";
  position: absolute; inset: 0;
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0;
  pointer-events: none;
}
.canvas-content {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  /* dimensions large enough to hold all nodes; wires use absolute coords */
  width: 1600px;
  height: 900px;
  transition: transform var(--t-fast) var(--ease);
  will-change: transform;
}

/* wires sit behind nodes */
.wires {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
}
.wire {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.75;
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px var(--accent-mid));
}
.wire[data-type="data"]    { stroke: var(--info);    filter: drop-shadow(0 0 4px rgba(96,165,250,.4)); }
.wire[data-type="signal"]  { stroke: var(--accent);  }
.wire[data-type="control"] { stroke: var(--warning); filter: drop-shadow(0 0 4px rgba(245,158,11,.4)); }
.wire-flow {
  /* animated dashes simulating data flowing */
  stroke-dasharray: 4 6;
  animation: wire-dash 1.2s linear infinite;
}
@keyframes wire-dash { to { stroke-dashoffset: -20; } }

/* ── NODE ────────────────────────────────────────────────────────────────── */
.node {
  position: absolute;
  width: 220px;
  background: var(--node-bg);
  border: 1px solid var(--node-border);
  border-radius: var(--r);
  box-shadow: var(--shadow-md);
  font-size: var(--text-xs);
  user-select: none;
  cursor: grab;
  transition: box-shadow var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
  z-index: 2;
}
.node:hover {
  border-color: var(--border3);
  z-index: 3;
}
.node[data-selected="true"] {
  border-color: var(--accent);
  box-shadow: var(--shadow-md), var(--glow-accent);
  z-index: 4;
}
.node[data-status="running"] {
  border-color: var(--accent);
  animation: node-pulse 1.6s ease-in-out infinite;
}
.node[data-status="error"] { border-color: var(--error); }
.node[data-status="done"]  { border-color: rgba(16,185,129,.5); }
@keyframes node-pulse {
  0%, 100% { box-shadow: var(--shadow-md), 0 0 0 0 var(--accent-mid); }
  50%      { box-shadow: var(--shadow-md), 0 0 0 8px transparent; }
}

.node-header {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 8px 10px;
  border-bottom: 1px solid var(--node-border);
  background: linear-gradient(to bottom, rgba(255,255,255,0.02), transparent);
  border-radius: var(--r) var(--r) 0 0;
}
.node-header::before {
  content: "";
  width: 3px;
  align-self: stretch;
  border-radius: var(--r-pill);
  background: var(--accent);
  flex-shrink: 0;
}
.node[data-type="input"]   .node-header::before { background: var(--info); }
.node[data-type="process"] .node-header::before { background: var(--accent); }
.node[data-type="output"]  .node-header::before { background: var(--success); }
.node[data-type="tool"]    .node-header::before { background: var(--warning); }

.node-title {
  flex: 1;
  font-weight: var(--fw-semibold);
  font-size: var(--text-xs);
  letter-spacing: var(--track-snug);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.node[data-status="ready"]   .node-status-dot { background: var(--muted); }
.node[data-status="running"] .node-status-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse-dot 1.6s ease-in-out infinite; }
.node[data-status="done"]    .node-status-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.node[data-status="error"]   .node-status-dot { background: var(--error);   box-shadow: 0 0 8px var(--error); }

.node-body { padding: 8px 10px; }

.node-row {
  display: flex; align-items: center;
  position: relative;             /* socket positions against the row */
  padding: 4px 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.node-row.input  { padding-left: 4px; }
.node-row.output { padding-right: 4px; justify-content: flex-end; text-align: right; }

.node-meta {
  margin-top: 6px; padding-top: 6px;
  border-top: 1px dashed var(--node-border);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--subtle);
  letter-spacing: var(--track-wide);
}

/* sockets — colored dots that sit on the node edge, vertically centered on their row */
.socket {
  position: absolute;
  width: 12px; height: 12px;
  top: 50%;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--node-bg);
  border: 2px solid var(--muted);
  z-index: 5;
  transition: transform var(--t-fast), border-color var(--t-fast);
}
.socket:hover { transform: scale(1.3); }
.socket.input  { left: -17px; }     /* push past node-body's 10px padding to land on node border */
.socket.output { right: -17px; }
.socket[data-dtype="data"]    { border-color: var(--info); }
.socket[data-dtype="signal"]  { border-color: var(--accent); }
.socket[data-dtype="control"] { border-color: var(--warning); }
.socket[data-connected="true"]::after {
  content: "";
  position: absolute; inset: 1px;
  border-radius: 50%;
}
.socket[data-dtype="data"][data-connected="true"]::after    { background: var(--info); }
.socket[data-dtype="signal"][data-connected="true"]::after  { background: var(--accent); }
.socket[data-dtype="control"][data-connected="true"]::after { background: var(--warning); }

/* ── CANVAS TOOLBAR (top-right floating) ─────────────────────────────────── */
.canvas-toolbar {
  position: absolute;
  top: var(--space-3); right: var(--space-3);
  display: flex; gap: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 4px;
  box-shadow: var(--shadow-md);
  z-index: 10;
}
.canvas-toolbar .btn { box-shadow: none; border: none; background: transparent; }
.canvas-toolbar .btn:hover { background: var(--surface2); }
.canvas-toolbar .divider { width: 1px; align-self: stretch; background: var(--border); margin: 4px 0; }

.canvas-zoom-display {
  display: inline-flex; align-items: center;
  padding: 0 var(--space-2);
  font-family: var(--mono);
  font-size: var(--text-2xs);
  color: var(--muted);
  min-width: 48px;
  justify-content: center;
}

/* ── CANVAS FAB (run button bottom-center) ───────────────────────────────── */
.canvas-fab {
  position: absolute;
  bottom: var(--space-4); left: 50%;
  transform: translateX(-50%);
  z-index: 10;
}
.canvas-fab .btn { box-shadow: var(--shadow-lg), var(--glow-accent); }

/* ── MINIMAP (bottom-right) ──────────────────────────────────────────────── */
.minimap {
  position: absolute;
  bottom: var(--space-3); right: var(--space-3);
  width: 180px; height: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  z-index: 10;
  box-shadow: var(--shadow-md);
  display: none;
}
@media (min-width: 1024px) {
  .minimap { display: block; }
}
.minimap-viewport {
  position: absolute;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  background: var(--accent-soft);
  pointer-events: none;
}

/* ── PROPERTIES PANEL (right side, opens when node selected) ─────────────── */
.props-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 300px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: var(--space-4);
  overflow-y: auto;
  z-index: 9;
  transform: translateX(100%);
  transition: transform var(--t-base) var(--ease);
}
.props-panel[data-open="true"] { transform: translateX(0); }

/* ════════════════════════════════════════════════════════════════════════════
   FLOW VIEW · vertical stack for mobile (< 768)
   Same nodes, same colors, same statuses, but stacked top-to-bottom.
   ════════════════════════════════════════════════════════════════════════════ */

.flow {
  display: flex;
  flex-direction: column;
  padding: var(--content-pad);
  padding-top: 0;
  position: relative;
}

/* the connecting wire that runs down the left margin */
.flow::before {
  content: "";
  position: absolute;
  left: calc(var(--content-pad) + 16px);
  top: 0; bottom: 60px;
  width: 2px;
  background: linear-gradient(to bottom,
    transparent 0%,
    var(--node-border) 4%,
    var(--node-border) 96%,
    transparent 100%);
  z-index: 0;
}

.flow-step {
  position: relative;
  margin-left: 44px;
  background: var(--node-bg);
  border: 1px solid var(--node-border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  z-index: 1;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.flow-step:hover { border-color: var(--border3); }
.flow-step[data-selected="true"] {
  box-shadow: var(--glow-accent);
  border-left-width: 4px;
}

/* status dot anchored on the wire */
.flow-step::before {
  content: "";
  position: absolute;
  left: -32px; top: 14px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg);
  box-shadow: 0 0 12px var(--accent);
  z-index: 2;
}

.flow-step[data-type="input"]   { border-left-color: var(--info); }
.flow-step[data-type="input"]::before { background: var(--info); box-shadow: 0 0 12px var(--info); }
.flow-step[data-type="process"] { border-left-color: var(--accent); }
.flow-step[data-type="process"]::before { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.flow-step[data-type="output"]  { border-left-color: var(--success); }
.flow-step[data-type="output"]::before { background: var(--success); box-shadow: 0 0 12px var(--success); }
.flow-step[data-type="tool"]    { border-left-color: var(--warning); }
.flow-step[data-type="tool"]::before { background: var(--warning); box-shadow: 0 0 12px var(--warning); }

.flow-step[data-status="running"]::before { animation: pulse-dot 1.6s ease-in-out infinite; }
.flow-step[data-status="error"]::before { background: var(--error); box-shadow: 0 0 12px var(--error); }

.flow-step-head {
  display: flex; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-1);
}
.flow-step-num {
  font-family: var(--mono);
  font-size: var(--text-2xs);
  color: var(--muted);
  letter-spacing: var(--track-wide);
}
.flow-step-title {
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  flex: 1;
  letter-spacing: var(--track-snug);
}
.flow-step-type {
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--track-wider);
  color: var(--muted);
  font-weight: var(--fw-medium);
}
.flow-step-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: var(--space-2);
  display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3);
}
.flow-step-meta span { display: inline-flex; align-items: center; gap: 4px; }
.flow-step-io {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px dashed var(--node-border);
  display: flex; flex-direction: column; gap: 4px;
  font-family: var(--mono);
  font-size: 11px;
}
.flow-step-io .io-row { display: flex; gap: var(--space-2); }
.flow-step-io .io-label {
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  min-width: 32px;
}
.flow-step-io .io-value { color: var(--text); }

/* expand toggle */
.flow-step-expand {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--muted);
  display: inline-flex; align-items: center; gap: 4px;
  cursor: pointer;
}
.flow-step-expand:hover { color: var(--accent); }

/* ── view switching ─────────────────────────────────────────────────────── */
.view-canvas { display: none; }
.view-flow   { display: block; }
@media (min-width: 768px) {
  .view-canvas { display: block; }
  .view-flow   { display: none; }
}

/* manual override — when the user toggles to flow on desktop */
[data-flow-forced="true"] .view-canvas { display: none !important; }
[data-flow-forced="true"] .view-flow   { display: block !important; }

/* in flow mode, constrain max width for readability */
[data-flow-forced="true"] .view-flow,
.view-flow {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

/* ── workflow page header (above voice card on mobile, top-bar adjacent on desktop) ── */
.workflow-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding: var(--content-pad);
  padding-bottom: 0;
  flex-wrap: wrap;
}
.workflow-header .title { font-size: var(--text-lg); font-weight: var(--fw-semibold); }
.workflow-header .subtitle { font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }


/* ── ACCESSIBILITY ───────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ════════════════════════════════════════════════════════════════════════════
   LIGHT REFACTOR ADDENDUM (Z.ai language) — appended; overrides by source order
   ════════════════════════════════════════════════════════════════════════════ */

/* Primary CTA → Z.ai near-black, not the accent */
.btn-primary        { --_bg: var(--btn); --_fg: var(--btn-text); --_bd: transparent; }
.btn-primary:hover  { --_bg: #27272a; }

/* Serif for hero / display moments ("What can I automate for you?") */
.hero-serif, .display-serif { font-family: var(--serif); font-weight: 500; letter-spacing: var(--track-snug); }

/* Optional dark "stage" treatment for the workflow canvas (Z.ai hero-media look).
   Add class .wf-wire-canvas--stage to opt a single canvas into dark framing. */
.wf-wire-canvas--stage,
.canvas--stage {
  --canvas-bg:   #18181b;
  --node-bg:     #27272a;
  --node-border: #3f3f46;
  --grid-dot:    rgba(255,255,255,.06);
  background: var(--canvas-bg);
  color: #fafafa;
}
.wf-wire-canvas--stage .node-title,
.canvas--stage .node-title { color: #fafafa; }
