/* =========================================================================
   ENERGIA CRM: Design tokens + cut-corner shape system + base components
   v1.0 · 3 Dec 2026 · Spec: docs/design/DESIGN_TOKENS.md
   Import once at the app root:  import "./styles/energia.css";
   ========================================================================= */

/* Fonts: self-host in production (put files in /public/brand/fonts) */
/* The CRM links this same font URL from index.html, so the @import is not repeated here:
   https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,400..800&family=Bebas+Neue&family=Alexandria:wght@400..700&display=swap */

:root {
  /* ---------- Brand primitives ---------- */
  --en-red: #FF004F;            /* Electric Red: primary */
  --en-red-pressed: #BF003D;
  --en-red-tint: #FFDFE9;
  --en-green: #00FF9C;          /* Lightning Green: fill only */
  --en-green-hover: #00E58C;    /* DERIVED */
  --en-green-text: #009F62;     /* large/bold text + icons on white */
  --en-green-text-strong: #00704A; /* DERIVED: small text on white */
  --en-green-tint: #DFFFF3;
  --en-ink: #141414;            /* Night Black */
  --en-white: #FFFFFF;
  --en-blue: #0072BB;           /* French Blue: Energia Weld badge + Info callouts only */
  --en-blue-text: #005A94;      /* DERIVED */
  --en-blue-tint: #D7F0FF;
  --en-magenta: #91278E;        /* Dark Magenta: Energia Modular badge */
  --en-violet: #3E2F5B;         /* Cyber Violet: Energia Events badge */
  --en-orange: #FF751F;         /* Energia Utilities badge (from master lockup) */
  --en-brown: #A84E04;          /* Energia CSS badge (from master lockup) */
  --en-cyan: #96DDE8;           /* Energia Cooling badge (from master lockup) */

  /* Neutrals */
  --n-50: #FAFAFA; --n-100: #F4F4F4; --n-200: #E2E2E2; --n-300: #C4C4C4; --n-400: #A7A7A7;
  --n-500: #8A8A8A; --n-600: #6C6C6C; --n-700: #4F4F4F; --n-800: #323232; --n-900: #141414;

  /* ---------- Division identity (see tokens/divisions.ts) ---------- */
  --div-group: var(--en-red);
  --div-leasing: var(--en-red);
  --div-utilities: var(--en-orange);
  --div-modular: var(--en-magenta);
  --div-events: var(--en-violet);
  --div-css: var(--en-brown);
  /* Rental streams with their own lockup (Leasing context) */
  --stream-cooling: var(--en-cyan);
  --stream-weld: var(--en-blue);
  --div-current: var(--div-group);     /* set by [data-division] below */

  /* ---------- Semantic: light ---------- */
  --bg-app: var(--n-50);
  --bg-surface: var(--en-white);
  --bg-subtle: var(--n-100);
  --bg-hover: var(--n-50);
  --bg-selected: var(--en-red-tint);
  --bg-sidebar: var(--en-ink);
  --bg-sidebar-hover: var(--n-800);
  --bg-sidebar-active: #1E1E1E;
  --bg-overlay: rgba(20,20,20,.55);
  --bg-inverse: var(--en-ink);

  --text-primary: var(--en-ink);
  --text-secondary: var(--n-700);
  --text-muted: var(--n-600);
  --text-disabled: var(--n-500);
  --text-inverse: var(--en-white);
  --text-on-red: var(--en-white);
  --text-sidebar: var(--n-300);
  --link: var(--en-red-pressed);

  --border-hairline: var(--n-200);
  --border-default: var(--n-300);
  --border-hover: var(--n-500);
  --border-strong: var(--en-ink);

  --action-primary: var(--en-red);
  --action-primary-hover: var(--en-red-pressed);
  --action-secondary: var(--en-ink);
  --action-secondary-hover: var(--n-800);
  --focus-ring: var(--en-red);

  /* Status (brand callout set) */
  --status-critical-text: var(--en-red-pressed);  --status-critical-bg: var(--en-red-tint);   --status-critical-border: var(--en-red);
  --status-positive-text: var(--en-green-text-strong); --status-positive-bg: var(--en-green-tint); --status-positive-border: var(--en-green-text);
  --status-info-text: var(--en-blue-text);        --status-info-bg: var(--en-blue-tint);      --status-info-border: var(--en-blue);
  --status-note-text: var(--n-800);               --status-note-bg: var(--n-100);             --status-note-border: var(--n-600);

  /* ---------- Typography ---------- */
  --font-sans: "Roboto Flex", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Bebas Neue", "Roboto Flex", sans-serif;
  --font-arabic: "Alexandria", "Segoe UI", Tahoma, sans-serif;

  --fs-cover: 72px; --fs-display: 40px; --fs-h1: 24px; --fs-h2: 17px; --fs-h3: 14px;
  --fs-body: 14.5px; --fs-body-sm: 13px; --fs-label: 11.5px; --fs-caption: 11.5px;
  --lh-body: 1.58; --lh-heading: 1.2; --lh-tight: 1.1;
  --ls-label: 0.14em;
  --fw-regular: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700; --fw-heavy: 800;

  /* ---------- Shape: cut corner (chamfer) ---------- */
  --radius: 0;              /* no rounded corners anywhere */
  --cut-none: 0px; --cut-xs: 4px; --cut-sm: 6px; --cut-md: 10px; --cut-lg: 18px; --cut-xl: 28px;

  /* ---------- Lines ---------- */
  --line-thin: 1px; --line-std: 1.5px; --line-bold: 3px; --bar-accent: 4px; --focus-width: 2px;

  /* ---------- Spacing (8px grid) ---------- */
  --space-0: 0; --space-0_5: 4px; --space-1: 8px; --space-1_5: 12px; --space-2: 16px; --space-3: 24px;
  --space-4: 32px; --space-5: 40px; --space-6: 48px; --space-8: 64px; --space-10: 80px;

  /* ---------- Layout ---------- */
  --sidebar-w: 248px; --sidebar-w-collapsed: 64px; --topbar-h: 56px; --content-max: 1440px;
  --control-sm: 32px; --control-md: 40px; --control-lg: 48px; --touch-min: 44px;
  --row-h: 44px; --row-h-compact: 36px;

  /* ---------- Elevation (flat brand) ---------- */
  --shadow-none: none;
  --shadow-overlay: 0 8px 24px rgba(20,20,20,.14); /* floating layers only */

  /* ---------- Z-index ---------- */
  --z-sticky: 10; --z-dropdown: 100; --z-drawer: 200; --z-modal: 300; --z-toast: 400; --z-tooltip: 500;

  /* ---------- Motion ---------- */
  --dur-fast: 120ms; --dur-base: 200ms; --dur-slow: 320ms; --ease: cubic-bezier(.2,0,0,1);
}

