/* =========================================================================
   Woodlam Agent Operations Console — Design System
   Mint / Teal HR-SaaS direction · soft cards · high whitespace · calm + premium
   Vanilla CSS, zero build step. Tokens derived from design.md.
   ========================================================================= */

:root {
  /* ---- Brand ---- */
  --primary: #2fc5a5;
  --primary-dark: #087e6b;
  --primary-light: #ddf7ec;
  --primary-tint: #f0faf6;
  /* Accent FOREGROUND (links, chips, tags, pills). Same as primary-dark in light,
     but flips light in dark so it stays readable on the dark primary tint.
     Use --accent for text/icons; keep --primary-dark for fills/gradients. */
  --accent: #087e6b;

  /* ---- Surfaces ---- */
  --bg: #e7f2ee;
  --bg-deep: #dcebe5;
  --surface: #f8fbfa;
  --white: #ffffff;
  --border: #e5efea;
  --border-strong: #d4e6df;

  /* ---- Text ---- */
  /* Greys tuned to clear WCAG AA (>=4.5:1) for normal text on white/surface
     while preserving the three-level hierarchy (main > muted > soft). */
  --text-main: #1d2b2a;
  --text-muted: #586a65;
  --text-soft: #647570;
  --text-inverse: #f3fbf8;

  /* ---- Status ---- */
  --success: #23b26d;
  --success-bg: #ddf7ec;
  --success-text: #06705e;
  --warning: #f4b740;
  --warning-bg: #fff5d9;
  --warning-text: #8a6200;
  --danger: #ef5b5b;
  --danger-bg: #ffe4e4;
  --danger-text: #b62d2d;
  --info: #3b9ed6;
  --info-bg: #e1f0f9;
  --info-text: #1d6a96;
  --neutral-bg: #eef1f0;
  --neutral-text: #6e7f7b;

  /* ---- Mobile glass chrome (bottom nav + sticky top bar). Token-ised so they
     follow the theme; only referenced by the mobile rules, so desktop is unaffected. */
  --nav-glass-bg: rgba(255, 255, 255, 0.88);
  --nav-glass-border: rgba(212, 230, 223, 0.82);
  --topbar-glass-bg: rgba(231, 242, 238, 0.88);

  /* ---- Chart palette ---- */
  --chart-primary: #2fc5a5;
  --chart-dark: #087e6b;
  --chart-soft: #bdefd9;
  --chart-pale: #e7f8da;
  --chart-yellow: #f3d98b;
  --chart-track: #eaf4ef;

  /* ---- Radius ---- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-card: 18px;
  --radius-xl: 20px;
  --radius-panel: 22px;
  --radius-full: 999px;

  /* ---- Shadows ---- */
  --shadow-sm: 0 2px 8px rgba(20, 80, 70, 0.05);
  --shadow-card: 0 8px 24px rgba(20, 80, 70, 0.06);
  --shadow-floating: 0 14px 44px rgba(20, 80, 70, 0.12);
  --ring: 0 0 0 3px rgba(47, 197, 165, 0.18);

  /* ---- Layout ---- */
  --sidebar-w: 268px;
  --rightpanel-w: 332px;
  --header-h: 76px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --font-sans: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system,
    "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent 300ms tap delay and remove grey tap highlight on touch devices */
button,
a,
.data-card,
.metric-card,
.lm-toggle-switch,
.ac-tab,
.icon-btn,
.nav button,
.ac-icon,
.ac-close,
.ac-expand,
.lm-toggle input,
.t-actions .btn,
.modal-close,
.lm-switch-slider,
.file-row button,
.run-item summary,
.lm-toggle-switch {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  color: var(--text-main);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 88% -8%, #f1fbf6 0, rgba(241, 251, 246, 0) 60%),
    radial-gradient(900px 600px at -6% 4%, #eef7f1 0, rgba(238, 247, 241, 0) 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
a {
  color: inherit;
  text-decoration: none;
}
::selection {
  background: var(--primary-light);
  color: var(--accent);
}

/* ---- Skip link (a11y) ---- */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary-dark);
  color: #fff;
  padding: 8px 16px;
  z-index: 10000;
  font-weight: 700;
  font-size: 14px;
  border-radius: 0 0 var(--radius-md) 0;
  transition: top 0.2s var(--ease);
}
.skip-link:focus {
  top: 0;
  outline: none;
  box-shadow: var(--ring);
}

/* ---- Focus-visible (a11y) ---- */
:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}
.nav button:focus-visible {
  box-shadow: inset var(--ring);
}
.ac-tab:focus-visible {
  box-shadow: var(--ring);
}

/* ---- Touch targets (mobile a11y) ---- */
.icon-btn,
.nav button,
.ac-icon,
.ac-close,
.ac-expand,
.lm-toggle input,
.t-actions .btn,
.modal-close,
.lm-switch-slider,
.file-row button,
.run-item summary,
.lm-toggle-switch {
  min-width: 44px;
  min-height: 44px;
}
/* Increase switch hit area */
.lm-toggle-switch {
  position: relative;
}
.lm-toggle-switch::before {
  content: '';
  position: absolute;
  inset: -12px;
}

/* ---- Scrollbar ---- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-soft);
  background-clip: padding-box;
}

/* =========================================================================
   Skeleton screens (loading placeholders)
   ========================================================================= */
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg-deep) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
}
.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 60%; }
.skeleton-text.long { width: 85%; }
.skeleton-title {
  height: 18px;
  width: 50%;
  margin-bottom: 12px;
}
.skeleton-card {
  padding: 18px;
  border-radius: var(--radius-card);
  background: var(--white);
  border: 1px solid var(--border);
}
.skeleton-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* =========================================================================
   Form validation & feedback
   ========================================================================= */
.field-error {
  color: var(--danger-text);
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.field-error::before {
  content: "⚠";
}
input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 91, 91, 0.18);
}
input[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 91, 91, 0.25);
}
/* The asterisk must ride on the caption, not become its own grid row.
   Required fields wrap their caption in a <span>; mark that span. */
label.field.required > span:first-child::after {
  content: " *";
  color: var(--danger);
  font-weight: 700;
}

/* =========================================================================
   Button loading state
   ========================================================================= */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
.btn.secondary.btn-loading::after,
.btn.ghost.btn-loading::after {
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* =========================================================================
   Page transitions
   ========================================================================= */
.page-transition {
  animation: page-in 0.35s var(--ease) both;
}
@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================================
   Toast improvements
   ========================================================================= */
.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 420px;
}
@media (max-width: 640px) {
  .toast-stack {
    left: 14px;
    right: 14px;
    bottom: calc(98px + var(--safe-bottom));
    max-width: none;
  }
}

/* =========================================================================
   Modal transitions
   ========================================================================= */
