  :root {
    /* Tact brand — Light theme (white + Tact Dark tints, per brand guidelines) */
    --bg: #F5F5F5;
    --surface: #FFFFFF;
    --surface-2: #F0F0F0;
    --border: #E5E5E5;
    --border-strong: #CDCDCE;
    --ink: #282829;              /* Tact Dark #282829 (Pantone 179-15 C) */
    --ink-muted: #58585A;
    --ink-subtle: #8C8C8E;
    --accent: #F15D2A;           /* Tact Orange #F15D2A (Pantone 37-08 C) */
    --accent-soft: #FDE1D2;
    --positive: #4CC0AF;         /* Tact Teal #4CC0AF (Pantone 130-05 C) */
    --positive-soft: #DEF2EE;
    --negative: #B23A48;
    --negative-soft: #F5DEE1;
    --warning: #FFC63E;          /* Tact Yellow #FFC63E (Pantone 10-07 C) */
    --warning-soft: #FFF1CE;
    --secondary: #32004B;        /* Tact Purple #32004B (Pantone 95-16 C) */
    --secondary-soft: #E7DAF0;

    /* Aging buckets — Tact sequential (safe → urgent) */
    --bucket-1: #4CC0AF;         /* Teal — within terms */
    --bucket-2: #FFC63E;         /* Yellow — mild delay */
    --bucket-3: #F15D2A;         /* Orange — needs follow-up */
    --bucket-4: #B23A48;         /* Red — active collection */
    --bucket-5: #32004B;         /* Purple — urgent / legal */

    /* Tact brand typeface — Readex Pro for Arabic & English */
    --font-display: "Readex Pro", "Segoe UI", sans-serif;
    --font-body: "Readex Pro", "Segoe UI", sans-serif;
    --font-mono: "Readex Pro", ui-monospace, monospace;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      /* Tact brand — Dark theme (built on Tact Dark #282829) */
      --bg: #1E1E1F;
      --surface: #282829;        /* Tact Dark */
      --surface-2: #313132;
      --border: #3B3B3D;
      --border-strong: #505052;
      --ink: #F5F5F5;
      --ink-muted: #B2B2B4;
      --ink-subtle: #7E7E81;
      --accent: #F15D2A;         /* Tact Orange stays vivid on dark */
      --accent-soft: #401E11;
      --positive: #4CC0AF;       /* Tact Teal */
      --positive-soft: #143128;
      --negative: #E06977;
      --negative-soft: #35222A;
      --warning: #FFC63E;        /* Tact Yellow */
      --warning-soft: #3E3316;
      --secondary: #B98CE0;      /* Purple lightened for dark ground */
      --secondary-soft: #2A1A3B;
      --bucket-1: #4CC0AF;
      --bucket-2: #FFC63E;
      --bucket-3: #F15D2A;
      --bucket-4: #E06977;
      --bucket-5: #B98CE0;
    }
  }
  :root[data-theme="dark"] {
    --bg: #1E1E1F;
    --surface: #282829;    
    --surface-2: #313132;
    --border: #3B3B3D;
    --border-strong: #505052;
    --ink: #F5F5F5;
    --ink-muted: #B2B2B4;
    --ink-subtle: #7E7E81;
    --accent: #F15D2A;
    --accent-soft: #401E11;
    --positive: #4CC0AF;
    --positive-soft: #143128;
    --negative: #E06977;
    --negative-soft: #35222A;
    --warning: #FFC63E;
    --warning-soft: #3E3316;
    --secondary: #B98CE0;
    --secondary-soft: #2A1A3B;
    --bucket-1: #4CC0AF;
    --bucket-2: #FFC63E;
    --bucket-3: #F15D2A;
    --bucket-4: #E06977;
    --bucket-5: #B98CE0;
  }

  * { box-sizing: border-box; }
  body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
    margin: 0;
  }
  html[dir="rtl"] body { direction: rtl; }
  html[dir="ltr"] body { direction: ltr; }
  html[lang="en"] body {
    font-family: var(--font-body);
  }
  html[lang="en"] .kpi-value,
  html[lang="en"] .card-title,
  html[lang="en"] .header-title,
  html[lang="en"] .lock-title {
    font-family: var(--font-body);
  }
  /* Flip position for LTR */
  html[dir="ltr"] .theme-toggle { left: auto; right: 20px; }
  html[dir="ltr"] .eye-btn { left: auto; right: 8px; }
  html[dir="ltr"] .pw-wrap input { padding-inline-end: 14px !important; padding-inline-start: 44px !important; }

  .app {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 28px 48px;
    display: flex;
    flex-direction: column;
    gap: 24px;
  }

  /* Header */
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
  }
  .header-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 24px;
    letter-spacing: -0.01em;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 12px;
  }
  /* Brand lockup — tact sub-logo "tact FINANCIAL ANALYSIS." */
  .brand-block { display: flex; align-items: center; gap: 18px; }
  .brand-lockup {
    display: inline-flex; align-items: flex-end; gap: 8px;
    direction: ltr; text-decoration: none; color: var(--ink-muted);
    flex-shrink: 0;
  }
  .brand-mark { height: 40px; width: calc(40px * 281.09 / 109.36); display: block; }
  .brand-sub {
    font-family: var(--font-body); font-weight: 400; font-size: 13px;
    letter-spacing: 0.04em; line-height: 1; padding-bottom: 2px;
    color: var(--ink-muted);
  }
  .brand-dot { color: var(--accent); font-weight: 700; }
  .brand-divider { width: 1px; align-self: stretch; background: var(--border-strong); min-height: 40px; }
  .header-subtitle { color: var(--ink-muted); font-size: 14px; margin-top: 4px; }
  .header-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
  .header-tools { display: flex; gap: 8px; align-items: center; }
  .icon-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink);
    padding: 8px 14px;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
  }
  .icon-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
  .icon-btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .icon-btn.primary:hover { opacity: 0.9; background: var(--ink); }
  .user-chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 12px 6px 6px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; font-size: 12px; color: var(--ink-muted);
  }
  .user-chip .avatar {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--accent); color: var(--bg);
    display: grid; place-items: center;
    font-size: 11px; font-weight: 700;
  }
  .last-updated { font-size: 12px; color: var(--ink-subtle); font-family: var(--font-mono); }

  /* KPI Row */
  .kpi-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  }
  .kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 22px;
    display: flex; flex-direction: column; gap: 8px;
  }
  /* Primary KPI tile: Tact Dark on light theme, Tact Orange on dark theme (brand 35/35 split) */
  .kpi.primary { background: #282829; border-color: #282829; color: #FFFFFF; }
  html[data-theme="dark"] .kpi.primary { background: #F15D2A; border-color: #F15D2A; }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .kpi.primary { background: #F15D2A; border-color: #F15D2A; }
  }
  .kpi.alert { border-right: 3px solid var(--negative); }
  .kpi-label {
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--ink-subtle); font-weight: 500;
  }
  .kpi.primary .kpi-label { color: rgba(255,255,255,0.75); }
  .kpi-value {
    font-family: var(--font-display); font-weight: 700; font-size: 30px;
    letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
    color: var(--ink); line-height: 1.1; direction: ltr; text-align: right;
  }
  .kpi.primary .kpi-value { color: #FFFFFF; }
  .kpi.alert .kpi-value { color: var(--negative); }
  .kpi-value .currency, .kpi-value .unit {
    font-family: var(--font-body); font-weight: 500; font-size: 14px;
    color: var(--ink-muted); margin-inline-start: 6px;
  }
  .kpi.primary .kpi-value .currency, .kpi.primary .kpi-value .unit { color: rgba(255,255,255,0.8); }
  .kpi.alert .kpi-value .currency { color: var(--ink-muted); }
  /* المقدم بالأخضر (المستحق بالأحمر عبر .alert) */
  .kpi.good { border-right: 3px solid var(--positive); }
  .kpi.good .kpi-value { color: var(--positive); }
  .kpi.good .kpi-value .currency { color: var(--ink-muted); }
  .kpi-sub {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-muted);
  }
  .kpi.primary .kpi-sub { color: rgba(255,255,255,0.8); }

  /* Main grid */
  .main-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; }
  .card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 22px 24px;
  }
  .card-head {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 20px; gap: 16px;
  }
  .card-title {
    font-family: var(--font-display); font-weight: 700; font-size: 17px;
    letter-spacing: -0.01em; color: var(--ink);
  }
  .card-subtitle { font-size: 12px; color: var(--ink-subtle); margin-top: 2px; }

  /* Aging */
  .aging-summary {
    display: flex; height: 40px; border-radius: 8px; overflow: hidden; margin-bottom: 20px;
  }
  .aging-summary div {
    display: grid; place-items: center; color: #fff;
    font-family: var(--font-mono); font-size: 12px; font-weight: 500;
    transition: width .3s ease;
  }
  .aging-legend {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
  }
  .aging-cell {
    padding: 14px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); display: flex; flex-direction: column; gap: 6px;
  }
  .aging-cell .top {
    display: flex; align-items: center; gap: 8px;
    font-size: 11px; color: var(--ink-subtle);
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .aging-cell .dot { width: 10px; height: 10px; border-radius: 3px; }
  .aging-cell .amount {
    font-family: var(--font-display); font-weight: 700; font-size: 18px;
    font-variant-numeric: tabular-nums; color: var(--ink);
    direction: ltr; text-align: right;
  }
  .aging-cell .count { font-size: 11px; color: var(--ink-muted); font-family: var(--font-mono); }

  /* Chart */
  .chart-container { width: 100%; overflow-x: auto; }
  svg { display: block; max-width: 100%; }
  .chart-legend { display: flex; gap: 16px; font-size: 12px; }
  .legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); }
  .legend-swatch { width: 10px; height: 10px; border-radius: 2px; }

  /* Debtors table */
  .table-wrap { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; font-size: 13px; }
  thead th {
    text-align: right; font-weight: 500; color: var(--ink-subtle);
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
    padding: 0 12px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
  }
  thead th.num { text-align: left; }
  tbody td {
    padding: 14px 12px; border-bottom: 1px solid var(--border);
    color: var(--ink); vertical-align: middle;
  }
  tbody tr:last-child td { border-bottom: 0; }
  tbody td.num {
    font-family: var(--font-mono); font-variant-numeric: tabular-nums;
    direction: ltr; text-align: left; font-weight: 500;
  }
  .client-cell { display: flex; align-items: center; gap: 12px; }
  .client-avatar {
    width: 34px; height: 34px; border-radius: 8px; background: var(--surface-2);
    display: grid; place-items: center;
    font-family: var(--font-display); font-weight: 700; font-size: 13px;
    color: var(--ink-muted); flex-shrink: 0;
  }
  .client-name { font-weight: 500; }
  .client-sub { font-size: 11px; color: var(--ink-subtle); margin-top: 1px; font-family: var(--font-mono); }
  .risk-pill {
    display: inline-flex; align-items: center; padding: 3px 9px;
    border-radius: 999px; font-size: 11px; font-weight: 500; gap: 5px;
  }
  .risk-pill::before {
    content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  }
  .risk-low { background: var(--positive-soft); color: var(--positive); }
  .risk-med { background: var(--warning-soft); color: var(--warning); }
  .risk-high { background: var(--negative-soft); color: var(--negative); }
  .overdue-days {
    font-family: var(--font-mono); font-size: 12px; color: var(--ink-muted); direction: ltr;
  }
  .overdue-days.late { color: var(--negative); font-weight: 500; }

  /* DSO card */
  .dso-card { display: flex; flex-direction: column; gap: 18px; }
  .dso-figure { display: flex; align-items: baseline; gap: 8px; }
  .dso-value {
    font-family: var(--font-display); font-weight: 700; font-size: 44px;
    letter-spacing: -0.02em; color: var(--ink);
    font-variant-numeric: tabular-nums; line-height: 1;
  }
  .dso-unit { font-size: 14px; color: var(--ink-muted); }
  .dso-note {
    font-size: 12px; color: var(--ink-subtle);
    padding: 10px 12px; background: var(--surface-2);
    border-radius: 8px; line-height: 1.6;
  }
  .dso-note b { color: var(--ink); font-weight: 500; }

  .lower-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

  .section-title {
    font-family: var(--font-display); font-weight: 700; font-size: 13px;
    color: var(--ink-subtle); text-transform: uppercase; letter-spacing: 0.08em;
    margin-top: 4px;
  }

  /* Lock screen */
  #lock {
    position: fixed; inset: 0; background: var(--bg);
    display: grid; place-items: center; z-index: 9999;
  }
  .lock-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 36px 32px;
    width: min(400px, 92vw);
    display: flex; flex-direction: column; gap: 14px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.08);
  }
  .lock-logo {
    display: block; height: 46px; width: calc(46px * 418.09 / 109.36);
    color: var(--ink); direction: ltr; margin-bottom: 10px;
  }
  .lock-logo { align-self: flex-start; }   /* start edge in both RTL & LTR */
  #lock .brand-shapes {
    position: fixed; top: auto; transform: none;
    bottom: 32px; inset-inline-end: 32px; opacity: 0.9;
  }
  @media (max-width: 900px) { #lock .brand-shapes { display: none; } }
  /* أثناء استرجاع الجلسة المحفوظة: الشعار ومؤشر تحميل بدل وميض النموذج */
  body.auth-checking #lock .lock-card > :not(.lock-logo) { display: none; }
  body.auth-checking #lock .lock-card { align-items: center; }
  body.auth-checking #lock .lock-logo { align-self: center; margin-bottom: 0; }
  body.auth-checking #lock .lock-card::after {
    content: ""; width: 26px; height: 26px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--accent);
    animation: auth-spin .8s linear infinite;
  }
  @keyframes auth-spin { to { transform: rotate(360deg); } }
  .lock-title {
    font-family: var(--font-display); font-weight: 700; font-size: 20px;
    color: var(--ink); letter-spacing: -0.01em;
  }
  .lock-sub { font-size: 13px; color: var(--ink-muted); margin-top: -8px; margin-bottom: 4px; }
  .field { display: flex; flex-direction: column; gap: 6px; }
  .field label {
    font-size: 12px; color: var(--ink-muted); font-weight: 500;
  }
  .field input {
    padding: 11px 14px;
    border: 1px solid var(--border-strong);
    border-radius: 8px; background: var(--bg); color: var(--ink);
    font-family: var(--font-body); font-size: 14px;
    outline: none; transition: border-color .15s;
    width: 100%;
  }
  .field input[type="email"], .field input[type="password"] { direction: ltr; text-align: right; }
  .field input:focus { border-color: var(--accent); }
  .field input.err { border-color: var(--negative); animation: shake .3s; }
  @keyframes shake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
  }
  .btn {
    padding: 12px; border: 0; border-radius: 8px;
    background: var(--ink); color: var(--bg);
    font-family: var(--font-body); font-weight: 500; font-size: 14px;
    cursor: pointer; transition: opacity .15s;
  }
  .btn:hover { opacity: 0.9; }
  .btn.ghost {
    background: transparent; color: var(--ink-muted);
    border: 1px solid var(--border);
  }
  .btn.ghost:hover { color: var(--ink); border-color: var(--border-strong); }
  .btn.danger { background: var(--negative); }
  .lock-err {
    font-size: 12px; color: var(--negative); text-align: center; min-height: 16px;
  }
  body.locked { overflow: hidden; }
  body.locked .app { visibility: hidden; }

  /* OTP screen */
  #otp {
    position: fixed; inset: 0;
    background: var(--bg);
    display: none;
    place-items: center;
    z-index: 9998;
    padding: 20px;
  }
  #otp.open { display: grid; }
  #otp .lock-card { width: min(420px, 92vw); }
  #otp .otp-logo { align-self: center; }
  #otp-input {
    padding: 14px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.5em;
    direction: ltr;
    outline: none;
    transition: border-color .15s;
    width: 100%;
    box-sizing: border-box;
  }
  #otp-input:focus { border-color: var(--accent); }
  #otp-input.err {
    border-color: var(--negative);
    animation: shake .3s;
  }
  .otp-info {
    font-size: 12px;
    color: var(--ink-muted);
    text-align: center;
    line-height: 1.7;
  }
  .otp-info b { color: var(--ink); font-family: var(--font-mono); direction: ltr; display: inline-block; }
  .otp-actions {
    display: flex; gap: 10px; align-items: center; justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
  }
  .otp-timer {
    font-size: 11px;
    color: var(--ink-subtle);
    font-family: var(--font-mono);
    direction: ltr;
  }

  /* Language toggle — same visual family as theme toggle */
  .lang-toggle {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    gap: 2px;
  }
  .lang-toggle button {
    background: transparent;
    border: 0;
    padding: 6px 12px;
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-muted);
    cursor: pointer;
    transition: all .15s;
  }
  .lang-toggle button:hover { color: var(--ink); }
  .lang-toggle button.active {
    background: var(--ink);
    color: var(--bg);
  }
  .lock-toolbar {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 10000;
    display: inline-flex;
    gap: 8px;
    align-items: center;
  }
  html[dir="ltr"] .lock-toolbar { left: auto; right: 20px; }

  /* Theme toggle */
  .theme-toggle {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    gap: 2px;
  }
  .theme-toggle button {
    background: transparent;
    border: 0;
    padding: 6px 12px;
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--ink-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all .15s;
  }
  .theme-toggle button:hover { color: var(--ink); }
  .theme-toggle button.active {
    background: var(--ink);
    color: var(--bg);
  }

  /* Password field wrapper for eye toggle */
  .pw-wrap {
    position: relative;
  }
  .pw-wrap input {
    padding-inline-end: 44px !important;
  }
  .eye-btn {
    position: absolute;
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    color: var(--ink-subtle);
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    line-height: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color .15s, background .15s;
  }
  .eye-btn svg { display: block; }
  .eye-btn:hover { color: var(--ink); background: var(--surface-2); }
  .eye-btn:focus { outline: none; color: var(--accent); }

  /* Forgot password link */
  .lock-actions {
    display: flex;
    justify-content: center;
    padding-top: 4px;
  }
  .link-btn {
    background: transparent;
    border: 0;
    color: var(--accent);
    font-family: var(--font-body);
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    text-decoration: none;
  }
  .link-btn:hover { text-decoration: underline; }

  /* Reset password inline form */
  .reset-form {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
    margin-top: 8px;
  }
  .reset-form.open { display: flex; }
  .reset-form .hint {
    font-size: 12px;
    color: var(--ink-muted);
    line-height: 1.5;
  }
  .reset-msg { font-size: 12px; text-align: center; min-height: 16px; }

  /* Editor drawer */
  #editor-backdrop {
    position: fixed; inset: 0; background: rgba(15,20,25,0.4);
    z-index: 998; display: none; opacity: 0; transition: opacity .2s;
  }
  #editor-backdrop.open { display: block; opacity: 1; }
  #editor {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(520px, 95vw);
    background: var(--bg);
    border-left: 1px solid var(--border);
    z-index: 999;
    transform: translateX(-100%);
    transition: transform .25s ease;
    display: flex; flex-direction: column;
  }
  #editor.open { transform: translateX(0); }
  .editor-head {
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--surface);
  }
  .editor-head h2 {
    font-family: var(--font-display); font-weight: 700; font-size: 18px;
    margin: 0; color: var(--ink);
  }
  .close-btn {
    background: transparent; border: 0; color: var(--ink-muted);
    font-size: 24px; cursor: pointer; padding: 0 6px; line-height: 1;
  }
  .close-btn:hover { color: var(--ink); }
  .editor-body {
    flex: 1; overflow-y: auto; padding: 20px 24px;
    display: flex; flex-direction: column; gap: 22px;
  }
  .editor-section {
    display: flex; flex-direction: column; gap: 10px;
  }
  .editor-section h3 {
    font-family: var(--font-display); font-weight: 700; font-size: 13px;
    text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--ink-subtle); margin: 0 0 4px;
  }
  .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .row-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; }
  .editor-foot {
    padding: 16px 24px; border-top: 1px solid var(--border);
    background: var(--surface);
    display: flex; gap: 10px; justify-content: space-between;
  }
  .editor-foot .actions { display: flex; gap: 10px; }
  .debtor-editor {
    padding: 12px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; display: flex; flex-direction: column; gap: 8px;
  }
  .debtor-editor .row-4 {
    display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px;
  }
  .small-input {
    padding: 8px 10px; font-size: 13px; border: 1px solid var(--border-strong);
    border-radius: 6px; background: var(--bg); color: var(--ink);
    font-family: var(--font-body); outline: none; width: 100%;
  }
  .small-input.num {
    font-family: var(--font-mono); direction: ltr; text-align: left;
    font-variant-numeric: tabular-nums;
  }
  .small-input:focus { border-color: var(--accent); }
  .del-btn {
    background: transparent; border: 0; color: var(--negative);
    cursor: pointer; padding: 6px 10px; font-size: 18px; line-height: 1;
    border-radius: 6px;
  }
  .del-btn:hover { background: var(--negative-soft); }
  .add-debtor {
    padding: 10px; border: 1px dashed var(--border-strong);
    background: transparent; color: var(--ink-muted);
    border-radius: 8px; cursor: pointer; font-family: var(--font-body); font-size: 13px;
  }
  .add-debtor:hover { border-color: var(--accent); color: var(--accent); }

  @media (max-width: 960px) {
    .app { padding: 20px 16px 32px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .aging-legend { grid-template-columns: repeat(2, 1fr); }
    .main-grid, .lower-grid { grid-template-columns: 1fr; }
    .header-title { font-size: 20px; }
    .brand-block { gap: 12px; }
    .brand-mark { height: 30px; width: calc(30px * 281.09 / 109.36); }
    .brand-sub { font-size: 11px; }
    .header-subtitle { display: none; }
    .header-actions { width: 100%; align-items: stretch; }
    .header-tools { flex-wrap: wrap; justify-content: flex-start; }
    #user-email { display: none; }
    .home-hero { padding: 24px 18px; }
    .home-hero h1 { font-size: 22px; }
    .app-footer { flex-wrap: wrap; }
    .kpi-value { font-size: 24px; }
    .dso-value { font-size: 34px; }
  }
  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }

  /* Details modal */
  .clickable {
    cursor: pointer;
    transition: opacity .15s;
    position: relative;
  }
  .clickable:hover { opacity: 0.82; }
  .clickable::after {
    content: "↗";
    font-size: 10px;
    color: var(--ink-subtle);
    margin-inline-start: 4px;
    opacity: 0;
    transition: opacity .15s;
  }
  .clickable:hover::after { opacity: 0.7; }
  tr.clickable-row { cursor: pointer; transition: background .15s; }
  tr.clickable-row:hover td { background: var(--surface-2); }

  #details-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,20,25,0.55);
    z-index: 1500;
    display: none; opacity: 0;
    transition: opacity .2s;
  }
  #details-backdrop.open { display: block; opacity: 1; }
  #details-modal {
    position: fixed; inset: 0;
    z-index: 1501;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 20px;
    pointer-events: none;
  }
  #details-modal.open { display: flex; }
  #details-modal .modal-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: min(920px, 100%);
    max-height: 90vh;
    display: flex; flex-direction: column;
    overflow: hidden;
    pointer-events: auto;
    box-shadow: 0 25px 60px rgba(0,0,0,0.15);
    transform: translateY(10px);
    opacity: 0;
    transition: transform .2s, opacity .2s;
  }
  #details-modal.open .modal-card { transform: translateY(0); opacity: 1; }
  .modal-head {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 16px;
  }
  .modal-head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 17px;
    color: var(--ink);
    letter-spacing: -0.01em;
  }
  .modal-head .sub {
    font-size: 12px;
    color: var(--ink-muted);
    margin-top: 3px;
  }
  .modal-body {
    padding: 18px 22px;
    overflow-y: auto;
    flex: 1;
  }
  .detail-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 18px;
  }
  .detail-summary .tile {
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  .detail-summary .tile .lbl {
    font-size: 11px;
    color: var(--ink-subtle);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
  }
  .detail-summary .tile .val {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    direction: ltr;
    text-align: right;
  }
  .invoice-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 18px;
  }
  .invoice-detail-grid .fld { display: flex; flex-direction: column; gap: 4px; }
  .invoice-detail-grid .fld .lbl {
    font-size: 11px;
    color: var(--ink-subtle);
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }
  .invoice-detail-grid .fld .val {
    font-size: 14px;
    color: var(--ink);
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    min-height: 20px;
    word-break: break-word;
  }
  .invoice-detail-grid .fld.wide { grid-column: 1 / -1; }
  .invoice-detail-grid .fld .val.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    direction: ltr;
    text-align: right;
  }

  /* Page tabs */
  .page-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
  }
  .page-tabs button {
    flex: 1;
    background: transparent;
    border: 0;
    padding: 10px 18px;
    border-radius: 7px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    color: var(--ink-muted);
    cursor: pointer;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  .page-tabs button .icn {
    font-size: 15px;
    opacity: 0.85;
  }
  .page-tabs button:hover { color: var(--ink); }
  .page-tabs button.active {
    background: var(--ink);
    color: var(--bg);
  }

  /* Projects specific */
  .kpi-grid-5 {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px;
  }
  .kpi-grid-5 .kpi { padding: 18px 16px; min-width: 0; }
  .kpi-grid-5 .kpi-value { font-size: clamp(18px, 1.7vw, 26px); white-space: nowrap; }
  @media (max-width: 1280px) {
    .kpi-grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .kpi-grid-5 .kpi-value { font-size: 24px; }
  }
  @media (max-width: 720px) {
    .kpi-grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-grid-5 .kpi-value { font-size: 20px; }
  }
  .project-progress {
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 4px;
  }
  .project-progress span {
    display: block;
    height: 100%;
    background: var(--positive);
    border-radius: 3px;
  }
  .project-progress.med span { background: var(--warning); }
  .project-progress.low span { background: var(--negative); }

  /* Home page — landing */
  .home-hero {
    padding: 34px 30px;
    /* Tact identity: solid Tact Dark ground + primary geometric patterns */
    background: #282829;
    color: #FFFFFF;
    border-radius: 14px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
  }
  .home-hero > :not(.brand-shapes) { position: relative; z-index: 1; }
  .brand-shapes {
    position: absolute;
    inset-inline-end: 32px;
    top: 50%;
    transform: translateY(-50%);
    width: 240px; height: 160px;
    pointer-events: none;
  }
  @media (min-width: 901px) {
    .home-hero { padding-inline-end: 304px; }
  }
  @media (max-width: 900px) {
    .brand-shapes { display: none; }
  }
  html[data-theme="dark"] .home-hero { border: 1px solid var(--border); }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .home-hero { border: 1px solid var(--border); }
  }
  .home-hero h1 {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 28px;
    letter-spacing: -0.02em;
    margin: 0 0 6px;
  }
  .home-hero p {
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    margin: 0;
  }

  /* AI Assistant widget on hero */
  .ai-widget {
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 16px;
    margin-top: 14px;
  }
  .ai-widget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
  }
  .ai-widget-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #FFFFFF;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 14px;
  }
  .ai-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    background: var(--accent);
    color: #1a1a1a;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
  }
  .ai-quota-chip {
    font-size: 11px;
    color: rgba(255,255,255,0.75);
    font-family: var(--font-mono);
    background: rgba(0,0,0,0.25);
    padding: 4px 10px;
    border-radius: 999px;
  }
  .ai-quota-chip b { color: var(--accent); font-weight: 600; }
  .ai-clear-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.85);
    font-family: var(--font-body);
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: all .15s;
  }
  .ai-clear-btn:hover {
    background: var(--negative);
    border-color: var(--negative);
    color: #fff;
  }
  .ai-clear-btn svg { flex-shrink: 0; }
  .ai-input-row {
    display: flex;
    gap: 8px;
  }
  .ai-input-row input {
    flex: 1;
    background: rgba(255,255,255,0.95);
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 11px 14px;
    font-family: var(--font-body);
    font-size: 13px;
    color: #1a2332;
    outline: none;
    min-width: 0;
  }
  .ai-input-row input:focus { border-color: var(--accent); }
  .ai-input-row input:disabled { opacity: 0.5; }
  .ai-submit {
    background: var(--accent);
    color: #1a1a1a;
    border: 0;
    border-radius: 8px;
    padding: 0 18px;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: opacity .15s;
  }
  .ai-submit:hover { opacity: 0.9; }
  .ai-submit:disabled { opacity: 0.4; cursor: not-allowed; }

  .ai-thread {
    margin-top: 12px;
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
  }
  .ai-thread:empty { display: none; }
  .ai-msg {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.6;
    max-width: 92%;
  }
  .ai-msg.q {
    background: rgba(255,255,255,0.15);
    color: #FFFFFF;
    align-self: flex-end;
    font-weight: 500;
  }
  .ai-msg.a {
    background: rgba(0,0,0,0.35);
    color: rgba(255,255,255,0.95);
    align-self: flex-start;
    border-inline-start: 3px solid var(--accent);
  }
  .ai-msg.a .ai-a-title {
    font-weight: 600;
    font-size: 12px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
    display: block;
  }
  .ai-msg.a b { color: var(--accent); font-family: var(--font-mono); font-variant-numeric: tabular-nums; direction: ltr; display: inline-block; }
  .ai-msg.a ul { margin: 6px 0 0; padding-inline-start: 20px; }
  .ai-msg.a li { margin: 2px 0; }
  .ai-msg.a.err { border-inline-start-color: var(--negative); color: rgba(255,200,200,0.9); }
  .home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
  }
  .home-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    overflow: hidden;
  }
  .home-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: 0 12px 32px rgba(0,0,0,0.08);
  }
  .home-card::before {
    content: "";
    position: absolute;
    top: 0;
    inset-inline-start: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    transform: scaleY(0);
    transition: transform 0.2s;
    transform-origin: top;
  }
  .home-card:hover::before { transform: scaleY(1); }
  .home-card .icn {
    width: 44px; height: 44px;
    color: var(--accent);
    line-height: 0;
  }
  .home-card .icn svg { width: 100%; height: 100%; display: block; }
  .home-card h3 {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin: 0;
  }
  .home-card .desc {
    font-size: 13px;
    color: var(--ink-muted);
    line-height: 1.6;
    flex: 1;
  }
  .home-card .stat {
    padding: 12px 14px;
    background: var(--surface-2);
    border-radius: 10px;
  }
  .home-card .stat .lbl {
    font-size: 11px;
    color: var(--ink-subtle);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
  }
  .home-card .stat .val {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    direction: ltr;
    text-align: end;
    line-height: 1.1;
  }
  .home-card .stat .val .unit {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 12px;
    color: var(--ink-muted);
    margin-inline-start: 4px;
  }
  .home-card .cta {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
    margin-top: 4px;
  }
  .home-card .cta .arrow {
    font-family: var(--font-mono);
    transition: transform 0.15s;
  }
  html[dir="ltr"] .home-card .cta .arrow { transform: scaleX(-1); }
  .home-card:hover .cta .arrow { transform: translateX(-3px); }
  html[dir="ltr"] .home-card:hover .cta .arrow { transform: scaleX(-1) translateX(-3px); }

  /* Report permission chips (Settings > Accounts) */
  .perm-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all .12s;
    user-select: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--ink-muted);
  }
  .perm-chip:hover { border-color: var(--border-strong); }
  .perm-chip.on {
    background: var(--positive-soft);
    border-color: var(--positive);
    color: var(--positive);
  }
  .perm-chip.off {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--ink-subtle);
    opacity: 0.6;
  }
  .perm-chip:has(input:disabled) {
    cursor: not-allowed;
    opacity: 0.7;
  }

  /* Chart cards */
  .charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
  }
  .chart-card { min-height: 320px; display: flex; flex-direction: column; }
  .chart-card canvas { flex: 1; min-height: 260px; max-height: 320px; }
  .chart-card .card-head { margin-bottom: 8px; }

  /* Column sorting */
  th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: color .12s;
  }
  th.sortable:hover { color: var(--ink); }
  th.sortable::after {
    content: "↕";
    font-size: 10px;
    opacity: 0.35;
    margin-inline-start: 4px;
  }
  th.sortable.sort-asc::after  { content: "▲"; opacity: 1; color: var(--accent); }
  th.sortable.sort-desc::after { content: "▼"; opacity: 1; color: var(--accent); }

  /* Global search modal */
  #search-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,20,25,0.55);
    z-index: 1900;
    display: none; opacity: 0;
    transition: opacity .15s;
  }
  #search-backdrop.open { display: block; opacity: 1; }
  #search-modal {
    position: fixed;
    top: 12vh;
    inset-inline-start: 50%;
    transform: translateX(-50%) translateY(-10px);
    width: min(640px, 92vw);
    max-height: 70vh;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    z-index: 1901;
    display: none; opacity: 0;
    box-shadow: 0 25px 60px rgba(0,0,0,0.25);
    transition: opacity .15s, transform .15s;
    overflow: hidden;
    flex-direction: column;
  }
  html[dir="ltr"] #search-modal { transform: translateX(-50%) translateY(-10px); }
  #search-modal.open {
    display: flex; opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  #search-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  #search-input-wrap .icn { color: var(--ink-subtle); font-size: 16px; }
  #search-input {
    flex: 1;
    background: transparent;
    border: 0;
    outline: none;
    font-family: var(--font-body);
    font-size: 15px;
    color: var(--ink);
    padding: 4px 0;
  }
  #search-input::placeholder { color: var(--ink-subtle); }
  #search-hint-key {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--ink-subtle);
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
  }
  #search-results {
    overflow-y: auto;
    padding: 6px;
    max-height: calc(70vh - 60px);
  }
  .search-result {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .12s;
  }
  .search-result:hover, .search-result.active {
    background: var(--surface-2);
  }
  .search-result .kind {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--surface-2);
    display: grid; place-items: center;
    flex-shrink: 0;
    font-size: 15px;
  }
  .search-result.active .kind { background: var(--accent-soft); }
  .search-result .body { flex: 1; min-width: 0; }
  .search-result .title {
    font-size: 13px; font-weight: 500; color: var(--ink);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .search-result .sub {
    font-size: 11px; color: var(--ink-subtle);
    margin-top: 2px;
  }
  .search-result .amount {
    font-family: var(--font-mono);
    font-size: 12px; font-weight: 500;
    color: var(--ink-muted);
    direction: ltr;
    flex-shrink: 0;
  }
  .search-group-title {
    padding: 8px 14px 4px;
    font-size: 10px;
    color: var(--ink-subtle);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }
  .search-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--ink-subtle);
    font-size: 13px;
  }

  /* Footer */
  .app-footer {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    margin-top: 16px; padding-top: 20px; border-top: 1px solid var(--border);
  }
  .footer-logo { height: 24px; width: calc(24px * 418.09 / 109.36); color: var(--ink); direction: ltr; }
  .footer-link { color: var(--ink-subtle); font-size: 12px; text-decoration: none; direction: ltr; }
  .footer-link:hover { color: var(--accent); }

  /* Print / PDF hint */
  @media print {
    .page-tabs, .home-hero, .hamburger, #open-editor, #open-settings,
    #logout, .lang-toggle, .theme-toggle, .user-chip, .clickable::after,
    #search-modal, #search-backdrop, .icon-btn, button, .home-card .cta {
      display: none !important;
    }
  }

  /* Header Home button (visible only inside reports) */
  .hamburger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--ink);
    cursor: pointer;
    padding: 0;
    transition: all .15s;
  }
  .hamburger:hover { border-color: var(--accent); background: var(--surface-2); }

  /* Hide the old horizontal tabs strip */
  .page-tabs { display: none !important; }

  /* Data grid editor */
  .grid-scroll {
    overflow: auto;
    max-height: 60vh;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
  }
  table.data-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
  }
  table.data-grid thead th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    padding: 8px 10px;
    text-align: start;
    font-weight: 500;
    color: var(--ink-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    border-inline-end: 1px solid var(--border);
    white-space: nowrap;
  }
  table.data-grid tbody td {
    padding: 0;
    border-bottom: 1px solid var(--border);
    border-inline-end: 1px solid var(--border);
    vertical-align: middle;
  }
  table.data-grid tbody tr:hover td { background: var(--surface-2); }
  table.data-grid .row-idx {
    background: var(--surface-2);
    color: var(--ink-subtle);
    font-family: var(--font-mono);
    text-align: center;
    padding: 6px 8px;
    font-size: 11px;
    width: 40px;
  }
  table.data-grid .cell-input {
    width: 100%;
    padding: 8px 10px;
    border: 0;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 12px;
    outline: none;
    box-sizing: border-box;
  }
  table.data-grid .cell-input.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    direction: ltr;
    text-align: end;
  }
  table.data-grid .cell-input:focus {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 2px var(--accent);
    border-radius: 3px;
  }
  table.data-grid thead th.actions-th,
  table.data-grid tbody td.actions-cell {
    position: sticky;
    inset-inline-end: 0;
    background: var(--surface);
    text-align: center;
    padding: 4px 8px;
    box-shadow: -1px 0 0 var(--border);
    z-index: 2;
    width: 64px;
    min-width: 64px;
  }
  html[dir="ltr"] table.data-grid thead th.actions-th,
  html[dir="ltr"] table.data-grid tbody td.actions-cell {
    box-shadow: 1px 0 0 var(--border);
  }
  table.data-grid thead th.actions-th {
    background: var(--surface-2);
    z-index: 3;
  }
  table.data-grid tbody tr:hover td.actions-cell {
    background: var(--surface-2);
  }
  .row-delete-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--negative);
    cursor: pointer;
    padding: 0;
    transition: all .12s;
  }
  .row-delete-btn:hover {
    background: var(--negative);
    color: #fff;
    border-color: var(--negative);
    transform: scale(1.05);
  }
  .row-delete-btn svg { display: block; }
  .grid-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
  }
  .grid-toolbar .status {
    font-size: 12px;
    color: var(--ink-muted);
    font-family: var(--font-mono);
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .grid-toolbar .status.saved { color: var(--positive); }
  .grid-toolbar .status.dirty { color: var(--warning); }
  .grid-toolbar .status::before {
    content: "●";
    font-size: 10px;
  }

/* أدوات Excel فوق جداول المشاريع والحملات */
.table-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.xl-tools { display: flex; gap: 6px; }
.xl-btn { padding: 8px 12px; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.xl-msg { font-size: 12px; margin-top: 4px; min-height: 0; }
.xl-msg:empty { display: none; }
@media (max-width: 720px) {
  #sec-proj-table .card-head, #sec-cmp-table .card-head { flex-wrap: wrap; gap: 10px; }
  .table-tools { width: 100%; }
  .table-tools input[type="search"] { min-width: 0 !important; flex: 1 1 180px; }
}

/* جدول مديونية العملاء حسب الأعمار */
.pivot-table th, .pivot-table td { white-space: nowrap; }
.pivot-table .pv-client { white-space: normal; min-width: 200px; font-weight: 500; }
.pivot-table .pv-cell { cursor: pointer; font-variant-numeric: tabular-nums; }
.pivot-table .pv-cell:hover { background: var(--accent-soft); color: var(--accent); }
.pivot-table th.late, .pivot-table td.late { color: var(--negative); }
.pivot-table .pv-total { font-weight: 700; }
.pivot-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); background: var(--surface-2); }
.pivot-table .pv-empty { color: var(--ink-subtle); }
/* عناصر الشبكة لا تتمدد بعرض جداولها — الجدول يمرَّر أفقياً داخل بطاقته */
.main-grid > *, .lower-grid > * { min-width: 0; }