/* ---------- Semantic: dark (DERIVED) ---------- */
:root[data-theme="dark"] {
  --bg-app: #141414; --bg-surface: #1E1E1E; --bg-subtle: #262626; --bg-hover: #262626;
  --bg-selected: #3A0F1D; --bg-sidebar: #0E0E0E; --bg-sidebar-hover: #262626; --bg-sidebar-active: #1E1E1E;
  --bg-inverse: #F4F4F4;
  --text-primary: #F4F4F4; --text-secondary: #C4C4C4; --text-muted: #A7A7A7; --text-disabled: #6C6C6C;
  --text-inverse: #141414; --link: #FF336F;
  --border-hairline: #323232; --border-default: #4F4F4F; --border-hover: #6C6C6C; --border-strong: #F4F4F4;
  --action-primary-hover: #FF336F; --action-secondary: #F4F4F4; --action-secondary-hover: #E2E2E2;
  --focus-ring: #FF336F;
  --status-critical-text: #FF8FB0; --status-critical-bg: #3A0F1D;
  --status-positive-text: #00FF9C; --status-positive-bg: #0B2E22;
  --status-info-text: #7CC4F2;     --status-info-bg: #0E2535;
  --status-note-text: #E2E2E2;     --status-note-bg: #262626;
  --shadow-overlay: 0 8px 24px rgba(0,0,0,.5);
}