.modal-overlay {
  opacity: 0;
  animation: modal-fade-in 0.2s var(--ease) forwards;
}
.modal-overlay.closing {
  animation: modal-fade-out 0.2s var(--ease) forwards;
}
.modal {
  transform: scale(0.96) translateY(8px);
  opacity: 0;
  animation: modal-scale-in 0.25s var(--ease) 0.05s forwards;
}
@keyframes modal-fade-in {
  to { opacity: 1; }
}
@keyframes modal-fade-out {
  to { opacity: 0; }
}
@keyframes modal-scale-in {
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* =========================================================================
   Empty state improvements
   ========================================================================= */
.empty-action {
  margin-top: 16px;
}

/* =========================================================================
   Boot loader
   ========================================================================= */
.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.boot-orbit {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(420px 420px at 30% 30%, rgba(47, 197, 165, 0.16), transparent 70%),
    radial-gradient(520px 520px at 72% 70%, rgba(8, 126, 107, 0.12), transparent 70%);
  animation: float 9s var(--ease) infinite alternate;
}
@keyframes float {
  to {
    transform: translate3d(0, -18px, 0) scale(1.04);
  }
}
.loader-card {
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-floating);
  padding: 40px 44px;
  width: min(420px, calc(100vw - 32px));
  text-align: center;
}
.loader-card h1 {
  font-size: 21px;
  margin: 18px 0 6px;
  letter-spacing: -0.03em;
}
.loader-card p {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
}
.boot-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--chart-track);
  overflow: hidden;
}
.boot-bar span {
  display: block;
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  animation: indeterminate 1.4s var(--ease) infinite;
}
@keyframes indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(320%);
  }
}

/* ---- Brand mark ---- */
.mark {
  width: 50px;
  height: 50px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.04em;
  background: linear-gradient(150deg, #34d6b3 0%, var(--primary) 42%, var(--primary-dark) 100%);
  box-shadow: 0 8px 20px rgba(8, 126, 107, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

/* =========================================================================
   Login
   ========================================================================= */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: 1.05fr 1.1fr;
  overflow: hidden;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-floating);
  animation: rise 0.6s var(--ease) both;
}
.login-hero {
  position: relative;
  padding: 52px 48px;
  color: var(--text-inverse);
  background:
    radial-gradient(640px 360px at 110% -10%, rgba(52, 214, 179, 0.55), transparent 60%),
    linear-gradient(155deg, #0b5f52 0%, #087e6b 48%, #0a4f44 100%);
  overflow: hidden;
}
.login-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(180deg, transparent, #000 40%);
  opacity: 0.6;
}
.login-hero > * {
  position: relative;
  z-index: 1;
}
.login-hero .mark {
  margin: 0;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: none;
}
.login-hero h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.02;
  margin: 26px 0 16px;
  letter-spacing: -0.045em;
}
.login-hero p {
  color: rgba(243, 251, 248, 0.82);
  font-size: 15px;
  line-height: 1.65;
  max-width: 46ch;
}
.login-hero .hero-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}
.hero-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: rgba(243, 251, 248, 0.92);
}
.login-form {
  padding: 48px 44px;
}
.login-form h2 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -0.03em;
}
.login-form > p {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}
.demo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}
.demo-user {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 14px 14px 13px;
  text-align: left;
  transition: all 0.18s var(--ease);
  display: flex;
  gap: 11px;
  align-items: center;
}
.demo-user:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  background: var(--white);
  box-shadow: var(--shadow-card);
}
.demo-user .avatar {
  flex: 0 0 auto;
}
.demo-user b {
  display: block;
  font-size: 14px;
  font-weight: 700;
}
.demo-user span {
  color: var(--text-muted);
  font-size: 12px;
}
.login-pass {
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.login-pass code {
  font-family: var(--font-mono);
  background: var(--primary-light);
  color: var(--accent);
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
}

/* =========================================================================
   App shell — three-zone layout
   ========================================================================= */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  contain: layout paint;
}

/* ---- Sidebar ---- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 22px;
}
.brand .mark {
  margin: 0;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  font-size: 19px;
}
.brand b {
  display: block;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand span {
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 500;
}
.nav-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
  padding: 4px 12px;
  margin: 6px 0 4px;
}
.nav {
  display: grid;
  gap: 3px;
}
.nav button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  gap: 11px;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  position: relative;
  transition: all 0.16s var(--ease);
}
.nav button svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  stroke-width: 1.9;
  opacity: 0.78;
}
.nav button:hover {
  background: var(--primary-tint);
  color: var(--accent);
}
.nav button:hover svg {
  opacity: 1;
}
.nav button.active {
  background: linear-gradient(135deg, var(--primary) 0%, #1fb898 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(8, 126, 107, 0.26);
}
.nav button.active svg {
  opacity: 1;
}
.nav button .nav-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  background: var(--danger-bg);
  color: var(--danger-text);
  padding: 1px 7px;
  border-radius: var(--radius-full);
}
.nav button.active .nav-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.sidebar-spacer {
  flex: 1;
}
.upsell {
  margin-top: 18px;
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  color: var(--text-inverse);
  background:
    radial-gradient(360px 180px at 120% -20%, rgba(52, 214, 179, 0.6), transparent 60%),
    linear-gradient(160deg, #0b5f52, #087e6b);
  position: relative;
  overflow: hidden;
}
.upsell h4 {
  margin: 0 0 6px;
  font-size: 14px;
  letter-spacing: -0.02em;
}
.upsell p {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(243, 251, 248, 0.82);
}
.upsell .btn {
  width: 100%;
  justify-content: center;
  background: #fff;
  color: var(--primary-dark);
}
.upsell .btn:hover {
  background: #fff;
  filter: brightness(0.97);
}
.sidebar-user {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-user .meta {
  min-width: 0;
}
.sidebar-user b {
  font-size: 13px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user span {
  font-size: 11px;
  color: var(--text-soft);
  text-transform: capitalize;
}
.sidebar-user .icon-btn {
  margin-left: auto;
}

/* ---- Main column ---- */
.content {
  min-width: 0;
  padding: 22px 26px 40px;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  min-height: var(--header-h);
}
.topbar .crumbs {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 5px;
}
.topbar .crumbs svg {
  width: 13px;
  height: 13px;
}
.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 30px);
  letter-spacing: -0.035em;
  font-weight: 800;
}
.topbar p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13.5px;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box svg {
  position: absolute;
  left: 13px;
  width: 17px;
  height: 17px;
  color: var(--text-soft);
  pointer-events: none;
}
.search-box input {
  width: 240px;
  height: 42px;
  padding: 0 14px 0 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 14px;
  transition: all 0.16s var(--ease);
}
.search-box input::placeholder {
  color: var(--text-soft);
}
.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--white);
  padding: 5px 12px 5px 6px;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
}
.user-pill .meta {
  line-height: 1.2;
}
.user-pill .meta b {
  font-size: 13px;
  display: block; /* stack name above timezone (was running together) */
}
.user-pill .meta span {
  font-size: 11px;
  color: var(--text-soft);
  display: block;
}

