/* ==========================================================================
   LONX Brand System 2.1 layer for LonxERP (app, landing, ESS).
   Owner decisions 2026-10-09: FIX-01/02/05/06/07/09/10/14.
   SCREEN ONLY on purpose: print output (invoices, ZATCA documents, reports)
   is never touched by this file.
   ========================================================================== */
@media screen {
  :root, :root[data-theme="light"], :root[data-theme=""] {
    --erp-red: #141214; --erp-red-10: rgba(20,18,20,.08); --erp-red-20: rgba(20,18,20,.16); --erp-red-hover: #2A272A;
    --primary: #141214; --primary-10: rgba(20,18,20,.08); --primary-20: rgba(20,18,20,.16);
    --bg: #F0F1F2; --bg-1: #F0F1F2; --bg-2: #E3DFE0;
    --bg-card: #FFFFFF; --bg-card2: #F7F7F8; --bg-input: #FFFFFF; --surface: #F7F7F8;
    --sidebar-bg: #FFFFFF; --topbar-bg: #FFFFFF; --sidebar-border: #E3DFE0;
    --text: #141214; --text-1: #141214; --text-2: #4A4548; --text-3: #6E696C; --text-inv: #141214;
    --border: #E3DFE0; --border-2: #E3DFE0;
    --shadow-xs: none; --shadow-sm: none;
    --shadow-md: 0 12px 32px -12px rgba(20,18,20,.28), 0 2px 6px -2px rgba(20,18,20,.08);
    --shadow-lg: 0 12px 32px -12px rgba(20,18,20,.28), 0 2px 6px -2px rgba(20,18,20,.08);
    --focus-ring: 0 0 0 3px rgba(20,18,20,.14);
    --r-sm: 5.5px; --r-md: 7px; --r-lg: 12px; --r-xl: 12px;
    --green: #1E9E62; --green-10: rgba(30,158,98,.10); --success: #1E9E62;
    --amber: #D18A00; --amber-10: rgba(209,138,0,.12);
    --blue: #2F6FDB; --blue-10: rgba(47,111,219,.10);
    --purple: #9F7FF9; --danger: #E01C40; --danger-10: rgba(224,28,64,.08); --danger-20: rgba(224,28,64,.16);
    --erp-green: #24A878;
    --color-hub: #24A499; --color-ai: #9F7FF9; --color-insight: #EDB90F;
  }
  :root[data-theme="dark"] {
    --erp-red: #F4F2F2; --erp-red-10: rgba(244,242,242,.08); --erp-red-20: rgba(244,242,242,.16); --erp-red-hover: #DCD8DA;
    --primary: #F4F2F2;
    --bg: #0A0A0B; --bg-1: #0A0A0B; --bg-2: #232023;
    --bg-card: #171517; --bg-card2: #1D1B1D; --bg-input: #171517; --surface: #1D1B1D;
    --sidebar-bg: #171517; --topbar-bg: #171517; --sidebar-border: #2B282A;
    --text: #F4F2F2; --text-1: #F4F2F2; --text-2: #C9C4C6; --text-3: #8A8487; --text-inv: #F4F2F2;
    --border: #2B282A; --border-2: #2B282A;
    --shadow-xs: none; --shadow-sm: none;
    --shadow-md: 0 16px 40px -12px rgba(0,0,0,.7), 0 0 0 1px #2B282A;
    --shadow-lg: 0 16px 40px -12px rgba(0,0,0,.7), 0 0 0 1px #2B282A;
    --focus-ring: 0 0 0 3px rgba(244,242,242,.16);
    --green: #3CC283; --success: #3CC283; --amber: #E8AE3A; --blue: #6E9EF0; --danger: #F0375A;
    --erp-green: #34D399;
  }
  body { font-family: 'Inter', 'Cairo', 'Noto Sans Arabic', Tahoma, sans-serif; }
  svg.lucide { stroke-width: 1.5; }
  /* F1 fields: visible boundary, Ink focus */
  .form-control, input.form-input, select.form-control, textarea.form-control { border-color: #8F8A8D; border-radius: 7px; }
  :root[data-theme="dark"] .form-control { border-color: #6E696C; }
    .form-control:focus { border-color: var(--text); box-shadow: var(--focus-ring); }

  /* Sidebar (owner 2026-10-09): hover = light sub-surface with Ink text; active = nav-active fill, Ink text,
     2 px ERP-green edge. No pink gradient, no forced white text, no glow, no sideways movement. */
  .sidebar .nav-link { color: #4A4548; }
  .sidebar .nav-link:hover { background: #F7F7F8; color: #141214; transform: none !important; }
  .sidebar .nav-link.active { background: #F0F1F2 !important; color: #141214 !important; font-weight: 600; box-shadow: none; }
  .sidebar .nav-link.active .nav-icon i, .sidebar .nav-link.active .nav-icon svg { color: #141214; }
  .sidebar .nav-link.active::before { background: #24A878 !important; width: 2px !important; box-shadow: none !important; }
  :root[data-theme="dark"] .sidebar .nav-link { color: #C9C4C6; }
  :root[data-theme="dark"] .sidebar .nav-link:hover { background: #1D1B1D; color: #FFFFFF; }
  :root[data-theme="dark"] .sidebar .nav-link.active { background: #232023 !important; color: #FFFFFF !important; }
  :root[data-theme="dark"] .sidebar .nav-link.active .nav-icon i, :root[data-theme="dark"] .sidebar .nav-link.active .nav-icon svg { color: #FFFFFF; }
  :root[data-theme="dark"] .sidebar .nav-link.active::before { background: #34D399 !important; }

  /* Empty states (FIX-19, option E2): the page icon in a 44 px sub-surface tile, a title saying what is missing,
     one line on what will appear, one button. No illustrations, no coloured circles. Table-cell empty rows untouched. */
  div.empty-state, .empty-state-card { gap: 12px; padding: 48px 24px; }
  div.empty-state > i:first-child, div.empty-state > svg.lucide:first-child,
  .empty-state-card > i:first-child, .empty-state-card > svg.lucide:first-child,
  div.empty-state .empty-state-icon, div.empty-state .empty-icon-wrap {
    box-sizing: border-box; width: 44px !important; height: 44px !important; margin: 0 !important; padding: 11px;
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    background: var(--bg-card2); border: 1px solid var(--border); border-radius: 10px;
    color: var(--text-2); font-size: 20px !important; stroke-width: 1.5;
  }
  div.empty-state .empty-icon-wrap > svg, div.empty-state .empty-state-icon > svg { width: 20px; height: 20px; }
  div.empty-state h3, .empty-state-card h3 { margin: 0; font-size: 16px; font-weight: 700; color: var(--text); }
  div.empty-state p, .empty-state-card p { margin: 0; font-size: 14px; line-height: 1.7; color: var(--text-2); max-width: 36ch; }
  div.empty-state .btn, .empty-state-card .btn { margin-top: 4px; }

  /* ── 2026-10-09 pass 2: S1 / M1 / D1 / T2 / F1 / U1 (screen only) ── */
  :root, :root[data-theme="light"], :root[data-theme=""] {
    --st-ok: #1E9E62; --st-warn: #D18A00; --st-bad: #E01C40; --st-info: #2F6FDB; --st-neutral: #8A858A;
    --st-ok-text: #157A4B; --st-warn-text: #8A5A00; --st-bad-text: #C4153A; --st-info-text: #1F5FAF; --st-neutral-text: #4A4548;
    --field-border: #8F8A8D; --premium-text: #8A6508; --scrim: rgba(20,18,20,.4);
    --toast-bg: #141214; --toast-fg: #F4F2F2;
    --t-ok: #3CC283; --t-bad: #F0375A; --t-warn: #E8AE3A; --t-info: #6E9EF0;
    --row-alt: #F7F7F8; --row-hover: #F0F1F2;
  }
  :root[data-theme="dark"] {
    --st-ok: #3CC283; --st-warn: #E8AE3A; --st-bad: #F0375A; --st-info: #6E9EF0; --st-neutral: #8F898F;
    --st-ok-text: #3CC283; --st-warn-text: #E8AE3A; --st-bad-text: #F0375A; --st-info-text: #6E9EF0; --st-neutral-text: #C9C4C6;
    --field-border: #6E696C; --premium-text: #E0B23C; --scrim: rgba(0,0,0,.6);
    --toast-bg: #F4F2F2; --toast-fg: #141214;
    --t-ok: #157A4B; --t-bad: #C4153A; --t-warn: #8A5A00; --t-info: #2F6FDB;
    --row-alt: #1D1B1D; --row-hover: #232023;
  }
  /* S1 status: an 8 px dot and the word in a readable shade; no filled pill. */
  html .badge { gap: 6px; padding: 2px 0; border: 0 !important; background: none !important; font-size: 12px; font-weight: 600; border-radius: 0; }
  html .badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--st-neutral); }
  html .badge-green, html .badge-success, html .badge-green.solid, html .badge-teal { color: var(--st-ok-text) !important; }
  html .badge-green::before, html .badge-success::before, html .badge-teal::before { background: var(--st-ok); }
  html .badge-red, html .badge-danger, html .badge-red.solid { color: var(--st-bad-text) !important; }
  html .badge-red::before, html .badge-danger::before { background: var(--st-bad); }
  html .badge-amber, html .badge-warning, html .badge-amber.solid { color: var(--st-warn-text) !important; }
  html .badge-amber::before, html .badge-warning::before { background: var(--st-warn); }
  html .badge-blue, html .badge-info, html .badge-purple, html .badge-blue.solid { color: var(--st-info-text) !important; }
  html .badge-blue::before, html .badge-info::before, html .badge-purple::before { background: var(--st-info); }
  html .badge-gray, html .badge-neutral, html .badge-secondary { color: var(--st-neutral-text) !important; }
  html .badge > i, html .badge > svg { display: none; }
  /* M1 messages: toast on Ink (Paper in dark), bottom centre, coloured icon. */
  html #toast-container, html[dir] #toast-container { inset-inline-start: auto; inset-inline-end: auto; left: 50%; right: auto; transform: translateX(-50%); align-items: center; }
  html .toast { background: var(--toast-bg) !important; color: var(--toast-fg); border: 0 !important; border-radius: 8px; box-shadow: var(--shadow-lg);
           min-height: 48px; padding: 12px 16px; font-size: 14px; max-width: min(420px, calc(100vw - 32px)); animation: lxToastIn .2s ease-out; }
  html .toast i, html .toast svg { width: 20px; height: 20px; }
  html .toast.success i, html .toast.success svg { color: var(--t-ok); }
  html .toast.error i, html .toast.error svg { color: var(--t-bad); }
  html .toast.warning i, html .toast.warning svg { color: var(--t-warn); }
  html .toast.info i, html .toast.info svg { color: var(--t-info); }
  @keyframes lxToastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
  /* D1 dialogs: Ink scrim, no blur, 12 px corners, 200 ms fade + 98 -> 100 %; bottom sheet on phones. */
  html .modal-backdrop { background: var(--scrim); -webkit-backdrop-filter: none; backdrop-filter: none; }
  html .modal { border-radius: 12px; box-shadow: var(--shadow-lg); animation: lxDlgIn .2s ease-out; }
  html .modal-footer { border-radius: 0 0 12px 12px; }
  html .modal-header h3 { font-size: 16px; }
  html .modal-close { width: 36px; height: 36px; }
  @keyframes lxDlgIn { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
  @media (max-width: 480px) {
    html .modal-backdrop { align-items: flex-end; padding: 0; }
    html .modal { max-width: none !important; border-radius: 12px 12px 0 0; max-height: 92dvh; }
    html .modal-footer { border-radius: 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  }
  /* M1 menus */
  html .sb-acct-menu { border-radius: 8px; padding: 4px; }
  html .sb-acct-menu-item { min-height: 36px; padding: 0 10px; border-radius: 6px; font-size: 14px; color: var(--text); }
  html .sb-acct-menu-item.sb-logout { color: var(--st-bad-text); }
  html .sb-acct-menu-item.sb-logout:hover { background: rgba(224,28,64,.08); color: var(--st-bad-text); }
  html .sb-menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
  /* U1 user card: first letter in Ink on the sub-surface, readable email, premium text readable. */
  html .user-avatar { background: var(--bg-card2) !important; color: var(--text) !important; border: 1px solid var(--border); font-size: 14px; font-weight: 600; }
  html .user-email, html .user-role { color: var(--text-2) !important; font-size: 12px; }
  html .user-plan-badge { font-size: 12px; }
  html .sb-acct-btn:hover { border-color: var(--field-border); }
  /* F1 fields: 40 px, 14 px text, 3:1 border; 16 px on phones (no iOS zoom). */
  html .form-control, html input.form-input, html select.form-control { min-height: 40px; font-size: 14px; border-color: var(--field-border); }
  html textarea.form-control { font-size: 14px; border-color: var(--field-border); }
  @media (max-width: 600px) { html .form-control, html input.form-input, html select.form-control, html textarea.form-control { font-size: 16px; } }
  /* T2 tables: 36 px rows, 13 px text, stripes instead of row lines, header on the sub-surface between hairlines. */
  html .table-wrap table thead th, html table.lv-table thead th { background: var(--bg-card2); color: var(--text-2); font-size: 13px; font-weight: 600;
    padding: 8px 12px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
  html .table-wrap table tbody td, html table.lv-table tbody td { font-size: 13px; padding: 7px 12px; border-bottom: 0; height: 36px; }
  html .table-wrap table tbody tr:nth-child(even), html table.lv-table tbody tr:nth-child(even) { background: var(--row-alt); }
  html .table-wrap table tbody tr:hover, html table.lv-table tbody tr:hover { background: var(--row-hover); }
  html .table-wrap table tbody tr[onclick]:hover td:first-child { color: inherit; }
  :root[data-theme="dark"] thead th { background: var(--bg-card2); }
  html td.num, html th.num, html .td-num, html .td-mono { font-variant-numeric: tabular-nums; }
  @media (max-width: 600px) { html .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; } }
  /* Invoices list (owner 2026-10-13): one step smaller and tighter so every row action fits without sideways scrolling;
     long customer names end in an ellipsis (full name on hover), ZATCA/notes tags sit under the invoice number. */
  html #invoices-list-view table.lv-table thead th { font-size: 12px; padding: 7px 6px; }
  html #invoices-list-view table.lv-table tbody td { font-size: 12px; padding: 5px 6px; height: 34px; }
  html #invoices-list-view table.lv-table .lv-check-col { width: 30px; }
  html #invoices-list-view .inv-cust { display: inline-block; max-width: 200px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
  html #invoices-list-view .inv-num-tags { display: block; margin-top: 2px; }
  html #invoices-list-view .inv-num-tags .badge { margin-inline-start: 0 !important; margin-inline-end: 4px; }
  html #invoices-list-view .inv-row-actions { gap: 0 !important; }
  html #invoices-list-view .inv-row-actions .btn-icon.btn-sm { width: 26px; height: 26px; }
  html #invoices-list-view .inv-row-actions svg.lucide { width: 15px; height: 15px; }
  html #invoices-list-view table.lv-table .badge { font-size: 11px; }

  /* Sidebar footer (owner 2026-10-13): much smaller; privacy, terms and the support email on one line. */
  html .sb-foot-legal { font-size: 10px; gap: 4px; margin-bottom: 6px; flex-wrap: nowrap; white-space: nowrap; }
  html .sb-foot-powered { gap: 4px; }
  html .sb-foot-powered-label { font-size: 9px; letter-spacing: .3px; }
  html .sb-foot-powered-mark .lon, html .sb-foot-powered-mark .dot { font-size: 10px; }
  html .sb-foot-powered-mark .box { width: 9px; height: 9px; border-radius: 2px; }
  html .sb-foot-powered-mark .box svg { width: 5px; height: 5px; }

  /* ── 2026-10-09 pass 3: live audit fixes ── */
  :root, :root[data-theme="light"], :root[data-theme=""] { --erp-green-text: #177A55; --tag-red: #C4153A;
    /* status colours used as text across the app: readable shades on white and the sub-surface (>= 4.5:1) */
    --green: #157A4B; --success: #157A4B; --amber: #9A6200; }
  :root[data-theme="dark"] { --erp-green-text: #34D399; --tag-red: #F0375A; }
  /* Primary actions: flat Ink (Paper in dark), no gradient or glow. Literal Ink, not var(--primary): a company's
     accent colour (applyCompanyBranding) sets --primary inline, and the accent never fills a button (Brand 2.1). */
  html .btn-primary, html .btn-solid { background: #141214 !important; color: #FFFFFF !important; box-shadow: none !important; border-color: #141214 !important; }
  html .btn-primary:hover, html .btn-solid:hover { background: #141214 !important; box-shadow: none !important; opacity: .88; }
  :root[data-theme="dark"] .btn-primary, :root[data-theme="dark"] .btn-solid { background: #F4F2F2 !important; border-color: #F4F2F2 !important; }
  :root[data-theme="dark"] .btn-primary, :root[data-theme="dark"] .btn-solid { color: #141214 !important; }
  /* Welcome banner: flat Ink card, no gradient */
  html .dash-banner { background: #141214; }
  :root[data-theme="dark"] .dash-banner { background: #1D1B1D; border: 1px solid var(--border); }
  /* Small coloured labels in readable shades (4.5:1) */
  html .co-tag { color: var(--tag-red); }
  html .topbar-plan-link { color: var(--erp-green-text); }
  html .user-plan-badge.premium { color: var(--premium-text); background: rgba(224,178,60,.14); }
  html .kv2-badge.up { color: var(--st-ok-text); }
  html .kv2-badge.down { color: var(--st-bad-text); }
  html .kv2-badge.neutral { color: var(--text-2); }
  html #page-dashboard .kv2-badge.up { color: var(--st-ok-text); }
  html #page-dashboard .kv2-badge.down { color: var(--st-bad-text); }
  html #page-dashboard .kv2-badge::before { width: 8px; height: 8px; }
  html .zatca-off { color: var(--text-2) !important; }
  html .text-red, html .pl-negative { color: var(--st-bad-text) !important; }
  html .text-green, html .pl-positive { color: var(--st-ok-text) !important; }

  /* ── Phones (FIX-17, 2026-10-09): top bar keeps launcher, theme, language and notifications on screen
     (plan link, install, ESS, website and sign-out live in the sidebar and the account menu); no page scrolls sideways. */
  @media (max-width: 600px) {
    html .topbar-actions { gap: 6px; flex-shrink: 0; }
    html .topbar-actions > .topbar-plan-link, html .topbar-actions > .pwa-install-btn,
    html .topbar-actions > .topbar-btn:not(#theme-toggle), html #pwa-install-btn, html .topbar-pwa-btn { display: none !important; }
    html .topbar-page { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    html .grid-2 > *, html .grid-3 > *, html .grid-4 > * { min-width: 0; }
    html .chart-wrap { max-width: 100%; }
    html .bi-report-panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    html .settings-shell { flex-direction: column; }
    html .settings-content { min-width: 0; width: 100%; }
    html .settings-panel > div:first-child { flex-wrap: wrap; }
    /* any table not already inside a scroll box scrolls inside its own parent, never the page */
    html div:has(> table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    html .bi-report-tabs { overflow-x: auto; flex-wrap: nowrap; }
  }

  /* ── LONX top-bar standard (owner 2026-10-10): 34 px square buttons, 7 px corners, 1 px grey edge, 16 px icons;
     language button reads EN / ع; start side = menu, page title, search ── */
  html .topbar-page { flex: 0 1 auto; margin-inline-end: 16px; }
  html .topbar-actions { gap: 6px; }
  html .topbar-actions .topbar-btn, html .topbar-actions .lang-btn, html .topbar-actions .topbar-pwa-btn {
    display: inline-flex; align-items: center; justify-content: center; position: relative; width: 34px; height: 34px; min-width: 34px; padding: 0;
    border-radius: 7px; border: 1px solid #8F8A8D; background: var(--bg-card); color: #4A4548; box-shadow: none; text-decoration: none; }
  html .topbar-actions .topbar-btn svg, html .topbar-actions .topbar-pwa-btn svg { width: 16px; height: 16px; }
  html .topbar-actions .topbar-btn:hover, html .topbar-actions .lang-btn:hover, html .topbar-actions .topbar-pwa-btn:hover { border-color: var(--text); color: var(--text); background: var(--bg-card2); }
  :root[data-theme="dark"] .topbar-actions .topbar-btn, :root[data-theme="dark"] .topbar-actions .lang-btn, :root[data-theme="dark"] .topbar-actions .topbar-pwa-btn { border-color: #6E696C; color: #C9C4C6; }
  html .topbar-actions .lang-btn { font-size: 13px; font-weight: 600; font-family: 'Inter', 'Cairo', sans-serif; gap: 0; }
}
