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

    html {
      overflow-x: hidden;
      max-width: 100%;
    }

    :root {
      --primary:       #0D5BFF;
      --primary-light: #E8F1FF;
      --primary-dark:  #0A49CC;
      --accent:        #35D6A8;
      --accent-dark:   #2AB88A;
      --danger:        #ef4444;
      --gray-50:  #f8fafc; --gray-100: #f1f5f9; --gray-200: #e2e8f0;
      --gray-300: #cbd5e1; --gray-400: #94a3b8; --gray-500: #64748b;
      --gray-600: #475569; --gray-700: #334155; --gray-900: #0f172a;
      --white: #ffffff;
      --border-subtle: rgba(0, 0, 0, 0.06);
      --border-default: rgba(0, 0, 0, 0.08);
      --border-strong: rgba(0, 0, 0, 0.12);
      --overlay-backdrop: rgba(0, 0, 0, 0.5);
      --focus-ring: rgba(13, 91, 255, 0.1);
      --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
      --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 10px 15px rgba(0,0,0,0.04);
      --shadow-lg: 0 20px 25px rgba(0,0,0,0.08), 0 10px 10px rgba(0,0,0,0.04);
      --shadow-xl: 0 25px 50px rgba(0,0,0,0.12);
      --radius: 12px;
      --radius-md: 9px;
      --radius-sm: 8px;
    }

    body {
      font-family: 'Inter', sans-serif;
      background: var(--gray-50);
      color: var(--gray-900);
      min-height: 100vh;
      font-size: 14px;
      line-height: 1.6;
      letter-spacing: -0.2px;
      overflow-x: hidden;
      max-width: 100%;
    }

    /* ═══════════════════════ HEADER ═══════════════════════ */
    header {
      background: var(--white);
      border-bottom: 1px solid var(--border-subtle);
      position: sticky;
      top: 0;
      z-index: 200;
      box-shadow: var(--shadow-sm);
      height: 64px;
      display: flex;
      align-items: center;
      max-width: 100%;
    }
    .header-inner {
      margin: 0 auto;
      width: 100%;
      min-width: 0;
      max-width: min(1280px, 100%);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 32px;
      padding-left: max(32px, env(safe-area-inset-left, 0px));
      padding-right: max(32px, env(safe-area-inset-right, 0px));
      gap: 20px;
    }
    .logo {
      display: flex;
      align-items: center;
      gap: 12px;
      text-decoration: none;
      color: inherit;
      flex-shrink: 0;
      transition: opacity 0.2s;
    }
    .logo:hover { opacity: 0.85; }
    .logo-img {
      display: block;
      height: 38px;
      width: auto;
      max-width: min(132px, 38vw);
      object-fit: contain;
    }

    .header-right {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-left: auto;
      min-width: 0;
      flex-shrink: 1;
    }

    .theme-toggle-btn {
      width: 40px;
      height: 40px;
      border-radius: 999px;
      border: 1px solid var(--border-default);
      background: var(--white);
      color: var(--gray-600);
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: border-color 0.2s, background 0.2s, color 0.2s, box-shadow 0.2s;
      box-shadow: var(--shadow-sm);
    }
    .theme-toggle-btn:hover {
      border-color: var(--primary);
      background: var(--primary-light);
      color: var(--primary);
    }
    .theme-toggle-btn svg {
      width: 18px;
      height: 18px;
      display: block;
    }
    [data-theme="dark"] .theme-icon-moon,
    [data-theme="light"] .theme-icon-sun,
    .theme-icon-sun[hidden],
    .theme-icon-moon[hidden] {
      display: none;
    }
    [data-theme="dark"] .theme-icon-sun,
    [data-theme="light"] .theme-icon-moon {
      display: block;
    }

    /* Company picker */
    .company-btn {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 16px;
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-md);
      background: var(--white);
      cursor: pointer;
      font-size: 14px;
      font-weight: 500;
      color: var(--gray-700);
      transition: all 0.2s;
      position: relative;
      height: 40px;
    }
    .company-btn:hover {
      border-color: var(--primary);
      background: var(--primary-light);
      color: var(--primary);
      box-shadow: var(--shadow-sm);
    }
    .company-avatar {
      width: 28px;
      height: 28px;
      border-radius: 7px;
      background: linear-gradient(135deg, #f59e0b, #ef4444);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      font-weight: 700;
      color: white;
      flex-shrink: 0;
    }
    .company-name {
      max-width: 140px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .chevron {
      color: var(--gray-400);
      transition: transform 0.2s;
    }
    .company-btn[aria-expanded="true"] .chevron {
      transform: rotate(180deg);
    }

    /* Company dropdown */
    .company-dropdown {
      position: absolute;
      top: calc(100% + 12px);
      left: 0;
      min-width: 280px;
      background: var(--white);
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      box-shadow: var(--shadow-lg);
      z-index: 300;
      display: none;
      overflow: hidden;
    }
    .company-dropdown.open { display: block; }
    .dropdown-header {
      padding: 14px 18px;
      border-bottom: 1px solid var(--border-subtle);
      background: var(--gray-50);
    }
    .dropdown-header p {
      font-size: 11px;
      color: var(--gray-500);
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.8px;
    }
    .company-list {
      max-height: 240px;
      overflow-y: auto;
    }
    .company-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 18px;
      cursor: pointer;
      transition: background 0.15s;
      font-size: 14px;
    }
    .company-item:hover {
      background: var(--gray-50);
    }
    .company-item.active {
      background: var(--primary-light);
      color: var(--primary);
      font-weight: 600;
    }
    .company-item .ci-avatar {
      width: 32px;
      height: 32px;
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 13px;
      font-weight: 700;
      color: white;
      flex-shrink: 0;
    }
    .ci-info {
      flex: 1;
    }
    .ci-name {
      font-size: 14px;
      font-weight: 600;
    }
    .ci-id {
      font-size: 12px;
      color: var(--gray-500);
      margin-top: 2px;
    }
    .check-icon {
      color: var(--primary);
      flex-shrink: 0;
    }
    .dropdown-footer {
      border-top: 1px solid rgba(0,0,0,0.06);
      padding: 12px 18px;
      background: var(--gray-50);
    }
    .add-company-btn {
      width: 100%;
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 10px 14px;
      border: 1px dashed var(--gray-300);
      border-radius: var(--radius-sm);
      background: none;
      cursor: pointer;
      font-size: 13px;
      color: var(--primary);
      font-weight: 600;
      transition: all 0.2s;
    }
    .add-company-btn:hover {
      background: var(--primary-light);
      border-color: var(--primary);
    }

    /* Profile btn */
    .profile-menu-wrap {
      position: relative;
    }
    .profile-btn {
      min-width: 40px;
      height: 40px;
      border-radius: 999px;
      background: var(--white);
      border: 1px solid var(--border-default);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      color: var(--gray-700);
      font-weight: 600;
      font-size: 13px;
      padding: 4px 10px 4px 4px;
      gap: 8px;
      transition: all 0.2s;
      position: relative;
      flex-shrink: 0;
      box-shadow: var(--shadow-sm);
    }
    .profile-btn:hover {
      border-color: var(--primary);
      background: var(--primary-light);
      color: var(--primary);
      box-shadow: var(--shadow-md);
    }
    .profile-avatar {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background: linear-gradient(135deg, var(--primary), var(--accent));
      color: var(--white);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      font-weight: 700;
      flex-shrink: 0;
    }
    .profile-name {
      max-width: 180px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 13px;
      font-weight: 600;
    }
    .profile-btn:not(.guest) .profile-name {
      max-width: 180px;
      color: var(--gray-800);
    }
    .profile-guest-label {
      max-width: none;
      white-space: nowrap;
      font-size: 13px;
      font-weight: 600;
      padding-right: 2px;
    }
    .profile-btn.guest {
      width: auto;
      min-width: 40px;
      padding: 4px 14px 4px 4px;
      justify-content: flex-start;
      border-radius: 999px;
      background: var(--primary-light);
      color: var(--primary);
      box-shadow: none;
      border: 1px solid rgba(13, 91, 255, 0.18);
    }
    .profile-btn.guest:hover {
      background: var(--primary);
      color: var(--white);
      border-color: var(--primary);
    }
    .profile-btn.guest .profile-avatar {
      width: 30px;
      height: 30px;
      background: var(--white);
      color: var(--primary);
    }
    .profile-btn.guest:hover .profile-avatar {
      background: rgba(255, 255, 255, 0.18);
      color: var(--white);
    }
    .profile-btn.guest .profile-guest-label {
      display: block;
      max-width: none;
      white-space: nowrap;
      font-size: 13px;
      font-weight: 600;
      padding-right: 2px;
    }
    .profile-btn:not(.guest) {
      width: auto;
      min-width: 40px;
      padding: 4px 14px 4px 4px;
    }
    .profile-dropdown {
      position: absolute;
      right: 0;
      top: calc(100% + 10px);
      min-width: 220px;
      border: 1px solid var(--border-default);
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-lg);
      display: none;
      overflow: hidden;
      z-index: 310;
    }
    .profile-dropdown.open {
      display: block;
    }
    .profile-dd-item {
      width: 100%;
      border: 0;
      background: transparent;
      text-align: left;
      padding: 11px 14px;
      font-size: 13px;
      color: var(--gray-700);
      cursor: pointer;
      transition: background 0.15s;
    }
    .profile-dd-item:hover {
      background: var(--gray-50);
    }
    .profile-dd-sep {
      border-top: 1px solid rgba(0,0,0,0.08);
      margin: 2px 0;
    }
    .profile-dd-item.danger {
      color: #dc2626;
      font-weight: 600;
    }
    .profile-dd-item.danger:hover {
      background: #fef2f2;
    }
    .profile-dd-logout-form {
      margin: 0;
    }

    .company-btn.company-btn-guest {
      opacity: 0.72;
      cursor: pointer;
    }

    /* Main column: stretch to grid row height so guest lock can truly center vertically */
    #views-wrap {
      position: relative;
      align-self: stretch;
      display: flex;
      flex-direction: column;
      width: 100%;
      min-width: 0;
      max-width: 100%;
      min-height: calc(100vh - 200px);
      z-index: 1;
    }

    .page-main[hidden] {
      display: none !important;
    }

    .page-main:not([hidden]) {
      flex: 1 1 auto;
      width: 100%;
      min-width: 0;
      max-width: 100%;
    }

    #view-invoice {
      flex: 1 1 auto;
      width: 100%;
      min-width: 0;
      max-width: 100%;
    }
    #view-history,
    #view-clients,
    #view-products,
    #view-stats,
    #view-templates {
      width: 100%;
      min-width: 0;
      max-width: 100%;
    }

    .guest-content-lock {
      flex: 1 1 auto;
      z-index: 40;
      display: none;
      flex-direction: column;
      flex-wrap: nowrap;
      align-items: center;
      justify-content: center;
      width: 100%;
      min-height: min(520px, calc(100vh - 240px));
      padding: clamp(24px, 5vw, 48px);
      box-sizing: border-box;
      background:
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(13, 91, 255, 0.07) 0%, transparent 55%),
        linear-gradient(165deg, rgba(248, 250, 252, 0.98) 0%, rgba(241, 245, 249, 0.95) 50%, rgba(239, 246, 255, 0.92) 100%);
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      border-radius: var(--radius);
      border: 1px solid rgba(226, 232, 240, 0.85);
    }

    .guest-content-lock.show {
      display: flex;
    }

    .guest-lock-card {
      position: relative;
      box-sizing: border-box;
      width: min(100%, 400px);
      max-width: 400px;
      flex: 0 0 auto;
      align-self: center;
      margin: 0 auto;
      padding: 2.5rem 2rem 2.25rem;
      display: grid;
      grid-template-columns: minmax(0, 1fr);
      justify-items: center;
      justify-content: center;
      align-content: center;
      row-gap: 0.875rem;
      column-gap: 0;
      text-align: center;
      background: linear-gradient(165deg, #ffffff 0%, #f8fafc 42%, #f1f5f9 100%);
      border-radius: 20px;
      border: 1px solid rgba(226, 232, 240, 0.9);
      box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.95) inset,
        0 1px 3px rgba(15, 23, 42, 0.05),
        0 16px 44px -12px rgba(13, 91, 255, 0.14),
        0 28px 56px -20px rgba(15, 23, 42, 0.1);
      animation: guestLockCardIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
      isolation: isolate;
      overflow: hidden;
    }

    .guest-lock-card::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 4px;
      border-radius: 20px 20px 0 0;
      background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 50%, var(--primary) 100%);
      background-size: 200% 100%;
      opacity: 0.95;
      z-index: 0;
    }

    .guest-lock-card > * {
      position: relative;
      z-index: 1;
    }

    .guest-lock-card .guest-lock-btn {
      margin-top: 0.35rem;
    }

    @keyframes guestLockCardIn {
      from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
      }
      to {
        opacity: 1;
        transform: translateY(0) scale(1);
      }
    }

    .guest-lock-icon-wrap {
      width: 68px;
      height: 68px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0;
      background: linear-gradient(155deg, #eff6ff 0%, #dbeafe 50%, #bfdbfe 100%);
      color: var(--primary);
      box-shadow:
        0 2px 8px rgba(13, 91, 255, 0.12),
        0 8px 24px rgba(13, 91, 255, 0.18);
      border: 1px solid rgba(191, 219, 254, 0.8);
    }

    .guest-lock-icon {
      display: block;
    }

    .guest-lock-title {
      font-size: 1.125rem;
      font-weight: 700;
      letter-spacing: -0.02em;
      color: var(--gray-900);
      width: 100%;
      max-width: 22rem;
      margin: 0;
      line-height: 1.45;
      text-align: center;
    }

    .guest-lock-sub {
      font-size: 0.9375rem;
      color: var(--gray-500);
      width: 100%;
      max-width: 21rem;
      margin: 0;
      line-height: 1.55;
      text-align: center;
    }

    .guest-lock-btn {
      padding: 0.7rem 1.65rem;
      font-size: 0.9375rem;
      font-weight: 600;
      border-radius: 12px;
      box-shadow: 0 2px 10px rgba(13, 91, 255, 0.28);
      transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .guest-lock-btn:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 22px rgba(13, 91, 255, 0.35);
    }

    @media (prefers-reduced-motion: reduce) {
      .guest-lock-card {
        animation: none;
      }
      .guest-lock-btn:hover {
        transform: none;
      }
    }

    /* ═══════════════════════ LAYOUT ═══════════════════════ */
    .main-wrap {
      max-width: min(1400px, 100%);
      margin: 0 auto;
      padding: 32px 32px;
      display: grid;
      grid-template-columns: 220px 1fr;
      gap: 32px;
      align-items: start;
      width: 100%;
      min-width: 0;
      box-sizing: border-box;
    }

    /* ═══════════════════════ SIDEBAR ═══════════════════════ */
    .sidebar {
      display: flex;
      flex-direction: column;
      gap: 20px;
      position: sticky;
      top: 80px;
      min-width: 0;
      max-width: 100%;
    }
    .sidebar-card {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      padding: 22px;
      border: 1px solid var(--border-subtle);
      min-width: 0;
      max-width: 100%;
    }
    .sidebar-card h3,
    .invoice-actions-footer h3 {
      font-size: 12px;
      font-weight: 700;
      margin-bottom: 16px;
      color: var(--gray-500);
      text-transform: uppercase;
      letter-spacing: 0.8px;
    }

    /* Sidebar nav */
    .sb-nav {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }
    .sb-nav-btn {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 11px 14px;
      border-radius: var(--radius-md);
      border: none;
      background: none;
      cursor: pointer;
      font-size: 14px;
      font-weight: 500;
      color: var(--gray-600);
      transition: all 0.2s;
      width: 100%;
      text-align: left;
    }
    a.sb-nav-btn {
      text-decoration: none;
      box-sizing: border-box;
    }
    .sb-nav-btn:hover {
      background: var(--gray-100);
      color: var(--gray-900);
    }
    .sb-nav-btn.active {
      background: var(--primary);
      color: white;
      font-weight: 600;
    }
    .sb-nav-btn svg {
      flex-shrink: 0;
      width: 20px;
      height: 20px;
    }
    .sb-nav-btn .nav-label {
      flex: 1;
    }
    .nav-badge {
      background: #ef4444;
      color: white;
      font-size: 11px;
      font-weight: 700;
      padding: 3px 8px;
      border-radius: 6px;
      min-width: 20px;
      text-align: center;
      flex-shrink: 0;
    }

    /* Sidebar action btns */
    .action-btns {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .btn {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 10px 18px;
      border-radius: var(--radius-md);
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      border: none;
      transition: all 0.2s;
      text-decoration: none;
      justify-content: center;
    }
    .btn-primary {
      background: linear-gradient(135deg, var(--primary), var(--primary-dark));
      color: white;
    }
    .btn-primary:hover {
      box-shadow: 0 8px 20px rgba(13,91,255,0.3);
      transform: translateY(-1px);
    }
    .btn-success {
      background: linear-gradient(135deg, var(--accent), var(--accent-dark));
      color: white;
    }
    .btn-success:hover {
      box-shadow: 0 8px 20px rgba(16,185,129,0.3);
      transform: translateY(-1px);
    }
    .btn-outline {
      background: var(--white);
      color: var(--gray-700);
      border: 1px solid var(--border-default);
    }
    .btn-outline:hover {
      background: var(--gray-50);
      border-color: rgba(0,0,0,0.12);
    }
    .btn-ghost {
      background: transparent;
      color: var(--gray-700);
    }
    .btn-ghost:hover {
      background: var(--gray-100);
    }
    .btn-lg {
      padding: 12px 18px;
      font-size: 14px;
      font-weight: 700;
      width: 100%;
      border-radius: var(--radius-md);
    }

    /* Settings toggles */
    .settings-list {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }
    .setting-item {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }
    .setting-item > label {
      font-size: 12px;
      color: var(--gray-500);
      font-weight: 600;
    }
    .toggle-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .toggle {
      position: relative;
      display: inline-block;
      width: 44px;
      height: 24px;
    }
    .toggle input {
      opacity: 0;
      width: 0;
      height: 0;
    }
    .slider {
      position: absolute;
      inset: 0;
      background: var(--gray-300);
      border-radius: 24px;
      transition: 0.3s;
      cursor: pointer;
    }
    .slider:before {
      content: '';
      position: absolute;
      height: 18px;
      width: 18px;
      left: 3px;
      top: 3px;
      background: white;
      border-radius: 50%;
      transition: 0.3s;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    input:checked + .slider {
      background: var(--accent);
    }
    input:checked + .slider:before {
      transform: translateX(20px);
    }

    /* Totals mini */
    .total-display {
      text-align: center;
      padding: 12px 0;
    }
    .total-display .amount {
      font-size: 36px;
      font-weight: 800;
      color: var(--primary);
      line-height: 1.1;
    }
    .total-display .curr {
      font-size: 13px;
      color: var(--gray-500);
      margin-top: 6px;
    }

    /* Visually hidden - kept for SEO / screen readers */
    .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      clip-path: inset(50%);
      white-space: nowrap;
      border: 0;
    }

    .landing-seo {
      margin-top: 20px;
      padding: 22px 24px;
      background: var(--white);
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
    }
    .landing-seo h2 {
      margin: 0 0 8px;
      font-size: 1.05rem;
      font-weight: 700;
      color: var(--gray-900);
      letter-spacing: -0.02em;
    }
    .landing-seo p {
      margin: 0 0 12px;
      font-size: 14px;
      line-height: 1.65;
      color: var(--gray-600);
      max-width: 720px;
    }
    .landing-seo-list {
      margin: 0;
      padding-left: 18px;
      color: var(--gray-600);
      font-size: 13px;
      line-height: 1.7;
    }
    [data-theme="dark"] .landing-seo {
      background: var(--gray-50);
      border-color: var(--border-default);
    }
    [data-theme="dark"] .landing-seo h2 {
      color: var(--gray-900);
    }
    [data-theme="dark"] .landing-seo p,
    [data-theme="dark"] .landing-seo-list {
      color: var(--gray-600);
    }

    .site-support {
      margin: 14px 0 0;
      font-size: 13px;
      line-height: 1.65;
      color: var(--gray-500);
    }
    .site-support a {
      color: var(--primary);
      text-decoration: none;
      font-weight: 500;
    }
    .site-support a:hover {
      text-decoration: underline;
    }
    footer .site-support {
      margin-top: 10px;
    }
    .about-cta .site-support {
      margin-bottom: 18px;
    }
    [data-theme="dark"] .site-support {
      color: var(--gray-500);
    }

    /* ═══════════════════════ PARAMS MODULE ═══════════════════════ */
    .params-module {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      padding: 16px 24px;
      display: flex;
      align-items: center;
      gap: 0;
      margin-bottom: 20px;
      border: 1px solid var(--border-subtle);
      max-width: 100%;
      min-width: 0;
      box-sizing: border-box;
    }
    .params-module-title {
      font-size: 12px;
      font-weight: 700;
      color: var(--gray-500);
      text-transform: uppercase;
      letter-spacing: 0.8px;
      margin: 0 24px 0 0;
      white-space: nowrap;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .params-module-title svg {
      width: 16px;
      height: 16px;
      color: var(--gray-400);
    }
    .params-divider {
      width: 1px;
      height: 24px;
      background: rgba(0,0,0,0.06);
      margin: 0 24px;
      flex-shrink: 0;
    }
    .params-controls {
      display: flex;
      align-items: center;
      gap: 0;
      flex: 1;
      min-width: 0;
    }
    .currency-select {
      background: var(--gray-50);
      border: 1px solid var(--border-default);
      color: var(--gray-700);
      border-radius: var(--radius-sm);
      padding: 8px 14px;
      font-size: 13px;
      font-weight: 500;
      cursor: pointer;
      outline: none;
      transition: all 0.2s;
      margin-right: 24px;
      min-width: 220px;
      max-width: min(320px, 100%);
    }
    .currency-select:focus {
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(13,91,255,0.1);
    }
    .ctrl-toggle-item {
      display: flex;
      align-items: center;
      gap: 10px;
      font-size: 13px;
      color: var(--gray-600);
      font-weight: 500;
      margin-right: 24px;
      white-space: nowrap;
    }
    .ctrl-toggle-item .toggle {
      width: 40px;
      height: 22px;
      flex-shrink: 0;
    }
    .ctrl-toggle-item .slider:before {
      height: 16px;
      width: 16px;
    }

    /* ═══════════════════════ INVOICE CARD ═══════════════════════ */
    .invoice-card {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-md);
      overflow: hidden;
      border: 1px solid var(--border-subtle);
      max-width: 100%;
      min-width: 0;
    }
    .invoice-topbar {
      background: linear-gradient(135deg, var(--primary), var(--primary-dark));
      padding: 20px 32px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: white;
    }
    .invoice-topbar h2 {
      font-size: 22px;
      font-weight: 800;
      letter-spacing: -0.5px;
    }

    .invoice-body {
      padding: 32px;
    }

    .invoice-actions-footer {
      padding: 22px 32px 28px;
      border-top: 1px solid rgba(0, 0, 0, 0.08);
      background: linear-gradient(180deg, var(--gray-50) 0%, var(--white) 55%);
      max-width: 100%;
      min-width: 0;
    }
    .invoice-actions-footer .action-btns {
      width: 100%;
      max-width: 100%;
    }

    .inv-header {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 32px;
      margin-bottom: 32px;
      min-width: 0;
      max-width: 100%;
    }
    .logo-upload-col {
      min-width: 0;
    }
    .logo-upload-label {
      display: block;
      cursor: pointer;
    }
    .logo-upload-area {
      border: 2px dashed var(--gray-300);
      border-radius: var(--radius);
      padding: 24px;
      text-align: center;
      cursor: pointer;
      transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
      background: var(--gray-50);
      min-height: 120px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }
    .logo-upload-area:hover {
      border-color: var(--primary);
      background: var(--primary-light);
    }
    .logo-upload-area.is-dragover {
      border-color: var(--primary);
      background: var(--primary-light);
      box-shadow: 0 0 0 3px rgba(13, 91, 255, 0.15);
    }
    .logo-upload-area svg {
      width: 32px;
      height: 32px;
      color: var(--gray-400);
    }
    .logo-upload-area p {
      font-size: 12px;
      color: var(--gray-500);
    }
    .logo-upload-hint {
      font-size: 11px;
      color: var(--gray-400);
      margin-top: 2px;
    }
    .logo-upload-area strong {
      font-size: 14px;
      color: var(--gray-700);
      font-weight: 600;
    }
    #logo-preview {
      max-width: 140px;
      max-height: 80px;
      object-fit: contain;
      display: none;
    }
    #logo-input {
      display: none;
    }
    .inv-title-area {
      display: flex;
      flex-direction: column;
      gap: 14px;
      justify-content: center;
      align-items: center;
      text-align: center;
    }
    .big-title-static {
      font-size: 40px;
      font-weight: 800;
      color: var(--gray-900);
      letter-spacing: -1.2px;
      line-height: 1.1;
      overflow-wrap: anywhere;
      word-break: break-word;
    }
    .sender-contact-row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 14px;
      width: 100%;
      text-align: left;
    }
    .sender-contact-row .field-group label {
      font-size: 12px;
      color: var(--gray-500);
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.6px;
    }
    .sender-contact-row .field-group input {
      font-size: 13px;
    }

    .two-col {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px 56px;
      margin-bottom: 24px;
      align-items: start;
    }
    .field-section {
      display: flex;
      flex-direction: column;
      gap: 10px;
      min-width: 0;
    }
    .two-col > .field-section:first-child { padding-right: 28px; border-right: 2px solid var(--gray-200); }
    .two-col > .field-section:last-child  { padding-left: 28px; }

    /* Bank select */
    .bank-select {
      width: 100%; padding: 8px 10px; border: 1px solid var(--gray-200);
      border-radius: 8px; font-size: 14px; color: var(--gray-700);
      background: var(--white); cursor: pointer; outline: none; transition: border-color .15s;
    }
    .bank-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,91,255,.1); }
    .sender-company-row {
      display: flex;
      gap: 8px;
      align-items: stretch;
    }
    .sender-company-row .bank-select {
      flex: 1;
      min-width: 0;
    }
    .sender-company-add-btn {
      flex-shrink: 0;
      white-space: nowrap;
      padding: 8px 12px;
      font-size: 12px;
    }

    /* Receiver search inline */
    .section-label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 2px; }
    .receiver-search {
      flex: 1; max-width: 300px; padding: 5px 10px;
      border: 1px solid var(--gray-200); border-radius: 7px;
      font-size: 12px; color: var(--gray-700); outline: none; transition: border-color .15s;
    }
    .receiver-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,91,255,.1); }
    .section-label {
      font-size: 16px;
      font-weight: 800;
      color: var(--gray-900);
      letter-spacing: -0.3px;
      margin-bottom: 6px;
    }
    .field-group {
      display: flex;
      flex-direction: column;
      gap: 7px;
    }
    .field-group label {
      font-size: 13px;
      color: var(--gray-600);
      font-weight: 600;
    }
    .field-required::after {
      content: " *";
      color: #dc2626;
      font-weight: 700;
    }
    .invoice-items-hint {
      margin: 4px 0 0;
      font-size: 12px;
      color: var(--gray-500);
      font-weight: 500;
    }
    .field-group.field-invalid label {
      color: #b91c1c;
    }
    .field-group.field-invalid input,
    .field-group.field-invalid select,
    .field-group.field-invalid textarea {
      border-color: #ef4444;
      box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
    }
    .items-table-wrap.field-invalid {
      outline: 2px solid rgba(239, 68, 68, 0.35);
      outline-offset: 2px;
      border-radius: var(--radius);
    }

    input[type=text],
    input[type=email],
    input[type=number],
    input[type=date],
    input[type=password],
    textarea,
    select {
      width: 100%;
      padding: 10px 14px;
      border: 1px solid var(--border-default);
      border-radius: var(--radius-sm);
      font-size: 14px;
      font-family: inherit;
      color: var(--gray-900);
      background: var(--white);
      transition: all 0.2s;
      outline: none;
    }
    input:focus,
    textarea:focus,
    select:focus {
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(13,91,255,0.1);
    }
    input::placeholder,
    textarea::placeholder {
      color: var(--gray-400);
    }
    textarea {
      resize: vertical;
      min-height: 76px;
      line-height: 1.5;
    }

    .meta-row {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 16px;
      background: var(--gray-50);
      border-radius: var(--radius);
      padding: 20px;
      margin-bottom: 28px;
      border: 1px solid var(--border-subtle);
    }
    .meta-field label {
      font-size: 12px;
      color: var(--gray-500);
      font-weight: 600;
      display: block;
      margin-bottom: 7px;
    }
    .invoice-num-hint {
      font-size: 11px;
      color: var(--gray-500);
      margin: 6px 0 0;
      line-height: 1.45;
    }

    .section-title {
      font-size: 13px;
      font-weight: 700;
      color: var(--gray-600);
      text-transform: uppercase;
      letter-spacing: 0.8px;
      margin-bottom: 12px;
      padding-bottom: 10px;
      border-bottom: 1px solid var(--border-subtle);
    }
    .section-title h3 {
      margin: 0;
      font: inherit;
      color: inherit;
      letter-spacing: inherit;
      text-transform: inherit;
    }
    .items-table {
      width: 100%;
      border-collapse: collapse;
      margin-bottom: 16px;
    }
    .table-scroll-wrap {
      width: 100%;
      max-width: 100%;
      min-width: 0;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      box-sizing: border-box;
    }
    .items-table-wrap {
      margin-bottom: 0;
    }
    .items-table thead th {
      text-align: left;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.6px;
      color: var(--gray-500);
      padding: 10px 12px;
      background: var(--gray-50);
      border-bottom: 1px solid rgba(0,0,0,0.08);
    }
    .items-table tbody tr {
      border-bottom: 1px solid var(--border-subtle);
    }
    .items-table tbody tr:hover td {
      background: var(--gray-50);
    }
    .items-table tbody td {
      padding: 10px 12px;
      vertical-align: middle;
    }
    /* all table inputs - visible editable box */
    .items-table tbody td input {
      border: 1px solid var(--border-default);
      background: var(--gray-50);
      padding: 8px 10px;
      font-size: 14px;
      border-radius: 7px;
      width: 100%;
      box-sizing: border-box;
      transition: all 0.15s;
      color: var(--gray-800);
    }
    .items-table tbody td input:hover {
      border-color: var(--gray-300);
      background: white;
    }
    .items-table tbody td input:focus {
      border-color: var(--primary);
      background: white;
      box-shadow: 0 0 0 3px rgba(13,91,255,0.1);
    }
    /* qty & price - right-aligned numbers */
    .items-table tbody td.col-qty input,
    .items-table tbody td.col-price input {
      text-align: right;
      font-weight: 600;
    }
    .items-table tbody td.col-num {
      width: 40px;
      text-align: center;
      font-size: 12px;
      color: var(--gray-400);
      font-weight: 700;
      padding: 10px 6px;
      user-select: none;
    }
    .items-table thead th.col-num { width: 40px; text-align: center; }
    .items-table thead th.col-qty { text-align: right; padding-right: 14px; }
    .items-table thead th.col-price { text-align: right; padding-right: 14px; }
    .items-table thead th.col-total { text-align: right; padding-right: 12px; }
    .items-table thead th.col-del { text-align: center; }
    .items-table tbody td.col-desc { width: 38%; }
    .items-table tbody td.col-qty { width: 11%; }
    .items-table tbody td.col-price { width: 17%; }
    .items-table tbody td.col-total {
      width: 17%;
      text-align: right;
      font-weight: 600;
      color: var(--gray-800);
      font-size: 14px;
      padding-right: 12px;
    }
    .items-table tbody td.col-del { width: 8%; text-align: center; }
    .del-btn {
      background: none;
      border: none;
      cursor: pointer;
      color: var(--gray-300);
      padding: 6px;
      border-radius: 6px;
      transition: all 0.15s;
    }
    .del-btn:hover {
      color: var(--danger);
      background: #fef2f2;
    }
    .add-item-btn {
      background: none;
      border: 1px dashed var(--gray-300);
      color: var(--primary);
      border-radius: var(--radius-sm);
      padding: 10px 16px;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      width: 100%;
      text-align: left;
      transition: all 0.2s;
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 28px;
    }
    .add-item-btn:hover {
      background: var(--primary-light);
      border-color: var(--primary);
    }

    .totals-row {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 24px;
      margin-bottom: 16px;
      flex-wrap: wrap;
    }
    .totals-row .totals-row-notes {
      flex: 1 1 300px;
      min-width: 0;
      margin-bottom: 0;
    }
    .totals-row .totals-row-notes textarea {
      min-height: 72px;
      resize: vertical;
    }
    .totals-box {
      flex: 0 0 auto;
      width: 340px;
      max-width: 100%;
      background: var(--gray-50);
      border-radius: var(--radius);
      padding: 22px;
      border: 1px solid var(--border-subtle);
    }
    .totals-line {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 0;
      font-size: 14px;
      color: var(--gray-600);
    }
    .totals-line .tl-label {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .totals-line input[type=number] {
      width: 60px;
      padding: 6px 10px;
      text-align: right;
      font-size: 13px;
      border: 1px solid var(--border-default);
      border-radius: 6px;
    }
    .totals-line.total-final {
      border-top: 2px solid rgba(0,0,0,0.1);
      margin-top: 10px;
      padding-top: 14px;
      font-size: 16px;
      font-weight: 800;
      color: var(--gray-900);
    }
    .totals-line.total-final .tl-val {
      color: var(--primary);
    }
    .suffix {
      font-size: 12px;
      color: var(--gray-400);
      margin-left: 4px;
    }

    .bottom-two { display: grid; grid-template-columns: 1fr; gap: 20px; margin-bottom: 10px; }
    .bottom-two .field-group label { font-size: 12px; color: var(--gray-500); font-weight: 500; }

    .invoice-signature-row {
      display: flex;
      justify-content: flex-end;
      margin-top: 4px;
      padding-top: 8px;
      min-height: 0;
    }
    .invoice-signature-block {
      width: min(380px, 100%);
      text-align: center;
    }
    .invoice-signature-line {
      border-bottom: 1px solid var(--gray-400);
      height: 52px;
      margin-bottom: 8px;
    }
    .invoice-signature-label {
      font-size: 12px;
      color: var(--gray-500);
      font-weight: 500;
    }
    .invoice-signature-optional {
      font-weight: 400;
      color: var(--gray-400);
    }
    .invoice-signature-block.has-signature {
      min-height: 88px;
    }
    .invoice-signature-img {
      display: block;
      max-width: 260px;
      max-height: 72px;
      margin: 0 auto 6px;
      object-fit: contain;
    }
    .invoice-signature-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: center;
      margin-top: 10px;
    }
    .invoice-signature-btn {
      background: #fff;
      color: var(--gray-700);
      border: 1px solid var(--gray-300);
      border-radius: var(--radius-sm);
      font-weight: 500;
    }
    .invoice-signature-btn:hover {
      background: var(--gray-50);
      border-color: var(--gray-400);
    }
    .sig-saved-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: center;
      margin-top: 12px;
      min-height: 28px;
    }
    .sig-saved-chip {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 4px 10px 4px 4px;
      border: 1px solid var(--gray-200);
      border-radius: 999px;
      background: var(--gray-50);
      font-size: 11px;
      color: var(--gray-700);
      cursor: pointer;
      max-width: 140px;
    }
    .sig-saved-chip:hover {
      border-color: var(--primary);
      background: #eff6ff;
    }
    .sig-saved-chip img {
      width: 28px;
      height: 20px;
      object-fit: contain;
    }
    .sig-saved-chip span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .sig-saved-empty {
      font-size: 11px;
      color: var(--gray-400);
    }
    .sig-modal .sig-tabs {
      display: flex;
      gap: 8px;
      margin-bottom: 16px;
    }
    .sig-tab {
      flex: 1;
      padding: 8px 12px;
      border: 1px solid var(--gray-200);
      border-radius: 8px;
      background: #fff;
      font-size: 13px;
      cursor: pointer;
    }
    .sig-tab.active {
      border-color: var(--primary);
      background: #eff6ff;
      color: var(--primary);
      font-weight: 600;
    }
    .sig-panel { display: none; }
    .sig-panel.active { display: block; }
    .sig-typed-preview-wrap {
      border: 1px dashed var(--gray-300);
      border-radius: 8px;
      padding: 16px;
      background: #fafafa;
      min-height: 72px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .sig-typed-preview {
      color: #0f172a;
      font-size: 32px;
      line-height: 1.2;
      text-align: center;
      word-break: break-word;
    }
    .sig-draw-canvas {
      width: 100%;
      height: 140px;
      border: 1px solid var(--gray-300);
      border-radius: 8px;
      background: #fff;
      touch-action: none;
      cursor: crosshair;
    }
    .sig-draw-hint {
      font-size: 12px;
      color: var(--gray-500);
      margin: 0 0 8px;
    }
    .sig-clear-draw { margin-top: 8px; }
    .sig-consent {
      display: flex;
      gap: 10px;
      align-items: flex-start;
      font-size: 12px;
      color: var(--gray-600);
      margin: 14px 0 16px;
      cursor: pointer;
    }
    .sig-consent input { margin-top: 3px; flex-shrink: 0; }

    /* ═══════════════════════ TEMPLATES / HISTORY ═══════════════════════ */
    .page-header-bar {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      margin-bottom: 28px;
      flex-wrap: wrap;
      gap: 16px;
      min-width: 0;
      max-width: 100%;
    }
    .page-header-bar > div:first-child {
      min-width: 0;
      flex: 1 1 200px;
    }
    .page-header-bar > div:last-child:not(:only-child) {
      flex: 1 1 200px;
      min-width: 0;
      max-width: 100%;
      display: flex;
      justify-content: flex-end;
    }
    .page-toolbar-flex {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-wrap: wrap;
      min-width: 0;
      max-width: 100%;
      justify-content: flex-end;
    }
    .page-toolbar-search {
      flex: 1 1 160px;
      min-width: 0;
      max-width: 100%;
      width: 100%;
      padding: 8px 12px;
      border: 1px solid var(--gray-200);
      border-radius: 8px;
      font-size: 13px;
      outline: none;
      font-family: inherit;
    }
    .page-toolbar-search:focus {
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(13, 91, 255, 0.1);
    }
    .page-toolbar-btn {
      padding: 9px 16px;
      font-size: 13px;
      flex-shrink: 0;
      white-space: nowrap;
    }
    .page-header-title-row {
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
      min-width: 0;
      max-width: 100%;
    }
    .page-title {
      font-size: 24px;
      font-weight: 800;
      color: var(--gray-900);
      margin-bottom: 4px;
    }
    .page-sub {
      font-size: 14px;
      color: var(--gray-500);
    }

    .templates-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 18px;
    }
    .template-card {
      background: var(--white);
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      overflow: hidden;
      cursor: pointer;
      transition: all 0.2s;
      box-shadow: var(--shadow-sm);
    }
    .template-card:hover {
      border-color: var(--primary);
      box-shadow: var(--shadow-md);
      transform: translateY(-4px);
    }
    .template-thumb {
      background: linear-gradient(135deg, var(--gray-100), var(--gray-50));
      height: 140px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 48px;
      border-bottom: 1px solid var(--border-subtle);
    }
    .template-info {
      padding: 16px;
    }
    .template-info h4 {
      font-size: 14px;
      font-weight: 700;
      color: var(--gray-900);
      margin-bottom: 4px;
    }
    .template-info p {
      font-size: 13px;
      color: var(--gray-500);
    }
    .template-badge {
      display: inline-block;
      margin-top: 10px;
      padding: 4px 12px;
      border-radius: 6px;
      font-size: 11px;
      font-weight: 700;
    }
    .badge-free {
      background: #dcfce7;
      color: var(--accent-dark);
    }
    .badge-pro {
      background: #ede9fe;
      color: var(--accent);
    }
    .template-meta {
      font-size: 12px;
      color: var(--gray-500);
      margin-bottom: 10px;
    }
    .template-card-actions {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
    }
    .template-card-actions .btn-sm {
      padding: 6px 12px;
      font-size: 12px;
    }
    .template-card {
      cursor: default;
    }
    .templates-grid-status {
      grid-column: 1 / -1;
      text-align: center;
      padding: 48px 16px;
      font-size: 14px;
      color: var(--gray-500);
    }
    .page-toolbar-loading {
      visibility: hidden;
    }

    .history-table-wrap {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      border: 1px solid var(--border-subtle);
      max-width: 100%;
      min-width: 0;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
    .history-table {
      width: 100%;
      border-collapse: collapse;
    }
    .history-table thead th {
      text-align: left;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.7px;
      color: var(--gray-500);
      padding: 14px 18px;
      background: var(--gray-50);
      border-bottom: 1px solid rgba(0,0,0,0.08);
    }
    .history-table tbody tr {
      border-bottom: 1px solid var(--border-subtle);
      transition: background 0.1s;
    }
    .history-table tbody tr:last-child {
      border-bottom: none;
    }
    .history-table tbody tr:hover {
      background: var(--gray-50);
    }
    .history-table tbody td {
      padding: 14px 18px;
      font-size: 14px;
      color: var(--gray-700);
    }
    .history-table tbody td:first-child {
      font-weight: 700;
      color: var(--primary);
    }
    .status-badge {
      display: inline-flex;
      align-items: center;
      padding: 5px 12px;
      border-radius: 6px;
      font-size: 12px;
      font-weight: 700;
    }
    .status-paid {
      background: #dcfce7;
      color: var(--accent-dark);
    }
    .status-pending {
      background: #fef9c3;
      color: #a16207;
    }
    .status-overdue {
      background: #fee2e2;
      color: #dc2626;
    }
    .status-draft {
      background: var(--gray-100);
      color: var(--gray-500);
    }
    .status-cancelled {
      background: #fce7f3;
      color: #9d174d;
    }
    .history-empty {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 64px 24px;
      gap: 12px;
      color: var(--gray-400);
      font-size: 14px;
    }

    /* ── History filter bar ── */
    .history-controls {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-bottom: 18px;
      flex-wrap: wrap;
    }
    .sort-btn {
      display: inline-flex;
      align-items: center;
      gap: 7px;
      padding: 8px 14px;
      border: 1px solid var(--border-default);
      border-radius: var(--radius-md);
      background: var(--white);
      font-size: 13px;
      font-weight: 600;
      color: var(--gray-600);
      cursor: pointer;
      transition: all 0.2s;
      white-space: nowrap;
    }
    .sort-btn:hover {
      border-color: var(--primary);
      color: var(--primary);
      background: var(--primary-light);
    }
    .sort-btn svg {
      transition: transform 0.2s;
    }
    .sort-btn.desc svg {
      transform: rotate(180deg);
    }
    .filter-chips {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
    }
    .filter-chip {
      padding: 7px 14px;
      border-radius: 8px;
      font-size: 13px;
      font-weight: 600;
      border: 1px solid var(--border-default);
      background: var(--white);
      cursor: pointer;
      color: var(--gray-600);
      transition: all 0.2s;
      white-space: nowrap;
    }
    .filter-chip:hover {
      border-color: var(--primary);
      color: var(--primary);
      background: var(--primary-light);
    }
    .filter-chip.active {
      background: var(--primary);
      border-color: var(--primary);
      color: white;
    }

    /* ── Status select in table ── */
    .status-select {
      appearance: none;
      -webkit-appearance: none;
      border: none;
      border-radius: 8px;
      padding: 5px 24px 5px 12px;
      font-size: 12px;
      font-weight: 700;
      cursor: pointer;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 8px center;
      outline: none;
      transition: box-shadow 0.15s;
    }
    .status-select:focus {
      box-shadow: 0 0 0 3px rgba(13,91,255,0.15);
    }
    .status-select.status-paid {
      background-color: #dcfce7;
      color: var(--accent-dark);
    }
    .status-select.status-pending {
      background-color: #fef9c3;
      color: #a16207;
    }
    .status-select.status-overdue {
      background-color: #fee2e2;
      color: #dc2626;
    }
    .status-select.status-draft {
      background-color: var(--gray-100);
      color: var(--gray-500);
    }
    .status-select.status-cancelled {
      background-color: #fce7f3;
      color: #9d174d;
    }

    /* ── Invoice Preview Modal ── */
    .inv-preview-overlay {
      position: fixed;
      inset: 0;
      background: var(--overlay-backdrop);
      z-index: 600;
      display: flex;
      align-items: flex-start;
      justify-content: center;
      padding: 40px 20px;
      padding-left: max(20px, env(safe-area-inset-left, 0px));
      padding-right: max(20px, env(safe-area-inset-right, 0px));
      overflow-y: auto;
      overflow-x: hidden;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s;
      box-sizing: border-box;
    }
    .inv-preview-overlay.open {
      opacity: 1;
      pointer-events: all;
    }
    .inv-preview-modal {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-xl);
      width: 100%;
      max-width: min(760px, 100%);
      overflow: hidden;
      transform: translateY(24px);
      transition: transform 0.2s;
      box-sizing: border-box;
    }
    .inv-preview-overlay.open .inv-preview-modal {
      transform: translateY(0);
    }
    .inv-preview-topbar {
      background: linear-gradient(135deg, var(--primary), var(--primary-dark));
      padding: 20px 32px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: white;
    }
    .inv-preview-topbar h2 {
      font-size: 18px;
      font-weight: 800;
    }
    .inv-preview-close {
      background: rgba(255,255,255,0.15);
      border: none;
      border-radius: var(--radius-sm);
      color: white;
      padding: 8px 14px;
      cursor: pointer;
      font-size: 13px;
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 6px;
      transition: background 0.2s;
    }
    .inv-preview-close:hover {
      background: rgba(255,255,255,0.25);
    }
    .inv-preview-body {
      padding: 36px 40px;
      max-width: 100%;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
    .pv-header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      margin-bottom: 32px;
    }
    .pv-title {
      font-size: 36px;
      font-weight: 800;
      color: var(--gray-900);
      letter-spacing: -1.2px;
    }
    .pv-meta-grid {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 12px;
      background: var(--gray-50);
      border-radius: var(--radius);
      padding: 20px;
      border: 1px solid var(--border-subtle);
      margin-bottom: 28px;
    }
    .pv-meta-item label {
      font-size: 11px;
      color: var(--gray-500);
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.7px;
      display: block;
      margin-bottom: 4px;
    }
    .pv-meta-item span {
      font-size: 14px;
      font-weight: 700;
      color: var(--gray-900);
    }
    .pv-two-col {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 0;
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      overflow: hidden;
      margin-bottom: 28px;
    }
    .pv-section {
      padding: 20px 24px;
    }
    .pv-section:first-child {
      border-right: 1px solid rgba(0,0,0,0.06);
    }
    .pv-section-label {
      font-size: 12px;
      font-weight: 800;
      text-transform: uppercase;
      letter-spacing: 0.8px;
      color: var(--gray-500);
      margin-bottom: 12px;
    }
    .pv-field {
      margin-bottom: 8px;
    }
    .pv-field label {
      font-size: 11px;
      color: var(--gray-500);
      display: block;
      margin-bottom: 2px;
    }
    .pv-field span {
      font-size: 14px;
      color: var(--gray-900);
      font-weight: 600;
    }
    .pv-table {
      width: 100%;
      border-collapse: collapse;
      margin-bottom: 16px;
    }
    .pv-table thead th {
      text-align: left;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.6px;
      color: var(--gray-500);
      padding: 10px 14px;
      background: var(--gray-50);
      border-bottom: 1px solid rgba(0,0,0,0.08);
    }
    .pv-table thead th.right {
      text-align: right;
    }
    .pv-table tbody td {
      padding: 12px 14px;
      font-size: 14px;
      color: var(--gray-700);
      border-bottom: 1px solid var(--border-subtle);
    }
    .pv-table tbody td.right {
      text-align: right;
      font-weight: 600;
    }
    .pv-table tbody td.num {
      color: var(--gray-400);
      font-size: 12px;
      text-align: center;
      width: 36px;
    }
    .pv-totals {
      display: flex;
      justify-content: flex-end;
      margin-bottom: 24px;
    }
    .pv-totals-box {
      width: 300px;
    }
    .pv-totals-line {
      display: flex;
      justify-content: space-between;
      padding: 7px 0;
      font-size: 14px;
      color: var(--gray-600);
    }
    .pv-totals-line.grand {
      border-top: 2px solid rgba(0,0,0,0.1);
      margin-top: 8px;
      padding-top: 12px;
      font-size: 16px;
      font-weight: 800;
      color: var(--gray-900);
    }
    .pv-totals-line.grand span:last-child {
      color: var(--primary);
    }
    .pv-notes {
      background: var(--gray-50);
      border-radius: var(--radius-sm);
      padding: 16px 18px;
      font-size: 13px;
      color: var(--gray-600);
      border: 1px solid var(--border-subtle);
    }
    .pv-notes label {
      font-size: 11px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.6px;
      color: var(--gray-500);
      display: block;
      margin-bottom: 6px;
    }
    .empty-view-placeholder {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 88px 24px;
      gap: 14px;
      color: var(--gray-400);
      font-size: 14px;
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      border: 1px solid var(--border-subtle);
    }
    .history-actions {
      display: flex;
      gap: 8px;
    }
    .icon-btn {
      background: none;
      border: 1px solid var(--border-default);
      color: var(--gray-500);
      border-radius: 7px;
      padding: 6px 10px;
      cursor: pointer;
      font-size: 12px;
      display: inline-flex;
      align-items: center;
      gap: 5px;
      transition: all 0.15s;
    }
    .icon-btn:hover {
      background: var(--gray-50);
      border-color: var(--gray-300);
      color: var(--gray-900);
    }
    .icon-btn-danger {
      color: #b91c1c;
      border-color: #fecaca;
    }
    .icon-btn-danger:hover {
      background: #fef2f2;
      color: #991b1b;
      border-color: #fca5a5;
    }
    .history-view-tabs {
      display: flex;
      gap: 8px;
      margin-bottom: 16px;
    }
    .history-view-tab {
      padding: 8px 16px;
      border: 1px solid var(--gray-200);
      border-radius: 999px;
      background: var(--white);
      font-size: 13px;
      font-weight: 500;
      color: var(--gray-600);
      cursor: pointer;
      transition: background 0.15s, border-color 0.15s, color 0.15s;
    }
    .history-view-tab.active {
      border-color: var(--primary);
      background: var(--primary-light);
      color: var(--primary);
      font-weight: 600;
    }
    .history-empty-hint {
      font-size: 12px;
      color: var(--gray-400);
      margin-top: 6px;
    }
    .trash-meta-cell {
      font-size: 12px;
      color: var(--gray-500);
    }
    .trash-meta-label {
      display: block;
      font-size: 10px;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: var(--gray-400);
      margin-bottom: 2px;
    }
    .btn-danger-solid {
      background: #dc2626;
      border-color: #dc2626;
    }
    .btn-danger-solid:hover:not(:disabled) {
      background: #b91c1c;
      border-color: #b91c1c;
    }
    .btn-danger-solid:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }

    /* ═══════════════════════ POLICY / LEGAL PAGES ═══════════════════════ */
    .policy-doc-wrap {
      max-width: 760px;
      margin: 0 auto;
      padding: 8px 8px 48px;
    }
    .policy-doc {
      background: #fff;
      border: 1px solid var(--gray-200);
      border-radius: var(--radius-lg);
      padding: 28px 32px 36px;
      box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    }
    .policy-back {
      margin: 0 0 16px;
      font-size: 13px;
    }
    .policy-back a {
      color: var(--primary);
      text-decoration: none;
    }
    .policy-back a:hover { text-decoration: underline; }
    .policy-nav {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      margin-bottom: 24px;
      padding-bottom: 16px;
      border-bottom: 1px solid var(--gray-200);
    }
    .policy-nav a {
      font-size: 12px;
      color: var(--gray-600);
      text-decoration: none;
      padding: 6px 10px;
      border-radius: 999px;
      border: 1px solid var(--gray-200);
      line-height: 1.25;
      text-align: center;
      max-width: 100%;
    }
    .policy-nav a:hover {
      border-color: var(--gray-300);
      color: var(--gray-900);
    }
    .policy-nav a.active {
      border-color: var(--primary);
      background: #eff6ff;
      color: var(--primary);
      font-weight: 600;
    }
    .policy-title {
      font-size: 1.65rem;
      font-weight: 700;
      margin: 0 0 8px;
      color: var(--gray-900);
      letter-spacing: -0.02em;
    }
    .policy-updated {
      font-size: 12px;
      color: var(--gray-500);
      margin: 0 0 22px;
    }
    .policy-doc h2 {
      font-size: 1.05rem;
      font-weight: 700;
      margin: 26px 0 10px;
      color: var(--gray-800);
    }
    .policy-doc h3 {
      font-size: 0.95rem;
      font-weight: 600;
      margin: 18px 0 8px;
      color: var(--gray-700);
    }
    .policy-doc ol {
      margin: 0 0 14px;
      padding-left: 1.35rem;
    }
    .policy-doc ol li { margin-bottom: 8px; }
    .policy-doc p,
    .policy-doc li {
      font-size: 14px;
      line-height: 1.65;
      color: var(--gray-700);
    }
    .policy-doc p { margin: 0 0 12px; }
    .policy-doc ul {
      margin: 0 0 14px;
      padding-left: 1.25rem;
    }
    .policy-doc li { margin-bottom: 8px; }
    .policy-doc a {
      color: var(--primary);
    }
    .policy-doc code {
      font-size: 0.9em;
      padding: 2px 6px;
      background: var(--gray-100);
      border-radius: 4px;
      border: 1px solid var(--gray-200);
    }
    .policy-muted {
      font-size: 13px;
      color: var(--gray-500);
      margin-top: 28px;
      padding-top: 16px;
      border-top: 1px dashed var(--gray-200);
    }

    /* ═══════════════════════ ABOUT PAGE ═══════════════════════ */
    .about-page-wrap {
      max-width: 980px;
      margin: 0 auto;
      padding: 12px 16px 56px;
    }
    .about-back {
      margin: 0 0 20px;
      font-size: 13px;
      font-weight: 500;
    }
    .about-back a {
      color: var(--primary);
      text-decoration: none;
      transition: color 0.15s;
    }
    .about-back a:hover { color: var(--primary-dark); text-decoration: underline; }

    .about-hero-text {
      /* Not the site nav — reset global `header` sticky/flex rules */
      position: static;
      z-index: auto;
      height: auto;
      display: block;
      align-items: unset;
      background: transparent;
      box-shadow: none;
      margin-bottom: 36px;
      padding-bottom: 28px;
      border-bottom: 1px solid var(--border-default);
    }
    .about-hero-eyebrow {
      margin: 0 0 10px;
      font-size: 12px;
      font-weight: 700;
      letter-spacing: 0.12em;
      text-transform: uppercase;
      color: var(--primary);
    }
    .about-title {
      font-size: clamp(1.65rem, 3.5vw, 2.35rem);
      font-weight: 800;
      margin: 0 0 14px;
      letter-spacing: -0.03em;
      line-height: 1.15;
      max-width: 720px;
      color: var(--gray-900);
    }
    .about-lead {
      margin: 0;
      font-size: clamp(14px, 2vw, 16px);
      line-height: 1.65;
      max-width: 620px;
      color: var(--gray-600);
    }

    .about-body {
      background: var(--white);
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      padding: 40px 40px 44px;
      box-shadow: var(--shadow-sm);
    }
    .about-section {
      margin-bottom: 48px;
    }
    .about-section:last-of-type { margin-bottom: 0; }
    .about-section-head {
      margin-bottom: 24px;
    }
    .about-section-head h2 {
      font-size: clamp(1.2rem, 2.5vw, 1.45rem);
      font-weight: 800;
      margin: 0 0 8px;
      color: var(--gray-900);
      letter-spacing: -0.02em;
    }
    .about-section-intro {
      margin: 0;
      font-size: 15px;
      line-height: 1.6;
      color: var(--gray-500);
      max-width: 560px;
    }

    .about-features-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 16px;
      margin-bottom: 28px;
    }
    .about-feature-card {
      background: var(--gray-50);
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      padding: 22px 20px;
      transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    }
    .about-feature-card:hover {
      border-color: rgba(13, 91, 255, 0.25);
      box-shadow: var(--shadow-md);
      transform: translateY(-2px);
    }
    .about-feature-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 44px;
      height: 44px;
      border-radius: 10px;
      background: var(--primary-light);
      color: var(--primary);
      margin-bottom: 14px;
    }
    .about-feature-card h3 {
      margin: 0 0 8px;
      font-size: 15px;
      font-weight: 700;
      color: var(--gray-900);
      letter-spacing: -0.01em;
    }
    .about-feature-card p {
      margin: 0;
      font-size: 14px;
      line-height: 1.6;
      color: var(--gray-600);
    }

    .about-visual {
      margin: 0;
      position: relative;
      overflow: hidden;
      border-radius: var(--radius);
    }
    .about-visual img {
      display: block;
      width: 100%;
      height: auto;
      border-radius: var(--radius);
      border: 1px solid var(--border-default);
      box-shadow: var(--shadow-sm);
      object-fit: cover;
    }
    .about-visual-wide img {
      max-height: 320px;
    }
    .about-visual figcaption {
      margin-top: 10px;
      font-size: 12px;
      color: var(--gray-500);
      text-align: center;
    }

    .about-cards {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 18px;
    }
    .about-card {
      background: var(--white);
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      padding: 24px 22px;
      box-shadow: var(--shadow-sm);
      transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    }
    .about-card:hover {
      border-color: rgba(13, 91, 255, 0.22);
      box-shadow: var(--shadow-md);
      transform: translateY(-2px);
    }
    .about-card-icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 40px;
      height: 40px;
      border-radius: 10px;
      background: var(--primary-light);
      color: var(--primary);
      margin-bottom: 14px;
    }
    .about-card h3 {
      font-size: 15px;
      font-weight: 700;
      margin: 0 0 10px;
      color: var(--gray-900);
      letter-spacing: -0.01em;
    }
    .about-card p {
      margin: 0;
      font-size: 14px;
      line-height: 1.62;
      color: var(--gray-600);
    }

    .about-principles-layout {
      display: grid;
      grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
      gap: 32px;
      align-items: start;
    }
    .about-visual-side img {
      aspect-ratio: 4 / 3;
      max-height: 360px;
    }
    .about-principles-grid {
      display: flex;
      flex-direction: column;
      gap: 14px;
    }
    .about-principle-card {
      background: var(--gray-50);
      border: 1px solid var(--border-default);
      border-radius: var(--radius);
      padding: 18px 20px;
      transition: border-color 0.15s;
    }
    .about-principle-card:hover {
      border-color: rgba(13, 91, 255, 0.2);
    }
    .about-principle-card h3 {
      margin: 0 0 6px;
      font-size: 14px;
      font-weight: 700;
      color: var(--gray-900);
    }
    .about-principle-card p {
      margin: 0;
      font-size: 14px;
      line-height: 1.6;
      color: var(--gray-600);
    }
    .about-principle-card a {
      color: var(--primary);
      font-weight: 600;
      text-decoration: none;
    }
    .about-principle-card a:hover { text-decoration: underline; }

    .about-cta {
      margin-top: 12px;
      border-radius: var(--radius);
      overflow: hidden;
      border: 1px solid rgba(13, 91, 255, 0.15);
      background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 55%, #ecfdf5 100%);
      box-shadow: var(--shadow-md);
    }
    .about-cta-inner {
      text-align: center;
      padding: 40px 28px;
    }
    .about-cta h2 {
      font-size: clamp(1.15rem, 2.5vw, 1.4rem);
      font-weight: 800;
      margin: 0 0 10px;
      color: var(--gray-900);
      letter-spacing: -0.02em;
    }
    .about-cta p {
      max-width: 480px;
      margin: 0 auto 24px;
      font-size: 15px;
      line-height: 1.6;
      color: var(--gray-600);
    }
    .about-cta-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      padding: 14px 28px;
      font-size: 15px;
      font-weight: 700;
      border-radius: 10px;
      box-shadow: 0 4px 14px rgba(13, 91, 255, 0.35);
      transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    }
    .about-cta-btn:hover {
      transform: translateY(-2px);
      box-shadow: 0 8px 22px rgba(13, 91, 255, 0.4);
    }
    .about-cta-btn:active {
      transform: translateY(0);
    }

    @media (max-width: 900px) {
      .about-features-grid {
        grid-template-columns: 1fr;
      }
      .about-cards {
        grid-template-columns: 1fr;
      }
      .about-principles-layout {
        grid-template-columns: 1fr;
      }
      .about-visual-side {
        order: -1;
      }
    }
    @media (max-width: 640px) {
      .about-page-wrap { padding: 8px 12px 40px; }
      .about-hero-text { margin-bottom: 28px; padding-bottom: 22px; }
      .about-body { padding: 28px 20px 32px; }
      .about-section { margin-bottom: 36px; }
      .about-cta-inner { padding: 32px 20px; }
      .about-cta-btn {
        width: 100%;
        max-width: 320px;
      }
    }

    [data-theme="dark"] .about-body {
      background: var(--gray-100);
      border-color: var(--border-default);
    }
    [data-theme="dark"] .about-back a {
      color: #60a5fa;
    }
    [data-theme="dark"] .about-back a:hover {
      color: #93c5fd;
    }
    [data-theme="dark"] .about-hero-text {
      border-bottom-color: var(--border-default);
    }
    [data-theme="dark"] .about-hero-eyebrow {
      color: #93c5fd;
    }
    [data-theme="dark"] .about-title {
      color: var(--gray-900);
    }
    [data-theme="dark"] .about-lead {
      color: var(--gray-600);
    }
    [data-theme="dark"] .about-feature-card,
    [data-theme="dark"] .about-principle-card {
      background: var(--gray-50);
      border-color: var(--border-default);
    }
    [data-theme="dark"] .about-feature-card:hover,
    [data-theme="dark"] .about-principle-card:hover {
      border-color: rgba(96, 165, 250, 0.35);
    }
    [data-theme="dark"] .about-card {
      background: var(--gray-50);
      border-color: var(--border-default);
    }
    [data-theme="dark"] .about-card:hover {
      border-color: rgba(96, 165, 250, 0.35);
    }
    [data-theme="dark"] .about-feature-icon,
    [data-theme="dark"] .about-card-icon {
      background: rgba(13, 91, 255, 0.22);
      color: #93c5fd;
    }
    [data-theme="dark"] .about-section-head h2,
    [data-theme="dark"] .about-feature-card h3,
    [data-theme="dark"] .about-card h3,
    [data-theme="dark"] .about-principle-card h3,
    [data-theme="dark"] .about-cta h2 {
      color: var(--gray-900);
    }
    [data-theme="dark"] .about-section-intro,
    [data-theme="dark"] .about-feature-card p,
    [data-theme="dark"] .about-card p,
    [data-theme="dark"] .about-principle-card p,
    [data-theme="dark"] .about-cta p {
      color: var(--gray-600);
    }
    [data-theme="dark"] .about-principle-card a {
      color: #60a5fa;
    }
    [data-theme="dark"] .about-principle-card a:hover {
      color: #93c5fd;
    }
    [data-theme="dark"] .about-visual figcaption {
      color: var(--gray-500);
    }
    [data-theme="dark"] .about-cta {
      background: linear-gradient(135deg, rgba(13, 91, 255, 0.18) 0%, var(--gray-50) 55%, rgba(53, 214, 168, 0.08) 100%);
      border-color: rgba(96, 165, 250, 0.28);
    }
    [data-theme="dark"] .about-visual img {
      border-color: var(--border-default);
      opacity: 0.92;
    }

    /* ═══════════════════════ MODALS ═══════════════════════ */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: var(--overlay-backdrop);
      z-index: 500;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: max(16px, env(safe-area-inset-top, 0px)) 20px max(16px, env(safe-area-inset-bottom, 0px));
      overflow-y: auto;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s;
    }
    .modal-overlay.open {
      opacity: 1;
      pointer-events: all;
    }
    .modal {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-xl);
      width: 100%;
      max-width: min(460px, 100%);
      max-height: min(calc(100dvh - 32px), 92vh);
      display: flex;
      flex-direction: column;
      overflow: hidden;
      transform: translateY(24px);
      transition: transform 0.2s;
      box-sizing: border-box;
      flex-shrink: 0;
    }
    .modal-overlay.open .modal {
      transform: translateY(0);
    }
    .modal-header {
      padding: 24px 32px 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      flex-shrink: 0;
    }
    .modal-header h2 {
      font-size: 20px;
      font-weight: 800;
    }
    .modal-close {
      background: none;
      border: none;
      cursor: pointer;
      color: var(--gray-400);
      padding: 6px;
      border-radius: 7px;
      transition: all 0.15s;
    }
    .modal-close:hover {
      background: var(--gray-100);
      color: var(--gray-700);
    }
    .modal-body {
      padding: 24px 32px 32px;
      overflow-y: auto;
      flex: 1 1 auto;
      min-height: 0;
      -webkit-overflow-scrolling: touch;
    }

    /* Auth tabs */
    .auth-tabs {
      display: flex;
      border-bottom: 1px solid var(--border-subtle);
      margin-bottom: 24px;
    }
    .auth-tab {
      padding: 12px 24px;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      border: none;
      background: none;
      color: var(--gray-500);
      border-bottom: 3px solid transparent;
      margin-bottom: -1px;
      transition: all 0.2s;
    }
    .auth-tab.active {
      color: var(--primary);
      border-bottom-color: var(--primary);
    }
    .auth-panel {
      display: none;
    }
    .auth-panel.active {
      display: block;
    }
    .form-group {
      display: flex;
      flex-direction: column;
      gap: 7px;
      margin-bottom: 16px;
    }
    .form-group label {
      font-size: 13px;
      font-weight: 600;
      color: var(--gray-700);
    }
    .form-group input {
      font-size: 14px;
    }
    .form-divider {
      text-align: center;
      font-size: 12px;
      color: var(--gray-400);
      margin: 18px 0;
      position: relative;
    }
    .form-divider::before,
    .form-divider::after {
      content: '';
      position: absolute;
      top: 50%;
      width: 42%;
      height: 1px;
      background: rgba(0,0,0,0.08);
    }
    .form-divider::before {
      left: 0;
    }
    .form-divider::after {
      right: 0;
    }
    .oauth-btn {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      padding: 12px;
      border: 1px solid var(--border-default);
      border-radius: var(--radius-md);
      background: white;
      cursor: pointer;
      font-size: 14px;
      font-weight: 600;
      transition: all 0.2s;
      text-decoration: none;
      color: inherit;
      box-sizing: border-box;
    }
    .oauth-btn:hover {
      background: var(--gray-50);
      border-color: rgba(0,0,0,0.12);
    }
    .btn-submit {
      width: 100%;
      padding: 12px;
      font-size: 15px;
      font-weight: 700;
      border-radius: var(--radius-md);
      margin-top: 6px;
    }
    .form-footer {
      font-size: 12px;
      color: var(--gray-500);
      text-align: center;
      margin-top: 16px;
    }
    .form-footer a {
      color: var(--primary);
      text-decoration: none;
      cursor: pointer;
      font-weight: 600;
    }
    .auth-context-box {
      display: flex;
      align-items: flex-start;
      gap: 12px;
      background: #eff6ff;
      border: 1px solid #bfdbfe;
      border-radius: var(--radius-sm);
      padding: 14px 16px;
      margin-bottom: 20px;
      font-size: 13px;
      color: #1e40af;
      line-height: 1.5;
    }
    .auth-context-box svg {
      flex-shrink: 0;
      margin-top: 2px;
    }
    .auth-err {
      font-size: 12px;
      color: var(--danger);
      margin-top: -4px;
      margin-bottom: 10px;
      display: none;
    }
    .auth-err.show {
      display: block;
    }

    /* Company modal */
    .company-modal {
      max-width: min(520px, 100%);
    }
    .company-modal .modal-header {
      padding: 18px 24px 0;
    }
    .company-modal .modal-body {
      padding: 16px 24px 20px;
    }
    .company-form-group {
      display: flex;
      flex-direction: column;
      gap: 6px;
      margin-bottom: 12px;
    }
    .company-form-group label {
      font-size: 13px;
      font-weight: 600;
      color: var(--gray-700);
    }
    .company-form-section {
      margin: 4px 0 14px;
      padding-top: 14px;
      border-top: 1px dashed var(--border-default);
    }
    .company-form-section-title {
      margin: 0 0 12px;
      font-size: 13px;
      font-weight: 700;
      color: var(--gray-900);
    }
    .company-form-grid-2 {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
    }
    .company-form-check {
      display: flex;
      align-items: flex-start;
      gap: 10px;
      margin: 10px 0 8px;
      font-size: 13px;
      color: var(--gray-600);
      cursor: pointer;
    }
    .company-form-check input {
      margin-top: 2px;
      accent-color: var(--primary);
    }
    .company-form-hint {
      margin: 0;
      font-size: 12px;
      color: var(--gray-500);
    }
    .company-logo-upload {
      display: flex;
      align-items: center;
      justify-content: center;
      border: 2px dashed var(--gray-300);
      border-radius: var(--radius-sm);
      padding: 12px;
      cursor: pointer;
      min-height: 68px;
      background: var(--gray-50);
      transition: all 0.2s;
    }
    .company-logo-upload:hover {
      border-color: var(--primary);
      background: var(--primary-light);
    }
    .company-logo-picker-btn {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      border: 2px dashed var(--gray-300);
      border-radius: var(--radius-sm);
      padding: 12px;
      cursor: pointer;
      min-height: 68px;
      background: var(--gray-50);
      transition: all 0.2s;
      box-sizing: border-box;
    }
    .company-logo-picker-btn:hover {
      border-color: var(--primary);
      background: var(--primary-light);
    }
    .company-logo-picker-placeholder {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 5px;
      color: var(--gray-500);
      font-size: 12px;
    }
    .logo-picker-modal {
      max-width: min(560px, 100%);
    }
    .logo-picker-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 12px;
    }
    .logo-picker-count {
      margin: 0;
      font-size: 12px;
      color: var(--gray-500);
      font-weight: 600;
    }
    .logo-picker-upload-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      flex-shrink: 0;
      padding: 10px 16px;
      font-size: 13px;
      font-weight: 700;
      border-radius: 9px;
      box-shadow: 0 2px 8px rgba(13, 91, 255, 0.28);
      white-space: nowrap;
    }
    .logo-picker-upload-btn:hover:not(:disabled) {
      box-shadow: 0 4px 14px rgba(13, 91, 255, 0.38);
      transform: translateY(-1px);
    }
    .logo-picker-upload-btn:disabled {
      opacity: 0.55;
      cursor: not-allowed;
      box-shadow: none;
    }
    @media (max-width: 480px) {
      .logo-picker-toolbar {
        flex-direction: column;
        align-items: stretch;
      }
      .logo-picker-upload-btn {
        width: 100%;
        white-space: normal;
        text-align: center;
      }
    }
    .logo-gallery-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
      gap: 10px;
    }
    .logo-gallery-item {
      position: relative;
      border: 2px solid var(--border-subtle);
      border-radius: 10px;
      padding: 10px;
      background: var(--gray-50);
      cursor: pointer;
      aspect-ratio: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: border-color 0.15s, box-shadow 0.15s;
    }
    .logo-gallery-item:hover,
    .logo-gallery-item.selected {
      border-color: var(--primary);
      box-shadow: 0 0 0 3px rgba(13, 91, 255, 0.12);
    }
    .logo-gallery-item img {
      max-width: 100%;
      max-height: 100%;
      object-fit: contain;
    }
    .logo-gallery-delete {
      position: absolute;
      top: 4px;
      right: 4px;
      width: 22px;
      height: 22px;
      border: none;
      border-radius: 999px;
      background: rgba(15, 23, 42, 0.72);
      color: #fff;
      font-size: 16px;
      line-height: 1;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0;
    }
    .logo-gallery-delete:hover {
      background: var(--danger);
    }
    .logo-picker-upload-zone {
      margin: 0;
    }
    .logo-picker-upload-title {
      font-size: 14px;
      font-weight: 700;
      color: var(--gray-700);
    }
    .logo-picker-upload-hint {
      font-size: 12px;
      color: var(--gray-500);
    }
    .color-swatches {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
      margin-top: 6px;
    }
    .swatch {
      width: 32px;
      height: 32px;
      border-radius: 8px;
      cursor: pointer;
      border: 2px solid transparent;
      transition: all 0.2s;
    }
    .swatch.selected {
      border-color: var(--gray-900);
      transform: scale(1.1);
      box-shadow: 0 0 0 3px rgba(0,0,0,0.1);
    }
    #companyModal .modal-body {
      display: grid;
      grid-template-columns: 1fr;
      column-gap: 12px;
      align-content: start;
    }
    #companyModal .company-form-group {
      grid-column: 1 / -1;
    }
    #companyModal .btn-submit {
      grid-column: 1 / -1;
      position: sticky;
      bottom: 0;
      z-index: 1;
      margin-top: 4px;
      padding-top: 14px;
      padding-bottom: 14px;
      background: var(--white);
      box-shadow: 0 -8px 16px -8px rgba(15, 23, 42, 0.12);
    }
    @media (min-width: 480px) {
      #companyModal .modal-body {
        grid-template-columns: 1fr 1fr;
      }
      #companyModal .company-form-group:nth-of-type(5),
      #companyModal .company-form-group:nth-of-type(6),
      #companyModal .company-form-group:nth-of-type(8),
      #companyModal .company-form-group:nth-of-type(9) {
        grid-column: span 1;
      }
    }

    /* ── Clients table ── */
    .clients-table-wrap {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      border: 1px solid var(--border-subtle);
      max-width: 100%;
      min-width: 0;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
    .clients-table {
      width: 100%;
      border-collapse: collapse;
    }
    .clients-table thead th {
      text-align: left;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.7px;
      color: var(--gray-500);
      padding: 14px 18px;
      background: var(--gray-50);
      border-bottom: 1px solid rgba(0,0,0,0.08);
    }
    .clients-table tbody tr {
      border-bottom: 1px solid var(--border-subtle);
      transition: background 0.1s;
      cursor: pointer;
    }
    .clients-table tbody tr:last-child {
      border-bottom: none;
    }
    .clients-table tbody tr:hover {
      background: var(--primary-light);
    }
    .clients-table tbody td {
      padding: 14px 18px;
      font-size: 14px;
      color: var(--gray-700);
    }
    .client-name-cell {
      display: flex;
      align-items: center;
      gap: 12px;
    }
    .client-avatar {
      width: 36px;
      height: 36px;
      border-radius: 9px;
      flex-shrink: 0;
      background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      font-weight: 700;
      color: white;
    }
    .client-name-main {
      font-weight: 700;
      color: var(--gray-900);
      font-size: 14px;
    }
    .client-name-sub {
      font-size: 12px;
      color: var(--gray-500);
      margin-top: 2px;
    }
    .clients-empty {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 64px 24px;
      gap: 12px;
      color: var(--gray-400);
      font-size: 14px;
    }
    .clients-count-badge {
      background: var(--primary-light);
      color: var(--primary);
      font-size: 12px;
      font-weight: 700;
      padding: 4px 12px;
      border-radius: 6px;
    }

    /* ── Stats page ── */
    #statsContent {
      max-width: 100%;
      min-width: 0;
    }
    .stats-kpi-row {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 18px;
      margin-bottom: 24px;
      min-width: 0;
      max-width: 100%;
    }
    .stat-kpi-card {
      background: var(--white);
      border-radius: var(--radius);
      padding: 24px;
      box-shadow: var(--shadow-sm);
      border: 1px solid var(--border-subtle);
    }
    .stat-kpi-icon {
      width: 44px;
      height: 44px;
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 14px;
    }
    .stat-kpi-value {
      font-size: 28px;
      font-weight: 800;
      color: var(--gray-900);
      letter-spacing: -1px;
      line-height: 1;
      margin-bottom: 6px;
    }
    .stat-kpi-label {
      font-size: 13px;
      color: var(--gray-600);
      font-weight: 600;
    }
    .stat-kpi-sub {
      font-size: 12px;
      color: var(--gray-400);
      margin-top: 6px;
    }
    .stats-row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 24px;
      margin-bottom: 24px;
      min-width: 0;
      max-width: 100%;
    }
    .chart-card {
      background: var(--white);
      border-radius: var(--radius);
      padding: 24px;
      box-shadow: var(--shadow-sm);
      border: 1px solid var(--border-subtle);
      max-width: 100%;
      min-width: 0;
      overflow-x: auto;
    }
    .chart-card-title {
      font-size: 12px;
      font-weight: 700;
      color: var(--gray-500);
      margin-bottom: 20px;
      display: flex;
      align-items: center;
      gap: 8px;
      text-transform: uppercase;
      letter-spacing: 0.8px;
    }
    .bar-legend {
      display: flex;
      gap: 18px;
      font-size: 12px;
      color: var(--gray-600);
      margin-bottom: 12px;
    }
    .bar-legend span {
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .legend-dot {
      width: 11px;
      height: 11px;
      border-radius: 3px;
      display: inline-block;
      flex-shrink: 0;
    }
    .progress-bar-wrap {
      margin-bottom: 16px;
    }
    .progress-bar-labels {
      display: flex;
      justify-content: space-between;
      margin-bottom: 6px;
    }
    .progress-bar-name {
      font-size: 13px;
      font-weight: 600;
      color: var(--gray-800);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 60%;
    }
    .progress-bar-val {
      font-size: 13px;
      font-weight: 700;
      color: var(--gray-900);
    }
    .progress-bar-track {
      height: 8px;
      background: var(--gray-100);
      border-radius: 10px;
      overflow: hidden;
    }
    .progress-bar-fill {
      height: 100%;
      border-radius: 10px;
    }
    .progress-bar-sub {
      font-size: 12px;
      color: var(--gray-400);
      margin-top: 4px;
    }
    .donut-legend-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--gray-100); }
    .donut-legend-row:last-child { border-bottom: none; }
    .donut-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
    .donut-label { font-size: 13px; color: var(--gray-600); flex: 1; }
    .donut-count { font-size: 13px; font-weight: 700; color: var(--gray-900); min-width: 20px; text-align: right; }
    .donut-amount { font-size: 11px; color: var(--gray-400); min-width: 80px; text-align: right; }
    .collection-rate-bar { background: var(--gray-100); border-radius: 10px; height: 10px; overflow: hidden; margin: 14px 0 6px; }
    .collection-rate-fill { height: 100%; border-radius: 10px; background: linear-gradient(90deg, var(--accent-dark), var(--accent)); }
    @media (max-width: 1100px) { .stats-kpi-row { grid-template-columns: repeat(2,1fr); } }
    @media (max-width: 900px)  { .stats-row { grid-template-columns: 1fr; } }
    .stats-full-card { background: var(--white); border-radius: var(--radius); padding: 22px 24px; box-shadow: var(--shadow-sm); border: 1px solid var(--gray-100); margin-bottom: 20px; max-width: 100%; min-width: 0; overflow-x: auto; }
    .time-filter-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
    .time-filter-group { display: flex; gap: 5px; flex-wrap: wrap; }
    .time-filter-btn { padding: 5px 12px; border-radius: 7px; border: 1px solid var(--gray-200); background: var(--white); font-size: 12px; font-weight: 600; color: var(--gray-500); cursor: pointer; transition: all .15s; font-family: inherit; }
    .time-filter-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
    .tf-active { border-color: var(--primary) !important; color: var(--white) !important; background: var(--primary) !important; }
    .date-range-wrap { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--gray-500); }
    .date-range-input { padding: 5px 9px; border-radius: 7px; border: 1px solid var(--gray-200); font-size: 12px; color: var(--gray-700); font-family: inherit; background: var(--white); outline: none; }
    .date-range-input:focus { border-color: var(--primary); }
    .revenue-total-row { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
    .revenue-big-num { font-size: 30px; font-weight: 800; color: var(--accent-dark); letter-spacing: -1px; }
    .revenue-big-sub { font-size: 13px; color: var(--gray-400); }
    .status-full-inner { display: flex; gap: 32px; align-items: flex-start; }
    .status-full-donut { flex-shrink: 0; display: flex; flex-direction: column; align-items: center; }
    .status-full-bars { flex: 1; }
    .sf-bar-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--gray-100); }
    .sf-bar-item:last-child { border-bottom: none; }
    .sf-bar-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
    .sf-bar-name { font-size: 13px; color: var(--gray-600); width: 100px; flex-shrink: 0; }
    .sf-bar-track-wrap { flex: 1; }
    .sf-bar-track { height: 8px; background: var(--gray-100); border-radius: 10px; overflow: hidden; }
    .sf-bar-fill { height: 100%; border-radius: 10px; transition: width .4s ease; }
    .sf-bar-meta { display: flex; justify-content: space-between; margin-top: 3px; }
    .sf-bar-count { font-size: 11px; color: var(--gray-400); }
    .sf-bar-amt { font-size: 11px; font-weight: 600; color: var(--gray-600); }
    @media (max-width: 760px) { .status-full-inner { flex-direction: column; } .time-filter-row { flex-direction: column; align-items: flex-start; } }

    /* ── Products table ── */
    .products-table-wrap {
      background: var(--white);
      border-radius: var(--radius);
      box-shadow: var(--shadow-sm);
      border: 1px solid var(--border-subtle);
      max-width: 100%;
      min-width: 0;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
    .products-table {
      width: 100%;
      border-collapse: collapse;
    }
    .products-table thead th {
      text-align: left;
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.7px;
      color: var(--gray-500);
      padding: 14px 18px;
      background: var(--gray-50);
      border-bottom: 1px solid rgba(0,0,0,0.08);
    }
    .products-table tbody tr {
      border-bottom: 1px solid var(--border-subtle);
      transition: background 0.1s;
      cursor: pointer;
    }
    .products-table tbody tr:last-child {
      border-bottom: none;
    }
    .products-table tbody tr:hover {
      background: #f0fdf4;
    }
    .products-table tbody td {
      padding: 14px 18px;
      font-size: 14px;
      color: var(--gray-700);
    }
    .product-name-cell {
      display: flex;
      align-items: center;
      gap: 12px;
    }
    .product-icon {
      width: 36px;
      height: 36px;
      border-radius: 9px;
      flex-shrink: 0;
      background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
    }
    .product-name-main {
      font-weight: 700;
      color: var(--gray-900);
      font-size: 14px;
    }
    .product-name-sub {
      font-size: 12px;
      color: var(--gray-500);
      margin-top: 2px;
    }
    .products-empty {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 64px 24px;
      gap: 12px;
      color: var(--gray-400);
      font-size: 14px;
    }
    .products-count-badge {
      background: #dcfce7;
      color: var(--accent-dark);
      font-size: 12px;
      font-weight: 700;
      padding: 4px 12px;
      border-radius: 6px;
    }
    .price-badge {
      background: var(--gray-100);
      color: var(--gray-700);
      font-size: 13px;
      font-weight: 700;
      padding: 4px 12px;
      border-radius: 6px;
      display: inline-block;
    }
    .usage-pill {
      background: #ede9fe;
      color: var(--accent);
      font-size: 12px;
      font-weight: 700;
      padding: 4px 12px;
      border-radius: 6px;
      display: inline-block;
    }

    /* ── Receiver search autocomplete ── */
    .receiver-search-wrap {
      position: relative;
      flex: 1;
      max-width: 300px;
      min-width: 200px;
    }
    .receiver-search-wrap[hidden],
    .payer-suggestions[hidden] {
      display: none !important;
    }
    .receiver-search-wrap .receiver-search {
      width: 100%;
      max-width: none;
      min-width: 0;
    }
    .autocomplete-drop {
      position: absolute;
      top: calc(100% + 8px);
      left: 0;
      right: 0;
      min-width: 240px;
      background: var(--white);
      border: 1px solid var(--border-default);
      border-radius: var(--radius-md);
      box-shadow: var(--shadow-lg);
      z-index: 400;
      max-height: 220px;
      overflow-y: auto;
      display: none;
    }
    .autocomplete-drop.open {
      display: block;
    }
    .ac-section-label {
      font-size: 11px;
      font-weight: 700;
      color: var(--gray-500);
      padding: 10px 14px 6px;
      text-transform: uppercase;
      letter-spacing: 0.04em;
    }
    .payer-suggestions {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 6px;
      margin: 0 0 12px;
      max-width: 100%;
    }
    .payer-suggestions-label {
      font-size: 11px;
      font-weight: 600;
      color: var(--gray-500);
      margin-right: 4px;
      flex: 0 0 auto;
    }
    .payer-chip {
      border: 1px solid rgba(0, 0, 0, 0.1);
      background: var(--gray-50);
      color: var(--gray-800);
      border-radius: 999px;
      padding: 5px 12px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      max-width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      transition: background 0.15s, border-color 0.15s;
    }
    .payer-chip:hover {
      background: var(--primary-light);
      border-color: var(--primary);
      color: var(--primary);
    }
    .ac-item {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 11px 14px;
      cursor: pointer;
      transition: background 0.1s;
    }
    .ac-item:hover {
      background: var(--primary-light);
    }
    .ac-item .ac-avatar {
      width: 32px;
      height: 32px;
      border-radius: 8px;
      flex-shrink: 0;
      background: linear-gradient(135deg, var(--primary), var(--accent));
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      font-weight: 700;
      color: white;
    }
    .ac-item .ac-info .ac-name {
      font-size: 13px;
      font-weight: 600;
      color: var(--gray-900);
    }
    .ac-item .ac-info .ac-sub {
      font-size: 11px;
      color: var(--gray-500);
      margin-top: 2px;
    }

    /* Footer */
    footer {
      background: var(--white);
      border-top: 1px solid rgba(0,0,0,0.06);
      padding: 24px 32px;
      text-align: center;
      font-size: 13px;
      color: var(--gray-600);
      margin-top: 40px;
    }
    footer a {
      color: var(--primary);
      text-decoration: none;
      font-weight: 600;
    }
    footer a:hover {
      text-decoration: underline;
    }

    /* ═══════════════════════ PRINT ═══════════════════════ */
    @media print {
      @page {
        size: A4 portrait;
        margin: 12mm;
      }
      header, .sidebar, .add-item-btn, .del-btn, .invoice-topbar, .params-module, .sr-only, .landing-seo, .site-support, .invoice-actions-footer, .modal-overlay, .receiver-search-wrap, .payer-suggestions, .autocomplete-drop { display: none !important; }
      body, html {
        background: white !important;
        width: auto !important;
        min-width: 0 !important;
      }
      .main-wrap {
        display: block !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
      }
      #views-wrap,
      .page-main,
      #view-invoice {
        min-height: 0 !important;
        height: auto !important;
      }
      .invoice-card {
        box-shadow: none !important;
        border: none !important;
        overflow: visible !important;
      }
      .invoice-body {
        padding: 0 !important;
      }
      .items-table-wrap {
        overflow: visible !important;
      }
      .inv-header,
      .meta-row,
      .two-col,
      .totals-row,
      .bottom-two,
      .invoice-signature-row,
      .field-section {
        break-inside: avoid;
        page-break-inside: avoid;
      }
      .two-col {
        gap: 10px;
      }
      .field-section {
        display: flex;
        flex-direction: column;
      }
      .two-col > .field-section:first-child,
      .two-col > .field-section:last-child {
        padding: 0 !important;
        border: none !important;
        margin: 0 !important;
      }
      .items-table {
        width: 100% !important;
        table-layout: fixed;
        border-collapse: collapse;
        page-break-inside: auto;
      }
      .items-table thead {
        display: table-header-group;
      }
      .items-table tr {
        break-inside: avoid;
        page-break-inside: avoid;
      }
      .items-table td,
      .items-table th {
        white-space: normal !important;
        word-break: break-word;
      }
      input, textarea, select {
        background: transparent !important;
        box-shadow: none !important;
      }
    }

    /* ═══════════════════════ RESPONSIVE ═══════════════════════ */
    /* Desktop / large laptop */
    @media (max-width: 1366px) {
      .header-inner { padding: 0 22px; }
      .main-wrap {
        padding: 24px 22px;
        gap: 24px;
      }
      .invoice-body { padding: 24px; }
      .invoice-actions-footer {
        padding: 20px 24px 24px;
      }
    }

    /* Non-mobile: make auth modal compact */
    @media (min-width: 761px) {
      #authModal .modal {
        max-width: 360px;
      }
      #authModal .modal-header {
        padding: 14px 18px 0;
      }
      #authModal .modal-body {
        padding: 14px 18px 16px;
      }
      #authModal .auth-tabs {
        margin-bottom: 10px;
      }
      #authModal .auth-tab {
        padding: 8px 12px;
        font-size: 13px;
      }
      #authModal .form-group {
        margin-bottom: 10px;
        gap: 5px;
      }
      #authModal .form-group label {
        font-size: 12px;
      }
      #authModal .form-group input {
        font-size: 13px;
        padding: 8px 10px;
      }
      #authModal .form-divider {
        margin: 10px 0;
      }
      #authModal .oauth-btn,
      #authModal .btn-submit {
        padding: 9px;
        font-size: 13px;
      }
      #authModal .form-footer {
        margin-top: 10px;
      }
    }

    /* Laptop */
    @media (max-width: 1180px) {
      .main-wrap {
        grid-template-columns: 200px 1fr;
        gap: 18px;
      }
      .sidebar-card { padding: 16px; }
      .profile-name { max-width: 140px; }
      .sender-contact-row { grid-template-columns: 1fr; }
      .inv-header { gap: 20px; }
      .big-title-static { font-size: 34px; }
    }

    /* Tablet */
    @media (max-width: 980px) {
      .main-wrap {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 18px 14px;
      }
      .sidebar {
        position: static;
        top: auto;
        gap: 12px;
      }
      .sidebar-card { padding: 14px; }
      .sb-nav {
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
      }
      .sb-nav-btn {
        white-space: nowrap;
        min-width: max-content;
        padding: 9px 12px;
      }
      #views-wrap { min-height: calc(100vh - 260px); }
      .guest-content-lock { min-height: min(380px, calc(100vh - 300px)); }
      .status-full-inner { flex-direction: column; }
      .time-filter-row { flex-direction: column; align-items: flex-start; }
      .inv-preview-modal {
        max-width: 100%;
        max-height: calc(100dvh - 24px);
      }
    }

    /* Mobile / pad portrait */
    @media (max-width: 760px) {
      .header-inner { padding: 0 10px; padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); gap: 10px; }
      .logo-img { height: 34px; }
      .main-wrap {
        padding: 12px 10px;
        padding-left: max(10px, env(safe-area-inset-left, 0px));
        padding-right: max(10px, env(safe-area-inset-right, 0px));
        padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
      }
      .page-title { font-size: 20px; }
      .page-sub { font-size: 13px; }
      .params-module {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 14px 16px;
      }
      .params-module-title {
        margin: 0;
      }
      .params-divider {
        display: none;
      }
      .params-controls {
        flex-wrap: wrap;
        gap: 10px 14px;
        align-items: center;
      }
      .currency-select {
        margin-right: 0;
        flex: 1 1 auto;
        min-width: 0;
      }
      .ctrl-toggle-item {
        margin-right: 0;
        flex: 1 1 auto;
        min-width: min(100%, 160px);
      }
      .invoice-topbar { padding: 14px 18px; }
      .invoice-topbar h2 { font-size: 18px; letter-spacing: -0.3px; }
      .invoice-body { padding: 16px; }
      #sb-invoice-actions {
        display: none !important;
      }
      .invoice-actions-footer {
        padding: 18px 16px 22px;
      }
      .inv-header,
      .two-col,
      .bottom-two { grid-template-columns: 1fr; }
      .two-col > .field-section:first-child {
        padding-right: 0;
        border-right: none;
        border-bottom: 1px solid var(--gray-200);
        padding-bottom: 12px;
        margin-bottom: 8px;
      }
      .two-col > .field-section:last-child {
        padding-left: 0;
      }
      .field-section {
        gap: 10px;
      }
      .meta-row { grid-template-columns: 1fr 1fr; padding: 14px; gap: 10px; }
      .section-label-row { flex-direction: column; align-items: stretch; }
      .receiver-search-wrap { max-width: none; width: 100%; }
      .autocomplete-drop { min-width: 0; }
      .profile-name { max-width: 110px; }
      .profile-dropdown { right: 0; left: auto; min-width: 210px; }
      .company-dropdown {
        left: auto;
        right: 0;
        min-width: min(280px, calc(100vw - 24px));
        max-width: calc(100vw - 16px);
      }
      .modal-overlay { padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
      .modal { max-height: min(92vh, calc(100dvh - 20px)); }
      .modal-header { padding: 18px 16px 0; }
      .modal-body { padding: 18px 16px 20px; }
      .company-modal .modal-header { padding: 16px 16px 0; }
      .company-modal .modal-body { padding: 14px 16px 16px; }
      #companyModal .modal-body { grid-template-columns: 1fr; }
      #companyModal .company-form-group:nth-of-type(5),
      #companyModal .company-form-group:nth-of-type(6),
      #companyModal .company-form-group:nth-of-type(8),
      #companyModal .company-form-group:nth-of-type(9) {
        grid-column: 1 / -1;
      }

      .totals-row {
        flex-direction: column;
        align-items: stretch;
      }
      .totals-row .totals-row-notes {
        flex: 1 1 auto;
        grid-template-columns: 1fr;
      }
      .totals-box {
        width: 100%;
        max-width: 100%;
      }
      .invoice-signature-row {
        justify-content: center;
      }

      .items-table,
      .history-table,
      .clients-table,
      .products-table {
        min-width: 680px;
      }
      .items-table-wrap .items-table {
        margin-bottom: 0;
      }
      .history-table-wrap,
      .clients-table-wrap,
      .products-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
      }
      .pv-meta-grid {
        grid-template-columns: 1fr;
      }
      .pv-two-col {
        grid-template-columns: 1fr;
      }
      .pv-section:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
      }
      .pv-title {
        font-size: 24px;
        overflow-wrap: anywhere;
      }
      .pv-header {
        flex-direction: column;
        gap: 12px;
      }
    }

    /* Small mobile */
    @media (max-width: 560px) {
      .page-toolbar-flex .page-toolbar-btn {
        white-space: normal;
        text-align: center;
      }
      .logo-img { height: 32px; max-width: 132px; }
      .header-inner { gap: 8px; }
      .profile-btn { padding-right: 8px; min-height: 44px; }
      .profile-name { max-width: 92px; font-size: 12px; }
      .profile-btn.guest { padding-right: 10px; }
      .profile-btn.guest .profile-guest-label { max-width: none; font-size: 11px; }
      .profile-btn:not(.guest) .profile-name { max-width: 110px; font-size: 12px; }
      .company-btn { min-height: 44px; }
      .meta-row { grid-template-columns: 1fr; }
      .big-title-static { font-size: 28px; }
      .items-table,
      .history-table,
      .clients-table,
      .products-table {
        min-width: 620px;
      }
      .inv-preview-overlay {
        padding: 16px 12px;
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
      }
      .inv-preview-body {
        padding: 20px 16px;
      }
      .toast {
        right: 10px;
        left: 10px;
        bottom: max(10px, env(safe-area-inset-bottom, 0px));
      }
    }

    /* ═══════════════════════ FOOTER ═══════════════════════ */
    footer { text-align: center; padding: 28px 24px; font-size: 13px; color: var(--gray-400); max-width: 100%; box-sizing: border-box; }
    footer a { color: var(--primary); text-decoration: none; }

    /* ═══════════════════════ TOAST ═══════════════════════ */
    .toast {
      position: fixed; bottom: 24px; right: 24px;
      background: var(--gray-900); color: white; padding: 11px 18px;
      border-radius: 10px; font-size: 14px; font-weight: 500;
      box-shadow: var(--shadow-lg); z-index: 9999;
      transform: translateY(70px); opacity: 0; transition: all .3s; pointer-events: none;
    }
    .toast.show { transform: translateY(0); opacity: 1; }

    /* ═══════════════════════ DARK THEME ═══════════════════════ */
    [data-theme="dark"] {
      color-scheme: dark;
      --gray-50: #0b1220;
      --gray-100: #111a2b;
      --gray-200: #1c2838;
      --gray-300: #2a3748;
      --gray-400: #7b8da8;
      --gray-500: #9aaabe;
      --gray-600: #b8c5d6;
      --gray-700: #d6dee8;
      --gray-900: #eef2f7;
      --white: #151f31;
      --primary-light: rgba(13, 91, 255, 0.18);
      --border-subtle: rgba(255, 255, 255, 0.08);
      --border-default: rgba(255, 255, 255, 0.12);
      --border-strong: rgba(255, 255, 255, 0.18);
      --overlay-backdrop: rgba(0, 0, 0, 0.72);
      --focus-ring: rgba(13, 91, 255, 0.28);
      --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
      --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
      --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.45);
      --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.55);
    }

    [data-theme="dark"] .logo-img {
      filter: brightness(1.08) contrast(1.02);
    }

    [data-theme="dark"] .guest-content-lock {
      background:
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(13, 91, 255, 0.12) 0%, transparent 55%),
        linear-gradient(165deg, rgba(17, 26, 43, 0.98) 0%, rgba(11, 18, 32, 0.96) 100%);
      border-color: var(--border-default);
    }

    [data-theme="dark"] .guest-lock-card {
      background: linear-gradient(165deg, #1a2438 0%, #151f31 42%, #111a2b 100%);
      border-color: var(--border-default);
      box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04) inset,
        0 16px 44px -12px rgba(13, 91, 255, 0.22),
        0 28px 56px -20px rgba(0, 0, 0, 0.45);
    }

    [data-theme="dark"] .profile-btn.guest {
      background: rgba(13, 91, 255, 0.14);
      border-color: rgba(13, 91, 255, 0.28);
    }

    [data-theme="dark"] .profile-btn.guest .profile-avatar {
      background: var(--gray-100);
    }

    [data-theme="dark"] .profile-dd-item.danger:hover {
      background: rgba(220, 38, 38, 0.12);
    }

    [data-theme="dark"] .history-table tbody tr:hover,
    [data-theme="dark"] .clients-table tbody tr:hover {
      background: rgba(13, 91, 255, 0.08);
    }

    [data-theme="dark"] .products-table tbody tr:hover {
      background: rgba(53, 214, 168, 0.1);
    }

    [data-theme="dark"] .products-count-badge {
      background: rgba(53, 214, 168, 0.16);
    }

    [data-theme="dark"] .usage-pill {
      background: rgba(53, 214, 168, 0.14);
    }

    [data-theme="dark"] .autocomplete-drop {
      background: var(--gray-100);
      border-color: var(--border-default);
      box-shadow: var(--shadow-lg);
    }

    [data-theme="dark"] .autocomplete-item:hover,
    [data-theme="dark"] .autocomplete-item.active {
      background: rgba(13, 91, 255, 0.12);
    }

    [data-theme="dark"] .toast {
      background: #1e293b;
      color: #f8fafc;
      border: 1px solid var(--border-default);
    }

    [data-theme="dark"] .invoice-actions-footer {
      background: linear-gradient(180deg, var(--gray-100) 0%, var(--white) 55%);
    }

    /* Keep printable invoice canvas paper-white in dark mode */
    [data-theme="dark"] .invoice-card,
    [data-theme="dark"] .inv-preview-body {
      --gray-50: #f8fafc;
      --gray-100: #f1f5f9;
      --gray-200: #e2e8f0;
      --gray-300: #cbd5e1;
      --gray-400: #94a3b8;
      --gray-500: #64748b;
      --gray-600: #475569;
      --gray-700: #334155;
      --gray-900: #0f172a;
      --white: #ffffff;
      --border-subtle: rgba(0, 0, 0, 0.06);
      --border-default: rgba(0, 0, 0, 0.08);
      --border-strong: rgba(0, 0, 0, 0.12);
      --focus-ring: rgba(13, 91, 255, 0.1);
      background: #ffffff;
      color: #0f172a;
    }

    [data-theme="dark"] .invoice-card .invoice-actions-footer {
      --gray-50: #f8fafc;
      --gray-100: #f1f5f9;
      --white: #ffffff;
      background: linear-gradient(180deg, #f8fafc 0%, #ffffff 55%);
      border-top-color: rgba(0, 0, 0, 0.08);
    }

    [data-theme="dark"] input:focus,
    [data-theme="dark"] textarea:focus,
    [data-theme="dark"] select:focus,
    [data-theme="dark"] .bank-select:focus,
    [data-theme="dark"] .receiver-search:focus,
    [data-theme="dark"] .currency-select:focus {
      box-shadow: 0 0 0 3px var(--focus-ring);
    }

    [data-theme="dark"] .params-divider {
      background: var(--border-subtle);
    }

    [data-theme="dark"] .oauth-btn {
      background: var(--gray-100);
      border-color: var(--border-default);
      color: var(--gray-700);
    }

    [data-theme="dark"] .oauth-btn:hover {
      background: var(--gray-200);
    }

    [data-theme="dark"] .form-divider span {
      background: var(--white);
      color: var(--gray-500);
    }

    [data-theme="dark"] .policy-content code,
    [data-theme="dark"] .policy-content pre {
      background: var(--gray-100);
      border-color: var(--border-default);
    }

    /* History / table controls */
    [data-theme="dark"] .status-select {
      border: 1px solid transparent;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23b8c5d6' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    }
    [data-theme="dark"] .status-select.status-paid {
      background-color: rgba(53, 214, 168, 0.14);
      color: #6ee7b7;
      border-color: rgba(53, 214, 168, 0.32);
    }
    [data-theme="dark"] .status-select.status-pending {
      background-color: rgba(234, 179, 8, 0.14);
      color: #fcd34d;
      border-color: rgba(234, 179, 8, 0.32);
    }
    [data-theme="dark"] .status-select.status-overdue {
      background-color: rgba(248, 113, 113, 0.14);
      color: #fca5a5;
      border-color: rgba(248, 113, 113, 0.32);
    }
    [data-theme="dark"] .status-select.status-draft {
      background-color: var(--gray-200);
      color: var(--gray-500);
      border-color: var(--border-default);
    }
    [data-theme="dark"] .status-select.status-cancelled {
      background-color: rgba(244, 114, 182, 0.12);
      color: #f9a8d4;
      border-color: rgba(244, 114, 182, 0.28);
    }

    [data-theme="dark"] .icon-btn {
      background: var(--gray-100);
      border-color: var(--border-default);
      color: var(--gray-500);
    }
    [data-theme="dark"] .icon-btn:hover {
      background: var(--gray-200);
      border-color: var(--border-strong);
      color: var(--gray-700);
    }
    [data-theme="dark"] .icon-btn-danger {
      color: #f87171;
      border-color: rgba(248, 113, 113, 0.35);
      background: rgba(220, 38, 38, 0.1);
    }
    [data-theme="dark"] .icon-btn-danger:hover {
      background: rgba(220, 38, 38, 0.2);
      border-color: rgba(248, 113, 113, 0.5);
      color: #fecaca;
    }

    [data-theme="dark"] .history-view-tab {
      background: var(--gray-100);
      border-color: var(--border-default);
      color: var(--gray-600);
    }
    [data-theme="dark"] .history-view-tab:hover {
      border-color: rgba(13, 91, 255, 0.35);
      color: var(--gray-700);
    }
    [data-theme="dark"] .history-view-tab.active {
      background: rgba(13, 91, 255, 0.2);
      border-color: rgba(96, 165, 250, 0.45);
      color: #93c5fd;
    }

    [data-theme="dark"] .filter-chip {
      background: var(--gray-100);
      border-color: var(--border-default);
      color: var(--gray-600);
    }
    [data-theme="dark"] .filter-chip:hover {
      background: rgba(13, 91, 255, 0.14);
      border-color: rgba(13, 91, 255, 0.35);
      color: #93c5fd;
    }
    [data-theme="dark"] .filter-chip.active {
      background: var(--primary);
      border-color: var(--primary);
      color: #fff;
    }

    [data-theme="dark"] .btn-outline {
      background: var(--gray-100);
      border-color: var(--border-default);
      color: var(--gray-700);
    }
    [data-theme="dark"] .btn-outline:hover {
      background: var(--gray-200);
      border-color: var(--border-strong);
    }

    [data-theme="dark"] .btn-ghost:hover {
      background: var(--gray-200);
    }

    [data-theme="dark"] .sort-btn {
      background: var(--gray-100);
      border-color: var(--border-default);
      color: var(--gray-600);
    }
    [data-theme="dark"] .sort-btn:hover,
    [data-theme="dark"] .sort-btn.active {
      background: rgba(13, 91, 255, 0.14);
      border-color: rgba(13, 91, 255, 0.35);
      color: #93c5fd;
    }

    [data-theme="dark"] .policy-nav a.active {
      background: rgba(13, 91, 255, 0.18);
      border-color: rgba(96, 165, 250, 0.4);
      color: #93c5fd;
    }

    [data-theme="dark"] .clients-empty,
    [data-theme="dark"] .history-empty {
      background: var(--white);
      border-color: var(--border-default);
    }
