/*
 * app.css — dashboard styling for the Konnexion AI SaaS.
 *
 * Brand palette (from logo/color_code.txt — blue → teal):
 *   Brand Blue      #1366EA  — primary accent / gradient start
 *   Brand Mid       #1D93C7  — gradient mid
 *   Brand Teal      #1DC7BA  — accent / gradient end
 *   Brand Navy      #0C2244  — sidebar rail base, heading ink
 *   White as Heaven #FEFEFE  — surface
 *   Lighthouse      #F4F4F4  — page background
 *   Wayward Wind    #DFDFE2  — borders
 *   Rough Asphalt   #BEC0BF  — disabled / faded
 *   Cool Slate      #5B7A95  — muted secondary
 *
 * NOTE ON TOKEN NAMES: the legacy `--newt*`/`--moor` custom-property NAMES are
 * intentionally kept (hundreds of rules reference them) but their VALUES now
 * point at the blue→teal brand. New rules should prefer the `--brand-*` aliases.
 *
 * Layout model (edge-flush rail, no boxed sidebar):
 *   .sidenav   — fixed 225px left column. Holds logo block, nav list,
 *                and an optional `.sidenav-promo` card pinned to the
 *                bottom. Border on the right, no radius.
 *   .topbar    — 60px strip above the content area, offset by the
 *                rail width. Right-aligned user/avatar info. The
 *                existing `.topbar .brand` is hidden because the logo
 *                now lives inside `.sidenav`.
 *   .shell     — content column. Edge padding only — not a flex
 *                container any more; the rail is position:fixed.
 *
 * Components (class names unchanged so every page works without
 * markup edits):
 *   .btn / .btn-primary / .btn-secondary / .btn-danger
 *   .card, .stat-card, .form-field, .table, .alert, .badge, .two-pane
 *
 * Borders are kept tight (4–6px radius) throughout. Shadows are minimal.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  /* ---- Konnexion AI brand tokens — exact values from the official brand kit
     (brand-spec.md, "Confluence" mark). Token NAMES are preserved so the whole
     stylesheet re-themes by repointing values; only the hex changed to the kit.
     Kit palette: g1 #1566E5 (royal blue) → g2 #20C4BA (teal-cyan); ink #042148;
     accent #0E63C9; bg #F4F7FB; surface #fff; muted #5B6B7E; border #E3E9F0;
     panel #06122A. Gradient is blue→teal; never recolour (no green/indigo). ---- */
  --brand-blue:     #1566e5;   /* g1 — gradient start (royal blue) */
  --brand-mid:      #1a93cf;   /* derived midpoint (blue→teal), for 3-stop washes */
  --brand-teal:     #20c4ba;   /* g2 — gradient end (teal-cyan) */
  --brand-navy:     #042148;   /* ink — wordmark / sidebar anchor */
  --brand-navy-700: #06306b;   /* lifted navy for the rail gradient bottom */
  --brand-gradient: linear-gradient(135deg, #1566e5 0%, #20c4ba 100%);

  --heaven:   #ffffff;         /* surface — cards / panels (kit: pure white) */
  --light:    #f4f7fb;         /* bg — cool off-white page canvas (kit --bg) */
  --wind:     #e3e9f0;         /* border — hairline (kit --border) */
  --asphalt:  #9fb0c0;         /* faded text */
  /* Legacy names, brand values (see header note). --moor = cool slate muted. */
  --moor:     #5b6b7e;         /* muted secondary text (kit --muted) */
  --newt:     #1566e5;   /* primary brand blue (g1) */
  --newt-600: #0e63c9;   /* text-safe / darker blue — hover / rail (kit --accent) */
  --newt-100: #e6f7f5;   /* faint teal tint */

  --color-primary:        var(--newt);
  --color-primary-dark:   var(--newt-600);
  --color-primary-soft:   #e7f0fe;

  --color-accent:         var(--brand-teal);
  --color-error:          #c2455a;
  --color-warn:           #c98a2d;
  --color-success:        #1f9d74;   /* keep a TRUE green for success states */
  --color-info:           #1a93cf;

  --color-bg:             var(--light);
  --color-surface:        var(--heaven);
  --color-border:         var(--wind);
  --color-divider:        #eef2f7;
  --color-text:           #042148;   /* ink — deep navy (kit --ink) */
  --color-text-muted:     var(--moor);
  --color-text-faded:     var(--asphalt);

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 8px;

  --shadow-sm: 0 1px 2px rgba(25, 40, 36, 0.04);
  --shadow-md: 0 2px 8px rgba(25, 40, 36, 0.06);

  --sidenav-width: 225px;
  --topbar-height: 60px;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  /* Brand font = Poppins (matches the Konnexion AI logo wordmark). The refined
     overlay (app-refined.css) declares the @import + the `--brand-font` token;
     this base fallback keeps the same family if that overlay ever fails to load. */
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3, h4 {
  margin: 0 0 8px;
  font-weight: 700;
  color: #0d1715;
  letter-spacing: -0.018em;
}
h1 { font-size: 1.55rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 0.98rem; font-weight: 700; text-transform: none; }

/* Stat-card labels get the same heavier treatment so dashboard tiles
   read with authority. */
.stat-card .label {
  color: #0d1715;
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

/* ---------- Fixed left rail ---------- */

/* Sidebar is inverted: dark navy brand background with light text.
   Label colors use rgba-white so hover/active steps are subtle and
   legible. Every icon is drawn with a white stroke. */
.sidenav {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidenav-width);
  background: var(--brand-navy);
  border-right: 1px solid rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 90;
  overflow-y: auto;
  padding: 0 16px 16px;
}

/* Brand block at the top of the rail: the Konnexion "X" icon + the white
   "Konnexion AI" wordmark. Real markup (a.brand-rail) so the logo image can
   sit beside the text — replaces the old CSS `::before` text-brand. */
.brand-rail {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 10px 16px;
  margin: 0 -16px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--brand-navy);
  position: sticky;
  top: 0;
  z-index: 2;
  text-decoration: none;
}
.brand-rail:hover {
  text-decoration: none;
}
.brand-rail-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  object-fit: contain;
}
.brand-rail-text {
  color: #fff;
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
/* The "AI" suffix mirrors the logo wordmark: a teal→blue gradient, set tight
   against "Konnexion" with a hair of space, like the brand art. Falls back to
   solid teal where background-clip:text is unsupported. */
.brand-rail-ai {
  margin-left: 3px;
  font-weight: 700;
  color: var(--brand-teal);
  background: linear-gradient(90deg, var(--brand-teal) 0%, var(--brand-mid) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
/* The "· Platform" suffix on operator pages renders smaller + dimmer. */
.brand-rail-text small {
  display: block;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}

/* Nav list. Tight rows, small text, flat SVG icons, and a right-edge
   accent on the active row. */
.sidenav ul {
  list-style: none;
  margin: 0;
  padding: 4px 0 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidenav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 500;
  font-size: 0.86rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}
.sidenav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  text-decoration: none;
}
.sidenav a.active {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  font-weight: 600;
}
/* Brand-teal right-edge bar on the active item — contrasts
   against the dark navy rail. */
.sidenav a.active::after {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  right: -16px;
  width: 3px;
  border-radius: 2px 0 0 2px;
  background: var(--brand-teal);
}

/* ---------- Nav accordion groups ----------
   The tenant rail groups its links under collapsible section headers
   (Overview, Commerce, Engage, Automation & AI, Audience, Settings). The
   group OPEN/CLOSED state is owned by public/js/nav.js (it toggles the
   `.collapsed` class + persists to localStorage). CSS here only paints. */
.nav-group {
  list-style: none;
  margin: 0;
}
.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px 6px;
  margin: 4px 0 1px;
  background: none;
  border: 0;
  cursor: pointer;
  /* 0.62 clears WCAG AA (~5.4:1) at the lightest end of the navy rail gradient
     (#103a6b); hover (0.85) + featured-group (0.92) already pass. */
  color: rgba(255, 255, 255, 0.62);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.nav-group-toggle:hover {
  color: rgba(255, 255, 255, 0.85);
}
/* Caret rotates to point down when the group is expanded. */
.nav-caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  transition: transform 0.15s ease;
  opacity: 0.8;
}
.nav-group.collapsed .nav-caret {
  transform: rotate(-90deg);
}
.nav-group-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-group.collapsed .nav-group-items {
  display: none;
}

/* The Commerce group is ELEVATED: a teal left keyline + faint tint so the
   strategic commerce wedge reads as a headline capability, not a buried tab. */
.nav-group--featured {
  position: relative;
  margin: 6px -8px;
  padding: 2px 8px 6px;
  border-radius: var(--radius);
  background: rgba(29, 199, 186, 0.08);
  box-shadow: inset 3px 0 0 var(--brand-teal);
}
.nav-group--featured .nav-group-toggle {
  color: rgba(255, 255, 255, 0.92);
}
.nav-group--featured .nav-group-toggle span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
/* A small "shop bag" glyph before the Commerce label. */
.nav-group--featured .nav-group-toggle span:first-child::before {
  content: "";
  width: 13px;
  height: 13px;
  background: no-repeat center / contain
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231dc7ba' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z'/><path d='M3 6h18'/><path d='M16 10a4 4 0 0 1-8 0'/></svg>");
}

/* Flat SVG icons, matched to each stable nav id. Rendered via
   `background-image` on the link's `::before` pseudo-element so no
   markup change is required. Strokes are white so they read on the
   dark rail; opacity softens inactive rows. */
.sidenav a::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
  opacity: 0.78;
}
.sidenav a:hover::before,
.sidenav a.active::before {
  opacity: 1;
}