/* ===== حركة ناعمة ===== */
html { scroll-behavior: smooth; }
:root { --ease-out: cubic-bezier(.2, .7, .2, 1); }
@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* دخول الصفحة: الأقسام تظهر بالتتابع */
.page-enter > * { animation: fade-up .38s var(--ease-out) backwards; }
.page-enter > *:nth-child(2) { animation-delay: .04s; }
.page-enter > *:nth-child(3) { animation-delay: .08s; }
.page-enter > *:nth-child(4) { animation-delay: .12s; }
.page-enter > *:nth-child(5) { animation-delay: .16s; }
.page-enter > *:nth-child(n+6) { animation-delay: .2s; }

/* شاشة الدخول تتلاشى والتطبيق يظهر بنعومة */
#lock { transition: opacity .28s ease; }
#lock.leaving { opacity: 0; pointer-events: none; }
#lock .lock-card { animation: fade-up .45s var(--ease-out) backwards; }
body.app-enter .app { animation: fade-in .4s ease backwards; }

/* البطاقات القابلة للضغط ترتفع قليلاً بدل الوميض */
.kpi, .card { transition: transform .2s var(--ease-out), box-shadow .2s var(--ease-out), border-color .2s ease; }
.kpi.clickable:hover { opacity: 1; transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0,0,0,0.08); }
.home-card { transition: transform .22s var(--ease-out), box-shadow .22s var(--ease-out), border-color .22s ease; }
.btn, .icon-btn, button { transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .1s ease, opacity .15s ease; }
.btn:active, .icon-btn:active { transform: scale(.97); }
tr.clickable-row, .pivot-table .pv-cell { transition: background-color .15s ease, color .15s ease; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .page-enter > *, #lock .lock-card, body.app-enter .app { animation: none !important; }
}
.xl-clear { color: var(--negative); }
.xl-clear:hover { border-color: var(--negative); }

