/* ==========================================================================
   TierLattice design system
   Author: TierLattice · self-hosted fonts · no external dependencies
   --------------------------------------------------------------------------
   1. Tokens
   2. Reset & base
   3. Typography
   4. Layout helpers
   5. Buttons
   6. Forms
   7. Cards & surfaces
   8. Tables
   9. Badges, chips, alerts
   10. Navigation (public header / app sidebar / topbar)
   11. Stats & dashboard
   12. Matrix grid
   13. Modals, toasts, dropdowns, tabs
   14. Pagination, empty states, progress
   15. Utilities
   16. Responsive & motion
   ========================================================================== */

/* 1. Tokens -------------------------------------------------------------- */
:root {
  /* brand — teal */
  --tl-teal-50: #f0fbf9;
  --tl-teal-100: #d6f4ef;
  --tl-teal-200: #b0e8e0;
  --tl-teal-300: #7fd6cb;
  --tl-teal-400: #4cbdb2;
  --tl-teal-500: #26a296;
  --tl-teal-600: #178179;
  --tl-teal-700: #14675f;
  --tl-teal-800: #13524c;
  --tl-teal-900: #0f3b38;

  /* accent — indigo */
  --tl-indigo-400: #818cf8;
  --tl-indigo-500: #6366f1;
  --tl-indigo-600: #4f46e5;
  --tl-indigo-700: #4338ca;

  /* CTA — orange */
  --tl-orange-400: #fb923c;
  --tl-orange-500: #f97316;
  --tl-orange-600: #ea580c;

  /* neutrals */
  --tl-ink: #0b1220;
  --tl-ink-soft: #131c2e;
  --tl-slate-900: #0f172a;
  --tl-slate-800: #1e293b;
  --tl-slate-700: #334155;
  --tl-slate-600: #475569;
  --tl-slate-500: #64748b;
  --tl-slate-400: #94a3b8;
  --tl-slate-300: #cbd5e1;
  --tl-slate-200: #e2e8f0;
  --tl-slate-100: #f1f5f9;
  --tl-slate-50: #f8fafc;
  --tl-white: #ffffff;

  /* semantic */
  --tl-success: #15803d;
  --tl-success-bg: #dcfce7;
  --tl-warning: #b45309;
  --tl-warning-bg: #fef3c7;
  --tl-danger: #b91c1c;
  --tl-danger-bg: #fee2e2;
  --tl-info: #0369a1;
  --tl-info-bg: #e0f2fe;

  /* semantic aliases */
  --tl-primary: var(--tl-teal-700);
  --tl-primary-hover: var(--tl-teal-800);
  --tl-primary-soft: var(--tl-teal-50);
  --tl-accent: var(--tl-orange-500);
  --tl-accent-hover: var(--tl-orange-600);
  --tl-bg: var(--tl-slate-50);
  --tl-surface: var(--tl-white);
  --tl-text: var(--tl-slate-900);
  --tl-text-muted: var(--tl-slate-500);
  --tl-border: var(--tl-slate-200);
  --tl-border-strong: var(--tl-slate-300);

  /* type */
  --tl-font-heading: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
  --tl-font-body: 'DM Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --tl-font-mono: 'SFMono-Regular', ui-monospace, Menlo, Consolas, monospace;

  /* radius */
  --tl-r-xs: 6px;
  --tl-r-sm: 9px;
  --tl-r: 13px;
  --tl-r-lg: 18px;
  --tl-r-xl: 26px;
  --tl-r-full: 999px;

  /* elevation */
  --tl-shadow-xs: 0 1px 2px rgba(15, 23, 42, .06);
  --tl-shadow-sm: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --tl-shadow: 0 4px 14px rgba(15, 23, 42, .08), 0 1px 3px rgba(15, 23, 42, .04);
  --tl-shadow-lg: 0 18px 40px rgba(15, 23, 42, .12), 0 4px 10px rgba(15, 23, 42, .05);
  --tl-ring: 0 0 0 3px rgba(38, 162, 150, .35);

  /* layout */
  --tl-sidebar-w: 264px;
  --tl-topbar-h: 62px;
  --tl-container: 1200px;

  /* motion */
  --tl-fast: 150ms;
  --tl-base: 220ms;
  --tl-ease: cubic-bezier(.4, 0, .2, 1);
}