/* White-stroke SVG icons for the inverted rail. The active-state
   overrides from the previous light-rail theme are removed — the
   base icon stroke is already white, so `.active` just bumps
   opacity to 1 via the selector above. */
#nav-home::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-7h-6v7H4a1 1 0 0 1-1-1z'/></svg>");
}
#nav-instance::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><rect x='6' y='2.5' width='12' height='19' rx='2'/><line x1='10' y1='18.5' x2='14' y2='18.5'/></svg>");
}
#nav-users::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M17 20v-1a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v1'/><circle cx='10' cy='8' r='3.5'/><path d='M21 20v-1a4 4 0 0 0-3-3.87'/><path d='M16 4.13a4 4 0 0 1 0 7.75'/></svg>");
}
#nav-templates::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/><polyline points='14 2 14 8 20 8'/><line x1='8' y1='13' x2='16' y2='13'/><line x1='8' y1='17' x2='14' y2='17'/></svg>");
}
#nav-contacts::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><rect x='3.5' y='4.5' width='17' height='15' rx='2'/><circle cx='12' cy='11' r='2.5'/><path d='M8 17c.5-2 2.2-3 4-3s3.5 1 4 3'/><line x1='3.5' y1='8.5' x2='6' y2='8.5'/><line x1='3.5' y1='15.5' x2='6' y2='15.5'/></svg>");
}
#nav-inbox::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-6l-4 3v-3H6a2 2 0 0 1-2-2z'/></svg>");
}
#nav-send::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><line x1='21' y1='3' x2='10' y2='14'/><polygon points='21 3 14.5 21 10 14 3 9.5 21 3'/></svg>");
}
#nav-orgs::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M3 21h18'/><path d='M5 21V7l7-4 7 4v14'/><path d='M9 21v-6h6v6'/></svg>");
}
#nav-campaigns::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M3 11l18-8-3 18-6-7-9-3z'/><path d='M12 14v6'/></svg>");
}
#nav-auto-replies::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M21 12a9 9 0 1 1-4.5-7.8'/><polyline points='21 4 21 10 15 10'/><polyline points='9 11 12 14 17 9'/></svg>");
}
#nav-audit::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M9 3h6l4 4v13a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h3z'/><path d='M8 12h8M8 16h5'/></svg>");
}
/* Newer pages (A/B build) — these nav ids were missing icon rules, so they
   rendered as blank gaps. Same white-stroke 24x24 style as the icons above. */