/* ---- Avatars ---- */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, var(--primary), var(--primary-dark));
  font-weight: 700;
  font-size: 14px;
  flex: 0 0 auto;
  text-transform: uppercase;
}
.avatar.sm {
  width: 30px;
  height: 30px;
  font-size: 12px;
}
.avatar.lg {
  width: 76px;
  height: 76px;
  font-size: 28px;
  border-radius: 24px;
}
.avatar.a1 { background: linear-gradient(140deg, #34d6b3, #087e6b); }
.avatar.a2 { background: linear-gradient(140deg, #6fd0e8, #2b7fa8); }
.avatar.a3 { background: linear-gradient(140deg, #f6c66b, #d68a1f); }
.avatar.a4 { background: linear-gradient(140deg, #e98aa0, #c0455f); }
.avatar.a5 { background: linear-gradient(140deg, #9bc36b, #4f8a2f); }
.avatar.a6 { background: linear-gradient(140deg, #a99af0, #5e4cc0); }

/* ---- Icon buttons ---- */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--white);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  transition: all 0.16s var(--ease);
  position: relative;
  flex: 0 0 auto;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}
.icon-btn:hover {
  color: var(--accent);
  border-color: var(--primary);
  background: var(--primary-tint);
}
.icon-btn.has-dot::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--white);
}

/* =========================================================================
   Grids & cards
   ========================================================================= */
.grid {
  display: grid;
  gap: 18px;
}
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rightpanel-w);
  gap: 18px;
  align-items: start;
}
.page-grid > *,
.split > *,
.grid > *,
.rail > * {
  min-width: 0;
}
.split {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
  align-items: start;
}

.panel,
.card,
.metric-card,
.data-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  min-width: 0;
}
.panel {
  padding: 22px;
}
.panel > h2,
.panel > h3 {
  margin-top: 0;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.panel-head .sub {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
}
.panel-head .spacer {
  flex: 1;
}
.panel-head svg.pi {
  width: 18px;
  height: 18px;
  color: var(--accent);
  flex: 0 0 auto;
  stroke-width: 2;
}
h2 {
  font-size: 18px;
  letter-spacing: -0.025em;
}
h3 {
  font-size: 16px;
  letter-spacing: -0.02em;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Above the FAB stack (1180), bottom nav (1000) and bottom-sheet scrim (1390). */
  z-index: 1500;
  padding: 24px;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-floating);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 0;
}
.modal-header h3 {
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-soft);
  border-radius: 6px;
}
.modal-close:hover {
  background: var(--surface);
  color: var(--text-main);
}
.modal-body {
  padding: 16px 22px 22px;
}

/* ---- Stat / metric cards ---- */
.metric-card {
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 118px;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.metric-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-floating);
  will-change: transform;
}
.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.metric-card .label {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}
.metric-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--primary-light);
  color: var(--accent);
  flex: 0 0 auto;
}
.metric-icon svg {
  width: 19px;
  height: 19px;
}
.metric-icon.amber { background: var(--warning-bg); color: var(--warning-text); }
.metric-icon.red { background: var(--danger-bg); color: var(--danger-text); }
.metric-icon.blue { background: var(--info-bg); color: var(--info-text); }
.metric-card .value {
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.metric-card .value.sm {
  font-size: 24px;
}
.metric-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-soft);
}
.trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 700;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}
.trend svg {
  width: 13px;
  height: 13px;
}
.trend.up { color: var(--success-text); background: var(--success-bg); }
.trend.down { color: var(--danger-text); background: var(--danger-bg); }
.trend.flat { color: var(--text-muted); background: var(--neutral-bg); }

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
  transition: all 0.16s var(--ease);
  box-shadow: 0 6px 14px rgba(47, 197, 165, 0.24);
}
/* Base size for all icon() SVGs. Single-class selector keeps this
   low-specificity so any context-specific `... svg` rule overrides it;
   it only fills in for icons in unstyled contexts (e.g. inline notes). */
.ic {
  width: 16px;
  height: 16px;
  flex: none;
  vertical-align: -0.18em;
}
.btn svg {
  width: 16px;
  height: 16px;
}
.btn:hover {
  filter: brightness(1.03);
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(47, 197, 165, 0.32);
}
.btn:active {
  transform: translateY(0);
}
.btn.secondary {
  background: var(--primary-light);
  color: var(--accent);
  box-shadow: none;
}
.btn.secondary:hover {
  background: #cdf1e1;
}
.btn.ghost {
  background: var(--white);
  color: var(--text-main);
  border-color: var(--border);
  box-shadow: none;
}
.btn.ghost:hover {
  border-color: var(--primary);
  color: var(--accent);
  background: var(--primary-tint);
}
.btn.danger {
  background: var(--danger);
  box-shadow: 0 6px 14px rgba(239, 91, 91, 0.24);
}
.btn.green {
  background: var(--success);
  box-shadow: 0 6px 14px rgba(35, 178, 109, 0.24);
}
.btn.small {
  padding: 7px 11px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  box-shadow: none;
}
.btn.small:hover {
  box-shadow: none;
}
.btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}

/* =========================================================================
   Inputs
   ========================================================================= */
.input,
input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 0 14px;
  height: 42px;
  color: var(--text-main);
  font-size: 14px;
  transition: all 0.16s var(--ease);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-soft);
}
textarea {
  min-height: 92px;
  padding: 11px 14px;
  height: auto;
  resize: vertical;
  line-height: 1.55;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236e7f7b' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 36px;
}
.input:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
label.field {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .grow {
  flex: 1;
  min-width: 160px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .wide {
  grid-column: 1 / -1;
}
.grid.form {
  gap: 12px;
}

/* =========================================================================
   Badges / status pills
   ========================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: capitalize;
  white-space: nowrap;
  background: var(--info-bg);
  color: var(--info-text);
  line-height: 1.4;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}
.badge.hot,
.badge.high,
.badge.critical,
.badge.overdue,
.badge.rejected,
.badge.failed,
.badge.error {
  background: var(--danger-bg);
  color: var(--danger-text);
}
.badge.warm,
.badge.medium,
.badge.pending_approval,
.badge.pending,
.badge.open {
  background: var(--warning-bg);
  color: var(--warning-text);
}
.badge.technical,
.badge.connected,
.badge.success,
.badge.done,
.badge.sent,
.badge.approved,
.badge.active,
.badge.qualified {
  background: var(--success-bg);
  color: var(--success-text);
}
.badge.cold,
.badge.resolved,
.badge.disabled,
.badge.inactive,
.badge.closed {
  background: var(--neutral-bg);
  color: var(--neutral-text);
}

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--white);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th,
td {
  padding: 13px 16px;
  text-align: left;
  vertical-align: middle;
}
thead th {
  background: var(--surface);
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  border-bottom: 1px solid var(--border);
}
tbody tr {
  transition: background 0.14s var(--ease);
}
tbody tr:hover {
  background: var(--primary-tint);
}
tbody tr:last-child td {
  border-bottom: 0;
}
.cell-lead {
  display: flex;
  align-items: center;
  gap: 11px;
}
.cell-lead .meta b {
  font-size: 13.5px;
  font-weight: 700;
}
.cell-lead .meta span {
  color: var(--text-soft);
  font-size: 12px;
}
.t-actions {
  display: flex;
  gap: 7px;
  justify-content: flex-end;
}

/* =========================================================================
   Card lists, data cards, notes, documents
   ========================================================================= */
.card-list {
  display: grid;
  gap: 12px;
}
.data-card {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease);
}
.data-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
  will-change: transform;
}
.data-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
}
.data-card p {
  color: var(--text-muted);
  margin: 8px 0;
  font-size: 13.5px;
  line-height: 1.55;
}
.data-card small {
  font-size: 12px;
}
.dc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.dc-head .spacer {
  flex: 1;
}