/* 2. Reset & base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

/* The sticky top bar must never cover the element a user scrolls to. */
.table tbody tr,
.table tbody tr a,
.matrix-node,
.card,
.panel {
  scroll-margin-top: calc(var(--tl-topbar-h) + 20px);
}

body {
  margin: 0;
  font-family: var(--tl-font-body);
  font-size: 15px;
  line-height: 1.65;
  color: var(--tl-text);
  background: var(--tl-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, canvas, video { max-width: 100%; height: auto; display: block; }
svg { fill: currentColor; }

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

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--tl-teal-600);
  outline-offset: 2px;
  border-radius: var(--tl-r-xs);
}

::selection { background: var(--tl-teal-200); color: var(--tl-teal-900); }

/* 3. Typography ---------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--tl-font-heading);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -.02em;
  color: var(--tl-slate-900);
  margin: 0 0 .5em;
}
h1 { font-size: clamp(2rem, 1.35rem + 2.6vw, 3.35rem); }
h2 { font-size: clamp(1.55rem, 1.15rem + 1.6vw, 2.35rem); }
h3 { font-size: clamp(1.2rem, 1.05rem + .6vw, 1.55rem); }
h4 { font-size: 1.1rem; }
h5 { font-size: .98rem; }
p  { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

.lead { font-size: 1.08rem; color: var(--tl-text-muted); line-height: 1.7; }
.muted { color: var(--tl-text-muted); }
.small { font-size: .86rem; }
.tiny  { font-size: .78rem; }
.strong { font-weight: 600; }
.mono { font-family: var(--tl-font-mono); font-size: .9em; }
.nowrap { white-space: nowrap; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.uppercase { text-transform: uppercase; letter-spacing: .08em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance { text-wrap: balance; }

.tl-gradient-text {
  background: linear-gradient(120deg, var(--tl-teal-600), var(--tl-indigo-600));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* 4. Layout helpers ------------------------------------------------------ */
.container { width: 100%; max-width: var(--tl-container); margin-inline: auto; padding-inline: 20px; }
.container-narrow { max-width: 820px; }
.container-wide { max-width: 1400px; }

.stack       { display: flex; flex-direction: column; gap: 16px; }
.stack-sm    { display: flex; flex-direction: column; gap: 8px; }
.stack-lg    { display: flex; flex-direction: column; gap: 28px; }
.row         { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-wrap    { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-top     { display: flex; align-items: flex-start; gap: 12px; }
.grow        { flex: 1 1 auto; min-width: 0; }
.spacer      { flex: 1 1 auto; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }

.section { padding-block: clamp(48px, 6vw, 88px); }
.section-sm { padding-block: clamp(32px, 4vw, 56px); }

/* 5. Buttons ------------------------------------------------------------- */
.btn {
  --btn-bg: var(--tl-primary);
  --btn-fg: #fff;
  --btn-bd: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--btn-bd);
  border-radius: var(--tl-r-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--tl-font-heading);
  font-size: .94rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--tl-fast) var(--tl-ease),
              border-color var(--tl-fast) var(--tl-ease),
              color var(--tl-fast) var(--tl-ease),
              box-shadow var(--tl-fast) var(--tl-ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--tl-teal-600); outline-offset: 2px; }
.btn[disabled], .btn.is-disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }

.btn-primary { --btn-bg: var(--tl-primary); --btn-fg: #fff; }
.btn-primary:hover { --btn-bg: var(--tl-primary-hover); }

.btn-accent { --btn-bg: var(--tl-accent); --btn-fg: #fff; }
.btn-accent:hover { --btn-bg: var(--tl-accent-hover); }

.btn-ghost { --btn-bg: transparent; --btn-fg: var(--tl-slate-700); --btn-bd: var(--tl-border-strong); }
.btn-ghost:hover { --btn-bg: var(--tl-slate-100); --btn-fg: var(--tl-slate-900); }

.btn-soft { --btn-bg: var(--tl-teal-50); --btn-fg: var(--tl-teal-800); --btn-bd: var(--tl-teal-100); }
.btn-soft:hover { --btn-bg: var(--tl-teal-100); }

.btn-danger { --btn-bg: var(--tl-danger); --btn-fg: #fff; }
.btn-danger:hover { --btn-bg: #991b1b; }

.btn-quiet { --btn-bg: transparent; --btn-fg: var(--tl-slate-600); --btn-bd: transparent; }
.btn-quiet:hover { --btn-bg: var(--tl-slate-100); --btn-fg: var(--tl-slate-900); }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .84rem; border-radius: var(--tl-r-xs); }
.btn-lg { min-height: 52px; padding: 14px 26px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }

.btn-group { display: inline-flex; gap: 8px; flex-wrap: wrap; }

/* 6. Forms --------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label, label.tl-label {
  font-size: .84rem;
  font-weight: 600;
  color: var(--tl-slate-700);
  letter-spacing: .01em;
}
.field-hint { font-size: .8rem; color: var(--tl-text-muted); }
.field-error { font-size: .8rem; color: var(--tl-danger); font-weight: 500; }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border: 1px solid var(--tl-border-strong);
  border-radius: var(--tl-r-sm);
  background: var(--tl-white);
  color: var(--tl-text);
  font-size: .95rem;
  transition: border-color var(--tl-fast) var(--tl-ease), box-shadow var(--tl-fast) var(--tl-ease);
}
.input::placeholder, .textarea::placeholder { color: var(--tl-slate-400); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--tl-slate-400); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--tl-teal-500);
  box-shadow: var(--tl-ring);
}
.input[readonly], .input[disabled], .select[disabled] { background: var(--tl-slate-100); color: var(--tl-slate-600); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--tl-r-sm) 0 0 var(--tl-r-sm); }
.input-group .btn { border-radius: 0 var(--tl-r-sm) var(--tl-r-sm) 0; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: .92rem;
  line-height: 1.5;
}
.check input[type="checkbox"], .check input[type="radio"] {
  width: 18px; height: 18px; margin-top: 2px; accent-color: var(--tl-primary); cursor: pointer; flex: none;
}
.check-row { padding: 10px 12px; border: 1px solid var(--tl-border); border-radius: var(--tl-r-sm); margin-bottom: 8px; background: var(--tl-white); }
.check-row:hover { border-color: var(--tl-teal-300); }

.form-grid { display: grid; gap: 0 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding-top: 8px; }

.input-prefix { position: relative; }
.input-prefix .input { padding-left: 38px; }
.input-prefix::before {
  content: attr(data-prefix);
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--tl-slate-500); font-size: .9rem; pointer-events: none;
}

/* 7. Cards & surfaces ---------------------------------------------------- */
.card {
  background: var(--tl-surface);
  border: 1px solid var(--tl-border);
  border-radius: var(--tl-r);
  box-shadow: var(--tl-shadow-xs);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--tl-border); flex-wrap: wrap;
}
.card-title { font-family: var(--tl-font-heading); font-size: 1rem; font-weight: 600; margin: 0; }
.card-body { padding: 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--tl-border); background: var(--tl-slate-50); border-radius: 0 0 var(--tl-r) var(--tl-r); }
.card-hover { transition: box-shadow var(--tl-base) var(--tl-ease), transform var(--tl-base) var(--tl-ease); }
.card-hover:hover { box-shadow: var(--tl-shadow); transform: translateY(-2px); }

.panel { background: var(--tl-slate-50); border: 1px solid var(--tl-border); border-radius: var(--tl-r); padding: 16px; }

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

/* 8. Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--tl-r); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left; font-weight: 600; font-size: .76rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--tl-slate-500); background: var(--tl-slate-50);
  padding: 11px 14px; border-bottom: 1px solid var(--tl-border); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--tl-border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--tl-fast) var(--tl-ease); }
.table tbody tr:hover { background: var(--tl-slate-50); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* 9. Badges, chips, alerts ------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--tl-r-full);
  font-size: .74rem; font-weight: 600; letter-spacing: .02em;
  background: var(--tl-slate-100); color: var(--tl-slate-700);
  white-space: nowrap;
}
.badge-success { background: var(--tl-success-bg); color: var(--tl-success); }
.badge-warning { background: var(--tl-warning-bg); color: var(--tl-warning); }
.badge-danger  { background: var(--tl-danger-bg);  color: var(--tl-danger); }
.badge-info    { background: var(--tl-info-bg);    color: var(--tl-info); }
.badge-primary { background: var(--tl-teal-100);   color: var(--tl-teal-800); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: var(--tl-r-full);
  border: 1px solid var(--tl-border); background: var(--tl-white);
  font-size: .82rem; color: var(--tl-slate-600);
}
.chip-active { background: var(--tl-teal-50); border-color: var(--tl-teal-300); color: var(--tl-teal-800); font-weight: 600; }

.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 13px 16px; border-radius: var(--tl-r-sm);
  border: 1px solid var(--tl-border); background: var(--tl-slate-50);
  font-size: .92rem; line-height: 1.6;
}
.alert-success { background: var(--tl-success-bg); border-color: #bbf7d0; color: #14532d; }
.alert-warning { background: var(--tl-warning-bg); border-color: #fde68a; color: #78350f; }
.alert-danger  { background: var(--tl-danger-bg);  border-color: #fecaca; color: #7f1d1d; }
.alert-info    { background: var(--tl-info-bg);    border-color: #bae6fd; color: #075985; }
.alert-icon { flex: none; margin-top: 1px; }

/* 10. Navigation ---------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--tl-sidebar-w);
  flex: none;
  background: var(--tl-ink);
  color: #cdd7e5;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto; z-index: 30;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; border-bottom: 1px solid rgba(255, 255, 255, .08);
  font-family: var(--tl-font-heading); font-weight: 700; color: #fff; font-size: 1.05rem;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-logo { width: 34px; height: 34px; border-radius: 9px; flex: none; }
.sidebar-section {
  padding: 16px 20px 6px; font-size: .68rem; text-transform: uppercase;
  letter-spacing: .12em; color: #64748b; font-weight: 700;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px; color: #cdd7e5; font-size: .9rem; font-weight: 500;
  border-left: 3px solid transparent; transition: background-color var(--tl-fast) var(--tl-ease), color var(--tl-fast) var(--tl-ease);
}
.sidebar-link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.sidebar-link.is-active { background: rgba(38, 162, 150, .16); color: #fff; border-left-color: var(--tl-teal-400); }
.sidebar-link svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.sidebar-link.is-active svg { opacity: 1; }
.sidebar-foot { margin-top: auto; padding: 16px 20px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .78rem; color: #64748b; }

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--tl-topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 22px; background: var(--tl-surface);
  border-bottom: 1px solid var(--tl-border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-family: var(--tl-font-heading); font-weight: 600; font-size: 1.02rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.content { padding: 24px; flex: 1 1 auto; }
.content-narrow { max-width: 1120px; margin-inline: auto; }

.breadcrumb { display: flex; align-items: center; gap: 7px; font-size: .84rem; color: var(--tl-text-muted); margin-bottom: 14px; flex-wrap: wrap; }
.breadcrumb a { color: var(--tl-text-muted); }
.breadcrumb a:hover { color: var(--tl-primary); }

.icon-btn {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--tl-r-sm); border: 1px solid transparent; background: transparent;
  color: var(--tl-slate-600); transition: background-color var(--tl-fast) var(--tl-ease), color var(--tl-fast) var(--tl-ease);
}
.icon-btn:hover { background: var(--tl-slate-100); color: var(--tl-slate-900); }
.icon-btn svg { width: 20px; height: 20px; }

.avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex: none;
  border: 2px solid var(--tl-surface); box-shadow: var(--tl-shadow-xs);
}
.avatar-sm { width: 30px; height: 30px; }
.avatar-lg { width: 64px; height: 64px; }

/* 11. Stats & dashboard --------------------------------------------------- */
.stat {
  background: var(--tl-surface); border: 1px solid var(--tl-border);
  border-radius: var(--tl-r); padding: 18px; display: flex; gap: 14px; align-items: flex-start;
}
.stat-icon {
  width: 44px; height: 44px; border-radius: var(--tl-r-sm); flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--tl-teal-50); color: var(--tl-teal-700);
}
.stat-icon svg { width: 21px; height: 21px; }
.stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--tl-text-muted); font-weight: 600; }
.stat-value { font-family: var(--tl-font-heading); font-size: 1.6rem; font-weight: 700; line-height: 1.2; letter-spacing: -.02em; }
.stat-meta { font-size: .8rem; color: var(--tl-text-muted); }