/* Division context: set data-division on <body> or a page wrapper */
[data-division="group"]     { --div-current: var(--div-group); }
[data-division="leasing"]   { --div-current: var(--div-leasing); }
[data-division="utilities"] { --div-current: var(--div-utilities); }
[data-division="modular"]   { --div-current: var(--div-modular); }
[data-division="events"]    { --div-current: var(--div-events); }
[data-division="css"]       { --div-current: var(--div-css); }
[data-stream="cooling"]     { --div-current: var(--stream-cooling); }
[data-stream="weld"]        { --div-current: var(--stream-weld); }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; border-radius: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg-app); color: var(--text-primary);
  font: var(--fw-regular) var(--fs-body)/var(--lh-body) var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
:lang(ar), [dir="rtl"] { font-family: var(--font-arabic); }
h1, .en-h1 { font-weight: var(--fw-heavy); font-size: var(--fs-h1); line-height: var(--lh-heading); margin: 0; }
h2, .en-h2 { font-weight: var(--fw-bold); font-size: var(--fs-h2); line-height: var(--lh-heading); margin: 0; }
h3, .en-h3 { font-weight: var(--fw-bold); font-size: var(--fs-h3); line-height: var(--lh-heading); margin: 0; }
.en-label { font-size: var(--fs-label); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--ls-label); color: var(--text-secondary); line-height: 1.3; }
.en-caption { font-size: var(--fs-caption); color: var(--text-muted); }
.en-num { font-variant-numeric: tabular-nums; }
.en-display { font-family: var(--font-display); font-size: var(--fs-display); line-height: 1; letter-spacing: .02em; font-weight: 400; }
.en-code { font-family: var(--font-display); letter-spacing: .04em; }
a { color: var(--link); text-underline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; } }

/* =========================================================================
   CUT-CORNER SHAPE SYSTEM (.en-cut)
   One chamfered corner, BOTTOM-LEFT (bottom-right in RTL), the same cut as the division badges in the Energia lockups. Drawn on two clipped
   pseudo-layers so the border follows the diagonal and focus rings work.
   Per-component knobs:
     --cut          corner size (use --cut-sm|md|lg|xl)
     --shape-fill   fill colour
     --shape-border border colour
     --shape-bw     border width (0 = no border)
   ========================================================================= */
.en-cut {
  --cut: var(--cut-md);
  --shape-fill: var(--bg-surface);
  --shape-border: transparent;
  --shape-bw: 0px;
  --_ci: max(0px, calc(var(--cut) - var(--shape-bw) * 0.5858)); /* inner cut = c − bw(2−√2) */
  position: relative;
  isolation: isolate;
  background: none !important;
  border: 0 !important;
  outline: none;
}
.en-cut::before, .en-cut::after {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  transition: background-color var(--dur-fast) var(--ease), inset var(--dur-fast) var(--ease);
}
/* border layer */
.en-cut::before {
  inset: 0; background: var(--shape-border);
  clip-path: polygon(0 0, 100% 0, 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)));
}
/* fill layer */
.en-cut::after {
  inset: var(--shape-bw); background: var(--shape-fill);
  clip-path: polygon(0 0, 100% 0, 100% 100%, var(--_ci) 100%, 0 calc(100% - var(--_ci)));
}
/* RTL: mirror to bottom-right */
[dir="rtl"] .en-cut::before { clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%); }
[dir="rtl"] .en-cut::after  { clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--_ci)), calc(100% - var(--_ci)) 100%, 0 100%); }
/* Chamfered focus ring: border layer grows outward in red */
.en-cut:focus-visible::before, .en-cut.is-focused::before, .en-cut:has(> input:focus-visible)::before, .en-cut:has(> select:focus-visible)::before, .en-cut:has(> textarea:focus-visible)::before {
  inset: calc(var(--focus-width) * -1 - 1px); background: var(--focus-ring);
}
.en-cut--none { --cut: var(--cut-none); }
.en-cut--xs { --cut: var(--cut-xs); }
.en-cut--sm { --cut: var(--cut-sm); }
.en-cut--md { --cut: var(--cut-md); }
.en-cut--lg { --cut: var(--cut-lg); }
.en-cut--xl { --cut: var(--cut-xl); }