/* مبالغ المستحق (أحمر) والمقدم (أخضر) في جداول المشاريع والحملات */
.amt-due { color: var(--negative) !important; font-weight: 600; }
.amt-adv { color: var(--positive) !important; font-weight: 600; }
.amt-zero { color: var(--ink-muted); }

/* ===== لوحة الإعدادات أوسع، وتبويب البيانات تقريباً بعرض الشاشة ===== */
#settings.wide { width: min(1440px, 100vw) !important; }
#settings.wide .grid-scroll { max-height: 70vh; }
.data-grid .cell-input.changed { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
/* شريط الحفظ يبقى ظاهراً أعلى تبويب البيانات */
.grid-savebar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0,0,0,0.10);
  animation: fade-up .25s var(--ease-out) both;
}
.grid-savebar[hidden] { display: none; }
.grid-savebar .msg { font-size: 13px; color: var(--ink); }
.grid-savebar .msg span { color: var(--ink-muted); }
.grid-savebar .acts { display: flex; gap: 8px; }

/* ===== الإعدادات كصفحة كاملة بدل لوحة جانبية ===== */
#settings, #settings.wide { width: 100vw !important; border-left: 0 !important; }
#settings .editor-head { padding-inline: max(24px, calc((100vw - 1440px) / 2)); }
#settings > div:not(.editor-head):not(.editor-body) { padding-inline: max(24px, calc((100vw - 1440px) / 2)); }
/* محتوى التبويبات في المنتصف بعرض مريح، وجداول البيانات بعرض الصفحة */
#settings .editor-body { padding-inline: max(24px, calc((100vw - 1440px) / 2)); }
#settings #tab-users, #settings #tab-display, #settings #tab-api { width: 100%; max-width: 960px; margin-inline: auto; }
#settings.wide .grid-scroll { max-height: calc(100vh - 330px); }