#nav-analytics::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M4 20V10'/><path d='M10 20V4'/><path d='M16 20v-7'/><path d='M21 20H3'/></svg>");
}
#nav-segments::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polygon points='3 4 21 4 14 12.5 14 19 10 21 10 12.5 3 4'/></svg>");
}
#nav-quick-replies::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M4 5a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H9l-4 3v-3H6a2 2 0 0 1-2-2z'/><polyline points='9 6.5 11 8.5 15 5'/><line x1='8' y1='12' x2='14' y2='12'/></svg>");
}
#nav-scheduled::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='9'/><polyline points='12 7 12 12 15.5 14'/></svg>");
}
#nav-flows::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><circle cx='6' cy='6' r='2.5'/><circle cx='6' cy='18' r='2.5'/><circle cx='18' cy='12' r='2.5'/><path d='M8.5 6H13a2 2 0 0 1 2 2v2.2'/><path d='M8.5 18H13a2 2 0 0 0 2-2v-2.2'/></svg>");
}
#nav-ai-agents::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><rect x='4' y='8' width='16' height='11' rx='2'/><path d='M12 8V4'/><circle cx='12' cy='3' r='1'/><line x1='9' y1='13' x2='9' y2='15'/><line x1='15' y1='13' x2='15' y2='15'/></svg>");
}
#nav-developers::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polyline points='9 8 5 12 9 16'/><polyline points='15 8 19 12 15 16'/></svg>");
}
#nav-knowledge::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2z'/><path d='M4 19a2 2 0 0 1 2-2h13'/></svg>");
}
#nav-wa-flows::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><rect x='4' y='3' width='16' height='18' rx='2'/><line x1='8' y1='8' x2='16' y2='8'/><line x1='8' y1='12' x2='16' y2='12'/><rect x='8' y='15.5' width='8' height='3' rx='1.5'/></svg>");
}