/* incident-style left accent */
.note-card {
  border-left: 3px solid var(--primary);
}
.note-card.warn { border-left-color: var(--warning); }
.note-card.danger { border-left-color: var(--danger); }
.note-card.info { border-left-color: var(--info); }

/* file rows */
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--white);
  transition: all 0.14s var(--ease);
}
.file-row:hover {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.file-ico {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  flex: 0 0 auto;
}
.file-ico.pdf { background: #e2574c; }
.file-ico.doc { background: #2b7fa8; }
.file-ico.xls { background: #1f9d5b; }
.file-ico.img { background: #d68a1f; }
.file-ico.zip { background: #7a6cc0; }
.file-row .meta b {
  font-size: 13.5px;
  display: block;
}
.file-row .meta span {
  font-size: 12px;
  color: var(--text-soft);
}
.file-row .spacer {
  flex: 1;
}

/* =========================================================================
   Right utility panel
   ========================================================================= */
.rail {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 22px;
}

/* =========================================================================
   Charts (inline SVG)
   ========================================================================= */
.chart {
  width: 100%;
  display: block;
}
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.donut {
  position: relative;
  flex: 0 0 auto;
}
.donut .center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}
.donut .center b {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.donut .center span {
  font-size: 11px;
  color: var(--text-soft);
  display: block;
}
.legend {
  display: grid;
  gap: 9px;
  font-size: 13px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
}
.legend-item .dot {
  width: 11px;
  height: 11px;
  border-radius: 4px;
  flex: 0 0 auto;
}
.legend-item .lv {
  margin-left: auto;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.legend-item .lk {
  color: var(--text-muted);
}

/* ring (circular progress) */
.ring {
  display: grid;
  place-items: center;
  text-align: center;
}
.ring svg {
  transform: rotate(-90deg);
}
.ring .ring-val {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
}
.ring .ring-label {
  font-size: 12px;
  color: var(--text-soft);
}

/* mini bars */
.spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 34px;
}
.spark i {
  flex: 1;
  background: var(--chart-soft);
  border-radius: 3px 3px 0 0;
  min-height: 4px;
}
.spark i.hot {
  background: var(--primary);
}

/* progress bar */
.progress {
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--chart-track);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  transition: width 0.6s var(--ease);
}
.progress.warn span { background: linear-gradient(90deg, #f7cf72, var(--warning)); }
.progress.danger span { background: linear-gradient(90deg, #f48484, var(--danger)); }

/* bar chart rows */
.barlist {
  display: grid;
  gap: 14px;
}
.barlist .row {
  display: grid;
  gap: 7px;
}
.barlist .row .top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}
.barlist .row .top b {
  font-weight: 600;
}
.barlist .row .top .v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Key-value lists, misc
   ========================================================================= */
.kv {
  display: grid;
  gap: 0;
  font-size: 13.5px;
}
.kv > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.kv > div:last-child {
  border-bottom: 0;
}
.kv dt {
  color: var(--text-muted);
}
.kv dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

.markdown,
pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  color: var(--text-main);
  line-height: 1.65;
  font-size: 13.5px;
}
pre {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--accent);
  background: var(--primary-tint);
}
.markdown b {
  color: var(--text-main);
  font-weight: 700;
}

.muted {
  color: var(--text-muted);
}
.soft {
  color: var(--text-soft);
}
hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.empty {
  padding: 36px 24px;
  text-align: center;
  color: var(--text-muted);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.empty .empty-ico {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  background: var(--primary-light);
  color: var(--accent);
}
.empty .empty-ico svg {
  width: 24px;
  height: 24px;
}
.empty h4 {
  margin: 0 0 6px;
  color: var(--text-main);
  font-size: 15px;
}
.empty p {
  margin: 0 0 16px;
  font-size: 13.5px;
}

.profile-card {
  text-align: center;
  padding: 26px 22px;
}
.profile-card .avatar.lg {
  margin: 0 auto 14px;
}
.profile-card h3 {
  margin: 0 0 2px;
  font-size: 19px;
}
.profile-card .role {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 14px;
}
.profile-pills {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

/* mini calendar */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-grid.head {
  margin-bottom: 6px;
}
.cal-grid.head span {
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-soft);
  padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 9px;
  color: var(--text-main);
  cursor: default;
  transition: background 0.14s var(--ease);
}
.cal-day:hover {
  background: var(--primary-tint);
}
.cal-day.today {
  background: var(--primary-dark);
  color: #fff;
}

/* toast */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: var(--text-main);
  color: #fff;
  padding: 13px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-floating);
  z-index: 200;
  max-width: 420px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.32s var(--ease) both;
}
.toast-action {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  min-height: 34px;
}
.toast svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
  flex: 0 0 auto;
}
.toast.err svg { color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px); }
}

.cached-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
  background: var(--neutral-bg);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}
.cached-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
}

.offline-banner {
  position: fixed;
  left: calc(16px + var(--safe-left));
  right: calc(16px + var(--safe-right));
  top: calc(12px + var(--safe-top));
  z-index: 1600;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(244, 183, 64, 0.38);
  border-radius: var(--radius-md);
  background: rgba(255, 245, 217, 0.96);
  color: var(--warning-text);
  padding: 11px 14px;
  box-shadow: var(--shadow-floating);
  font-size: 13px;
  font-weight: 700;
}
.offline-banner svg {
  width: 17px;
  height: 17px;
  flex: none;
}
.offline-banner[hidden] {
  display: none;
}

/* =========================================================================
   Mobile nav
   ========================================================================= */
.scrim {
  display: none;
}
.mobile-bottom-nav {
  display: none;
}

/* =========================================================================
   Entrance animations
   ========================================================================= */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}
/* Entrance animation for view content. Exclude modal overlays: they are
   direct children of #view but manage their own fade/scale animation, and
   `rise` (which has no `to` keyframe) would otherwise pin them to the base
   opacity:0 and make every in-view modal invisible. */