.kpi-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }

.progress { height: 8px; border-radius: var(--tl-r-full); background: var(--tl-slate-200); overflow: hidden; }
.progress-bar { height: 100%; width: var(--tl-fill, 0%); background: linear-gradient(90deg, var(--tl-teal-500), var(--tl-indigo-500)); border-radius: var(--tl-r-full); transition: width var(--tl-base) var(--tl-ease); }

/* 12. Matrix grid --------------------------------------------------------- */
.matrix {
  display: grid; gap: 14px; padding: 18px;
  grid-template-columns: repeat(var(--tl-cols, 3), minmax(148px, 1fr));
  background: var(--tl-slate-50); border: 1px solid var(--tl-border);
  border-radius: var(--tl-r); overflow-x: auto;
}
.matrix-col { display: flex; flex-direction: column; gap: 10px; min-width: 148px; }
.matrix-col-head {
  text-align: center; font-size: .72rem; text-transform: uppercase; letter-spacing: .09em;
  font-weight: 700; color: var(--tl-slate-500); padding-bottom: 2px;
}
.matrix-node {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border-radius: var(--tl-r-sm);
  background: var(--tl-white); border: 1px solid var(--tl-border);
  box-shadow: var(--tl-shadow-xs);
  transition: border-color var(--tl-fast) var(--tl-ease), box-shadow var(--tl-fast) var(--tl-ease);
}
.matrix-node:hover { border-color: var(--tl-teal-400); box-shadow: var(--tl-shadow-sm); }
.matrix-node.is-empty { background: transparent; border-style: dashed; color: var(--tl-slate-400); justify-content: center; min-height: 46px; }
.matrix-node.is-me { border-color: var(--tl-orange-500); box-shadow: 0 0 0 3px rgba(249, 115, 22, .18); }
.matrix-node-info { min-width: 0; }
.matrix-node-name { font-size: .86rem; font-weight: 600; line-height: 1.25; }
.matrix-node-meta { font-size: .72rem; color: var(--tl-text-muted); }
.matrix-connector { height: 14px; width: 2px; background: var(--tl-slate-300); margin: -4px auto; }