/* Optional promo card pinned to the bottom of the rail. On the
   inverted dark rail, the card flips to a LIGHT background so it
   stands out instead of blending in. */
.sidenav-promo {
  margin-top: auto;
  margin-bottom: 6px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}
.sidenav-promo h4 {
  margin: 6px 0 4px;
  color: var(--newt-600);
  font-size: 0.92rem;
}
.sidenav-promo p {
  margin: 0 0 12px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}
.sidenav-promo .btn {
  background: var(--newt-600);
  border-color: var(--newt-600);
  color: #fff;
  width: 100%;
  font-weight: 600;
  padding: 7px 10px;
  font-size: 0.82rem;
}
.sidenav-promo .btn:hover {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ---------- Top strip + shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: var(--topbar-height);
  padding: 0 24px;
  margin-left: var(--sidenav-width);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
/* Hide the legacy `.brand` inside the topbar — logo now lives in the
   sidebar. */
.topbar .brand {
  display: none;
}
.topbar .user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--color-text-muted);
  font-size: 0.88rem;
}
.topbar .user .name {
  color: var(--color-text);
  font-weight: 500;
}
/* Small round avatar bubble beside the user name. Hooked off
   `.topbar .user` existing markup — rendered via ::before so no HTML
   changes. */
.topbar .user::before {
  content: "";
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary-soft);
  border: 1px solid var(--color-border);
}

.shell {
  display: block;
  min-height: calc(100vh - var(--topbar-height));
  margin-left: var(--sidenav-width);
  padding: 8px 24px 32px;
}

.content {
  min-width: 0;
}

/* ---------- Cards ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
  box-shadow: none;
}
.card h2,
.card h3 {
  margin-top: 0;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.stat-card .value {
  font-size: 1.85rem;
  font-weight: 700;
  color: #0d1715;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.stat-card .hint {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  margin-top: 6px;
}

/* ---------- Forms ---------- */

.form-field {
  margin-bottom: 14px;
}
label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: var(--color-text);
  font-size: 0.84rem;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="number"],