/* Accent bars */
.en-accent-start { border-inline-start: var(--bar-accent) solid var(--en-red); padding-inline-start: var(--space-1_5); }
.en-division-bar { border-top: var(--bar-accent) solid var(--div-current); }

/* =========================================================================
   BUTTONS
   ========================================================================= */
.en-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1);
  height: var(--control-md); padding: 0 var(--space-2); min-width: var(--touch-min);
  font: var(--fw-bold) 14px/1 var(--font-sans); letter-spacing: .01em; white-space: nowrap;
  color: var(--text-primary); cursor: pointer; user-select: none; text-decoration: none;
  transition: color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
:is([dir="rtl"], :lang(ar)) .en-btn { font-family: var(--font-arabic); }
.en-btn:active:not(:disabled) { transform: translateY(1px); }
.en-btn--sm { height: var(--control-sm); padding: 0 var(--space-1_5); font-size: 13px; --cut: var(--cut-sm); }
.en-btn--lg { height: var(--control-lg); padding: 0 var(--space-3); font-size: 15px; }
.en-btn--icon { width: var(--control-md); padding: 0; }

.en-btn--primary     { --shape-fill: var(--action-primary); color: var(--text-on-red); }
.en-btn--primary:hover:not(:disabled)   { --shape-fill: var(--action-primary-hover); }
.en-btn--secondary   { --shape-fill: var(--action-secondary); color: var(--text-inverse); font-weight: var(--fw-semibold); }
.en-btn--secondary:hover:not(:disabled) { --shape-fill: var(--action-secondary-hover); }
.en-btn--outline     { --shape-fill: var(--bg-surface); --shape-border: var(--border-strong); --shape-bw: var(--line-std); font-weight: var(--fw-semibold); }
.en-btn--outline:hover:not(:disabled)   { --shape-fill: var(--bg-subtle); }
.en-btn--ghost       { --shape-fill: transparent; font-weight: var(--fw-semibold); }
.en-btn--ghost:hover:not(:disabled)     { --shape-fill: var(--bg-subtle); }
.en-btn--destructive { --shape-fill: var(--bg-surface); --shape-border: var(--en-red); --shape-bw: var(--line-std); color: var(--status-critical-text); }
.en-btn--destructive:hover:not(:disabled) { --shape-fill: var(--en-red-tint); }
.en-btn--accent      { --shape-fill: var(--en-green); color: var(--en-ink); }
.en-btn--accent:hover:not(:disabled)    { --shape-fill: var(--en-green-hover); }
.en-btn:disabled, .en-btn[aria-disabled="true"] { --shape-fill: var(--n-200); --shape-border: transparent; color: var(--text-disabled); cursor: not-allowed; }

/* =========================================================================
   FORM CONTROLS: wrap the native control: <div class="en-field en-cut en-cut--sm"><input></div>
   ========================================================================= */