#view > *:not(.modal-overlay) {
  animation: rise 0.45s var(--ease) both;
}
.stagger > * {
  animation: rise 0.5s var(--ease) both;
}
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.06s; }
.stagger > *:nth-child(3) { animation-delay: 0.1s; }
.stagger > *:nth-child(4) { animation-delay: 0.14s; }
.stagger > *:nth-child(5) { animation-delay: 0.18s; }
.stagger > *:nth-child(6) { animation-delay: 0.22s; }

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

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 1280px) {
  .page-grid {
    grid-template-columns: 1fr;
  }
  .rail {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .table-wrap.mobile-card-table {
    border: 0;
    background: transparent;
    overflow: visible;
    box-shadow: none;
  }
  .table-wrap.mobile-card-table table,
  .table-wrap.mobile-card-table thead,
  .table-wrap.mobile-card-table tbody,
  .table-wrap.mobile-card-table tr,
  .table-wrap.mobile-card-table th,
  .table-wrap.mobile-card-table td {
    display: block;
    width: 100%;
  }
  .table-wrap.mobile-card-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .table-wrap.mobile-card-table tbody {
    display: grid;
    gap: 10px;
  }
  .table-wrap.mobile-card-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--white);
    box-shadow: var(--shadow-sm);
    padding: 10px 12px;
  }
  .table-wrap.mobile-card-table td {
    border: 0;
    padding: 8px 0;
    min-height: 34px;
    display: grid;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    word-break: break-word;
  }
  .table-wrap.mobile-card-table td + td {
    border-top: 1px solid var(--border);
  }
  .table-wrap.mobile-card-table td::before {
    content: attr(data-label);
    color: var(--text-soft);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .table-wrap.mobile-card-table .cell-lead {
    min-width: 0;
  }
  .table-wrap.mobile-card-table .t-actions {
    justify-content: flex-start;
  }
  .table-wrap.mobile-card-table .t-actions .btn {
    flex: 1 1 120px;
  }
}

/* Tablet & mobile: collapse sidebar to a drawer */
@media (max-width: 920px) {
  :root {
    --sidebar-w: 0px;
  }
  .layout {
    grid-template-columns: 1fr;
    contain: none;
  }
  .sidebar {
    position: fixed;
    top: auto;
    left: calc(8px + var(--safe-left));
    right: calc(8px + var(--safe-right));
    bottom: 0;
    width: auto;
    max-width: 560px;
    height: min(78dvh, 720px);
    margin: 0 auto;
    z-index: 1310;
    transform: translateY(calc(100% + 24px));
    transition: transform 0.28s var(--ease);
    box-shadow: var(--shadow-floating);
    border-right: 0;
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    padding-bottom: calc(20px + var(--safe-bottom));
    will-change: transform;
  }
  .sidebar::before {
    content: "";
    width: 42px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--border-strong);
    align-self: center;
    margin: 0 0 8px;
  }
  .layout.drawer-open .sidebar,
  .sidebar.open {
    transform: translateY(0) !important;
  }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 50, 44, 0.42);
    backdrop-filter: blur(2px);
    z-index: 1300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s var(--ease);
  }
  .layout.drawer-open .scrim,
  .scrim.open {
    opacity: 1 !important;
    pointer-events: auto;
  }
  .content {
    padding: calc(18px + var(--safe-top)) 18px calc(112px + var(--safe-bottom));
  }
  /* When a FAB stack is parked bottom-right, give the scroll a little more tail
     so the last row/actions can always be scrolled out from under the buttons. */
  body.fab-present .content {
    padding-bottom: calc(196px + var(--safe-bottom));
  }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mobile-bottom-nav {
    position: fixed;
    left: calc(12px + var(--safe-left));
    right: calc(12px + var(--safe-right));
    bottom: calc(10px + var(--safe-bottom));
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--nav-glass-border);
    border-radius: 22px;
    background: var(--nav-glass-bg);
    backdrop-filter: blur(18px) saturate(1.25);
    -webkit-backdrop-filter: blur(18px) saturate(1.25);
    box-shadow: 0 18px 44px rgba(20, 80, 70, 0.16);
  }
  .mobile-bottom-nav button {
    border: 0;
    background: transparent;
    color: var(--text-muted);
    min-width: 0;
    min-height: 52px;
    border-radius: 17px;
    display: grid;
    place-items: center;
    gap: 2px;
    padding: 6px 2px;
    font-size: 10.5px;
    font-weight: 800;
    transition: background 0.16s var(--ease), color 0.16s var(--ease), transform 0.16s var(--ease);
  }
  .mobile-bottom-nav button:active {
    transform: scale(0.96);
  }
  .mobile-bottom-nav svg {
    width: 19px;
    height: 19px;
  }
  .mobile-bottom-nav button.active {
    background: var(--primary-light);
    color: var(--accent);
  }
}
@media (max-width: 640px) {
  .grid-2,
  .grid-3,
  .form-grid,
  .demo-grid,
  .login-card,
  .rail {
    grid-template-columns: 1fr;
  }
  /* KPI stat cards stay 2-up on phones: compact, far more scannable than a
     single tall column, and halves the scroll to reach content below. */
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .metric-card {
    min-height: 104px;
    padding: 15px 15px 13px;
    gap: 9px;
  }
  .metric-card .value {
    font-size: 27px;
  }
  .login-hero {
    padding: 36px 28px;
  }
  .login-form {
    padding: 32px 24px;
  }
  .topbar {
    flex-wrap: wrap;
    position: sticky;
    top: var(--safe-top);
    z-index: 70;
    margin: 0 -6px 18px;
    padding: 10px 6px 12px;
    background: var(--topbar-glass-bg);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
    border-bottom: 1px solid var(--nav-glass-border);
  }
  .topbar-actions {
    width: 100%;
    margin-left: 0;
  }
  /* The user identity is already shown in the drawer; hiding the pill here
     stops it crowding the toolbar so global search gets a usable width. */
  .user-pill {
    display: none;
  }
  .search-box {
    flex: 1;
  }
  .search-box input {
    width: 100%;
  }
  .content {
    padding: calc(14px + var(--safe-top)) 14px calc(116px + var(--safe-bottom));
  }
  body {
    font-size: 15px;
  }
  .metric-card .value {
    font-size: 26px;
  }
  .topbar h1 {
    font-size: 22px;
  }
  .search-box input {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
  input,
  textarea,
  select {
    font-size: 16px;
  }
  .btn,
  .btn.small,
  .btn.ghost,
  .btn.secondary,
  .toast-action,
  .toolbar .btn,
  .t-actions .btn,
  .demo-user,
  .ac-tab {
    min-height: 44px;
  }
  .toolbar {
    align-items: stretch;
  }
  .toolbar .search-box.grow,
  .toolbar .search-box.grow input {
    min-width: 0;
  }
  .agent-chat {
    right: calc(14px + var(--safe-right));
    bottom: calc(88px + var(--safe-bottom));
  }
  .ac-panel {
    max-width: calc(100vw - 20px);
    height: calc(100vh - 100px);
  }
}

/* Recent-conversations history items (Agent Command page) */
.run-item { cursor: pointer; }
.run-item summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.run-item summary::-webkit-details-marker { display: none; }
.run-item[open] > div { border-top: 1px solid var(--border); padding-top: 8px; color: var(--text-main); }

/* ============================ Agent chat (sticky) ============================ */
.agent-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1200;
  font-family: inherit;
}
.ac-launcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--text-inverse);
  padding: 13px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-floating);
  transition: transform 0.15s ease;
}
.ac-launcher:hover { transform: translateY(-1px); }
.ac-launcher svg { width: 18px; height: 18px; stroke: currentColor; }
.agent-chat.open .ac-launcher { display: none; }

