  :root{
    --navy:#FFFFFF;
    --navy-light:#41B3A3;
    --ink:#FFFFFF;
    --paper:#0B132B;
    --paper-card:#1C2541;
    --line:rgba(255,255,255,0.12);
    --line-strong:rgba(255,255,255,0.2);
    --muted:#95A5A6;
    --accent-1:#41B3A3;
    --accent-2:#00A8E8;
    --accent-3:#41B3A3;
    --accent-deep:#00A8E8;
    --danger:#c0392b;
    --warn:#b2790c;
    --radius:10px;
    --radius-lg:16px;
    --font-fa:'Vazirmatn', sans-serif;
    /* DM Mono has no Persian letters: Vazirmatn comes next so words such as
       "افغانی" next to an amount stay joined instead of falling back to a
       monospace font with separated letters. Latin digits still use DM Mono. */
    --font-mono:'DM Mono', 'Vazirmatn', monospace;
    /* Header palette — Deep Ocean Navy, teal/turquoise accent from logo */
    --header-bg:#1C2541;
    --header-bg-raised:#283A5E;
    --header-text:#FFFFFF;
    --header-text-dim:#95A5A6;
    --header-active:#41B3A3;
    --header-hover:#00A8E8;
  }

  html[data-theme="light"]{
    --navy:#1A2B49;
    --navy-light:#00A8E8;
    --ink:#1A2B49;
    --paper:#F4F7F6;
    --paper-card:#FFFFFF;
    --line:rgba(26,43,73,0.08);
    --line-strong:rgba(26,43,73,0.15);
    --muted:#5C6B73;
    --accent-1:#00A8E8;
    --accent-2:#41B3A3;
    --accent-3:#00A8E8;
    --accent-deep:#41B3A3;
    --danger:#d32f2f;
    --warn:#f57c00;
    --header-bg:#FFFFFF;
    --header-bg-raised:#F4F7F6;
    --header-text:#1A2B49;
    --header-text-dim:#5C6B73;
    --header-active:#00A8E8;
    --header-hover:#41B3A3;
  }
  *{box-sizing:border-box;}
  html,body{margin:0;padding:0;height:100%;overflow:hidden;}
  body{
    font-family:var(--font-fa);
    background:var(--paper);
    color:var(--ink);
    -webkit-font-smoothing:antialiased;
    overflow-x:hidden;
    max-width:100vw;
  }
  #root{height:100vh;overflow:hidden;display:flex;flex-direction:column;}
  button{font-family:var(--font-fa);cursor:pointer;}
  input,select,textarea{font-family:var(--font-fa);}
  /* Number fields: no up/down spinner arrows — values change only by typing
     (see also js/number-inputs.js for the mouse wheel / arrow keys). */
  input[type=number]::-webkit-outer-spin-button,
  input[type=number]::-webkit-inner-spin-button{ -webkit-appearance:none; margin:0; }
  input[type=number]{ -moz-appearance:textfield; appearance:textfield; }
  /* Dari: amounts are shown with Persian digits (drawn in Vazirmatn), while a
     number field can only hold Western digits — give the fields the same font
     so the digits on screen look alike side by side. */
  html[lang="fa"] input[type=number]{ font-family:'Vazirmatn', sans-serif !important; }
  /* Dates and codes such as ۱۴۰۵-۰۹-۰۶ inside right-to-left text: keep the
     parts in reading order (year-month-day) instead of letting them flip. */
  .ltr-num{ direction:ltr; unicode-bidi:isolate; display:inline-block; }
  /* Keyboard focus: a clear ring in the accent colour on every control
     (many fields set outline:none inline, so this needs !important). */
  :focus-visible{ outline:2px solid var(--accent-1) !important; outline-offset:2px; }
  input:focus-visible, select:focus-visible, textarea:focus-visible{ outline-offset:0; }
  /* Respect the system setting "reduce motion". */
  @media (prefers-reduced-motion: reduce){
    *, *::before, *::after{ animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; scroll-behavior:auto !important; }
  }
  ::selection{background:#41B3A3; color:#0B132B;}

  /* ===== Brand wave divider (signature element) ===== */
  .brand-wave{ display:block; width:100%; height:8px; }

  /* ===== Login ===== */
  .login-wrap{
    min-height:100vh;
    display:flex;
    align-items:center;
    justify-content:center;
    background:linear-gradient(165deg, #0B132B 0%, #1C2541 45%, #0B132B 100%);
    padding:24px;
    position:relative;
  }
  .login-lang{
    position:absolute;
    inset-block-start:22px;
    inset-inline-end:22px;
  }
  .login-card{
    width:100%;
    max-width:420px;
    background:var(--paper-card);
    border-radius:var(--radius-lg);
    border:1px solid rgba(255,255,255,0.1);
    box-shadow:0 24px 60px -30px rgba(0,0,0,0.5), 0 0 40px rgba(255,255,255,0.1);
    padding:42px 38px 32px;
    text-align:center;
    position:relative;
    overflow:hidden;
  }
  .login-card::before{
    content:"";
    position:absolute;
    top:-60px; inset-inline-end:-60px;
    width:160px;height:160px;
    border-radius:50%;
    background:radial-gradient(circle at 30% 30%, #41B3A3, #00A8E8);
    opacity:0.08;
  }
  .login-logo-row{ display:flex; flex-direction:column; align-items:center; gap:14px; margin-bottom:6px; }
  /* The Dari lock-up image has the company name baked in as dark text on a
     transparent background. On the dark theme that text becomes nearly
     invisible against the dark card, so give it a light backing chip. */
  [data-theme="dark"] .brand-logo-img{
    background:#F4F7F6;
    border-radius:16px;
    padding:14px 22px;
    box-shadow:0 4px 18px rgba(0,0,0,0.25);
  }
  .login-company-name{
    font-size:18.5px;
    font-weight:800;
    color:var(--navy);
    line-height:1.55;
    margin:0;
    max-width:320px;
  }
  .login-sub{
    font-size:12.5px;
    color:var(--muted);
    margin:6px 0 26px;
    letter-spacing:normal; /* no letter-spacing on Persian text: it breaks the joined letters */
  }
  .field{
    text-align:start;
    margin-bottom:16px;
  }
  .field label{
    display:block;
    font-size:12.5px;
    color:var(--navy-light);
    font-weight:500;
    margin-bottom:6px;
  }
  .field input{
    width:100%;
    height:44px;
    border-radius:var(--radius);
    border:1px solid var(--line-strong);
    background:var(--paper-card);
    padding:0 14px;
    font-size:14px;
    color:var(--ink);
    transition:border-color .15s, box-shadow .15s;
    outline:none;
  }
  .field input:focus{
    border-color:var(--accent-1);
    box-shadow:0 0 0 3px rgba(65,179,163,0.2);
    background:var(--paper-card);
  }
  .btn-primary{
    width:100%;
    height:46px;
    border:none;
    border-radius:var(--radius);
    background:linear-gradient(135deg, #41B3A3, #1C8F82);
    color:#fff;
    font-size:14.5px;
    font-weight:600;
    letter-spacing:normal;
    margin-top:6px;
    transition:filter .15s, box-shadow .15s, transform .1s;
  }
  .btn-primary:hover{filter:brightness(1.15); box-shadow:0 8px 20px rgba(255,255,255,0.4);}
  .btn-primary:active{transform:scale(0.99);}
  .login-error{
    background:rgba(192,57,43,0.15);
    border:1px solid rgba(192,57,43,0.4);
    color:#FF6B6B;
    font-size:12.5px;
    border-radius:var(--radius);
    padding:9px 12px;
    margin-bottom:14px;
    text-align:start;
  }
  .login-hint{
    margin-top:22px;
    font-size:12px;
    color:#9aacba;
    line-height:1.9;
    border-top:1px dashed var(--line);
    padding-top:14px;
  }
  .login-hint a{ color:var(--accent-1); cursor:pointer; }

  /* ===== App shell ===== */
  .app{ display:flex; flex-direction:column; height:100vh; overflow:hidden; }

  /* ===== Header / Topbar ===== */
  .topbar{
    background:var(--header-bg);
    border-bottom:2px solid rgba(65,179,163,0.3);
    box-shadow:0 6px 16px -8px rgba(0,0,0,0.3);
    position:sticky;
    top:0;
    z-index:100;
  }
  .topbar-inner{
    height:76px;
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:0 28px;
    gap:16px;
  }
  .topbar-brand{
    display:flex;
    align-items:center;
    gap:14px;
    min-width:0;
    cursor:pointer;
    background:none;
    border:none;
    padding:4px;
  }
  .topbar-brand-text{ text-align:start; line-height:1.3; min-width:0; }
  .topbar-brand-line1{
    font-size:16.5px;
    font-weight:800;
    color:var(--header-text);
    letter-spacing:normal;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    max-width:340px;
  }
  .topbar-brand-line2{
    font-size:12px;
    color:var(--header-active);
    font-weight:600;
    letter-spacing:normal;
  }

  .topbar-nav{
    display:flex;
    align-items:center;
    gap:4px;
    flex:1;
    justify-content:center;
  }
  .tnav-group{ position:relative; }
  .tnav-btn{
    display:flex; align-items:center; gap:5px;
    padding:10px 16px;
    background:none; border:none;
    color:var(--header-text);
    font-size:13.5px; font-weight:600;
    font-family:var(--font-fa);
    border-radius:8px;
    cursor:pointer;
    transition:color .15s, background .15s, text-shadow .15s;
    white-space:nowrap;
  }
  .tnav-btn:hover, .tnav-btn.open{ color:var(--header-hover); background:rgba(255,255,255,0.12); text-shadow:0 0 8px rgba(255,255,255,0.3); }
  .tnav-btn.active-page{ color:var(--header-active); font-weight:700; }
  .tnav-chevron{ transition:transform .2s; opacity:0.7; }
  .tnav-chevron.open{ transform:rotate(180deg); opacity:1; }
  .tnav-dropdown{
    position:absolute; top:calc(100% + 8px); inset-inline-start:0;
    min-width:200px; background:var(--header-bg-raised); border:1px solid rgba(255,255,255,0.15);
    border-radius:12px; box-shadow:0 16px 40px -10px rgba(0,0,0,0.6), 0 0 16px rgba(255,255,255,0.1);
    padding:6px; z-index:200; animation: dropIn .15s ease;
  }
  @keyframes dropIn{ from{opacity:0; transform:translateY(-6px);} to{opacity:1; transform:translateY(0);} }
  .tnav-item{
    display:flex; align-items:center; gap:10px; width:100%;
    padding:10px 14px; border-radius:8px; background:none; border:none;
    color:var(--header-text); font-size:13px; font-weight:500; font-family:var(--font-fa);
    text-align:start; cursor:pointer; transition:background .12s, color .12s;
  }
  .tnav-item:hover{ background:rgba(255,255,255,0.16); color:var(--header-hover); }
  .tnav-item.active{ background:rgba(65,179,163,0.24); color:var(--header-active); font-weight:600; }
  .tnav-item-dot{ width:6px; height:6px; border-radius:50%; background:var(--header-active); flex-shrink:0; }

  .topbar-right{ display:flex; align-items:center; gap:10px; }
  .lang-switch{
    display:flex; align-items:center; background:rgba(255,255,255,0.06); border-radius:20px;
    padding:3px; gap:2px; border:1px solid rgba(255,255,255,0.1);
  }
  .lang-btn{
    padding:6px 13px; border-radius:16px; border:none; background:transparent;
    color:var(--header-text-dim); font-size:12px; font-weight:700; font-family:var(--font-fa);
    cursor:pointer; transition:all .15s; white-space:nowrap;
  }
  .lang-btn.active{ background:var(--header-active); color:#06201c; box-shadow:0 1px 8px rgba(65,179,163,0.4); }

  .user-icon-btn{
    display:flex; align-items:center; justify-content:center; gap:5px;
    background:none; color:var(--header-text);
    border:none; border-radius:50%; padding:7px;
    cursor:pointer; transition:filter .15s, box-shadow .15s, transform .1s;
  }
  .user-icon-btn:hover{ background:rgba(128,128,128,0.18); }
  .user-icon-btn:active{ transform:scale(0.94); }
  .user-avatar-btn{
    display:flex; align-items:center; justify-content:center;
    background:none; border:1px solid transparent; padding:3px; cursor:pointer; border-radius:24px;
    line-height:0; transition:filter .15s, transform .1s, background .15s, border-color .15s;
  }
  .user-avatar-btn:hover{ background:rgba(128,128,128,0.12); border-color:var(--line); }
  .user-avatar-btn:hover{ filter:brightness(1.1); }
  .user-avatar-btn:active{ transform:scale(0.95); }
  /* Signed-in user's photo (or initials): a solid accent disc with a ring, so it
     reads clearly on both the dark and the white top bar. */
  .user-icon-avatar{
    width:36px; height:36px; border-radius:50%;
    background:linear-gradient(135deg, var(--accent-1), var(--accent-deep)); color:#fff; font-size:14px; font-weight:700;
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
    overflow:hidden; border:2px solid var(--header-bg); box-shadow:0 0 0 1.5px var(--accent-1);
  }
  .user-icon-avatar img, .user-icon-big img{ width:100%; height:100%; object-fit:cover; }
  .user-icon-big{
    width:46px; height:46px; border-radius:50%;
    background:linear-gradient(135deg, var(--accent-1), var(--accent-deep));
    color:#fff; font-size:17px; font-weight:700;
    display:flex; align-items:center; justify-content:center; margin:0 auto 10px;
    overflow:hidden;
  }
  .user-dropdown{
    position:absolute; top:calc(100% + 10px); inset-inline-end:0;
    min-width:210px; background:var(--paper-card); border:1px solid var(--line);
    border-radius:12px; box-shadow:0 12px 40px -12px rgba(0,0,0,0.4);
    padding:8px; z-index:200; animation: dropIn .15s ease;
  }
  .user-dropdown-head{ padding:12px 14px 14px; border-bottom:1px solid var(--line); margin-bottom:6px; text-align:center; }
  .user-dropdown-head .dn{ font-size:13.5px; font-weight:700; color:var(--navy); }
  .user-dropdown-head .dr{ font-size:12px; color:var(--muted); margin-top:2px; }
  .ud-item{
    display:flex; align-items:center; gap:9px; width:100%; padding:9px 12px; border-radius:7px;
    background:none; border:none; color:var(--navy); font-size:13px; font-weight:500;
    font-family:var(--font-fa); text-align:start; cursor:pointer; transition:background .12s, color .12s;
  }
  .ud-item:hover{ background:rgba(65,179,163,0.15); color:var(--accent-1); }
  .ud-item.danger{ color:var(--danger); }
  .ud-item.danger:hover{ background:rgba(192,57,43,0.15); color:#FF6B6B; }

  .mobile-nav-toggle{ display:none; background:none; border:1px solid rgba(255,255,255,0.15); border-radius:8px; padding:8px; color:var(--header-text); }
  .mobile-nav-panel{ display:none; }

  .mobile-nav-group{ border-bottom:1px solid var(--line); }
  .mobile-nav-group:last-child{ border-bottom:none; }
  .mobile-nav-group-btn{
    width:100%; display:flex; align-items:center; justify-content:space-between;
    background:none; border:none; padding:14px 4px; min-height:48px;
    font-family:var(--font-fa); font-size:14px; font-weight:700; color:var(--navy);
    cursor:pointer; text-align:start;
  }
  .mobile-nav-group-btn.open{ color:#0FA4AF; }
  .mobile-nav-caret{ font-size:10px; color:var(--muted); transition:transform .15s; }
  .mobile-nav-sub{
    display:flex; flex-direction:column; gap:2px;
    padding:2px 0 10px 14px; animation:mobileSubOpen .15s ease;
  }
  @keyframes mobileSubOpen{ from{opacity:0; transform:translateY(-4px);} to{opacity:1; transform:none;} }

  /* ===== Main / content ===== */
  .main{ flex:1; display:flex; flex-direction:column; min-width:0; overflow:hidden; }
  .content{ flex:1; padding:28px; width:100%; overflow-y:auto; background: linear-gradient(135deg, #e8f4fd 0%, #f0f7ff 30%, #faf5ff 60%, #f0fbfd 100%); }
  [data-theme="dark"] .content{ background: linear-gradient(135deg, #0d1b2a 0%, #111827 50%, #0f172a 100%); }
  .page-header{
    display:flex; align-items:flex-end; justify-content:space-between;
    margin-bottom:22px; flex-wrap:wrap; gap:12px;
  }
  .page-header h1{ font-size:21px; font-weight:700; color:var(--navy); margin:0 0 4px; }
  .page-header p{ font-size:13px; color:var(--muted); margin:0; }

  /* Buttons */
  .btn{
    display:inline-flex; align-items:center; gap:7px;
    border:1.5px solid #CBD5E1; background:#F8FAFC; color:#1C2541;
    font-size:13px; font-weight:600; padding:10px 16px; border-radius:9px;
    transition:all .15s;
  }
  .btn:hover{ background:#EEF8F8; border-color:#41B3A3; color:#0FA4AF; box-shadow:0 2px 8px rgba(65,179,163,0.15); }
  .btn-accent{ background:linear-gradient(135deg, #41B3A3, #1C8F82); color:#fff !important; border:none; transition:filter .15s, box-shadow .15s; }
  .btn-accent:hover{ background:linear-gradient(135deg, #4ec5b5, #24a093) !important; color:#fff !important; box-shadow:0 4px 16px rgba(65,179,163,0.35); filter:none; }
  .btn-ghost{ background:transparent; border:1.5px solid #CBD5E1; color:#64748B; transition:all .15s; }
  .btn-ghost:hover{ background:#EEF8F8; color:#0FA4AF; border-color:#41B3A3; }
  .btn-danger{ color:#C0392B; border-color:#CBD5E1; background:#F8FAFC; }
  .btn-danger:hover{ background:#FEF2F2; border-color:#C0392B; color:#C0392B; }
  .btn-sm{ padding:6px 11px; font-size:12px; border-radius:7px; }

  /* Stat cards */
  .stat-grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(190px,1fr)); gap:14px; margin-bottom:24px; }
  .stat-card{ background:var(--paper-card); border:1px solid var(--line); border-radius:var(--radius-lg); padding:18px; position:relative; overflow:hidden; }
  .stat-card .label{ font-size:12px; color:var(--muted); margin-bottom:8px; }
  .stat-card .value{ font-size:24px; font-weight:700; color:var(--navy); font-family:var(--font-mono); direction:ltr; text-align:start; }
  .stat-card .sub{ font-size:12px; color:var(--accent-3); margin-top:4px; font-weight:500; }
  .area-chip-grid{ display:grid; grid-template-columns:repeat(auto-fill, minmax(170px,1fr)); gap:10px; }
  .area-chip{
    display:flex; flex-direction:column; align-items:flex-start; gap:4px;
    background: rgba(255,255,255,0.35);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.55);
    border-radius: 12px;
    padding:11px 14px; text-align:start;
    box-shadow: 0 2px 12px rgba(11,19,43,0.07), inset 0 1px 0 rgba(255,255,255,0.6);
    transition: border-color .15s, background .15s, box-shadow .15s;
  }
  .area-chip:hover{
    border-color: rgba(15,164,175,0.5);
    background: rgba(255,255,255,0.55);
    box-shadow: 0 4px 20px rgba(11,19,43,0.12), inset 0 1px 0 rgba(255,255,255,0.8);
  }
  [data-theme="dark"] .area-chip{ background: rgba(30,40,70,0.4); border: 1px solid rgba(255,255,255,0.08); }
  [data-theme="dark"] .area-chip:hover{ background: rgba(30,40,70,0.6); border-color: rgba(15,164,175,0.4); }
  /* ثبت میتر / ثبت رسیدها quick-registration cards — the light teal card
     designed for the light theme reads poorly on a dark background, so give
     it a distinct dark teal treatment with a clear accent border. */
  [data-theme="dark"] .reg-card{
    background: #12333a !important;
    border: 1.5px solid #0FA4AF !important;
  }
  /* The individual field boxes inside those cards (شماره قبض, نام مشتری, etc.)
     own their background/text color here instead of inline, so the dark-theme
     override below can take effect without fighting inline style specificity. */
  .reg-field-box{ background:#fff; color:#1A2B49; }
  [data-theme="dark"] .reg-field-box{
    background: #0d262b;
    color: #EAF6FB;
  }
  .area-chip-name{ font-size:13px; font-weight:700; color:var(--navy); }
  .area-chip-count{ font-size:12px; color:var(--muted); }
  .stat-card .value{ font-size:20px; }
  .stat-card .ic-bg{ position:absolute; inset-inline-start:-10px; bottom:-14px; width:64px; height:64px; opacity:0.07; }

  /* Cards */
  .card{ background:var(--paper-card); border:1px solid var(--line); border-radius:var(--radius-lg); padding:22px; }
  .glass-card{
    background: rgba(255,255,255,0.35);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.55);
    border-radius: 12px;
    box-shadow: 0 2px 16px rgba(11,19,43,0.08), inset 0 1px 0 rgba(255,255,255,0.6);
  }
  [data-theme="dark"] .glass-card{
    background: rgba(30,40,70,0.4);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 2px 16px rgba(0,0,0,0.3);
  }

  /* Tables */
  .table-wrap{ overflow-x:auto; }
  table.data{ width:100%; border-collapse:collapse; font-size:13px; }
  table.data th{ text-align:start; color:var(--muted); font-weight:500; font-size:12px; padding:10px 12px; border-bottom:1px solid var(--line); white-space:nowrap; }
  table.data td{ padding:13px 12px; border-bottom:1px solid var(--line); color:var(--ink); white-space:nowrap; }
  table.data tbody tr{ transition:background .12s; }
  table.data tbody tr:hover{ background:rgba(65,179,163,0.08); }
  table.data tbody tr:last-child td{ border-bottom:none; }
  .row-link{ color:var(--accent-1); font-weight:500; direction:ltr; text-align:start; display:inline-block; }

  .pill{ display:inline-flex; align-items:center; gap:5px; font-size:12px; font-weight:500; padding:3px 10px; border-radius:20px; }
  .pill-green{ background:rgba(65,179,163,0.2); color:#41B3A3; }
  .pill-amber{ background:rgba(178,121,12,0.2); color:#FFB84D; }
  .pill-red{ background:rgba(192,57,43,0.2); color:#FF6B6B; }
  .pill-blue{ background:rgba(65,179,163,0.2); color:#41B3A3; }
  .pill-teal{ background:rgba(65,179,163,0.2); color:#41B3A3; }

  .area-filter-row{ display:flex; flex-wrap:wrap; gap:8px; margin-bottom:16px; }
  .area-filter-pill{
    border:1px solid var(--line-strong); background:var(--paper-card); color:var(--muted);
    font-size:12px; font-weight:500; padding:6px 14px; border-radius:20px; transition:all .15s;
  }
  .area-filter-pill:hover{ border-color:var(--accent-1); color:var(--accent-1); }
  .area-filter-pill.active{ background:var(--accent-1); border-color:var(--accent-1); color:#fff; }

  .search-bar{
    display:flex; align-items:center; gap:10px; background:var(--paper-card); border:1px solid var(--line);
    border-radius:10px; padding:0 14px; height:42px; margin-bottom:16px; max-width:400px;
  }
  .search-bar input{ border:none; outline:none; flex:1; font-size:13.5px; background:transparent; height:100%; color:var(--ink); }
  .search-bar svg{ flex-shrink:0; color:var(--muted); }

  .empty-state{ text-align:center; padding:60px 20px; color:var(--muted); }
  .empty-state svg{ width:48px; height:48px; margin:0 auto 14px; opacity:0.35; }
  .empty-state h3{ font-size:15px; color:var(--ink); margin:0 0 6px; font-weight:600; }
  .empty-state p{ font-size:13px; margin:0; }

  /* A4 form */
  .form-toolbar{ display:flex; gap:10px; align-items:center; margin-bottom:18px; flex-wrap:wrap; }
  .a4-wrap{ display:flex; justify-content:center; position:relative; }
  .a4-page{
    background:#ffffff; width:100%; max-width:794px; min-height:1000px;
    border:1px solid #e0e0e0; border-radius:8px;
    box-shadow:0 8px 32px rgba(0,0,0,0.12);
    padding:0; position:relative; overflow:hidden; color:#1a1a1a;
    font-family:'Vazirmatn', sans-serif;
  }
  .a4-page::before{
    content:""; display:none;
  }
  .a4-head{
    display:flex; align-items:center; justify-content:space-between;
    padding:28px 40px 20px; gap:14px; border-bottom:2px solid #f0f0f0;
    background:#fff;
  }
  .a4-head .brand{ display:flex; align-items:center; gap:14px; }
  .a4-head .brand .bn{ font-size:15px; font-weight:800; color:#0B132B; line-height:1.5; }
  .a4-head .meta{ text-align:end; font-size:11.5px; color:#666; line-height:2; }
  .a4-body{ padding:24px 40px 36px; }
  .a4-title{
    text-align:center; font-size:17px; font-weight:800; color:#0B132B;
    margin:0 0 20px; letter-spacing:normal;
    background:#f5fbff; border-radius:8px; padding:12px 20px;
    border:1.5px solid #cce8f8;
  }
  .a4-section-title{
    font-size:11.5px; font-weight:800; color:#0FA4AF;
    margin:20px 0 8px; padding:7px 14px;
    border-inline-start:4px solid #0FA4AF;
    background:linear-gradient(90deg,#f0fbfd,transparent);
    border-radius:0 6px 6px 0; display:flex; align-items:center;
    letter-spacing:normal; text-transform:uppercase;
  }
  .a4-watermark{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; opacity:0.035; pointer-events:none; }
  .a4-footer{ margin-top:28px; padding-top:14px; border-top:2px solid #f0f0f0; display:flex; justify-content:space-between; font-size:11px; color:#888; gap:10px; flex-wrap:wrap; }

  /* Bill table — professional clean grid */
  .bill-table{ width:100%; border-collapse:collapse; font-size:13px; margin-top:6px; border-radius:8px; overflow:hidden; border:1.5px solid #e0e8ee; }
  .bill-table td{ border:1px solid #e8edf0; padding:10px 13px; color:#1a1a1a; vertical-align:middle; }
  .bill-table .bt-label{ color:#555; font-weight:700; background:#f7f9fc; white-space:nowrap; font-size:12px; }
  .bill-table .bt-value{ font-weight:700; font-family:var(--font-mono); direction:ltr; text-align:end; background:#fff; }
  .bill-table .bt-head{ text-align:center; font-weight:700; color:#fff; background:#1C2541; font-size:12px; padding:11px 12px; }
  .bill-table .bt-total td{ font-size:14px; font-weight:800; color:#0B132B; background:#e4f8f8; }
  .bill-table .bt-sig{ text-align:center; min-height:50px; }

  /* Total payable highlight box */
  .a4-total-box{
    display:flex; align-items:center; justify-content:space-between;
    background:linear-gradient(135deg,#0B132B 60%,#0FA4AF);
    color:#fff; border-radius:10px; padding:16px 24px; margin-top:16px;
    font-size:19px; font-weight:800; box-shadow:0 4px 16px rgba(11,19,43,0.25);
  }
  .a4-total-box .label{ font-size:13px; font-weight:600; opacity:0.8; }
  .a4-paid-badge{
    display:inline-flex; align-items:center; gap:6px;
    padding:6px 16px; border-radius:20px; font-size:12px; font-weight:700; margin-top:10px;
  }
  .a4-paid-badge.paid{ background:#e6f9ef; color:#1a7a45; border:1.5px solid #a3e6bf; }
  .a4-paid-badge.unpaid{ background:#fff4e5; color:#b45309; border:1.5px solid #fcd09a; }
  .a4-barcode-area{ display:flex; flex-direction:column; align-items:center; gap:4px; margin:18px 0 4px; }

  .a4-grid{ display:grid; grid-template-columns:1fr 1fr; gap:14px 18px; }
  .a4-grid.full{ grid-template-columns:1fr; }
  .a4-field{ display:flex; flex-direction:column; gap:5px; }
  .a4-field label{ font-size:12px; color:var(--muted); font-weight:500; text-align:start; }
  .a4-field input, .a4-field select, .a4-field textarea{
    border:none; border-bottom:1px solid var(--line-strong); padding:6px 2px; font-size:13.5px; color:var(--ink);
    background:transparent; outline:none; transition:border-color .15s; font-family:var(--font-fa); text-align:start;
  }
  .a4-field input:focus, .a4-field select:focus, .a4-field textarea:focus{ border-color:var(--accent-1); }
  .a4-field textarea{ resize:vertical; min-height:54px; font-family:var(--font-fa); }
  .a4-field input:disabled, .a4-field select:disabled, .a4-field textarea:disabled{ color:var(--ink); -webkit-text-fill-color:var(--ink); opacity:1; }

  /* Jalali calendar date picker */
  .jdp-wrap{ position:relative; }
  .jdp-input{
    width:100%; display:flex; align-items:center; gap:8px;
    padding:10px 12px; border-radius:var(--radius); border:1px solid var(--line-strong);
    background:var(--paper-card); color:var(--ink); font-family:var(--font-fa);
    font-size:13.5px; cursor:pointer; text-align:start;
  }
  .jdp-input:hover{ border-color:var(--accent-1); }
  .jdp-placeholder{ color:var(--muted); }
  .jdp-pop{
    position:fixed; z-index:9999;
    width:260px; background:var(--paper-card); border:1px solid var(--line-strong);
    border-radius:var(--radius-lg); box-shadow:0 16px 40px -10px rgba(0,0,0,0.4);
    padding:12px;
  }
  .jdp-head{ display:flex; align-items:center; justify-content:space-between; gap:6px; margin-bottom:8px; }
  .jdp-head-labels{ display:flex; gap:6px; flex:1; }
  .jdp-head-labels select{
    flex:1; min-width:0; padding:5px 6px; border-radius:7px; border:1px solid var(--line-strong);
    background:var(--paper); color:var(--ink); font-family:var(--font-fa); font-size:12.5px;
  }
  .jdp-nav{
    width:26px; height:26px; flex-shrink:0; display:flex; align-items:center; justify-content:center;
    border:1px solid var(--line-strong); background:var(--paper); color:var(--ink);
    border-radius:7px; cursor:pointer; font-size:14px;
  }
  .jdp-nav:hover{ border-color:var(--accent-1); color:var(--accent-1); }
  .jdp-weekdays{ display:grid; grid-template-columns:repeat(7,1fr); text-align:center; font-size:12px; color:var(--muted); margin-bottom:4px; }
  .jdp-grid{ display:grid; grid-template-columns:repeat(7,1fr); gap:2px; }
  .jdp-cell{
    aspect-ratio:1; display:flex; align-items:center; justify-content:center;
    border:none; background:none; color:var(--ink); border-radius:7px; cursor:pointer; font-size:12.5px;
  }
  .jdp-cell:hover{ background:rgba(65,179,163,0.15); }
  .jdp-cell.empty{ cursor:default; }
  .jdp-cell.empty:hover{ background:none; }
  .jdp-cell.today{ font-weight:700; color:var(--accent-1); }
  .jdp-cell.selected{ background:var(--accent-1); color:#fff; font-weight:700; }
  .jdp-foot{ display:flex; gap:8px; justify-content:space-between; margin-top:10px; }
  .a4-field textarea{ resize:vertical; min-height:54px; font-family:var(--font-fa); }
  .a4-field input:disabled, .a4-field select:disabled, .a4-field textarea:disabled{ color:var(--ink); -webkit-text-fill-color:var(--ink); opacity:1; }
  .a4-footer{ margin-top:40px; padding-top:18px; border-top:1px solid var(--line); display:flex; justify-content:space-between; font-size:11px; color:var(--muted); font-family:var(--font-mono); gap:10px; flex-wrap:wrap; }
  .a4-watermark{ position:absolute; inset:0; display:flex; align-items:center; justify-content:center; opacity:0.04; pointer-events:none; }

  /* Bill table — mirrors the official paper receipt grid */
  .bill-table{ width:100%; border-collapse:collapse; font-size:12.5px; margin-top:18px; }
  .bill-table td{ border:1px solid var(--line-strong); padding:9px 10px; color:var(--ink); vertical-align:middle; }
  .bill-table .bt-label{ color:var(--muted); font-weight:600; background:var(--paper); white-space:nowrap; font-size:11.5px; }
  .bill-table .bt-value{ font-weight:600; font-family:var(--font-mono); direction:ltr; text-align:end; }
  .bill-table .bt-head{ text-align:center; font-weight:700; color:var(--accent-3); background:var(--paper); font-size:11.5px; }
  .bill-table .bt-total td{ font-size:15px; font-weight:800; color:var(--navy); background:rgba(65,179,163,0.08); }
  .bill-table .bt-sig{ text-align:center; min-height:50px; }

  /* Customer detail */
  .detail-grid{ display:grid; grid-template-columns:320px 1fr; gap:20px; }
  .profile-card{ text-align:center; padding-bottom:24px; }
  .profile-avatar{
    width:74px; height:74px; border-radius:50%;
    background:linear-gradient(135deg, var(--accent-1), var(--accent-deep));
    color:#fff; font-size:26px; font-weight:700;
    display:flex; align-items:center; justify-content:center; margin:0 auto 14px;
  }
  .profile-name{ font-size:17px; font-weight:700; color:var(--navy); margin-bottom:2px; }
  .profile-sub{ font-size:12px; color:var(--muted); margin-bottom:18px; }
  .info-list{ text-align:start; font-size:13px; }
  .info-list .row{ display:flex; justify-content:space-between; padding:10px 0; border-bottom:1px solid #eef2f6; gap:10px; }
  .info-list .row:last-child{ border-bottom:none; }
  .info-list .row .k{ color:var(--muted); white-space:nowrap; }
  .info-list .row .v{ font-weight:500; color:var(--ink); font-family:var(--font-mono); text-align:end; }

  .receipt-card{
    border:1px solid var(--line); border-radius:10px; padding:10px 14px; margin-bottom:8px;
    display:flex; justify-content:space-between; align-items:center; gap:12px; flex-wrap:wrap;
  }
  .receipt-card .left{ display:flex; flex-direction:column; gap:2px; }
  .receipt-card .sn{ font-family:var(--font-mono); font-size:12px; color:var(--muted); direction:ltr; }
  .receipt-card .date{ font-size:12.5px; font-weight:600; color:var(--ink); }
  .receipt-card .meta{ font-size:12px; color:var(--muted); }
  .receipt-card .amount{ font-size:15px; font-weight:700; color:var(--navy); font-family:var(--font-mono); direction:ltr; }

  /* Modal */
  .modal-overlay{ position:fixed; inset:0; background:rgba(0,0,0,0.5); display:flex; align-items:center; justify-content:center; z-index:300; padding:20px; }
  .modal{ background:var(--paper-card); border-radius:var(--radius-lg); padding:26px; width:100%; max-width:500px; max-height:88vh; overflow-y:auto; }
  .modal h2{ font-size:16px; font-weight:700; color:var(--navy); margin:0 0 18px; }
  .modal .a4-grid{ margin-bottom:18px; }
  .modal-actions{ display:flex; gap:10px; justify-content:flex-start; margin-top:8px; }

  /* Settings */
  .settings-grid{ display:grid; grid-template-columns:1fr 1fr; gap:18px; }
  .settings-grid .a4-field{ margin-bottom:14px; }

  /* ═══════════════════════════════════════════
     RESPONSIVE — tablet 768-1023px
  ═══════════════════════════════════════════ */
  @media screen and (max-width: 1023px){
    .topbar-inner{ padding:0 16px; height:64px; }
    .topbar-brand-line1{ font-size:13px; max-width:180px; }
    .topbar-brand-line2{ font-size:12px; }
    .content{ padding:18px; }
    .stat-grid{ grid-template-columns:repeat(2, 1fr); }
    .detail-grid{ grid-template-columns:1fr; }
    .settings-grid{ grid-template-columns:1fr; }
    .a4-grid{ grid-template-columns:1fr; }
    .a4-page{ padding:24px 16px; }
    .table-wrap{ overflow-x:auto; -webkit-overflow-scrolling:touch; }
    .data{ min-width:600px; }
  }

  /* ═══════════════════════════════════════════
     RESPONSIVE — tablet 768–880px (iPad)
  ═══════════════════════════════════════════ */
  @media screen and (max-width: 880px){
    .topbar-nav{ display:none; }
    .mobile-nav-toggle{ display:flex; align-items:center; justify-content:center; }
    .mobile-nav-panel.open{
      display:flex; flex-direction:column; gap:2px; padding:10px 16px 16px;
      border-top:1px solid var(--line); background:var(--paper-card);
      max-height:calc(100vh - 56px); overflow-y:auto; -webkit-overflow-scrolling:touch;
    }
    .topbar-brand-line1{ max-width:160px; }
    .content{ padding:18px; }
    .a4-page{ padding:24px 18px; }
    .stat-grid{ grid-template-columns:repeat(2,1fr); }
    .receipt-page{ max-width:100% !important; }
  }

  @media screen and (max-width: 767px){
    /* Prevent iOS Safari from auto-zooming when any input/select/textarea is
       focused — iOS zooms if a field's font-size is under 16px. This overrides
       any smaller inline font-size set throughout the app for touch usability. */
    input, select, textarea { font-size:16px !important; }

    /* Topbar */
    .topbar-inner{ padding:0 12px; height:56px; gap:8px; }
    /* logo box 32 × 32; the image keeps its own proportions inside it */
    .topbar-brand-logo > span,
    .topbar-brand-logo svg{ width:32px!important; height:32px!important; }
    .topbar-brand-logo img{ width:auto!important; height:32px!important; }
    .topbar-brand-line1{ font-size:12px; max-width:130px; }
    .topbar-brand-line2{ display:none; }
    .topbar-right{ gap:6px; }

    /* Content */
    .content{ padding:12px; }

    /* Stats */
    .stat-grid{ grid-template-columns:1fr 1fr; gap:10px; margin-bottom:16px; }
    .stat-card{ padding:14px 12px; }
    .stat-card .value{ font-size:18px; }
    .stat-card .label{ font-size:12px; }

    /* Cards */
    .card{ padding:14px; border-radius:10px; }
    .page-header{ flex-direction:column; align-items:flex-start; gap:10px; }
    .page-header h1{ font-size:20px; }
    .page-header > div:last-child{ width:100%; display:flex; flex-wrap:wrap; gap:8px; }

    /* Tables — horizontal scroll */
    .table-wrap{ overflow-x:auto; -webkit-overflow-scrolling:touch; border-radius:8px; }
    .data{ min-width:480px; font-size:12px; }
    .data th, .data td{ padding:9px 8px; white-space:nowrap; }

    /* Grids */
    .a4-grid{ grid-template-columns:1fr; gap:10px; }
    .detail-grid{ grid-template-columns:1fr; gap:12px; }
    .settings-grid{ grid-template-columns:1fr; }

    /* Receipt cards in customer detail */
    .receipt-card{ flex-direction:column; align-items:flex-start; gap:10px; }
    .receipt-card > div:last-child{ width:100%; justify-content:flex-start; flex-wrap:wrap; gap:8px; }

    /* Modals */
    .modal{ width:95vw; max-width:95vw; padding:18px; margin:12px; max-height:90vh; overflow-y:auto; }

    /* Forms */
    .a4-field label{ font-size:12px; }
    .a4-field input, .a4-field select, .a4-field textarea{ font-size:14px; padding:9px 10px; }

    /* Buttons — bigger touch targets */
    .btn{ padding:10px 14px; font-size:12.5px; min-height:42px; }
    .btn-sm{ padding:8px 12px; min-height:36px; }
    .btn-accent{ padding:10px 16px; }
    .form-toolbar{ flex-wrap:wrap; gap:8px; padding:10px 12px; }

    /* Profile & avatar */
    .profile-card{ padding-bottom:16px; }
    .profile-avatar{ width:56px; height:56px; font-size:18px; }

    /* Receipt edit page — full width on mobile */
    .receipt-page{ max-width:100% !important; margin:0 !important; border-radius:8px; }

    /* Dashboard summary grid — stack to 1 col on small phones */
    .dash-summary-grid{ grid-template-columns:1fr 1fr !important; }
    .dash-monthly-grid{ grid-template-columns:1fr 1fr !important; }

    /* Bill table in A4 receipt */
    .bill-table{ font-size:11px; }
    .bill-table td{ padding:6px 7px; }

    /* Calendar picker */
    .jdp-pop{ width:min(280px, 92vw); }

    /* Area chips on dashboard */
    .area-chips{ gap:8px; }
    .area-chip{ padding:10px 12px; font-size:12px; }

    /* Nav panel items — bigger tap targets */
    .tnav-item{ padding:11px 14px; min-height:44px; }
    .tnav-dropdown{ min-width:200px; }

    /* ── تمام مشتریان on phones ── */
    /* area filter + quick-select chips: one row each that scrolls sideways */
    .area-filter-row, .quick-select-row{
      flex-wrap:nowrap !important; overflow-x:auto; -webkit-overflow-scrolling:touch;
      scrollbar-width:none; padding-bottom:2px;
    }
    .area-filter-row::-webkit-scrollbar, .quick-select-row::-webkit-scrollbar{ display:none; }
    .area-filter-row > *, .quick-select-row > *{ flex-shrink:0; white-space:nowrap; }
    .search-bar input{ text-overflow:ellipsis; }
    .search-bar input::placeholder{ text-overflow:ellipsis; }

    /* customer table → one card per customer (no sideways scrolling) */
    .data.customer-cards{ min-width:0 !important; }
    .data.customer-cards thead{ display:none; }
    .data.customer-cards, .data.customer-cards tbody{ display:block; width:100%; }
    .data.customer-cards tr{
      display:flex; flex-wrap:wrap; align-items:center; gap:6px 10px;
      padding:12px 10px; border-bottom:1px solid var(--line);
    }
    .data.customer-cards td{ display:block; padding:0 !important; border:none !important; white-space:normal !important; }
    .data.customer-cards td.cc-check{ order:1; }
    .data.customer-cards td.cc-name{ order:2; flex:1 1 0; min-width:0; font-size:14.5px; }
    .data.customer-cards td.cc-actions{ order:3; display:flex; gap:6px; }
    .data.customer-cards td.cc-idx{ display:none; }
    .data.customer-cards td.cc-father{ order:4; flex-basis:100%; font-size:12.5px; }
    .data.customer-cards td.cc-field{ order:5; font-size:12.5px; color:var(--muted); }
    .data.customer-cards td.cc-amount{ order:6; margin-inline-start:auto; font-weight:700; color:var(--navy); }
    .data.customer-cards td[data-label]::before{ content:attr(data-label) ": "; color:var(--muted); font-weight:500; }
    .data.customer-cards td.cc-check input[type=checkbox]{ width:20px !important; height:20px !important; }

    /* bigger touch targets */
    .btn-sm{ min-height:40px; }
    .data .btn-sm{ min-width:40px; justify-content:center; }
    .pay-btn{ min-height:40px !important; height:auto !important; }
    .area-filter-pill, .quick-select-row > button{ min-height:38px; }

    /* ثبت میتر / ثبت رسیدها: one column instead of two, so nothing runs
       off the right edge of the screen */
    .reg-grid{ grid-template-columns:1fr !important; gap:10px !important; }
    /* باقیداری انشعاب / حق الامتیاز: 2 × 2 instead of 4 narrow cells */
    .pay-grid:has(> :nth-child(2)){ grid-template-columns:repeat(2, minmax(0,1fr)) !important; }

    /* Hide a less important column on mobile — except in tables whose 3rd
       column is the person's name (تمام مشتریان, کد ضامن/عمومی/موقت),
       which are marked .keep-col3 */
    .data:not(.keep-col3) th:nth-child(3), .data:not(.keep-col3) td:nth-child(3){ display:none; }
  }

  /* ═══════════════════════════════════════════
     RESPONSIVE — small phones ≤ 390px
  ═══════════════════════════════════════════ */
  @media screen and (max-width: 390px){
    .stat-grid{ grid-template-columns:1fr; }
    .dash-summary-grid{ grid-template-columns:1fr !important; }
    .dash-monthly-grid{ grid-template-columns:1fr !important; }
    .topbar-brand-line1{ max-width:100px; font-size:12px; }
    .content{ padding:8px; }
    .card{ padding:10px; }
    .data{ min-width:400px; font-size:12px; }
    .data th, .data td{ padding:8px 6px; }
    .modal{ width:98vw; padding:14px; }
    .jdp-pop{ width:96vw; }
    .btn{ padding:9px 12px; font-size:12px; }
    .page-header h1{ font-size:18px; }
  }

  /* RECEIPT PRINT STYLES — single, unified rule covering both receipt
     layouts (.a4-page bill-table and .receipt-page thermal slip).
     Hides everything else on the page so only the receipt prints. */
  /* Batch print overlay — hidden on screen */
  /* Selection action bar */
  .selection-bar {
    position: sticky; top: 80px; z-index: 200;
    background: #0B132B; color: #fff;
    padding: 10px 20px; border-radius: 10px;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px;
    box-shadow: 0 4px 20px rgba(11,19,43,0.3);
    animation: slideDown .2s ease;
  }
  @keyframes slideDown { from{opacity:0;transform:translateY(-10px);} to{opacity:1;transform:none;} }

  #print-portal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg, #f4f6f8);
    z-index: 9999;
    overflow-y: auto;
  }
  #batch-print-overlay { display: none; }

  /* PRINT / PDF: A4 is the single source of truth.
     The screen preview can keep its normal responsive layout, but print
     uses fixed physical dimensions so Chrome cannot re-center or resize
     the receipt contents unexpectedly. */
  @page {
    size: A4 portrait;
    margin: 0;
  }

  /* Named page used only by printable list pages so that continuation pages
     keep a top/bottom margin (the default @page margin is 0). */
  @page list-print {
    size: A4 portrait;
    margin: 12mm 0;
  }

  @media print {
    html, body {
      width: 210mm !important;
      min-width: 210mm !important;
      margin: 0 !important;
      padding: 0 !important;
      background: #fff !important;
      overflow: visible !important;
    }

    body {
      -webkit-print-color-adjust: exact !important;
      print-color-adjust: exact !important;
    }

    body * { visibility: hidden; }

    #root {
      width: 210mm !important;
      min-width: 210mm !important;
      height: auto !important;
      margin: 0 !important;
      padding: 0 !important;
      overflow: visible !important;
    }

    /* .app and .main are fixed to 100vh with overflow:hidden on screen, which
       would clip everything after the first page when printing. */
    .app, .main {
      display: block !important;
      width: 210mm !important;
      min-width: 210mm !important;
      height: auto !important;
      min-height: 0 !important;
      overflow: visible !important;
    }

    /* Page wrapper rendered by the app (inline padding:20px, min-height:100vh)
       would shift the A4 sheets 5mm and push the last copy onto a new page. */
    .content > div:has(> .a4-preview-wrap),
    #print-portal > div:has(> .a4-preview-wrap) {
      padding: 0 !important;
      margin: 0 !important;
      min-height: 0 !important;
      background: #fff !important;
    }

    .content {
      width: 210mm !important;
      min-width: 210mm !important;
      height: auto !important;
      margin: 0 !important;
      padding: 0 !important;
      overflow: visible !important;
      flex: none !important;
    }

    #print-portal {
      display: block !important;
      visibility: visible !important;
      position: static !important;
      width: 210mm !important;
      min-width: 210mm !important;
      max-width: 210mm !important;
      margin: 0 !important;
      padding: 0 !important;
      background: #fff !important;
      overflow: visible !important;
    }

    /* When a print portal is open (batch print from the customers list, list
       summaries, receipt print from other pages) the app underneath must not
       take up space, otherwise blank pages are printed before the portal. */
    body:has(#print-portal[style*="block"]) #root { display: none !important; }

    #print-portal * { visibility: visible !important; }
    #print-portal .no-print { display: none !important; }

    .topbar, .nav-group, .form-toolbar { display: none !important; }

    /* The preview page itself is exactly one physical A4 sheet. */
    .a4-preview-wrap {
      display: block !important;
      break-inside: avoid !important;
      page-break-inside: avoid !important;
      width: 210mm !important;
      min-width: 210mm !important;
      max-width: 210mm !important;
      height: 297mm !important;
      min-height: 297mm !important;
      max-height: 297mm !important;
      margin: 0 !important;
      padding: 0 !important;
      box-sizing: border-box !important;
      background: #fff !important;
      box-shadow: none !important;
      border: 0 !important;
      overflow: hidden !important;
      visibility: visible !important;
    }

    /* Receipt content is rendered inside .content (not #print-portal), and
       "body * { visibility: hidden }" hides every element individually, so
       everything inside the A4 sheets must be made visible again. */
    .a4-preview-wrap * { visibility: visible !important; }

    .a4-preview-wrap-first {
      page-break-after: always !important;
      break-after: page !important;
      page-break-inside: avoid !important;
      break-inside: avoid !important;
    }

    .a4-preview-wrap-last {
      page-break-before: avoid !important;
      break-before: avoid-page !important;
      page-break-inside: avoid !important;
      break-inside: avoid !important;
    }

    .a4-preview-page {
      display: flex !important;
      flex-direction: column !important;
      justify-content: flex-start !important;
      align-items: stretch !important;
      width: 210mm !important;
      min-width: 210mm !important;
      max-width: 210mm !important;
      height: 297mm !important;
      min-height: 297mm !important;
      max-height: 297mm !important;
      margin: 0 !important;
      padding: 0 !important;
      box-sizing: border-box !important;
      background: #fff !important;
      overflow: hidden !important;
      visibility: visible !important;
    }

    /* Prevent the inline top/bottom margins in renderPage() from collapsing
       outside the fixed A4 page. */
    .a4-preview-page > div {
      flex: 0 0 auto !important;
      box-sizing: border-box !important;
    }

    .a4-preview-page > div:first-child {
      margin-top: 5mm !important;
    }

    .a4-preview-page > div:last-child {
      margin-bottom: 5mm !important;
    }

    /* Each receipt is exactly 200mm wide and 94mm high.
       Explicit 5mm left/right margins prevent RTL/flex centering from
       changing the horizontal print position. */
    .receipt-copy-200x94 {
      display: flex !important;
      width: 200mm !important;
      min-width: 200mm !important;
      max-width: 200mm !important;
      height: 94mm !important;
      min-height: 94mm !important;
      max-height: 94mm !important;
      margin-left: 5mm !important;
      margin-right: 5mm !important;
      margin-top: 0 !important;
      margin-bottom: 0 !important;
      padding: 0 !important;
      box-sizing: border-box !important;
      border: none !important;
      overflow: hidden !important;
      break-inside: avoid !important;
      page-break-inside: avoid !important;
    }

    .a4-field input,
    .a4-field select,
    .a4-field textarea {
      border-bottom: 1px solid #999;
    }

    .no-print { display: none !important; }

    /* Batch print */
    body.batch-printing .a4-preview-wrap {
      visibility: hidden !important;
      display: none !important;
    }

    /* The batch overlay is made of the same A4 sheets, so they must stay
       visible inside it, and the rest of the page (the receipts table) must
       not take up space, otherwise it adds dozens of blank pages. */
    body.batch-printing #batch-print-overlay .a4-preview-wrap,
    body.batch-printing #print-portal .a4-preview-wrap {
      display: block !important;
      visibility: visible !important;
    }

    body.batch-printing .content > div > *:not(#batch-print-overlay),
    body.batch-printing .content > section.keep-alive > div > *:not(#batch-print-overlay) {
      display: none !important;
    }

    /* Each receipt's own page wrapper (padding:20px, min-height:100vh, dark
       background) must not add offsets or extra pages inside the overlay. */
    body.batch-printing .batch-receipt-item > div {
      padding: 0 !important;
      margin: 0 !important;
      min-height: 0 !important;
      background: #fff !important;
    }

    body.batch-printing #batch-print-overlay {
      display: block !important;
      visibility: visible !important;
      position: static !important;
      width: 210mm !important;
      min-width: 210mm !important;
      max-width: 210mm !important;
      margin: 0 !important;
      padding: 0 !important;
      background: #fff !important;
    }

    body.batch-printing #batch-print-overlay * {
      visibility: visible !important;
    }

    body.batch-printing #batch-print-overlay .no-print {
      display: none !important;
      visibility: hidden !important;
    }

    body.batch-printing .batch-receipt-item {
      width: 210mm !important;
      page-break-after: always !important;
      break-after: page !important;
      page-break-inside: avoid !important;
      break-inside: avoid !important;
    }

    body.batch-printing .batch-receipt-item:last-child {
      page-break-after: auto !important;
      break-after: auto !important;
    }

    body.batch-printing .batch-receipt-item .receipt-page {
      visibility: visible !important;
      display: block !important;
      position: static !important;
      width: 80mm !important;
      max-width: 80mm !important;
      margin: 0 auto !important;
      box-shadow: none !important;
      border: none !important;
    }

    body.batch-printing .batch-receipt-item .receipt-page * {
      visibility: visible !important;
    }

    /* ── Customer registration form (.a4-wrap) ──────────────────────────
       The form lives inside .content, which is hidden by
       "body * { visibility: hidden }", so it used to print as blank pages.
       Hide the page header/toolbar, show only the A4 form sheet. */
    .content > div:has(> .a4-wrap) {
      padding: 0 !important;
      margin: 0 !important;
      min-height: 0 !important;
      background: #fff !important;
    }
    .content > div:has(> .a4-wrap) > *:not(.a4-wrap) { display: none !important; }
    .a4-wrap {
      display: block !important;
      width: 210mm !important;
      max-width: 210mm !important;
      margin: 0 !important;
      padding: 0 !important;
    }
    .a4-wrap, .a4-wrap * { visibility: visible !important; }
    .a4-wrap .a4-page {
      width: 210mm !important;
      max-width: 210mm !important;
      min-height: 296mm !important;
      margin: 0 !important;
      border: 0 !important;
      border-radius: 0 !important;
      box-shadow: none !important;
      box-sizing: border-box !important;
    }

    /* ── Printable list pages (portal + .a4-page) ───────────────────────
       The wrapper has a dark screen background, 20px padding and
       min-height:100vh, which printed as a dark frame around every page and
       added extra pages. Print them as a plain white A4 sheet. */
    #print-portal > div:has(> .a4-page) {
      padding: 0 !important;
      margin: 0 !important;
      min-height: 0 !important;
      background: #fff !important;
    }
    #print-portal .a4-page {
      page: list-print;
      width: 210mm !important;
      max-width: 210mm !important;
      min-height: 0 !important;
      margin: 0 !important;
      border: 0 !important;
      border-radius: 0 !important;
      box-shadow: none !important;
      box-sizing: border-box !important;
      overflow: visible !important;
    }

    /* ── Larger, easier-to-read text on printed receipts ───────────────
       Print-only (the on-screen preview is unchanged). The receipt font sizes
       are inline styles, so they are matched by their exact value and scaled.
       The company name (4.3mm, front header) and the back-page title (3.2mm,
       which contains the company name) are deliberately NOT listed, so they
       keep exactly their current size. On the front, line-height is reduced by
       the same factor the font grows, so every line box keeps its height and
       the fixed 200mm x 94mm receipt layout does not move. */
    /* Front side. Font sizes are scaled; line-height is scaled down by the same
       factor so every line box (and therefore the receipt layout) keeps its height. */
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.2mm;"] { font-size: calc(2.2mm * 1.25) !important; line-height: calc(1.55 / 1.25) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.2mm;"][style*="Inter"] { line-height: calc(1.2 / 1.25) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.31mm;"] { font-size: calc(2.31mm * 1.25) !important; line-height: calc(1.55 / 1.25) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.31mm;"][style*="Inter"] { line-height: calc(1.2 / 1.25) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.42mm;"] { font-size: calc(2.42mm * 1.25) !important; line-height: calc(1.55 / 1.25) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.42mm;"][style*="Inter"] { line-height: calc(1.2 / 1.25) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.53mm;"] { font-size: calc(2.53mm * 1.22) !important; line-height: calc(1.55 / 1.22) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.53mm;"][style*="Inter"] { line-height: calc(1.2 / 1.22) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.59mm;"] { font-size: calc(2.59mm * 1.22) !important; line-height: calc(1.55 / 1.22) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.59mm;"][style*="Inter"] { line-height: calc(1.2 / 1.22) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.64mm;"] { font-size: calc(2.64mm * 1.18) !important; line-height: calc(1.55 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.64mm;"][style*="Inter"] { line-height: calc(1.2 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.7mm;"] { font-size: calc(2.7mm * 1.18) !important; line-height: calc(1.55 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.7mm;"][style*="Inter"] { line-height: calc(1.2 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] table[style*="font-size: 2.75mm;"] { font-size: calc(2.75mm * 1.15) !important; line-height: calc(1.55 / 1.15) !important; }
    .receipt-copy-200x94[style*="position: relative"] :not(table)[style*="font-size: 2.75mm;"] { font-size: calc(2.75mm * 1.18) !important; line-height: calc(1.55 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] :not(table)[style*="font-size: 2.75mm;"][style*="Inter"] { line-height: calc(1.2 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.81mm;"] { font-size: calc(2.81mm * 1.18) !important; line-height: calc(1.55 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.81mm;"][style*="Inter"] { line-height: calc(1.2 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.86mm;"] { font-size: calc(2.86mm * 1.18) !important; line-height: calc(1.55 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 2.86mm;"][style*="Inter"] { line-height: calc(1.2 / 1.18) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.08mm;"] { font-size: calc(3.08mm * 1.12) !important; line-height: calc(1.55 / 1.12) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.08mm;"][style*="Inter"] { line-height: calc(1.2 / 1.12) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.14mm;"] { font-size: calc(3.14mm * 1.12) !important; line-height: calc(1.55 / 1.12) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.14mm;"][style*="Inter"] { line-height: calc(1.2 / 1.12) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.19mm;"] { font-size: calc(3.19mm * 1.12) !important; line-height: calc(1.55 / 1.12) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.19mm;"][style*="Inter"] { line-height: calc(1.2 / 1.12) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.96mm;"] { font-size: calc(3.96mm * 1.05) !important; line-height: calc(1.55 / 1.05) !important; }
    .receipt-copy-200x94[style*="position: relative"] [style*="font-size: 3.96mm;"][style*="Inter"] { line-height: calc(1.2 / 1.05) !important; }
    /* Back side (plenty of free space, so line-heights are left as they are). */
    .receipt-copy-200x94[style*="padding: 3mm 6mm"] [style*="font-size: 2.68mm;"] { font-size: calc(2.68mm * 1.25) !important; }
    .receipt-copy-200x94[style*="padding: 3mm 6mm"] [style*="font-size: 2.75mm;"] { font-size: calc(2.75mm * 1.25) !important; }
    .receipt-copy-200x94[style*="padding: 3mm 6mm"] [style*="font-size: 2.9mm;"] { font-size: calc(2.9mm * 1.25) !important; }
    .receipt-copy-200x94[style*="padding: 3mm 6mm"] [style*="font-size: 3.04mm;"] { font-size: calc(3.04mm * 1.25) !important; }
    .receipt-copy-200x94[style*="padding: 3mm 6mm"] [style*="font-size: 3.33mm;"] { font-size: calc(3.33mm * 1.25) !important; }
  }
  .receipt-page {
    margin: 20px auto;
    padding: 0;
    background: var(--paper-card);
    color: var(--ink);
    font-family: 'Vazirmatn', sans-serif;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  }
  .a4-preview-wrap {
    width: 210mm; height: 297mm;
    margin: 20px auto;
    background: white;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    border: 1px solid var(--line-strong);
    overflow: hidden;
  }
  .a4-preview-page {
    width: 210mm; height: 297mm;
    box-sizing: border-box;
    background: white;
  }
  .receipt-copy-200x94 { border: 2px solid #0B132B; }
  .receipt-header {
    text-align: center;
    padding: 20px 22px 14px;
    background: #ffffff;
    color: #0B132B;
    margin-bottom: 0;
    border-bottom: 1px solid #eee;
  }
  .receipt-logo {
    width: 56px; height: 56px;
    margin: 0 auto 8px; display: block;
  }
  .receipt-company {
    font-size: 14px; font-weight: 800;
    margin: 4px 0; color: #0B132B; letter-spacing: normal;
  }
  .receipt-header::after {
    content: ""; display: block; height: 3px;
    background: linear-gradient(90deg, #0B132B, #0FA4AF);
    margin: 12px -22px -14px;
  }
  .receipt-info {
    font-size: 13px; padding: 10px 20px 6px;
    border-bottom: 1px solid var(--line);
  }
  .receipt-info-row {
    display: flex; justify-content: space-between;
    align-items: center; padding: 3px 0;
    border-bottom: 1px solid var(--line);
    gap: 8px;
  }
  .receipt-info-row:last-child { border-bottom: none; }
  .receipt-info-row span:first-child { color: var(--muted); font-size: 12px; }
  .receipt-info-row span:last-child { font-weight: 700; color: var(--ink); font-size: 13px; }
  .receipt-section {
    padding: 8px 20px 10px;
    border-bottom: 1px solid var(--line);
  }
  .receipt-section-title {
    font-size: 10px; font-weight: 800; letter-spacing: normal;
    text-transform: uppercase; color: #0FA4AF;
    margin-bottom: 7px; padding-bottom: 4px;
    border-bottom: 2px solid var(--line);
    display: flex; align-items: center; gap: 6px;
  }
  .receipt-section-title::before {
    content: ""; width: 3px; height: 11px;
    background: #0FA4AF; border-radius: 2px;
    display: inline-block;
  }
  .receipt-line {
    display: flex; justify-content: space-between;
    font-size: 12px; margin: 3px 0;
    color: var(--ink); gap: 8px;
  }
  .receipt-line span:first-child { color: var(--muted); }
  .receipt-line span:last-child { font-weight: 600; }
  .receipt-total {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 20px;
    background: #ffffff;
    border-top: 2px solid #eee;
  }
  .receipt-total span:first-child { font-size: 12px; font-weight: 600; color: #888; }
  .receipt-total span:last-child { font-size: 18px; font-weight: 800; color: #0FA4AF; }
  .receipt-qr {
    text-align: center; padding: 10px 20px 6px;
    border-top: 1px solid var(--line);
    background: var(--paper);
  }
  .receipt-qr canvas { max-width: 100%; height: auto; }
  .receipt-footer {
    text-align: center; font-size: 11px; padding: 10px 20px 16px;
    color: var(--muted); background: var(--paper);
    border-top: 1px solid var(--line);
  }