/* ===== إدارة البيانات (تصميم جديد) ===== */
.dm-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.dm-title { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--ink); margin: 0 0 4px; }
.dm-sub { font-size: 13px; color: var(--ink-muted); line-height: 1.7; max-width: 720px; }
.dm-more { display: flex; gap: 8px; flex-wrap: wrap; }
.dm-more .btn { font-size: 12.5px; padding: 8px 12px; }
#seed-msg:empty { display: none; }

/* أزرار اختيار الجدول */
.dm-seg { display: flex; gap: 6px; padding: 5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
.dm-seg-btn {
  flex: 1 1 0; min-width: max-content; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 16px; border: 0; border-radius: 9px; background: transparent; cursor: pointer;
  font-family: var(--font-body); font-size: 14px; font-weight: 500; color: var(--ink-muted);
}
.dm-seg-btn:hover { color: var(--ink); background: var(--surface); }
.dm-seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.dm-seg-btn .cnt { font-family: var(--font-mono); font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-muted); }
.dm-seg-btn.active .cnt { background: var(--accent); color: #fff; }
.dm-seg-btn[hidden] { display: none; }

/* شريط الأدوات */
.dm-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dm-toolbar #grid-search { flex: 1 1 280px; margin: 0; padding: 10px 14px; font-size: 14px; }
.dm-status [hidden] { display: none; }
.dm-add { padding: 10px 18px; font-size: 14px; font-weight: 600; }

/* الجدول */
.dm-table { padding: 14px; }
.dm-table[hidden] { display: none !important; }
.dm-table-sub { font-size: 12px; color: var(--ink-muted); margin: 0 4px 10px; }
.dm-hint { font-size: 12px; color: var(--ink-subtle); }
.data-grid tbody tr { cursor: default; }
.data-grid .actions-cell { white-space: nowrap; }
.row-edit-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); cursor: pointer; font-size: 14px; margin-inline-end: 6px; vertical-align: middle;
}
.row-edit-btn:hover { border-color: var(--accent); color: var(--accent); }
@keyframes dm-flash { 0%, 60% { background: var(--accent-soft); } 100% { background: transparent; } }
.data-grid tr.dm-flash td { animation: dm-flash 2.2s ease; }

