    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    :root {
      --bg: #f0f4f8;
      --surface: #ffffff;
      --surface2: #f7fafc;
      --border: #e2e8f0;
      --border2: #cbd5e0;
      --text: #1a202c;
      --text2: #4a5568;
      --text3: #a0aec0;
      --blue: #3182ce;
      --blue-light: #ebf8ff;
      --blue-dim: rgba(49,130,206,0.12);
      --blue-dark: #2c5282;
      --green: #38a169;
      --green-dim: rgba(56,161,105,0.1);
      --red: #e53e3e;
      --red-dim: rgba(229,62,62,0.1);
      --orange: #dd6b20;
      --orange-dim: rgba(221,107,32,0.1);
      --amber: #b7791f;
      --amber-dim: rgba(214,158,46,0.12);
      --font: 'Inter', sans-serif;
      --mono: 'JetBrains Mono', monospace;
      --radius: 8px;
      --radius-lg: 12px;
      --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    }
    html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; visibility: hidden; }
    button { cursor: pointer; font-family: inherit; }
    input, select { font-family: inherit; }
    ::-webkit-scrollbar { width: 5px; height: 5px; }
    ::-webkit-scrollbar-track { background: transparent; }
    ::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

    /* ── Layout ── */
    .app { display: flex; height: 100vh; overflow: hidden; }
    .sidebar { width: 220px; min-width: 220px; background: #2d3748; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
    .sidebar-top { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
    .sidebar-logo { display: flex; align-items: center; gap: 10px; color: white; font-size: 15px; font-weight: 700; margin-bottom: 4px; }
    .sidebar-logo svg { opacity: 0.9; }
    .sidebar-logo-mark { width: 22px; height: 22px; object-fit: contain; flex-shrink: 0; }
    /* The drawer's close button exists for the mobile menu only. Without this base
       rule it rendered as a bare browser button beside the logo on desktop. */
    .sidebar-close-btn { display: none; }
    .sidebar-sub { font-size: 11px; color: rgba(255,255,255,0.5); letter-spacing: 0.05em; }
    .sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
    .nav-item {
      display: flex; align-items: center; gap: 10px;
      padding: 9px 12px; border-radius: var(--radius);
      color: rgba(255,255,255,0.65); font-size: 13px; font-weight: 500;
      cursor: pointer; border: none; background: none; width: 100%; text-align: left;
      transition: all 0.15s;
    }
    .nav-item:hover { color: white; background: rgba(255,255,255,0.1); }
    .nav-item.active { color: white; background: rgba(255,255,255,0.15); }
    .nav-item svg { opacity: 0.8; flex-shrink: 0; }
    .sidebar-footer { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,0.1); }

    /* ── Mobile top bar ── */
    .mobile-topbar {
      position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 220;
      background: #2d3748; color: white;
      align-items: center; gap: 12px; padding: 0 14px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    }
    .hamburger-btn {
      display: flex; align-items: center; justify-content: center;
      width: 36px; height: 36px; border-radius: 8px;
      background: rgba(255,255,255,0.08); border: none; color: white;
      cursor: pointer; flex-shrink: 0;
    }
    .hamburger-btn:hover { background: rgba(255,255,255,0.15); }
    .mobile-topbar-title { font-size: 15px; font-weight: 700; }
    .main { flex: 1; overflow-y: auto; padding: 28px 32px; }

    /* ── Pages ── */
    .page { display: none; }
    .page.active { display: block; animation: fadeIn 0.2s ease; }
    @keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

    .page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
    .page-title { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
    .page-sub { font-size: 13px; color: var(--text3); margin-top: 3px; }

    /* ── Stat cards ── */
    .stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
    .stat-card {
      background: var(--surface); border: 1px solid var(--border);
      border-radius: var(--radius-lg); padding: 18px 20px;
      box-shadow: var(--shadow); position: relative; overflow: hidden;
    }
    .stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--c, var(--blue)); }
    .stat-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
    .stat-value { font-size: 28px; font-weight: 700; color: var(--text); font-family: var(--mono); line-height: 1; }
    .stat-sub { font-size: 11px; color: var(--text3); margin-top: 6px; }

    /* ── Company breakdown ── */
    .breakdown-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); margin-bottom: 24px; }
    .breakdown-table table { width: 100%; border-collapse: collapse; }
    .breakdown-table th { background: var(--surface2); text-align: left; padding: 10px 16px; font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.07em; border-bottom: 1px solid var(--border); }
    .breakdown-table th.num, .breakdown-table td.num { text-align: right; }
    .breakdown-table td { padding: 12px 16px; font-size: 13px; border-bottom: 1px solid var(--border); }
    .breakdown-table tr:last-child td { border-bottom: none; }
    .breakdown-table td.num { font-family: var(--mono); }

    /* ── Section title ── */
    .section-title { font-size: 14px; font-weight: 700; color: var(--text); margin: 24px 0 12px; }

    /* ── Company tabs ── */
    .filter-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
    .filter-tab {
      padding: 8px 16px; border-radius: var(--radius);
      border: 1px solid var(--border); background: var(--surface);
      color: var(--text2); font-size: 13px; font-weight: 500;
      box-shadow: var(--shadow); transition: all 0.15s;
    }
    .filter-tab:hover { border-color: var(--blue); color: var(--blue); }
    .filter-tab.active { background: var(--blue-dim); border-color: var(--blue); color: var(--blue); }

    /* ── AR/AP table ── */
    .ar-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); overflow-x: auto; }
    .ar-table { width: 100%; border-collapse: collapse; min-width: 900px; }
    .ar-table th { background: var(--surface2); text-align: right; padding: 10px 14px; font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--border); white-space: nowrap; }
    .ar-table th:first-child, .ar-table td:first-child { text-align: left; }
    .ar-table td { padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--border); text-align: right; font-family: var(--mono); white-space: nowrap; }
    .ar-table td:first-child { font-family: var(--font); font-weight: 500; white-space: normal; }
    .ar-table tr:last-child td { border-bottom: none; }
    .ar-table tr:hover td { background: var(--surface2); }

    .ar-table tr.expandable td:first-child { cursor: pointer; }
    .expand-arrow { display: inline-block; margin-right: 8px; color: var(--text3); transition: transform 0.15s; font-size: 11px; }
    .expand-arrow.open { transform: rotate(90deg); }
    .detail-row td { padding: 0; background: var(--surface2); }
    .detail-row.collapsed { display: none; }
    .detail-inner { padding: 10px 14px 14px 38px; }
    .detail-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
    .detail-table th { text-align: left; padding: 5px 10px; color: var(--text3); font-weight: 600; text-transform: uppercase; font-size: 10px; letter-spacing: 0.06em; font-family: var(--font); }
    .detail-table td { padding: 5px 10px; color: var(--text2); }
    .detail-table th:last-child, .detail-table td:last-child { text-align: right; }
    .detail-table tr.invoice-overdue td { color: var(--red); font-weight: 600; }

    /* Overdue / no-terms row highlighting — background only on every cell, accent bar on first cell only */
    .ar-table tr.overdue-row td { background: #fee2e2 !important; }
    .ar-table tr.overdue-row:hover td { background: #fecaca !important; }
    .ar-table tr.overdue-row td:first-child { box-shadow: inset 4px 0 0 0 var(--red); }
    .ar-table tr.no-terms-row td { background: #fefcbf !important; }
    .ar-table tr.no-terms-row:hover td { background: #fbf3a0 !important; }
    .ar-table tr.no-terms-row td:first-child { box-shadow: inset 4px 0 0 0 var(--amber); }

    .status-badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 12px; white-space: nowrap; }
    .status-ok { background: var(--green-dim); color: var(--green); }
    .status-overdue { background: var(--red); color: white; }
    .status-no-terms { background: #f6e05e; color: #744210; }

    .terms-input {
      width: 60px; padding: 5px 8px; text-align: center;
      font-family: var(--mono); font-size: 13px; font-weight: 600;
      color: var(--text2); background: var(--surface); cursor: text;
      border: 1px solid var(--border); border-radius: 6px; outline: none;
      transition: border-color 0.12s;
    }
    .terms-input:focus { border-color: var(--blue); color: var(--text); }
    .terms-input.saved { border-color: var(--green); }
    .terms-input::placeholder { color: var(--amber); font-weight: 700; }

    /* ── Buttons ── */
    .btn-primary {
      display: flex; align-items: center; gap: 7px;
      background: var(--blue); color: white; border: none;
      border-radius: var(--radius); padding: 9px 16px;
      font-size: 13px; font-weight: 600; font-family: inherit;
      transition: background 0.15s; box-shadow: var(--shadow);
    }
    .btn-primary:hover { background: var(--blue-dark); }
    .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
    .btn-ghost {
      background: var(--surface); border: 1px solid var(--border);
      color: var(--text2); border-radius: var(--radius);
      padding: 9px 16px; font-size: 13px; font-family: inherit;
      transition: all 0.15s;
    }
    .btn-ghost:hover { border-color: var(--border2); color: var(--text); }
    .btn-send {
      background: #2d3748; color: white; border: none;
      border-radius: var(--radius); padding: 7px 14px;
      font-size: 12px; font-weight: 600; font-family: inherit;
      transition: background 0.15s; white-space: nowrap;
    }
    .btn-send:hover { background: #1a202c; }

    .loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px 0; color: var(--text3); font-size: 13px; }
    .spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.7s linear infinite; }
    @keyframes spin { to { transform: rotate(360deg); } }
    .empty-state { padding: 40px; text-align: center; color: var(--text3); font-size: 13px; }

    /* ── Modal ── */
    .modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 300; display: none; align-items: center; justify-content: center; padding: 16px; }
    .modal-overlay.visible { display: flex; }
    .modal-box { background: var(--surface); border-radius: var(--radius-lg); width: 460px; max-width: 95vw; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
    .modal-box-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
    .modal-box-header h3 { font-size: 15px; font-weight: 700; }
    .modal-close-btn { border: none; background: none; font-size: 18px; color: var(--text3); cursor: pointer; line-height: 1; padding: 0; }
    .modal-body { padding: 20px 22px; max-height: 70vh; overflow-y: auto; }
    .modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
    .pi-total { font-size: 22px; font-weight: 700; font-family: var(--mono); color: var(--text); margin: 4px 0 18px; }
    .pi-option-btns { display: flex; flex-direction: column; gap: 10px; }
    .pi-amount-row { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
    .pi-amount-input {
      flex: 1; padding: 9px 12px; border-radius: var(--radius);
      border: 1px solid var(--border); background: var(--surface2);
      font-family: var(--mono); font-size: 14px; color: var(--text); outline: none;
    }
    .pi-amount-input:focus { border-color: var(--blue); }
    .pi-success { text-align: center; padding: 12px 0; color: var(--green); font-size: 13px; font-weight: 600; }
    .email-note-area { width: 100%; min-height: 80px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-family: inherit; font-size: 13px; color: var(--text); background: var(--surface2); resize: vertical; outline: none; transition: border-color 0.15s; box-sizing: border-box; margin-top: 14px; }
    .email-note-area:focus { border-color: var(--blue); }
    .email-note-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 14px; display: block; }

    /* ── Bill selection ── */
    .bill-check { cursor: pointer; accent-color: var(--blue); width: 14px; height: 14px; vertical-align: -2px; margin-right: 6px; }
    .selection-bar {
      position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
      display: none; align-items: center; gap: 12px;
      background: #1a202c; color: white;
      padding: 12px 20px; border-radius: 12px;
      box-shadow: 0 8px 32px rgba(0,0,0,0.35);
      font-size: 13px; font-weight: 500; z-index: 100;
      white-space: nowrap;
    }
    .selection-bar.visible { display: flex; }
    #invoice-selection-bar { bottom: 84px; }
    .sel-count { color: #a0aec0; }
    .sel-count strong { color: white; }
    .sel-divider { width: 1px; height: 20px; background: #4a5568; }
    .btn-sel-send {
      background: var(--blue); border: none; color: white;
      padding: 7px 14px; border-radius: 8px; font-size: 13px;
      font-weight: 600; cursor: pointer; transition: opacity 0.15s;
    }
    .btn-sel-send:hover { opacity: 0.85; }
    .btn-sel-cancel { background: none; border: none; color: #a0aec0; font-size: 13px; cursor: pointer; padding: 4px 8px; }
    .btn-sel-cancel:hover { color: white; }
    .pi-vendor-section { margin-bottom: 14px; }
    .pi-vendor-name { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
    .pi-subtotal { display: flex; justify-content: space-between; font-size: 12px; color: var(--text2); padding: 4px 0; }

    /* ── Commission cards ── */
    .commission-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 14px; }
    .commission-card-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
    .commission-card-title { font-size: 14px; font-weight: 700; color: var(--text); }
    .commission-card-sub { font-size: 12px; color: var(--text3); }
    .commission-amount { font-size: 18px; font-weight: 700; font-family: var(--mono); color: var(--text); }
    .commission-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 12px; }
    .commission-field-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
    .commission-input { width: 100%; padding: 7px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface2); font-family: var(--mono); font-size: 13px; color: var(--text); outline: none; }
    .commission-input:focus { border-color: var(--blue); }
    .commission-cc-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text2); }
    .commission-cc-row input { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; }
    .po-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
    .po-row .commission-input { flex: 1; }
    .po-remove-btn { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 16px; padding: 0 4px; line-height: 1; }
    .po-remove-btn:hover { color: var(--red); }
    .commission-result { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; border-top: 1px solid var(--border); margin-top: 4px; }
    .commission-result-label { font-size: 13px; font-weight: 700; color: var(--text2); }
    .commission-result-value { font-size: 20px; font-weight: 700; font-family: var(--mono); color: var(--amber); }

    @media (max-width: 900px) {
      .stat-grid { grid-template-columns: repeat(2, 1fr); }

      .mobile-topbar { display: flex; }
      .app { padding-top: 52px; }

      .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh; z-index: 210;
        width: 240px; min-width: 240px;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 8px 0 24px rgba(0,0,0,0.25);
      }
      .sidebar.open { transform: translateX(0); }
      .sidebar-logo span, .sidebar-sub, .nav-item span { display: inline; }

      .sidebar-backdrop {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
        z-index: 205;
      }
      .sidebar-backdrop.visible { display: block; }

      .sidebar-close-btn {
        display: flex; align-items: center; justify-content: center;
        width: 28px; height: 28px; border-radius: 6px;
        background: rgba(255,255,255,0.08); border: none; color: rgba(255,255,255,0.7);
        cursor: pointer; flex-shrink: 0;
      }
      .sidebar-close-btn:hover { background: rgba(255,255,255,0.15); color: white; }

      .main { padding: 16px; }
    }

    @media (max-width: 600px) {
      .stat-grid { grid-template-columns: 1fr; }
      .page-title { font-size: 19px; }
      .selection-bar {
        left: 12px; right: 12px; transform: none; bottom: 12px;
        white-space: normal; flex-wrap: wrap; justify-content: center;
        text-align: center; font-size: 12px; padding: 10px 14px; gap: 8px;
      }
      #invoice-selection-bar { bottom: 76px; }
      .modal-box { width: 100%; }
      .commission-fields { grid-template-columns: 1fr; }
    }

    @media (min-width: 901px) {
      .mobile-topbar { display: none; }
    }

    /* Touch pass (2). */
    @media (max-width: 900px) {
      input[type="checkbox"] { width: 24px; height: 24px; }
      .doc-link { display: inline-block; padding: 6px 0; }
    }