select,
textarea {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder,
textarea::placeholder {
  color: var(--color-text-faded);
}
input:focus,
select:focus,
textarea:focus {
  outline: 0;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(19, 102, 234, 0.18);
}
textarea {
  min-height: 76px;
  resize: vertical;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
  background: var(--color-surface);
  color: var(--color-text);
}
.btn:hover {
  background: var(--color-bg);
  border-color: var(--color-asphalt, var(--asphalt));
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
  color: #fff;
}
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-secondary:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
}
.btn-danger {
  background: var(--color-error);
  border-color: var(--color-error);
  color: #fff;
}
.btn-danger:hover {
  background: #a83649;
  border-color: #a83649;
}

/* ---------- Tables ---------- */

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th,
.table td {
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--color-divider);
  vertical-align: middle;
}
.table th {
  font-weight: 600;
  color: var(--color-text-muted);
  background: #fafafb;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-bottom-color: var(--color-border);
}
.table tbody tr:last-child td {
  border-bottom: 0;
}
.table tbody tr:hover {
  background: #f8f8f9;
}

/* ---------- Alerts ---------- */

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  margin-bottom: 12px;
  font-size: 0.88rem;
}
.alert-info    { color: #2a4c63; background: #e3eef6; border-color: #c8dcea; }
.alert-success { color: #2b4f47; background: #e4ecea; border-color: #c6d6d1; }
.alert-warn    { color: #6a4b14; background: #fbecd1; border-color: #edd6a6; }
.alert-error   { color: #6e2634; background: #f5d9df; border-color: #e4b6be; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 10px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.badge-success { background: var(--color-primary-soft); color: var(--color-primary-dark); border-color: #cbdcd8; }
.badge-warn    { background: #fbecd1; color: #6a4b14; border-color: #edd6a6; }
.badge-error   { background: #f5d9df; color: #6e2634; border-color: #e4b6be; }
.badge-info    { background: #e3eef6; color: #2a4c63; border-color: #c8dcea; }

.badge.dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------- Two-pane inbox ---------- */

.two-pane {
  display: flex;
  gap: 14px;
  height: calc(100vh - var(--topbar-height) - 64px);
}
.two-pane .pane-list {
  width: 320px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow-y: auto;
  flex-shrink: 0;
}
.two-pane .pane-list .item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-divider);
  cursor: pointer;
  transition: background-color 0.12s;
}
.two-pane .pane-list .item:last-child {
  border-bottom: 0;
}
.two-pane .pane-list .item:hover {
  background: var(--color-bg);
}
.two-pane .pane-list .item.active {
  background: var(--color-primary-soft);
}
.two-pane .pane-list .item .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.88rem;
  flex-shrink: 0;
  text-transform: uppercase;
}
.two-pane .pane-list .item .meta-row {
  flex: 1;
  min-width: 0;
}
.two-pane .pane-list .item .meta-row .top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.two-pane .pane-list .item .meta-row .top .name {
  font-weight: 600;
  color: #1e2a27;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.two-pane .pane-list .item .meta-row .top .time {
  color: var(--color-text-muted);
  font-size: 11px;
  white-space: nowrap;
}
.two-pane .pane-list .item .meta-row .bottom {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
  align-items: baseline;
}
.two-pane .pane-list .item .meta-row .bottom .snippet {
  color: var(--color-text-muted);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.two-pane .pane-list .item .meta-row .bottom .unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  flex-shrink: 0;
}

.two-pane .pane-thread {
  flex: 1;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.two-pane .pane-thread .chat-header {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.two-pane .pane-thread .chat-header .chat-header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
}
.two-pane .pane-thread .chat-header .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  text-transform: uppercase;
}
.two-pane .pane-thread .chat-header .title {
  font-weight: 600;
  color: #13201d;
}
.two-pane .pane-thread .chat-header .subtitle {
  color: var(--color-text-muted);
  font-size: 12px;
}
.two-pane .pane-thread .session-strip {
  padding: 6px 18px;
  font-size: 12px;
  border-top: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  gap: 6px;
}
.two-pane .pane-thread .session-strip.open {
  background: #eaf2ef;
  color: var(--color-primary-dark);
}
.two-pane .pane-thread .session-strip.closed {
  background: #fbecd1;
  color: #6a4b14;
}
.two-pane .pane-thread .messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: #f5f5f4;
  display: flex;
  flex-direction: column;
}
.two-pane .date-sep {
  align-self: center;
  font-size: 11px;
  color: var(--color-text-muted);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--color-divider);
  padding: 2px 10px;
  border-radius: 999px;
  margin: 10px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.two-pane .msg {
  max-width: 68%;
  padding: 7px 11px 5px;
  border-radius: 8px;
  margin-bottom: 6px;
  word-wrap: break-word;
  font-size: 0.9rem;
  position: relative;
  line-height: 1.35;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}
.two-pane .msg.inbound {
  background: #ffffff;
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}
.two-pane .msg.outbound {
  background: #d7eadb;
  color: #13201d;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}
.two-pane .msg .meta-line {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--color-text-muted);
}
.two-pane .msg.outbound .meta-line {
  color: #0e63c9;
}
.two-pane .msg .tick {
  font-size: 12px;
  letter-spacing: -1px;
}
.two-pane .msg .tick.sent { color: var(--color-text-muted); }
.two-pane .msg .tick.delivered { color: var(--color-text-muted); }
.two-pane .msg .tick.read { color: #3b6be0; }
.two-pane .msg .tick.failed { color: var(--color-error); }

.two-pane .composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  align-items: flex-end;
}
.two-pane .composer textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
}
.two-pane .composer textarea:disabled {
  background: var(--color-bg);
  color: var(--color-text-faded);
  cursor: not-allowed;
}
.two-pane .composer button {
  border-radius: 20px;
  padding: 9px 18px;
  height: 40px;
}

/* Conversation-list row layout (avatar + name/preview/time). */
.two-pane .pane-list .conv-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-divider);
  cursor: pointer;
  transition: background-color 0.12s;
}
.two-pane .pane-list .conv-row:hover {
  background: var(--color-bg);
}
.two-pane .pane-list .conv-row.active {
  background: var(--color-primary-soft);
  border-left: 3px solid var(--color-primary);
  padding-left: 11px;
}
.two-pane .pane-list .conv-row .avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
}
.two-pane .pane-list .conv-row .conv-meta {
  flex: 1;
  min-width: 0;
}
.two-pane .pane-list .conv-row .conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}
.two-pane .pane-list .conv-row .conv-name {
  font-weight: 600;
  color: #13201d;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
}
.two-pane .pane-list .conv-row .conv-time {
  font-size: 11px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}