.en-field { --shape-fill: var(--bg-surface); --shape-border: var(--border-default); --shape-bw: var(--line-std); display: flex; align-items: center; height: var(--control-md); }
.en-field:hover { --shape-border: var(--border-hover); }
.en-field:focus-within { --shape-border: var(--border-strong); }
.en-field.is-invalid, .en-field:has(:user-invalid) { --shape-border: var(--en-red); }
.en-field.is-disabled { --shape-fill: var(--bg-subtle); }
.en-field > input, .en-field > select, .en-field > textarea {
  all: unset; box-sizing: border-box; width: 100%; height: 100%; padding: 0 var(--space-1_5);
  font: var(--fw-regular) var(--fs-body) var(--font-sans); color: var(--text-primary);
}
.en-field > textarea { padding: var(--space-1) var(--space-1_5); }
.en-field--textarea { height: auto; min-height: 96px; align-items: stretch; }
.en-field ::placeholder { color: var(--text-muted); }
.en-help { font-size: var(--fs-caption); color: var(--text-muted); margin-top: var(--space-0_5); }
.en-help--error { color: var(--status-critical-text); }

/* =========================================================================
   CARDS, KPI TILES, PANELS
   ========================================================================= */
.en-card { --cut: var(--cut-lg); --shape-fill: var(--bg-surface); --shape-border: var(--border-hairline); --shape-bw: var(--line-thin); padding: var(--space-3); }
.en-kpi { --cut: var(--cut-lg); --shape-fill: var(--bg-surface); --shape-border: var(--border-hairline); --shape-bw: var(--line-thin); padding: var(--space-2) var(--space-3); display: grid; gap: var(--space-0_5); cursor: pointer; }
.en-kpi:hover { --shape-border: var(--border-strong); }
.en-kpi__value { font-family: var(--font-display); font-size: var(--fs-display); line-height: 1; color: var(--text-primary); }
.en-kpi__delta { font-size: var(--fs-body-sm); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.en-kpi__delta--up { color: var(--status-positive-text); }
.en-kpi__delta--down { color: var(--status-critical-text); }
.en-kpi__delta--flat { color: var(--text-muted); }

/* =========================================================================
   TAGS / CHIPS / COUNTERS
   ========================================================================= */
.en-tag { --cut: var(--cut-sm); display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 var(--space-1); font-size: 12.5px; font-weight: var(--fw-bold); white-space: nowrap; }
.en-tag--critical { --shape-fill: var(--status-critical-bg); color: var(--status-critical-text); }
.en-tag--positive { --shape-fill: var(--status-positive-bg); color: var(--status-positive-text); }
.en-tag--info     { --shape-fill: var(--status-info-bg);     color: var(--status-info-text); }
.en-tag--note     { --shape-fill: var(--status-note-bg);     color: var(--status-note-text); }
.en-tag--won      { --shape-fill: var(--en-green);           color: var(--en-ink); }
.en-tag--division { --shape-fill: var(--bg-surface); --shape-border: var(--div-current); --shape-bw: var(--line-std); color: var(--text-primary); }
/* Badge-style division label (mirrors the lockup badge: deep cut, uppercase). Text: white on all badges except Cooling (ink). */
.en-badge { --cut: 12px; --shape-fill: var(--div-current); display: inline-flex; align-items: center; height: 22px; padding: 0 8px 0 16px; font-size: 12px; font-weight: var(--fw-medium); letter-spacing: .02em; text-transform: uppercase; color: #fff; }
[dir="rtl"] .en-badge { padding: 0 16px 0 8px; }
[data-stream="cooling"] .en-badge, .en-badge[data-stream="cooling"] { color: var(--en-ink); }
.en-swatch { width: 10px; height: 10px; background: var(--div-current); flex: none; }
.en-counter { font-family: var(--font-display); font-size: 14px; line-height: 1; min-width: 18px; height: 18px; padding: 2px 5px 0; background: var(--en-red); color: #fff; text-align: center; }
.en-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; } /* the only circle besides radios */

/* =========================================================================
   NAVIGATION
   ========================================================================= */
.en-sidebar { width: var(--sidebar-w); background: var(--bg-sidebar); color: var(--text-sidebar); min-height: 100vh; padding: var(--space-2) 0; }
.en-sidebar__group { font-size: var(--fs-label); font-weight: var(--fw-bold); letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--n-500); padding: var(--space-2) var(--space-3) var(--space-1); }
.en-nav-item { display: flex; align-items: center; gap: var(--space-1_5); min-height: var(--touch-min); padding: 0 var(--space-3); color: var(--text-sidebar); font-weight: var(--fw-semibold); font-size: 14px; text-decoration: none; border-inline-start: var(--bar-accent) solid transparent; }
.en-nav-item:hover { background: var(--bg-sidebar-hover); color: #fff; }
.en-nav-item[aria-current="page"] { background: var(--bg-sidebar-active); color: #fff; border-inline-start-color: var(--en-red); }
.en-topbar { height: var(--topbar-h); background: var(--bg-surface); border-bottom: var(--line-thin) solid var(--border-hairline); display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-3); }
.en-tabs { display: flex; gap: var(--space-3); border-bottom: var(--line-thin) solid var(--border-hairline); }
.en-tab { padding: var(--space-1_5) 0; color: var(--text-secondary); font-weight: var(--fw-semibold); border-bottom: var(--line-bold) solid transparent; margin-bottom: -1px; cursor: pointer; background: none; border-top: 0; border-inline: 0; font-family: inherit; font-size: 14px; }
.en-tab[aria-selected="true"] { color: var(--text-primary); font-weight: var(--fw-bold); border-bottom-color: var(--en-red); }

/* =========================================================================
   TABLES
   ========================================================================= */
.en-table { width: 100%; border-collapse: collapse; background: var(--bg-surface); font-size: var(--fs-body-sm); }
.en-table th { text-align: start; font-size: var(--fs-label); font-weight: var(--fw-bold); letter-spacing: var(--ls-label); text-transform: uppercase; color: var(--text-secondary); padding: var(--space-1_5); border-bottom: var(--line-std) solid var(--border-strong); position: sticky; top: 0; background: var(--bg-surface); z-index: var(--z-sticky); }
.en-table td { padding: 0 var(--space-1_5); height: var(--row-h); border-bottom: var(--line-thin) solid var(--border-hairline); vertical-align: middle; }
.en-table--compact td { height: var(--row-h-compact); }
.en-table tbody tr:hover { background: var(--bg-hover); }
.en-table tbody tr[aria-selected="true"] { background: var(--bg-selected); box-shadow: inset var(--bar-accent) 0 0 var(--en-red); }
[dir="rtl"] .en-table tbody tr[aria-selected="true"] { box-shadow: inset calc(var(--bar-accent) * -1) 0 0 var(--en-red); }
.en-table .is-num { text-align: end; font-variant-numeric: tabular-nums; }

/* =========================================================================
   OVERLAYS
   ========================================================================= */
.en-modal   { --cut: var(--cut-lg); --shape-fill: var(--bg-surface); padding: var(--space-3); filter: drop-shadow(0 8px 24px rgba(20,20,20,.14)); z-index: var(--z-modal); }
.en-menu    { --cut: var(--cut-md); --shape-fill: var(--bg-surface); --shape-border: var(--border-hairline); --shape-bw: var(--line-thin); padding: var(--space-0_5) 0; filter: drop-shadow(0 8px 24px rgba(20,20,20,.14)); z-index: var(--z-dropdown); }
.en-toast   { --cut: var(--cut-md); --shape-fill: var(--bg-inverse); color: var(--text-inverse); padding: var(--space-1_5) var(--space-2); z-index: var(--z-toast); }
.en-tooltip { --cut: var(--cut-sm); --shape-fill: var(--en-ink); color: #fff; font-size: 12.5px; padding: 6px 10px; z-index: var(--z-tooltip); }
.en-backdrop { position: fixed; inset: 0; background: var(--bg-overlay); z-index: calc(var(--z-modal) - 1); }
/* Note: drop-shadow (not box-shadow) so the shadow follows the cut corner. */