/* 13. Modals, toasts, dropdowns, tabs ------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11, 18, 32, .55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--tl-surface); border-radius: var(--tl-r-lg); width: min(560px, 100%);
  max-height: 88vh; overflow-y: auto; box-shadow: var(--tl-shadow-lg);
}
.modal-lg { width: min(820px, 100%); }

.toast-stack { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 260px; max-width: 380px; padding: 13px 16px;
  border-radius: var(--tl-r-sm); background: var(--tl-ink); color: #fff;
  box-shadow: var(--tl-shadow-lg); font-size: .9rem;
  border-left: 3px solid var(--tl-teal-400);
  animation: tl-toast-in .22s var(--tl-ease);
}
.toast-success { border-left-color: var(--tl-teal-400); }
.toast-danger { border-left-color: #f87171; }
@keyframes tl-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--tl-surface); border: 1px solid var(--tl-border);
  border-radius: var(--tl-r-sm); box-shadow: var(--tl-shadow-lg);
  padding: 6px; z-index: 40; display: none;
}
.dropdown.is-open .dropdown-menu { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: var(--tl-r-xs); color: var(--tl-slate-700); font-size: .9rem;
}
.dropdown-item:hover { background: var(--tl-slate-100); color: var(--tl-slate-900); text-decoration: none; }
.dropdown-item svg { width: 16px; height: 16px; }
.dropdown-divider { height: 1px; background: var(--tl-border); margin: 5px 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--tl-border); margin-bottom: 20px; overflow-x: auto; }
.tab {
  padding: 10px 15px; font-size: .9rem; font-weight: 500; color: var(--tl-slate-600);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--tl-slate-900); text-decoration: none; }
.tab.is-active { color: var(--tl-primary); border-bottom-color: var(--tl-primary); font-weight: 600; }

.accordion { border: 1px solid var(--tl-border); border-radius: var(--tl-r-sm); background: var(--tl-white); margin-bottom: 10px; overflow: hidden; }
.accordion summary {
  padding: 14px 16px; cursor: pointer; font-weight: 600; font-size: .95rem;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; list-style: none;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after { content: "+"; font-size: 1.2rem; color: var(--tl-slate-400); }
.accordion[open] summary::after { content: "\2212"; }
.accordion-body { padding: 0 16px 16px; color: var(--tl-slate-600); font-size: .93rem; }

/* 14. Pagination, empty states -------------------------------------------- */
.pagination { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pagination a, .pagination span {
  min-width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 10px; border: 1px solid var(--tl-border); border-radius: var(--tl-r-xs);
  font-size: .88rem; color: var(--tl-slate-600); background: var(--tl-white);
}
.pagination a:hover { border-color: var(--tl-teal-400); color: var(--tl-primary); text-decoration: none; }
.pagination .is-current { background: var(--tl-primary); border-color: var(--tl-primary); color: #fff; font-weight: 600; }
.pagination .is-disabled { opacity: .45; }

.empty-state { text-align: center; padding: 44px 20px; color: var(--tl-text-muted); }
.empty-state svg { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--tl-slate-300); }
.empty-state h3 { font-size: 1.05rem; margin-bottom: 4px; }

/* 15. Utilities ----------------------------------------------------------- */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.text-teal { color: var(--tl-teal-700); }
.text-orange { color: var(--tl-orange-600); }
.text-danger { color: var(--tl-danger); }
.text-success { color: var(--tl-success); }
.bg-soft { background: var(--tl-slate-50); }
.border-soft { border: 1px solid var(--tl-border); }
.rounded { border-radius: var(--tl-r-sm); }
.rounded-lg { border-radius: var(--tl-r); }
.shadow-sm { box-shadow: var(--tl-shadow-sm); }
.shadow { box-shadow: var(--tl-shadow); }
.p-0 { padding: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }
.w-full { width: 100%; }
.relative { position: relative; }
.sticky-top { position: sticky; top: 0; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.9rem; }

/* 16. Responsive & motion ------------------------------------------------- */
@media (max-width: 1024px) {
  .grid-sidebar { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; transform: translateX(-100%);
    transition: transform var(--tl-base) var(--tl-ease); box-shadow: var(--tl-shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .content { padding: 16px; }
  .sidebar-scrim { position: fixed; inset: 0; background: rgba(11, 18, 32, .5); z-index: 25; }
}

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .card-pad, .card-body { padding: 16px; }
  .btn { width: 100%; }
  .btn-group .btn, .form-actions .btn { width: auto; }
  .topbar { padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 13b. Authentication and installation screens ----------------------------- */
        .auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
        @media (min-width: 960px) { .auth-shell { grid-template-columns: 1.05fr .95fr; } }
        .auth-aside {
            background: radial-gradient(120% 120% at 15% 10%, #14675f 0%, #0f3b38 42%, #0b1220 100%);
            color: #e2e8f0; padding: 44px; display: flex; flex-direction: column; justify-content: space-between;
        }
        .auth-aside h2 { color: #fff; max-width: 15ch; }
        .auth-aside p { color: #cbd5e1; max-width: 46ch; }
        .auth-feature { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; }
        .auth-feature svg { width: 20px; height: 20px; color: #7fd6cb; flex: none; margin-top: 3px; }
        .auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; background: #f8fafc; }
        .auth-card { width: min(460px, 100%); }
        .auth-logo { display: inline-flex; margin-bottom: 22px; }

/* 14. Template utilities -------------------------------------------------
   The templates never carry style attributes: every rule lives in this file
   and only the value that changes at runtime is passed as a custom property.
   ------------------------------------------------------------------------ */
.tl-link-plain { color: inherit; text-decoration: none; }
.tl-text-muted { color: #94a3b8; }
.tl-text-dim { color: #64748b; }
.tl-m-0 { margin: 0; }
.tl-mt-6 { margin-top: 6px; }
.tl-mt-10 { margin-top: 10px; }
.tl-mt-26 { margin-top: 26px; }
.tl-mb-2 { margin-bottom: 2px; }
.tl-mb-10 { margin-bottom: 10px; }
.tl-mb-18 { margin-bottom: 18px; }
.tl-ml-6 { margin-left: 6px; }
.tl-w-auto { width: auto; }
.tl-w-140 { width: 140px; }
.tl-w-220 { width: 220px; }
.tl-min-180 { min-width: 180px; }
.tl-min-220 { min-width: 220px; }
.tl-min-230 { min-width: 230px; }
.tl-block { display: block; }
.tl-hidden { display: none; }
.tl-justify-end { justify-content: flex-end; }
.tl-drop-head { padding: 8px 10px; border-bottom: 1px solid var(--tl-border); margin-bottom: 4px; }
.tl-drop-item { width: 100%; border: 0; background: none; text-align: left; }
.tl-admin-logout { width: 100%; border-color: rgba(255, 255, 255, .14); color: #cbd5e1; }
.tl-panel-staff { border-color: var(--tl-teal-300); background: var(--tl-teal-50); }
.tl-panel-read { opacity: .65; }
.tl-panel-fresh { border-color: var(--tl-teal-300); }
.tl-list-plain { padding-left: 18px; margin: 0; }
.tl-tree { list-style: none; padding-left: 0; margin: 0; }
.tl-tree > li { padding: 8px 0; border-bottom: 1px solid var(--tl-border); }
.tl-tree-note { margin-top: 6px; }
.tl-bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; }
.tl-bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; }
.tl-bar { width: 100%; height: var(--tl-bar-h, 4px); background: linear-gradient(180deg, var(--tl-teal-400), var(--tl-teal-600)); border-radius: 6px 6px 0 0; }

@media print {
  .sidebar, .topbar, .btn, .toast-stack { display: none !important; }
  .content { padding: 0; }
  .card { border: 1px solid #ddd; box-shadow: none; }
}

/* 15. Installation screen ------------------------------------------------- */
.tl-mt-18 { margin-top: 18px; }
.tl-pre {
  margin: 10px 0 0; padding: 12px; border-radius: var(--tl-r-sm);
  background: var(--tl-slate-900); color: var(--tl-slate-100);
  font-family: var(--tl-font-mono); font-size: 12px; line-height: 1.6;
  overflow: auto; max-height: 320px; white-space: pre-wrap;
}
.check-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check-row input { width: 16px; height: 16px; accent-color: var(--tl-teal-500); }