.two-pane .pane-list .conv-row .conv-preview {
  color: var(--color-text-muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}
.two-pane .pane-list .conv-row .unread-dot {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--color-primary);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  font-weight: 600;
  flex-shrink: 0;
}

.two-pane .empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--color-text-muted);
  padding: 24px;
}

.two-pane .msg .msg-error {
  margin-top: 4px;
  padding: 4px 8px;
  background: rgba(194, 69, 90, 0.1);
  color: var(--color-error);
  border-radius: 4px;
  font-size: 11px;
}

/* ---------- Auth pages ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--color-bg);
}
/* Konnexion AI horizontal logo above the auth card (reads on light bg). */
.auth-brand {
  margin-bottom: 22px;
  text-align: center;
}
.auth-brand img {
  height: 69px;
  width: auto;
  display: block;
}
.auth-page .card {
  width: 100%;
  max-width: 400px;
  margin: 0;
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-md);
  border-radius: var(--radius);
}
.auth-page .card h1 {
  margin-bottom: 4px;
}

/* ---------- Utilities ---------- */

.muted      { color: var(--color-text-muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex         { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }

.nav-toggle {
  display: none;
  background: none;
  border: 0;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--color-text);
}

@media (max-width: 768px) {
  .sidenav {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
  }
  .sidenav.open {
    transform: translateX(0);
  }
  .topbar {
    margin-left: 0;
    justify-content: space-between;
    padding: 0 16px;
  }
  .shell {
    margin-left: 0;
    padding: 8px 16px 16px;
  }
  .nav-toggle {
    display: inline-block;
  }
  .two-pane {
    flex-direction: column;
    height: auto;
  }
  .two-pane .pane-list {
    width: 100%;
    max-height: 320px;
  }
}

/* ===========================================================================
 * Flow builder — stacked visual sequence (A7)
 * A trigger card at the top, then numbered step cards in a single column
 * connected by down-arrows. Pure CSS connectors (no SVG); cards reuse the
 * existing surface/border/token palette. Reorder via the per-card controls.
 * ======================================================================== */

#flow-seq {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  max-width: 640px;
}