.ac-panel {
  display: none;
  flex-direction: column;
  width: 384px;
  max-width: calc(100vw - 28px);
  height: 560px;
  max-height: calc(100vh - 110px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-floating);
  overflow: hidden;
}
.agent-chat.open .ac-panel { display: flex; }

.ac-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  flex: none;
}
.ac-head .ac-title { display: flex; flex-direction: column; line-height: 1.2; }
.ac-head .ac-title b { font-size: 14px; color: var(--text-main); }
.ac-head .ac-status { font-size: 11px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 5px; }
.ac-head .spacer { flex: 1; }
.ac-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-soft); flex: none; }
.ac-dot.on { background: var(--success); }
.ac-dot.idle { background: var(--warning); }
.ac-dot.off { background: var(--danger); }
.ac-close { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); flex: none; }
.ac-close:hover { background: var(--neutral-bg); }
.ac-close svg { width: 16px; height: 16px; stroke: currentColor; transform: rotate(90deg); }
.ac-expand { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); flex: none; }
.ac-expand:hover { background: var(--neutral-bg); }
.ac-expand svg { width: 15px; height: 15px; stroke: currentColor; }

/* Maximized: panel grows to nearly fill the viewport instead of cramped internal scroll */
.agent-chat.maximized .ac-panel {
  width: 920px;
  max-width: calc(100vw - 44px);
  height: calc(100vh - 44px);
  max-height: calc(100vh - 44px);
}

.ac-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  overflow-x: auto;
  flex: none;
  scrollbar-width: none;
}
.ac-tabs::-webkit-scrollbar { display: none; }
.ac-tab {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s var(--ease);
}
.ac-tab:hover { border-color: var(--primary); color: var(--text-main); }
.ac-tab.active { background: var(--primary-light); border-color: var(--primary); color: var(--accent); }

.ac-msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}
.ac-msg {
  max-width: 86%;
  width: fit-content;
  padding: 9px 12px;
  border-radius: 15px;
  font-size: 13.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ac-msg.user { align-self: flex-end; background: var(--primary); color: var(--text-inverse); border-bottom-right-radius: 5px; }
.ac-msg.agent { align-self: flex-start; background: var(--white); border: 1px solid var(--border); color: var(--text-main); border-bottom-left-radius: 5px; }
.ac-msg.system { align-self: center; background: var(--neutral-bg); color: var(--text-muted); font-size: 12px; text-align: center; max-width: 100%; border-radius: 10px; }
.ac-msg.typing { color: var(--text-muted); font-style: italic; }
.ac-msg.streaming::after { content: '▋'; margin-left: 1px; color: var(--primary); animation: ac-blink 1s steps(2) infinite; }
@keyframes ac-blink { 50% { opacity: 0; } }

/* Rendered markdown inside agent replies */
.ac-msg.agent.md { max-width: 94%; overflow-x: auto; }
.ac-msg.md > :first-child { margin-top: 0; }
.ac-msg.md > :last-child { margin-bottom: 0; }
.ac-msg.md p { margin: 6px 0; }
.ac-msg.md h3, .ac-msg.md h4, .ac-msg.md h5, .ac-msg.md h6 { margin: 10px 0 4px; font-size: 13.5px; font-weight: 700; color: var(--text-main); }
.ac-msg.md ul, .ac-msg.md ol { margin: 6px 0; padding-left: 18px; }
.ac-msg.md li { margin: 2px 0; }
.ac-msg.md code { background: var(--neutral-bg); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.ac-msg.md hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.ac-msg.md a { color: var(--accent); }
.ac-tbl { border-collapse: collapse; margin: 6px 0; font-size: 12.5px; }
.ac-tbl th, .ac-tbl td { border: 1px solid var(--border); padding: 5px 7px; text-align: left; vertical-align: top; }
.ac-tbl th { background: var(--primary-tint); font-weight: 700; white-space: nowrap; }
.ac-chip { display: inline-flex; align-items: center; gap: 3px; background: var(--primary-light); color: var(--accent); border: 1px solid var(--primary); border-radius: 999px; padding: 1px 8px; font-size: 11.5px; font-weight: 600; cursor: pointer; font-family: inherit; }
.ac-chip:hover { background: var(--primary); color: var(--text-inverse); }

/* Structured lead result cards (action buttons) */
.lead-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.lead-card { background: var(--white); border: 1px solid var(--border-strong); border-radius: var(--radius-md); padding: 10px 12px; }
.lc-head { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.lc-head b { color: var(--text-main); }
.lc-tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--accent); background: var(--primary-light); border-radius: 999px; padding: 1px 8px; }
.lc-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.lc-why { font-size: 12.5px; color: var(--text-main); margin-top: 5px; }
.lc-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.lc-btn { border: 1px solid var(--primary); background: var(--primary); color: var(--text-inverse); border-radius: var(--radius-sm); padding: 5px 10px; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; }
.lc-btn.ghost { background: var(--surface); color: var(--accent); }
.lc-btn:hover:not(:disabled) { filter: brightness(1.05); }
.lc-btn:disabled { opacity: .5; cursor: default; }
.lc-status { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; min-height: 0; }
.lc-status b { color: var(--accent); }

.ac-input {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: var(--white);
  flex: none;
}
/* Beat the global input/textarea rules (width:100%, height:42px, min-height:92px). */
.agent-chat .ac-input textarea {
  flex: 1 1 auto;
  width: auto;
  min-height: 0;
  height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  resize: none;
  color: var(--text-main);
  background: var(--surface);
}
.agent-chat .ac-input textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.ac-send {
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ac-send svg { width: 17px; height: 17px; }

/* New-conversation button (matches the expand/close icons) */
.ac-icon { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); flex: none; }
.ac-icon:hover { background: var(--neutral-bg); }
.ac-icon svg { width: 15px; height: 15px; stroke: currentColor; }

/* Launcher unread badge */
.ac-badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; }
.ac-badge[hidden] { display: none; }