/* نموذج الإضافة / التعديل */
.dm-modal { position: fixed; inset: 0; z-index: 1100; background: rgba(0,0,0,0.45); display: grid; place-items: center; padding: 16px; }
.dm-modal[hidden] { display: none; }
.dm-modal-card {
  width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25); animation: fade-up .25s var(--ease-out) both;
}
.dm-modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.dm-modal-head h3 { margin: 0; font-size: 18px; font-weight: 700; color: var(--ink); }
#dm-form { padding: 18px 22px 20px; }
.dm-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.dm-field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--ink-muted); }
.dm-field.wide { grid-column: 1 / -1; }
.dm-field input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg);
  color: var(--ink); font-family: var(--font-body); font-size: 14px; outline: none;
}
.dm-field input.num { font-family: var(--font-mono); direction: ltr; text-align: right; }
.dm-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dm-form-err { min-height: 18px; margin-top: 12px; font-size: 13px; color: var(--negative); }
.dm-modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin: 8px -22px -20px; padding: 14px 22px; position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); }
.dm-modal-foot .btn { padding: 10px 18px; }
@media (max-width: 640px) { .dm-form-grid { grid-template-columns: 1fr; } .dm-add { width: 100%; } }

/* مؤشر "جارٍ التحليل" في المساعد */
.ai-typing { display: inline-flex; gap: 3px; vertical-align: middle; margin-inline-end: 6px; }
.ai-typing i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .35; animation: ai-dot 1s infinite ease-in-out; }
.ai-typing i:nth-child(2) { animation-delay: .15s; } .ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-dot { 0%, 100% { opacity: .25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }
.ai-msg.a ul { margin: 6px 0; padding-inline-start: 18px; }

/* جدول توقعات التحصيل */
.fc-table th.fc-past, .fc-table td.fc-past { color: var(--negative); }
.fc-table th.fc-none, .fc-table td.fc-none { color: var(--ink-muted); }
/* صف الإجمالي في الجداول المحورية بنفس محاذاة وخط أرقام الصفوف */
tfoot td { padding: 12px; }
tfoot td.num { direction: ltr; text-align: left; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