/* One step (or the trigger) as a card. */
.flow-step {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px 14px;
}

/* Down-arrow connector drawn in the gap above every card except the first. */
.flow-step + .flow-step,
#flow-seq .flow-step.trigger + .flow-step {
  margin-top: 26px;
}
.flow-step + .flow-step::before {
  content: "▼";
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--color-text-faded);
  font-size: 14px;
  line-height: 1;
}

/* The trigger card gets an accent edge so it reads as the entry point. */
.flow-step.trigger {
  border-color: var(--color-primary);
  border-left-width: 4px;
}

/* Header row: number badge + icon + summary on the left, controls on the right. */
.flow-step .flow-step-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.flow-step .flow-step-num {
  flex: 0 0 auto;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.flow-step .flow-step-summary {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
}
.flow-step .flow-step-summary .muted {
  font-weight: 400;
}
.flow-step .flow-step-controls {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
}
.flow-step .flow-step-controls .btn {
  padding: 2px 8px;
  font-size: 13px;
  line-height: 1.4;
}

/* Collapsible edit region, toggled by the card's Edit button. */
.flow-step .flow-step-edit {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--color-divider);
}
.flow-step .flow-step-edit label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 2px;
}

/* ========================================================================
 * A7.1 — free-form flow CANVAS. Replaces the stacked #flow-seq view: draggable
 * absolutely-positioned nodes on a scrollable canvas, joined by an SVG edge
 * layer, with a docked editor panel to the side. Vanilla SVG + DOM (no diagram
 * library, no bundler). Reuses the existing surface/border/token palette.
 * ======================================================================== */

/* Two-column layout: the canvas viewport + the docked editor beside it. */
.flow-builder {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

/* The scrollable canvas viewport. flows.js sets an explicit min-height so it
   grows to contain every node. */
#flow-canvas {
  position: relative;
  flex: 1 1 560px;
  min-width: 320px;
  min-height: 360px;
  background:
    radial-gradient(var(--color-divider) 1px, transparent 1px) 0 0 / 22px 22px;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  overflow: auto;
}

/* SVG connector layer sits behind the nodes and never eats pointer events. */
#flow-edges {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}
.flow-edge {
  stroke: var(--color-text-faded);
  stroke-width: 1.6;
  fill: none;
}
.flow-edge.then { stroke: var(--color-primary); }
.flow-edge.else { stroke: #c2762b; }
.flow-arrowhead { fill: var(--color-text-faded); }
.flow-edge-label {
  font-size: 10px;
  font-weight: 700;
  fill: var(--color-text-muted);
  paint-order: stroke;
  stroke: var(--color-bg);
  stroke-width: 3px;
}

/* The node layer holds the absolutely-positioned draggable nodes. */
#flow-nodes {
  position: absolute;
  inset: 0;
  z-index: 2;
}
.flow-node {
  position: absolute;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  user-select: none;
}
.flow-node.trigger {
  border-color: var(--color-primary);
  border-left-width: 4px;
}
.flow-node.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-soft);
}
/* The head is the drag handle (grab cursor); its buttons stopPropagation. */
.flow-node .flow-node-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: grab;
}
.flow-node .flow-node-head:active { cursor: grabbing; }
.flow-node .flow-node-num {
  flex: 0 0 auto;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.flow-node .flow-node-summary {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.flow-node .flow-node-controls {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.flow-node .flow-node-controls .btn {
  padding: 1px 7px;
  font-size: 12px;
  line-height: 1.4;
}

/* The docked editor panel for the selected node. */
#flow-editor {
  flex: 0 0 320px;
  max-width: 360px;
}
#flow-editor label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin: 8px 0 2px;
}