/* Tab status dot (busy = pulsing amber, unread = solid teal) */
.ac-tdot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; margin-left: 2px; background: transparent; }
.ac-tdot.unread { background: var(--primary); }
.ac-tdot.busy { background: var(--warning); animation: ac-pulse 1s ease-in-out infinite; }
@keyframes ac-pulse { 50% { opacity: 0.3; } }

/* Message rows wrap a bubble + its meta (copy button + timestamp) */
.ac-row { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.ac-row.user { align-self: flex-end; align-items: flex-end; }
.ac-row.agent { align-self: flex-start; align-items: flex-start; }
.ac-row.system { align-self: center; align-items: center; max-width: 100%; }
.ac-row .ac-msg { align-self: auto; }
.ac-meta { display: flex; align-items: center; gap: 6px; padding: 0 4px; font-size: 10.5px; color: var(--text-soft); }
.ac-row.user .ac-meta { flex-direction: row-reverse; }
.ac-time { font-variant-numeric: tabular-nums; }
.ac-copy { border: none; background: none; padding: 2px; border-radius: 4px; cursor: pointer; color: var(--text-soft); opacity: 0; transition: opacity 0.12s; display: inline-flex; }
.ac-row:hover .ac-copy, .ac-copy:focus-visible { opacity: 1; }
.ac-copy:hover { color: var(--accent); background: var(--neutral-bg); }
.ac-copy svg { width: 13px; height: 13px; }
.ac-retry { margin-left: 6px; border: 1px solid var(--primary); background: var(--surface); color: var(--accent); border-radius: 6px; padding: 1px 8px; font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; }
.ac-retry:hover { background: var(--primary); color: #fff; }

/* Starter-prompt chips on an empty thread */
.ac-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; background: var(--bg); flex: none; }
.ac-suggest[hidden] { display: none; }
.ac-sg { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-muted); border-radius: 999px; padding: 5px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; text-align: left; }
.ac-sg:hover { border-color: var(--primary); color: var(--accent); background: var(--primary-light); }

/* Stop button replaces Send while a turn is in flight */
.ac-stop { flex: none; width: 42px; height: 42px; padding: 0; border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; background: var(--danger); border-color: var(--danger); color: #fff; }
.ac-stop svg { width: 16px; height: 16px; }
.ac-stop[hidden], .ac-send[hidden] { display: none; }
.agent-chat .ac-input textarea:disabled { opacity: 0.6; cursor: not-allowed; }

/* Attach button + pending text-attachment chips */
.ac-attach-btn { flex: none; width: 42px; height: 42px; padding: 0; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-md); color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.ac-attach-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--accent); }
.ac-attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ac-attach-btn svg { width: 17px; height: 17px; stroke: currentColor; }
.ac-attach { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; background: var(--bg); flex: none; }
.ac-attach[hidden] { display: none; }
.ac-att { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; background: var(--primary-light); border: 1px solid var(--primary); color: var(--accent); border-radius: 999px; padding: 3px 6px 3px 9px; font-size: 11.5px; font-weight: 600; }
.ac-att svg { width: 12px; height: 12px; stroke: currentColor; flex: none; }
.ac-att-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-att-x { border: none; background: none; padding: 1px; margin: 0; color: var(--accent); cursor: pointer; display: inline-flex; border-radius: 50%; flex: none; }
.ac-att-x:hover { background: var(--primary); color: #fff; }

@media (max-width: 520px) {
  .agent-chat {
    right: calc(16px + var(--safe-right));
    bottom: calc(88px + var(--safe-bottom));
    left: auto;
  }
  .ac-launcher {
    width: 56px;
    height: 56px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
  .ac-launcher span:not(.ac-badge) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .agent-chat.open {
    left: 0;
    right: 0;
    bottom: 0;
  }
  .ac-panel {
    width: 100%;
    max-width: none;
    height: min(78dvh, calc(100dvh - 72px));
    max-height: calc(100dvh - 28px);
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    padding-bottom: var(--safe-bottom);
  }
  .agent-chat.maximized .ac-panel {
    width: 100%;
    max-width: none;
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
  }
  .ac-tabs {
    padding-bottom: 12px;
  }
  .ac-tab {
    padding: 7px 12px;
  }
}

/* Market intelligence reports (Research view + Overview card). */
.mkt-highlights { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.mkt-hl { display: flex; align-items: flex-start; gap: 6px; font-size: 13px; line-height: 1.4; }
.mkt-hl .ic { width: 15px; height: 15px; flex-shrink: 0; margin-top: 2px; color: var(--warning-text); }
.mkt-hl a { color: var(--accent); text-decoration: none; }
.mkt-details { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.mkt-details > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent); }
.mkt-sec { margin: 8px 0; }
.mkt-sec > b { display: block; margin-bottom: 2px; }
.mkt-src { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.mkt-src li { margin: 3px 0; }
.mkt-src a { color: var(--accent); }

/* WhatsApp Connection panel — QR matrix rendered client-side from the parsed ANSI grid. */
.wa-qr { display: grid; width: 220px; max-width: 100%; aspect-ratio: 1; gap: 0; background: #fff; padding: 8px; border-radius: 8px; }
.wa-qr i { display: block; width: 100%; aspect-ratio: 1; }
.wa-qr i.d { background: #000; }
.wa-qr i.l { background: #fff; }

@media (max-width: 920px) {
  nav.sidebar.open {
    transform: none !important;
  }
  div.scrim.open {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

/* =========================================================================
   Pull-to-refresh
   ========================================================================= */
.ptr-wrap {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.ptr-indicator {
  position: fixed;
  top: calc(var(--safe-top) + 10px);
  left: 50%;
  width: 38px;
  height: 38px;
  margin-left: -19px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow-floating);
  opacity: 0;
  transition: opacity 0.2s var(--ease);
  z-index: 1300;
  pointer-events: none;
}
.ptr-indicator.active {
  opacity: 1;
}
.ptr-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}

/* =========================================================================
   Floating Action Button
   ========================================================================= */
.fab {
  position: fixed;
  right: calc(16px + var(--safe-right));
  /* Stacked above the agent-chat launcher (which sits at 88px + safe). */
  bottom: calc(154px + var(--safe-bottom));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 20px rgba(8, 126, 107, 0.35);
  z-index: 1180;
  transition: transform 0.18s var(--ease-spring), box-shadow 0.2s;
  border: none;
  cursor: pointer;
}
.fab:active {
  transform: scale(0.9);
}
/* Tuck the FAB out of the way while the side drawer is open. */
.layout.drawer-open .fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}
/* Modern browsers: also hide it under an open bottom sheet (progressive). */
body:has(.bottom-sheet.open) .fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}
/* Tuck BOTH floating controls away while a modal dialog is open so they never
   sit on top of the dialog's form fields. (.modal-open is toggled in app.js.) */
body.modal-open .fab,
body.modal-open .agent-chat:not(.open) {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}
.fab svg {
  width: 24px;
  height: 24px;
}
@media (min-width: 921px) {
  .fab { display: none; }
}

/* =========================================================================
   Bottom Sheet
   ========================================================================= */
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: var(--radius-panel) var(--radius-panel) 0 0;
  box-shadow: var(--shadow-floating);
  z-index: 1400;
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.bottom-sheet.open {
  transform: translateY(0);
  transition: transform 0.36s var(--ease-spring);
}
.bottom-sheet .bs-grip {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0 4px;
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
  padding-top: calc(10px + var(--safe-top, 0px));
}
.bottom-sheet .bs-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  flex-shrink: 0;
}
.bottom-sheet .bs-content {
  overflow-y: auto;
  padding: 0 20px calc(20px + var(--safe-bottom));
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.bottom-sheet .bs-title {
  font-size: 17px;
  font-weight: 800;
  margin: 4px 0 12px;
  padding: 0 20px;
}
.bs-scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 50, 44, 0.42);
  z-index: 1390;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.bs-scrim.open {
  opacity: 1;
  pointer-events: auto;
}

/* =========================================================================
   Touch ripple press effect
   ========================================================================= */
.press-effect {
  position: relative;
  overflow: hidden;
}
.press-effect::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--px, 50%) var(--py, 50%), rgba(255,255,255,0.25) 10%, transparent 10%);
  background-repeat: no-repeat;
  transform: scale(4);
  opacity: 0;
  transition: transform 0.5s, opacity 0.5s;
  pointer-events: none;
}
.press-effect.is-pressed::after {
  transform: scale(0);
  opacity: 1;
  transition: 0s;
}

/* =========================================================================
   Swipe actions on list items
   ========================================================================= */
.swipe-row {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}
.swipe-actions {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0;
  z-index: 0;
}
.swipe-actions button {
  height: 100%;
  padding: 0 20px;
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.swipe-actions .swipe-primary { background: var(--primary); }
.swipe-actions .swipe-danger { background: var(--danger); }
.swipe-actions .swipe-ghost { background: var(--text-soft); }
.swipe-content {
  position: relative;
  z-index: 1;
  background: var(--white);
  transition: transform 0.25s var(--ease);
}

/* =========================================================================
   View content fade-in
   ========================================================================= */
.view-content {
  animation: fade-in 0.3s var(--ease);
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   Spring physics easing
   ========================================================================= */
:root {
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal {
  animation: modal-scale-in 0.35s var(--ease-spring) forwards;
}

/* =========================================================================
   Dark mode
   ========================================================================= */
/* Dark palette. Defined once via a custom-property recipe so the system (auto)
   and forced (html.dark) paths can never drift apart. Forced light (html.light)
   must beat the system-dark media query, so the auto path is scoped to
   html:not(.light) rather than a bare :root. */
@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --bg: #0f1f1c;
    --bg-deep: #0a1715;
    --surface: #162b27;
    --white: #1a302b;
    --border: #23423a;
    --border-strong: #2d5248;
    --text-main: #e1f0ec;
    --text-muted: #8a9e98;
    --text-soft: #84968e;
    --text-inverse: #0a1715;
    --primary-light: #1a4a3f;
    --primary-tint: #122e28;
    --chart-track: #1a302b;
    --success-bg: #1a4a3f;
    --danger-bg: #4a1f1f;
    --warning-bg: #4a3a1a;
    --info-bg: #1a3a4a;
    /* Status text must be LIGHT in dark mode (it rides on the dark tints above). */
    --success-text: #5fd3b0;
    --warning-text: #ecc25e;
    --danger-text: #f29393;
    --info-text: #76c4ec;
    --neutral-bg: #283a35;
    --neutral-text: #9fb3ad;
    --accent: #5fe0c2;
    --nav-glass-bg: rgba(22, 43, 39, 0.9);
    --nav-glass-border: rgba(45, 82, 72, 0.7);
    --topbar-glass-bg: rgba(15, 31, 28, 0.85);
  }
}
html.dark {
  --bg: #0f1f1c;
  --bg-deep: #0a1715;
  --surface: #162b27;
  --white: #1a302b;
  --border: #23423a;
  --border-strong: #2d5248;
  --text-main: #e1f0ec;
  --text-muted: #8a9e98;
  --text-soft: #84968e;
  --text-inverse: #0a1715;
  --primary-light: #1a4a3f;
  --primary-tint: #122e28;
  --chart-track: #1a302b;
  --success-bg: #1a4a3f;
  --danger-bg: #4a1f1f;
  --warning-bg: #4a3a1a;
  --info-bg: #1a3a4a;
  --success-text: #5fd3b0;
  --warning-text: #ecc25e;
  --danger-text: #f29393;
  --info-text: #76c4ec;
  --neutral-bg: #283a35;
  --neutral-text: #9fb3ad;
  --accent: #5fe0c2;
  --nav-glass-bg: rgba(22, 43, 39, 0.9);
  --nav-glass-border: rgba(45, 82, 72, 0.7);
  --topbar-glass-bg: rgba(15, 31, 28, 0.85);
}

/* =========================================================================
   Chip filter bar
   ========================================================================= */
.chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chip-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--white);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.16s;
}
.chip.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--accent);
}

/* =========================================================================
   Settings: Device & app preference rows
   ========================================================================= */
.set-rows {
  display: flex;
  flex-direction: column;
}
.set-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.set-row:first-child {
  border-top: 0;
}
.set-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 220px;
}
.set-row-text b {
  font-size: 14px;
}
.set-row-text .muted {
  font-size: 12.5px;
}
.set-row .chip-bar {
  flex: 0 1 auto;
}


/* =========================================================================
   Dark mode polish — neutralise the light decorative gradients and keep
   contrast on the accent chips / floating surfaces.
   ========================================================================= */
/* The forced light/dark marker classes live on <html>, so scope around them. */
@media (prefers-color-scheme: dark) {
  html:not(.light) body {
    background-image:
      radial-gradient(1100px 520px at 88% -8%, rgba(26, 74, 63, 0.35) 0, rgba(10, 23, 21, 0) 60%),
      radial-gradient(900px 600px at -6% 4%, rgba(18, 46, 40, 0.4) 0, rgba(10, 23, 21, 0) 55%);
  }
  html:not(.light) { color-scheme: dark; }
}
html.dark body {
  background-image:
    radial-gradient(1100px 520px at 88% -8%, rgba(26, 74, 63, 0.35) 0, rgba(10, 23, 21, 0) 60%),
    radial-gradient(900px 600px at -6% 4%, rgba(18, 46, 40, 0.4) 0, rgba(10, 23, 21, 0) 55%);
}
html.dark { color-scheme: dark; }
/* Forced-light beats the system-dark media query. */
html.light { color-scheme: light; }
