    :root {
      --bg: #0f172a; --sidebar: #0b1220; --card: #1e293b; --text: #f1f5f9;
      --muted: #94a3b8; --accent: #38bdf8; --accent-hover: #0ea5e9;
      --danger: #f87171; --warning: #fbbf24; --success: #4ade80;
      --border: #334155; --purple: #a78bfa; --green: #34d399;
      --high: #f87171; --medium: #fbbf24; --low: #4ade80;
      --sidebar-w: 240px;
    }
    * { margin: 0; padding: 0; box-sizing: border-box; }
    body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

    /* Auth */
    .auth-wrap { min-height: 100vh; display: flex; justify-content: center; align-items: center; padding: 24px 16px; }
    .auth-box { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; }
    .auth-box h1 { font-size: 1.5rem; font-weight: 700; text-align: center; }
    .auth-box .sub { color: var(--muted); font-size: 0.9rem; text-align: center; margin-bottom: 24px; }
    .auth-box h2 { font-size: 1.15rem; margin-bottom: 18px; text-align: center; }
    .auth-field { margin-bottom: 14px; }
    .auth-field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
    .auth-field input { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; color: var(--text); font-size: 1rem; outline: none; }
    .auth-field input:focus { border-color: var(--accent); }
    .auth-btn { width: 100%; background: var(--accent); color: #0f172a; padding: 13px; border-radius: 10px; font-size: 1rem; margin-top: 8px; border: none; cursor: pointer; font-weight: 600; }
    .auth-btn:hover { background: var(--accent-hover); }
    .auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }
    .auth-switch { text-align: center; margin-top: 16px; font-size: 0.9rem; color: var(--muted); }
    .auth-switch a { color: var(--accent); cursor: pointer; }
    .auth-error { background: rgba(248,113,113,0.15); border: 1px solid var(--danger); color: var(--danger); padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 0.9rem; display: none; }

    /* Layout */
    .layout { display: flex; min-height: 100vh; }
    .sidebar { width: var(--sidebar-w); background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; transition: transform 0.25s ease; }
    .sidebar-header { padding: 22px 18px 18px; border-bottom: 1px solid var(--border); }
    .sidebar-header h1 { font-size: 1.1rem; font-weight: 700; }
    .sidebar-header .sub { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
    .sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 3px; }
    .nav-item { display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 10px; color: var(--muted); font-size: 0.92rem; font-weight: 500; cursor: pointer; border: none; background: transparent; width: 100%; text-align: left; }
    .nav-item:hover { color: var(--text); background: rgba(255,255,255,0.04); }
    .nav-item.active { background: rgba(56,189,248,0.12); color: var(--accent); }
    .nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
    .sidebar-footer { padding: 14px 10px 18px; border-top: 1px solid var(--border); }
    .user-info { padding: 0 8px 10px; font-size: 0.82rem; color: var(--muted); }
    .user-info strong { color: var(--text); }
    .logout-btn { display: flex; align-items: center; gap: 9px; width: 100%; padding: 10px 13px; border-radius: 10px; background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: 0.88rem; cursor: pointer; }
    .logout-btn:hover { color: var(--danger); border-color: var(--danger); }
    .logout-btn svg { width: 17px; height: 17px; }

    .main { flex: 1; margin-left: var(--sidebar-w); padding: 26px 26px 50px; max-width: 820px; }
    .page-title { font-size: 1.35rem; font-weight: 700; margin-bottom: 18px; }

    .mobile-header { display: none; align-items: center; gap: 12px; padding: 12px 14px; background: var(--sidebar); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
    .hamburger { background: transparent; border: none; color: var(--text); cursor: pointer; padding: 5px; display: flex; }
    .hamburger svg { width: 22px; height: 22px; }
    .mobile-title { font-size: 1rem; font-weight: 600; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90; }

    /* Dashboard */
    .dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 10px; }
    .dash-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 16px; cursor: pointer; transition: border-color 0.2s, transform 0.15s; }
    .dash-card:hover { border-color: var(--accent); transform: translateY(-2px); }
    .dash-card h3 { font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; font-weight: 500; }
    .dash-card .big { font-size: 1.9rem; font-weight: 700; margin-bottom: 3px; }
    .dash-card .sub { font-size: 0.78rem; color: var(--muted); }
    .dash-card .overdue-text { color: var(--danger); font-weight: 500; }
    .dash-card .pending-amt { color: var(--green); font-weight: 600; font-size: 1.05rem; margin-top: 6px; }

    /* Forms */
    .input-section { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 18px; }
    .form-row { display: flex; gap: 10px; margin-bottom: 11px; flex-wrap: wrap; }
    .form-row:last-child { margin-bottom: 0; }
    .form-row input, .form-row select, .form-row textarea {
      flex: 1; min-width: 110px; background: #0f172a; border: 1px solid var(--border);
      border-radius: 9px; padding: 10px 12px; color: var(--text); font-size: 0.92rem; outline: none; font-family: inherit;
      color-scheme: dark;
    }
    .form-row textarea { min-height: 60px; resize: vertical; }
    .form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--accent); }
    .form-row input::placeholder, .form-row textarea::placeholder { color: var(--muted); }
    input[type="date"], input[type="datetime-local"], input[type="file"] { color-scheme: dark; }
    input[type="file"] { padding: 8px 10px; font-size: 0.85rem; }

    .add-btn { background: var(--accent); color: #0f172a; padding: 10px 16px; border-radius: 9px; border: none; cursor: pointer; font-weight: 600; font-size: 0.92rem; white-space: nowrap; }
    .add-btn:hover { background: var(--accent-hover); }
    .add-btn:disabled { opacity: 0.6; cursor: not-allowed; }

    .filters { display: flex; gap: 7px; margin-bottom: 14px; flex-wrap: wrap; }
    .filter-btn { background: transparent; color: var(--muted); padding: 6px 12px; border: 1px solid transparent; border-radius: 8px; font-size: 0.82rem; cursor: pointer; }
    .filter-btn.active { background: var(--card); color: var(--text); border-color: var(--border); }
    .filter-btn:hover:not(.active) { color: var(--text); }

    /* Items */
    .item { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px; margin-bottom: 9px; display: flex; gap: 11px; align-items: flex-start; }
    .item.overdue:not(.done) { border-color: rgba(248,113,113,0.45); background: rgba(248,113,113,0.06); }
    .item.done .main-text { text-decoration: line-through; color: var(--muted); }

    .check { width: 21px; height: 21px; border: 2px solid var(--border); border-radius: 6px; cursor: pointer; flex-shrink: 0; margin-top: 2px; display: flex; align-items: center; justify-content: center; }
    .item.done .check { background: var(--success); border-color: var(--success); }
    .check svg { width: 12px; height: 12px; opacity: 0; }
    .item.done .check svg { opacity: 1; }

    .item-content { flex: 1; min-width: 0; }
    .main-text { font-size: 0.95rem; word-break: break-word; }
    .meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 5px; font-size: 0.78rem; color: var(--muted); align-items: center; }
    .meta .overdue { color: var(--danger); font-weight: 500; }
    .meta .amount { color: var(--green); font-weight: 600; }
    .badge { display: inline-flex; align-items: center; gap: 3px; font-size: 0.72rem; padding: 2px 7px; border-radius: 8px; font-weight: 500; }
    .badge-priority-high { background: rgba(248,113,113,0.15); color: var(--high); }
    .badge-priority-medium { background: rgba(251,191,36,0.15); color: var(--medium); }
    .badge-priority-low { background: rgba(74,222,128,0.15); color: var(--low); }
    .badge-cat { background: rgba(56,189,248,0.12); color: var(--accent); }
    .badge-repeat { background: rgba(167,139,250,0.12); color: var(--purple); }
    .badge-status-pending { background: rgba(148,163,184,0.15); color: var(--muted); }
    .badge-status-partial { background: rgba(251,191,36,0.15); color: var(--warning); }
    .badge-status-paid { background: rgba(74,222,128,0.15); color: var(--success); }
    .badge-status-overdue { background: rgba(248,113,113,0.15); color: var(--danger); }
    .badge-method { background: rgba(56,189,248,0.1); color: var(--accent); }
    .badge-assign { background: rgba(167,139,250,0.15); color: var(--purple); }
    .badge-from { background: rgba(52,211,153,0.12); color: var(--green); }

    .item-actions { display: flex; gap: 4px; flex-shrink: 0; }
    .act-btn { background: transparent; color: var(--muted); padding: 5px 7px; border-radius: 7px; border: none; cursor: pointer; font-size: 0.85rem; }
    .act-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); }
    .client-due-acts { white-space:nowrap; }
    .client-due-acts .act-btn { margin:0 2px; }
    .due-existing-tag { display:inline-block; margin-left:6px; font-size:0.7rem; padding:2px 6px; border-radius:6px; background:rgba(20,184,166,0.2); color:#2dd4bf; font-weight:600; }
    .pay-due-line.existing-due { border-color: rgba(20,184,166,0.35); }
    .act-btn.add-due { color: var(--accent); }
    .act-btn.del:hover { background: rgba(248,113,113,0.15); color: var(--danger); }

    .empty, .loading { text-align: center; color: var(--muted); padding: 36px 20px; font-size: 0.92rem; }
    .error-banner { background: rgba(248,113,113,0.15); border: 1px solid var(--danger); color: var(--danger); padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 0.88rem; display: none; }
    .stats-line { margin-top: 14px; display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem; color: var(--muted); }
    .clear-btn { background: transparent; color: var(--muted); border: none; cursor: pointer; font-size: 0.82rem; }
    .clear-btn:hover { color: var(--danger); }
    .file-link { color: var(--accent); text-decoration: none; font-size: 0.78rem; }
    .file-link:hover { text-decoration: underline; }

    /* Modal */
    .modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 3000; justify-content: center; align-items: flex-start; padding: 30px 16px; overflow-y: auto; }
    .modal-overlay.open { display: flex; }
    .modal { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: 100%; max-width: 640px; margin: auto; }
    .modal h2 { font-size: 1.15rem; margin-bottom: 18px; }
    .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
    .btn-cancel { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 10px 18px; border-radius: 9px; cursor: pointer; font-weight: 500; }
    .btn-cancel:hover { color: var(--text); }
    .btn-save { background: var(--accent); color: #0f172a; border: none; padding: 10px 18px; border-radius: 9px; cursor: pointer; font-weight: 600; }
    .btn-save:hover { background: var(--accent-hover); }


    /* ERP View Modal */
    .view-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
    .view-field label { display: block; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 4px; }
    .view-field .val { font-size: 0.95rem; font-weight: 500; color: var(--text); word-break: break-word; }
    .view-field.full { grid-column: 1 / -1; }
    .view-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; gap: 12px; }
    .view-header h2 { margin: 0; font-size: 1.2rem; }
    .view-status { font-size: 0.78rem; font-weight: 600; padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
    .view-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
    .view-notes { background: var(--bg); border-radius: 10px; padding: 12px 14px; font-size: 0.9rem; color: var(--muted); white-space: pre-wrap; min-height: 40px; }
    .view-file { display: inline-flex; align-items: center; gap: 8px; background: rgba(56,189,248,0.1); color: var(--accent); padding: 8px 14px; border-radius: 8px; text-decoration: none; font-size: 0.88rem; font-weight: 500; }
    .view-file:hover { background: rgba(56,189,248,0.18); }
    .view-amount { font-size: 1.35rem; font-weight: 700; color: var(--green); }
    .view-remaining { color: var(--warning); font-weight: 600; }

    /* Upload progress */
    .upload-progress { display: none; margin-top: 10px; }
    .upload-progress.active { display: block; }
    .progress-bar-bg { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
    .progress-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; width: 0%; transition: width 0.15s; }
    .progress-text { font-size: 0.8rem; color: var(--muted); margin-top: 5px; text-align: right; }

    @media (max-width: 500px) { .view-grid { grid-template-columns: 1fr; } }


    .attach-preview { margin-top: 12px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); max-width: 100%; }
    .attach-preview img { display: block; width: 100%; max-height: 280px; object-fit: contain; background: var(--bg); }
    .remove-attach { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.85rem; color: var(--danger); cursor: pointer; }
    .remove-attach input { accent-color: var(--danger); }


    .pdf-preview { margin-top: 12px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--bg); }
    .pdf-preview iframe { width: 100%; height: 420px; border: none; display: block; }
    .pdf-fallback { padding: 16px; text-align: center; color: var(--muted); font-size: 0.9rem; }


    .brand-logo { display: flex; align-items: center; gap: 12px; }
    .brand-logo img { width: 84px; height: 84px; object-fit: contain; border-radius: 12px; background: #fff; padding: 5px; }
    .brand-logo .brand-text h1 { font-size: 1.15rem; font-weight: 700; margin: 0; line-height: 1.2; }
    .brand-logo .brand-text .sub { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
    .auth-logo { display: flex; flex-direction: column; align-items: center; margin-bottom: 8px; }
    .auth-logo img { width: 216px; height: 216px; object-fit: contain; border-radius: 16px; background: #fff; padding: 10px; margin-bottom: 16px; }
    .auth-logo h1 { font-size: 1.35rem; font-weight: 700; text-align: center; margin: 0; color: #1e3a5f; }
    .auth-logo .sub { color: var(--muted); font-size: 0.88rem; text-align: center; margin-top: 4px; margin-bottom: 20px; }


    .chat-layout {
      display: flex; gap: 0;
      height: calc(100dvh - 130px);
      max-height: calc(100dvh - 130px);
      min-height: 280px;
      border: 1px solid var(--border); border-radius: 14px;
      overflow: hidden; background: var(--card);
    }
    .chat-sidebar { width: 220px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--sidebar); flex-shrink: 0; min-height: 0; }
    .chat-sidebar-title { padding: 12px 14px; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
    .chat-user-list { flex: 1; overflow-y: auto; min-height: 0; }
    .chat-user { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; border: none; background: transparent; width: 100%; text-align: left; color: var(--text); font-size: 0.92rem; }
    .chat-user:hover { background: rgba(255,255,255,0.04); }
    .chat-user.active { background: rgba(56,189,248,0.12); color: var(--accent); }
    .chat-user .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--border); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 0.85rem; flex-shrink: 0; }
    .chat-user .meta { flex: 1; min-width: 0; }
    .chat-user .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .chat-badge { background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 600; padding: 2px 7px; border-radius: 10px; min-width: 18px; text-align: center; }
    .chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
    .chat-header { padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 1rem; flex-shrink: 0; }
    .chat-typing { flex-shrink: 0; }
    .chat-messages { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
    .chat-bubble { max-width: 75%; padding: 10px 14px; border-radius: 14px; font-size: 0.92rem; line-height: 1.45; word-break: break-word; }
    .chat-bubble.me { align-self: flex-end; background: rgba(56,189,248,0.2); color: var(--text); border-bottom-right-radius: 4px; }
    .chat-bubble.them { align-self: flex-start; background: var(--bg); color: var(--text); border-bottom-left-radius: 4px; }
    .chat-time { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }
    .chat-composer { flex-shrink: 0; border-top: 1px solid var(--border); background: var(--card); }
    .chat-input-row { display: flex; gap: 8px; padding: 12px; align-items: center; }
    .chat-input-row input { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; color: var(--text); font-size: 0.95rem; outline: none; min-width: 0; }
    .chat-input-row input:focus { border-color: var(--accent); }
    .chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.95rem; padding: 24px; text-align: center; }
    .nav-badge { background: var(--danger); color: #fff; font-size: 0.65rem; font-weight: 700; padding: 1px 6px; border-radius: 8px; margin-left: auto; }
    .chat-pdf-card { margin-top: 8px; padding: 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); text-align: center; max-width: 260px; }
    .chat-pdf-card .pdf-name { font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; word-break: break-all; }
    .chat-pdf-card .pdf-open { display: inline-block; background: var(--accent); color: #0f172a; padding: 10px 20px; border-radius: 20px; font-weight: 600; text-decoration: none; font-size: 0.9rem; }
    @media (max-width: 900px) {
      .chat-layout { flex-direction: column; height: calc(100dvh - 150px - env(safe-area-inset-bottom, 0px)); max-height: calc(100dvh - 150px - env(safe-area-inset-bottom, 0px)); }
      .chat-sidebar { width: 100%; max-height: 100px; border-right: none; border-bottom: 1px solid var(--border); flex-shrink: 0; }
      .chat-user-list { display: flex; overflow-x: auto; overflow-y: hidden; }
      .chat-user { flex-direction: column; min-width: 72px; padding: 8px; }
      .chat-user .name { font-size: 0.72rem; max-width: 64px; }
      .chat-main { flex: 1; min-height: 0; }
      .chat-messages { padding: 12px; }
      .chat-bubble { max-width: 88%; }
      .chat-pdf iframe { display: none; }
    }
    @media (max-width: 768px) {
      .chat-layout { height: calc(100dvh - 160px - env(safe-area-inset-bottom, 0px)); max-height: calc(100dvh - 160px - env(safe-area-inset-bottom, 0px)); }
      #view-chat .page-title { margin-bottom: 10px; font-size: 1.1rem; }
      .chat-compose { flex-wrap: wrap; gap: 8px; }
      .chat-compose input, .chat-compose textarea { font-size: 16px !important; min-height: 44px; }
      .chat-compose button { min-height: 44px; min-width: 44px; }
    }


    .chat-bubble.deleted { opacity: 0.55; font-style: italic; }
    .chat-ticks { font-size: 0.7rem; margin-left: 6px; color: var(--muted); }
    .chat-ticks.read { color: var(--accent); }
    .chat-typing { font-size: 0.82rem; color: var(--muted); padding: 4px 16px 8px; min-height: 24px; }
    .chat-sub { font-size: 0.78rem; color: var(--muted); font-weight: 400; margin-top: 2px; }
    .chat-attach { display: block; margin-top: 6px; max-width: 220px; border-radius: 8px; overflow: hidden; }
    .chat-attach img { width: 100%; display: block; border-radius: 8px; }
    .chat-attach a { color: var(--accent); font-size: 0.85rem; }
    .chat-pdf { margin-top: 8px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--bg); max-width: 100%; }
    .chat-pdf iframe { width: 100%; height: 280px; border: none; display: block; }
    .chat-bubble.me .chat-pdf { max-width: 320px; }
    .chat-bubble.them .chat-pdf { max-width: 320px; }
    @media (max-width: 768px) {
      .chat-pdf iframe { height: 220px; }
    }
    .chat-bubble-actions { margin-top: 4px; }
    .chat-bubble-actions button { background: transparent; border: none; color: var(--muted); font-size: 0.75rem; cursor: pointer; padding: 2px 4px; }
    .chat-bubble-actions button:hover { color: var(--danger); }
    .chat-file-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 10px; padding: 10px 12px; cursor: pointer; font-size: 1rem; }
    .chat-file-btn:hover { color: var(--text); border-color: var(--muted); }


    .chat-preview { display: none; padding: 8px 12px; background: var(--bg); align-items: center; gap: 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
    .chat-preview.active { display: flex; }
    .chat-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
    .chat-preview .preview-info { flex: 1; font-size: 0.85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .chat-preview .preview-remove { background: transparent; border: none; color: var(--danger); cursor: pointer; font-size: 1.1rem; padding: 6px; }
    .avatar-img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
    .profile-avatar-preview { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; background: var(--border); display: block; margin-bottom: 12px; }


    .notif-item { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 8px; cursor: pointer; transition: border-color 0.15s; }
    .notif-item:hover { border-color: var(--accent); }
    .notif-item.unread { border-color: rgba(56,189,248,0.4); background: rgba(56,189,248,0.06); }
    .notif-item .notif-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
    .notif-item .notif-body { font-size: 0.88rem; color: var(--muted); }
    .notif-item .notif-time { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }


    .role-badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 8px; background: rgba(56,189,248,0.12); color: var(--accent); font-weight: 500; }
    .role-super_admin { background: rgba(251,191,36,0.15); color: var(--warning); }
    .role-engineer { background: rgba(56,189,248,0.12); color: var(--accent); }
    .role-sales_manager { background: rgba(52,211,153,0.12); color: var(--green); }
    .role-qc { background: rgba(148,163,184,0.15); color: var(--muted); }
    .admin-user-row { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; flex-wrap: wrap; }
    .admin-user-row select { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 8px 10px; }


    body.role-readonly-todos #todoForm { display: none !important; }
    body.role-readonly-todos #view-todos .item-actions .edit,
    body.role-readonly-todos #view-todos .item-actions .del,
    body.role-readonly-todos #view-todos .check { pointer-events: none; opacity: 0.4; }
    body.role-readonly-payments #payForm { display: none !important; }
    body.role-readonly-payments #view-payments .item-actions .edit,
    body.role-readonly-payments #view-payments .item-actions .del,
    body.role-readonly-payments #view-payments .check { pointer-events: none; opacity: 0.4; }


    .lic-products { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
    .lic-product-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 20px; cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
    .lic-product-card:hover { border-color: var(--accent); transform: translateY(-2px); }
    .lic-product-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
    .lic-product-card h3 { margin: 0 0 6px; font-size: 1.05rem; }
    .lic-product-card p { margin: 0; color: var(--muted); font-size: 0.85rem; }
    .lic-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
    .lic-tab { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 0.88rem; }
    .lic-tab.active { background: var(--accent); color: #0f172a; border-color: var(--accent); font-weight: 600; }
    .lic-client-list .item { cursor: pointer; }
    .lic-back { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 8px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 12px; font-size: 0.88rem; }
    .lic-back:hover { color: var(--text); }


    .erp-view { background: var(--card); }
    .erp-view-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
    .erp-view-header h2 { margin: 0; font-size: 1.25rem; }
    .erp-view-header .sub { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
    .erp-section { margin-bottom: 18px; }
    .erp-section-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
    .erp-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
    .erp-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.3px; }
    .erp-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
    .erp-table tr:last-child td { border-bottom: none; }
    .erp-modal { max-width: 720px; max-height: 90vh; overflow-y: auto; }
    .erp-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
    .erp-kv .k { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 3px; }
    .erp-kv .v { font-size: 0.95rem; font-weight: 500; word-break: break-word; }
    @media (max-width: 600px) {
      .erp-kv { grid-template-columns: 1fr; }
      .erp-table { display: block; overflow-x: auto; }
    }


    .stmt-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
    .stmt-bar select, .stmt-bar .stmt-btn {
      background: var(--bg); border: 1px solid var(--border); color: var(--text);
      border-radius: 10px; padding: 10px 14px; font-size: 0.88rem;
    }
    .stmt-btn { cursor: pointer; font-weight: 500; }
    .stmt-btn:hover { border-color: var(--accent); color: var(--accent); }
    .stmt-btn.primary { background: var(--accent); color: #0f172a; border-color: var(--accent); font-weight: 600; }
    .stmt-paper { background: #fff; color: #0f172a; border-radius: 12px; padding: 18px 14px; width: 100%; box-sizing: border-box; overflow: hidden; }
    .stmt-paper * { color: inherit; }
    .stmt-top { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 2px solid #0f172a; padding-bottom: 16px; margin-bottom: 20px; }
    .stmt-brand { font-size: 1.35rem; font-weight: 700; color: #0f172a; }
    .stmt-brand span { display: block; font-size: 0.8rem; font-weight: 500; color: #64748b; margin-top: 2px; }
    .stmt-meta { text-align: right; font-size: 0.85rem; color: #475569; }
    .stmt-meta strong { display: block; font-size: 1.1rem; color: #0f172a; margin-bottom: 4px; }
    .stmt-info { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; font-size: 0.9rem; }
    .stmt-info .box { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 10px; padding: 12px 14px; }
    .stmt-info .lbl { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.4px; color: #64748b; margin-bottom: 4px; }
    .stmt-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.78rem; margin-bottom: 20px; table-layout: fixed; }
    .stmt-table th { background: #0f172a; color: #fff !important; text-align: left; padding: 10px 8px; font-weight: 600; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.15px; }
    .stmt-table td { padding: 10px 8px; border-bottom: 1px solid #e2e8f0; color: #0f172a !important; vertical-align: middle; }
    .stmt-table tr:nth-child(even) td { background: #f8fafc; }
    .stmt-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
    .stmt-table .col-num { width: 36px; }
    .stmt-table .col-client { width: 28%; }
        .stmt-table .col-due { width: 100px; white-space: nowrap; }
    .stmt-table .col-amt { width: 110px; white-space: nowrap; text-align: right; }
    .stmt-table .col-rec { width: 110px; white-space: nowrap; text-align: right; }
    .stmt-table .col-bal { width: 110px; white-space: nowrap; text-align: right; }
    .stmt-totals { margin-left: auto; width: min(320px, 100%); border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; }
    .stmt-totals .row { display: flex; justify-content: space-between; padding: 10px 14px; font-size: 0.9rem; border-bottom: 1px solid #e2e8f0; color: #0f172a; }
    .stmt-totals .row:last-child { border-bottom: none; background: #0f172a; color: #fff; font-weight: 700; font-size: 1rem; }
    .stmt-totals .row:last-child span { color: #fff; }
    .stmt-foot { margin-top: 24px; padding-top: 12px; border-top: 1px dashed #cbd5e1; font-size: 0.78rem; color: #64748b; text-align: center; }
    @media print {
      body * { visibility: hidden; }
      #stmtPrintArea, #stmtPrintArea * { visibility: visible; }
      #stmtPrintArea { position: absolute; left: 0; top: 0; width: 100%; background: #fff; padding: 20px; }
      .no-print { display: none !important; }
    }
    @media (max-width: 600px) {
      .stmt-info { grid-template-columns: 1fr; }
      .stmt-paper { padding: 16px; }
    }


    .pay-dues-head { display:flex; justify-content:space-between; align-items:center; margin:12px 0 8px; }
    .pay-dues-head span { font-size:0.88rem; font-weight:600; color:var(--text); }
    .pay-due-line { background:var(--bg); border:1px solid var(--border); border-radius:10px; padding:12px; margin-bottom:10px; position:relative; }
    .pay-due-line .due-num { position:absolute; top:10px; right:12px; font-size:0.75rem; color:var(--muted); }
    .pay-due-line .remove-due { background:transparent; border:none; color:var(--danger); cursor:pointer; font-size:1rem; padding:4px 8px; }
    .btn-secondary { background:transparent; border:1px solid var(--accent); color:var(--accent); border-radius:10px; padding:10px 14px; cursor:pointer; font-size:0.88rem; font-weight:500; }
    .btn-secondary:hover { background:rgba(56,189,248,0.1); }

    
    #clientPayModal.modal-overlay { background: rgba(2, 6, 23, 0.85); backdrop-filter: blur(6px); }

    #clientPayModal.modal-overlay { z-index: 3000; }
    #payModal.modal-overlay,
    #payViewModal.modal-overlay,
    #todoModal.modal-overlay,
    #todoViewModal.modal-overlay { z-index: 3200; }

    .cpv-card { max-width: 960px; width: 96%; padding: 0; overflow: hidden; background: #0f172a !important; opacity: 1 !important; box-shadow: 0 25px 50px rgba(0,0,0,0.5); }
    .cpv-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px 24px; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); border-bottom: 2px solid #14b8a6; }
    .cpv-header-left { display: flex; gap: 14px; align-items: center; }
    .cpv-avatar { width: 48px; height: 48px; border-radius: 12px; background: linear-gradient(135deg, #14b8a6, #0d9488); color: #fff; font-weight: 700; font-size: 1.25rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
    .cpv-title { font-size: 1.25rem; font-weight: 700; color: #f8fafc; margin-bottom: 6px; }
    .cpv-sub { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 0.85rem; color: #94a3b8; }
    .cpv-header .modal-close { color: #94a3b8; background: transparent; border: none; font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }
    .cpv-header .modal-close:hover { color: #fff; }
    .cpv-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 16px 24px; background: #1e293b; opacity: 1; }
    .cpv-kpi { background: #0f172a; border: 1px solid #334155; border-radius: 12px; padding: 14px 16px; opacity: 1; }
    .cpv-kpi.highlight { border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.06); }
    .cpv-kpi-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted, #94a3b8); margin-bottom: 6px; font-weight: 600; }
    .cpv-kpi-value { font-size: 1.2rem; font-weight: 700; color: var(--text, #f1f5f9); font-variant-numeric: tabular-nums; }
    .cpv-kpi-value small { font-size: 0.75rem; font-weight: 500; color: var(--muted); }
    .cpv-kpi-value.ok { color: #4ade80; }
    .cpv-kpi-value.warn { color: #fbbf24; }
    .cpv-table-wrap { padding: 0 24px 8px; overflow-x: auto; max-height: 50vh; background: #0f172a; opacity: 1; position: relative; z-index: 2; }
    .cpv-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; background: #0f172a; }
    .cpv-table thead th { text-align: left; padding: 12px 10px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.3px; color: #94a3b8; border-bottom: 1px solid #334155; font-weight: 600; background: #1e293b; }
    .cpv-table tbody td { padding: 12px 10px; border-bottom: 1px solid #1e293b; color: #e2e8f0; vertical-align: middle; background: #0f172a; }
    .cpv-table tbody tr:hover td { background: #1e293b; }
    .cpv-table .cpv-num { color: var(--muted); width: 40px; }
    .cpv-table .cpv-project { font-weight: 500; }
    .cpv-table .cpv-amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
    .cpv-table .cpv-amt.pending { color: #fbbf24; font-weight: 600; }
    .cpv-acts { text-align: right; white-space: nowrap; }
    .cpv-icon { background: transparent; border: 1px solid var(--border, #334155); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; margin-left: 4px; color: var(--text); font-size: 0.85rem; }
    .cpv-icon:hover { border-color: var(--accent, #38bdf8); color: var(--accent); }
    .cpv-icon.danger:hover { border-color: #f87171; color: #f87171; }
    .cpv-footer { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-top: 1px solid #334155; background: #1e293b; opacity: 1; position: relative; z-index: 2; }
    @media (max-width: 640px) {
      .cpv-kpis { grid-template-columns: 1fr; }
      .cpv-header { flex-direction: column; gap: 12px; }
    }

    
    .pay-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
    .pay-tab { background: transparent; border: none; color: var(--muted); padding: 10px 16px; cursor: pointer; font-size: 0.9rem; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
    .pay-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
    .pay-tab-panel { display: none; }
    .pay-tab-panel.active { display: block; }
    .cmt-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; padding-right: 4px; }
    .cmt-item { background: #0f172a; border: 1px solid #334155; border-radius: 12px; padding: 12px 14px; }
    .cmt-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.78rem; color: #94a3b8; gap: 8px; flex-wrap: wrap; }
    .cmt-author { font-weight: 600; color: #f1f5f9; }
    .cmt-time { color: #64748b; }
    .cmt-body { font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: #e2e8f0; }
    .cmt-attach { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 8px 12px; background: #1e293b; border: 1px solid #334155; border-radius: 8px; font-size: 0.85rem; color: #38bdf8; text-decoration: none; max-width: 100%; }
    .cmt-attach:hover { border-color: #38bdf8; background: rgba(56,189,248,0.08); }
    .cmt-attach img { max-width: 160px; max-height: 120px; border-radius: 6px; display: block; }
    .cmt-del { background: transparent; border: 1px solid #334155; border-radius: 6px; color: #94a3b8; cursor: pointer; font-size: 0.75rem; padding: 2px 8px; }
    .cmt-del:hover { color: #f87171; border-color: #f87171; }
    .cmt-compose { display: flex; flex-direction: column; gap: 10px; background: #0f172a; border: 1px solid #334155; border-radius: 12px; padding: 12px; }
    .cmt-compose textarea {
      width: 100%; min-height: 72px; resize: vertical; box-sizing: border-box;
      background: #1e293b !important; color: #f1f5f9 !important; border: 1px solid #475569 !important;
      border-radius: 10px; padding: 10px 12px; font-size: 0.92rem; font-family: inherit;
    }
    .cmt-compose textarea::placeholder { color: #64748b; }
    .cmt-compose textarea:focus { outline: none; border-color: #38bdf8 !important; }
    .cmt-compose-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
    .cmt-file-label {
      display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
      font-size: 0.85rem; color: #94a3b8; padding: 8px 12px; border: 1px dashed #475569; border-radius: 8px;
    }
    .cmt-file-label:hover { color: #38bdf8; border-color: #38bdf8; }
    .cmt-file-label input { display: none; }
    .cmt-file-name { font-size: 0.8rem; color: #38bdf8; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .cmt-empty { text-align: center; color: #64748b; padding: 24px 12px; font-size: 0.88rem; background: #0f172a; border-radius: 10px; border: 1px dashed #334155; }

    .hidden { display: none !important; }

    /* Large phones / Fold */

    /* ===== Container queries (component-level responsive) ===== */
    .cpv-card {
      container-type: inline-size;
      container-name: paycard;
    }
    #payModal .modal,
    #payViewModal .modal {
      container-type: inline-size;
      container-name: paymodal;
    }
    #view-chat {
      container-type: inline-size;
      container-name: chatbox;
    }
    .rcpt-box {
      container-type: inline-size;
      container-name: rcptbox;
    }

    /* Client payment card */
    @container paycard (max-width: 520px) {
      .cpv-kpis { grid-template-columns: 1fr; }
      .cpv-header { flex-wrap: wrap; gap: 10px; }
      .cpv-table-wrap { padding-left: 12px; padding-right: 12px; }
      .cpv-table { font-size: 0.84rem; }
    }
    @container paycard (min-width: 521px) and (max-width: 700px) {
      .cpv-kpis { grid-template-columns: 1fr 1fr; }
      .cpv-kpis .cpv-kpi.highlight { grid-column: 1 / -1; }
    }
    @container paycard (min-width: 701px) {
      .cpv-kpis { grid-template-columns: repeat(3, 1fr); }
    }

    /* Payment edit / view modals */
    @container paymodal (max-width: 560px) {
      .form-row.labeled { flex-direction: column; align-items: stretch; }
      .form-row.labeled .fld { width: 100%; }
      .rcpt-add { grid-template-columns: 1fr; }
      .view-grid { grid-template-columns: 1fr; }
      .pay-tabs { gap: 2px; }
      .modal-actions { flex-direction: column-reverse; align-items: stretch; }
      .modal-actions .btn-secondary { margin-right: 0 !important; width: 100%; }
      .modal-actions button { width: 100%; }
      .erp-rcpt-table { font-size: 0.82rem; }
    }
    @container paymodal (min-width: 561px) {
      .rcpt-add { grid-template-columns: 1fr 1fr; }
      .view-grid { grid-template-columns: 1fr 1fr; }
      .form-row.labeled { flex-direction: row; align-items: flex-end; }
    }

    /* Chat panel (not only viewport — works in split / fold open) */
    @container chatbox (max-width: 600px) {
      .chat-layout { flex-direction: column; }
      .chat-sidebar {
        width: 100%;
        max-height: 110px;
        border-right: none;
        border-bottom: 1px solid var(--border);
      }
      .chat-user-list {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
      }
      .chat-user {
        flex-direction: column;
        min-width: 72px;
        padding: 8px;
      }
      .chat-user .name { font-size: 0.72rem; max-width: 64px; }
      .chat-bubble { max-width: 88%; }
      .chat-pdf iframe { display: none; }
    }
    @container chatbox (min-width: 601px) {
      .chat-layout { flex-direction: row; }
      .chat-sidebar {
        width: 220px;
        max-height: none;
        border-right: 1px solid var(--border);
        border-bottom: none;
      }
      .chat-user-list {
        display: block;
        overflow-y: auto;
        overflow-x: hidden;
      }
      .chat-user { flex-direction: row; min-width: 0; }
      .chat-bubble { max-width: 75%; }
    }


    /* Receipt add box inside edit modal */
    @container rcptbox (max-width: 480px) {
      .rcpt-add { grid-template-columns: 1fr; }
      .rcpt-item { grid-template-columns: 1fr 1fr; }
    }
    @container rcptbox (min-width: 481px) {
      .rcpt-add { grid-template-columns: 1fr 1fr; }
    }

    /* ===== Responsive: tablet / Fold open (cover + main) ===== */
    @media (max-width: 1024px) {
      .main { padding: 22px 18px 50px; max-width: 100%; }
      .cpv-card { width: 96%; max-width: 920px; }
    }

    /* ===== Phones + Fold cover (drawer nav) ===== */
    @media (max-width: 768px) {
      html { -webkit-text-size-adjust: 100%; }
      body { overscroll-behavior-y: contain; }
      .sidebar {
        transform: translateX(-100%);
        width: min(300px, 86vw);
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
      }
      .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,0.45); }
      .sidebar-overlay.open { display: block; }
      .main {
        margin-left: 0;
        padding: 14px 14px calc(56px + env(safe-area-inset-bottom, 0px));
        max-width: 100%;
        min-width: 0;
      }
      .mobile-header {
        display: flex;
        padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 12px;
        gap: 10px;
      }
      .hamburger {
        min-width: 44px; min-height: 44px;
        display: inline-flex; align-items: center; justify-content: center;
        border-radius: 10px;
      }
      .dash-grid { grid-template-columns: 1fr; gap: 12px; }
      .page-title { font-size: 1.2rem; margin-bottom: 12px; }
      .nav-item {
        padding: 14px 14px; min-height: 48px; font-size: 0.95rem;
        border-radius: 12px;
      }
      .filter-btn, .filter-bar button {
        padding: 10px 14px; min-height: 44px; font-size: 0.9rem;
      }
      .add-btn, .auth-btn, .btn-save, .btn-cancel, .btn-secondary {
        min-height: 48px; padding: 12px 18px; font-size: 1rem;
        border-radius: 12px;
      }
      .act-btn, .cpv-icon {
        padding: 10px; min-width: 44px; min-height: 44px; font-size: 1rem;
        border-radius: 10px;
      }
      .check { width: 28px; height: 28px; flex-shrink: 0; }
      .item {
        padding: 14px; gap: 12px; flex-wrap: wrap;
        border-radius: 14px;
      }
      .item-content { min-width: 0; flex: 1 1 160px; }
      .item-actions {
        flex-direction: row; flex-wrap: wrap; gap: 6px;
        width: 100%; justify-content: flex-end;
      }
      /* 16px inputs avoid iOS zoom */
      .form-row { flex-direction: column; gap: 10px; }
      .form-row input, .form-row select, .form-row textarea,
      .fld input, .fld select, .fld textarea,
      input, select, textarea {
        padding: 12px 14px; font-size: 16px !important; min-height: 48px;
        min-width: 100%; width: 100%; box-sizing: border-box;
        border-radius: 12px;
      }
      .form-row.labeled { flex-direction: column; align-items: stretch; }
      .auth-box {
        padding: 24px 18px;
        margin: 12px;
        max-width: calc(100% - 24px);
        border-radius: 18px;
      }
      .auth-logo img { width: 140px; height: 140px; }
      .auth-field input { min-height: 48px; font-size: 16px !important; }
      .modal-overlay {
        z-index: 2000;
        padding: env(safe-area-inset-top, 8px) 8px env(safe-area-inset-bottom, 8px);
        align-items: flex-start;
        overflow-y: auto; -webkit-overflow-scrolling: touch;
      }
      .modal, .modal-card, .cpv-card {
        max-width: 100% !important;
        width: calc(100% - 8px) !important;
        margin: 8px auto 24px;
        padding: 18px 16px;
        border-radius: 16px;
        max-height: none;
      }
      #payViewModal .modal, #payModal .modal {
        max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
        overflow-y: auto;
      }
      .pdf-preview iframe { height: 280px; }
      .view-grid { grid-template-columns: 1fr; }
      .brand-logo img { width: 56px; height: 56px; }
      .pay-tabs {
        display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 4px;
        -webkit-overflow-scrolling: touch; scrollbar-width: none;
      }
      .pay-tabs::-webkit-scrollbar { display: none; }
      .pay-tab {
        flex: 0 0 auto; min-height: 44px; padding: 10px 14px;
        white-space: nowrap; font-size: 0.9rem;
      }
      .cpv-kpis { grid-template-columns: 1fr; gap: 10px; padding: 12px 14px; }
      .cpv-table-wrap {
        padding: 0 12px 8px; max-height: 45vh;
        -webkit-overflow-scrolling: touch;
      }
      .cpv-table { min-width: 560px; font-size: 0.84rem; }
      .cpv-header { padding: 14px 16px; flex-wrap: wrap; gap: 10px; }
      .erp-rcpt-table { min-width: 520px; }
      .erp-kv { grid-template-columns: 1fr; }
      .stmt-info { grid-template-columns: 1fr; }
      .lic-products { grid-template-columns: 1fr; }
      .rcpt-add { grid-template-columns: 1fr; }
      .rcpt-item { grid-template-columns: 1fr 1fr; }
      .modal-actions {
        flex-direction: column-reverse; gap: 10px; align-items: stretch;
      }
      .modal-actions .btn-secondary { margin-right: 0 !important; }
      .modal-actions button { width: 100%; }
    }

    /* S24 Ultra / large phones in portrait (~384–430 CSS px) */
    @media (min-width: 390px) and (max-width: 480px) {
      .main { padding-left: 16px; padding-right: 16px; }
      .item { padding: 16px; }
      .cpv-kpi-value { font-size: 1.15rem; }
    }

    /* Fold cover / very narrow (Fold 7 closed ~280–360) */
    @media (max-width: 360px) {
      .main { padding: 10px 8px calc(48px + env(safe-area-inset-bottom, 0px)); }
      .page-title { font-size: 1.05rem; }
      .auth-logo img { width: 112px; height: 112px; }
      .mobile-header { padding-left: 10px; padding-right: 10px; }
      .item { padding: 12px; }
      .cpv-table { min-width: 500px; font-size: 0.8rem; }
      .modal { padding: 14px 12px; }
      .pay-tab { padding: 8px 12px; font-size: 0.84rem; }
    }

    /* Fold open / small tablet landscape */
    @media (min-width: 700px) and (max-width: 1024px) {
      .dash-grid { grid-template-columns: 1fr 1fr; }
      .cpv-kpis { grid-template-columns: repeat(3, 1fr); }
      .form-row:not(.labeled) { flex-direction: row; }
      .form-row:not(.labeled) input,
      .form-row:not(.labeled) select { min-width: 0; width: auto; flex: 1; }
      .chat-layout {
        flex-direction: row;
        height: calc(100dvh - 140px);
        max-height: calc(100dvh - 140px);
      }
      .chat-sidebar {
        width: 200px; max-height: none;
        border-right: 1px solid var(--border); border-bottom: none;
      }
      .chat-user-list { display: block; overflow-y: auto; overflow-x: hidden; }
      .chat-user { flex-direction: row; min-width: 0; }
    }

    /* Landscape phones */
    @media (max-height: 500px) and (orientation: landscape) {
      .auth-logo img { width: 88px; height: 88px; }
      .pdf-preview iframe { height: 200px; }
      .mobile-header { padding-top: 8px; padding-bottom: 8px; }
      .chat-layout { height: calc(100dvh - 100px); max-height: calc(100dvh - 100px); }
      .modal-overlay { align-items: stretch; }
    }

    /* Safe areas */
    @supports (padding: env(safe-area-inset-bottom)) {
      .main { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
      .sidebar-footer { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
      .mobile-header { padding-top: calc(10px + env(safe-area-inset-top)); }
      .chat-compose {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
      }
      .modal-actions {
        padding-bottom: env(safe-area-inset-bottom, 0px);
      }
    }

    /* Touch feedback */
    @media (hover: none) and (pointer: coarse) {
      .nav-item:active, .item:active, .act-btn:active, .filter-btn:active {
        opacity: 0.85;
      }
      .act-btn, .cpv-icon, .hamburger, .nav-item, .pay-tab {
        -webkit-tap-highlight-color: transparent;
      }
    }
  
    .pay-section { margin: 0 0 16px; }
    .pay-section-title {
      font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
      color: var(--muted); margin: 0 0 10px; padding-bottom: 6px;
      border-bottom: 1px solid var(--border);
    }
    .fld { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
    .fld label { font-size: 0.75rem; color: var(--muted); font-weight: 500; }
    .fld input, .fld select, .fld textarea { width: 100%; }
    .form-row.labeled { align-items: flex-end; gap: 10px; }
    .rcpt-box {
      margin: 4px 0 8px; padding: 14px; border: 1px solid var(--border);
      border-radius: 12px; background: rgba(15,23,42,0.55);
    }
    .rcpt-box-head {
      display: flex; align-items: center; justify-content: space-between;
      gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
    }
    .rcpt-box-head h4 { margin: 0; font-size: 0.9rem; color: var(--accent); font-weight: 600; }
    .rcpt-total-pill {
      font-size: 0.8rem; color: var(--muted); background: rgba(56,189,248,0.1);
      border: 1px solid rgba(56,189,248,0.25); padding: 4px 10px; border-radius: 999px;
    }
    .rcpt-total-pill strong { color: var(--accent); }
    .rcpt-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; max-height: 200px; overflow-y: auto; }
    .rcpt-item {
      display: grid; grid-template-columns: 1.1fr 1fr 0.9fr auto auto;
      gap: 8px; align-items: center; padding: 10px 12px;
      background: var(--card); border-radius: 10px; border: 1px solid var(--border); font-size: 0.85rem;
    }
    .rcpt-item .rcpt-amt { font-weight: 700; color: var(--text); }
    .rcpt-item .rcpt-date { color: var(--muted); }
    .rcpt-item .rcpt-meth { color: var(--muted); text-transform: capitalize; }
    .rcpt-item .rcpt-note { grid-column: 1 / -1; font-size: 0.78rem; color: var(--muted); }
    .rcpt-add {
      display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
      padding-top: 12px; border-top: 1px dashed var(--border);
    }
    .rcpt-add .full { grid-column: 1 / -1; }
    .rcpt-add-title { grid-column: 1 / -1; font-size: 0.78rem; font-weight: 600; color: var(--text); margin: 0; }
    @media (max-width: 560px) {
      .rcpt-add { grid-template-columns: 1fr; }
      .rcpt-item { grid-template-columns: 1fr 1fr; }
      .rcpt-item .rcpt-amt { grid-column: 1 / -1; }
    }

    #payViewModal .modal { max-height: 92vh; display: flex; flex-direction: column; }
    #payViewModal .pay-tab-panel { overflow-y: auto; max-height: min(62vh, 560px); padding-right: 2px; }
    .erp-rcpt-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
    .erp-rcpt-table thead th {
      text-align: left; padding: 10px 12px; font-size: 0.7rem; letter-spacing: 0.04em;
      text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border);
      background: rgba(15,23,42,0.6); position: sticky; top: 0;
    }
    .erp-rcpt-table tbody td {
      padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text);
    }
    .erp-rcpt-table tbody tr:hover { background: rgba(56,189,248,0.06); }
    .erp-rcpt-table .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
    .erp-rcpt-table .muted { color: var(--muted); }
    .erp-rcpt-table .meth {
      display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.78rem;
      background: rgba(148,163,184,0.12); color: var(--muted); text-transform: capitalize;
    }
    .erp-rcpt-foot {
      display: flex; justify-content: flex-end; align-items: center; gap: 12px;
      padding: 12px 4px 4px; margin-top: 8px; border-top: 1px solid var(--border);
      font-size: 0.9rem; color: var(--muted);
    }
    .erp-rcpt-foot strong { color: var(--accent); font-size: 1.05rem; }
    .erp-rcpt-empty { text-align: center; padding: 28px 12px; color: var(--muted); font-size: 0.9rem; }


    /* ===== Client Master (ERP) ===== */
    .cm-toolbar {
      display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
      margin-bottom: 18px;
    }
    .cm-search {
      flex: 1 1 220px; min-width: 0; position: relative;
    }
    .cm-search input {
      width: 100%; padding: 12px 14px 12px 40px; border-radius: 12px;
      border: 1px solid var(--border); background: var(--card); color: var(--text);
      font-size: 0.95rem;
    }
    .cm-search svg {
      position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
      width: 18px; height: 18px; color: var(--muted); pointer-events: none;
    }
    .cm-filters { display: flex; gap: 6px; flex-wrap: wrap; }
    .cm-chip {
      border: 1px solid var(--border); background: transparent; color: var(--muted);
      padding: 8px 14px; border-radius: 999px; font-size: 0.85rem; cursor: pointer;
      min-height: 40px;
    }
    .cm-chip.active {
      background: rgba(56,189,248,0.15); border-color: rgba(56,189,248,0.4); color: var(--accent);
    }
    .cm-stats {
      display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px;
    }
    .cm-stat {
      background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
      border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
      position: relative; overflow: hidden;
    }
    .cm-stat::after {
      content: ''; position: absolute; right: -10px; top: -10px; width: 60px; height: 60px;
      border-radius: 50%; background: rgba(56,189,248,0.08);
    }
    .cm-stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
    .cm-stat-value { font-size: 1.4rem; font-weight: 700; margin-top: 4px; color: var(--text); }
    .cm-grid {
      display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px;
    }
    .cm-card {
      background: var(--card); border: 1px solid var(--border); border-radius: 16px;
      padding: 16px; cursor: pointer; transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
      display: flex; flex-direction: column; gap: 12px; min-height: 160px;
    }
    .cm-card:hover {
      border-color: rgba(56,189,248,0.35);
      box-shadow: 0 12px 28px rgba(0,0,0,0.25);
      transform: translateY(-2px);
    }
    .cm-card-top { display: flex; gap: 12px; align-items: flex-start; }
    .cm-avatar {
      width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
      display: flex; align-items: center; justify-content: center;
      font-weight: 700; font-size: 1.15rem; color: #0f172a;
      background: linear-gradient(135deg, #38bdf8, #818cf8);
    }
    .cm-card-title { font-weight: 650; font-size: 1.05rem; color: var(--text); line-height: 1.3; }
    .cm-card-sub { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
    .cm-badge {
      font-size: 0.7rem; padding: 3px 8px; border-radius: 999px; font-weight: 600;
      text-transform: uppercase; letter-spacing: 0.03em;
    }
    .cm-badge.active { background: rgba(74,222,128,0.15); color: #4ade80; }
    .cm-badge.inactive { background: rgba(148,163,184,0.15); color: var(--muted); }
    .cm-meta { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
    .cm-meta-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
    .cm-meta-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .cm-card-foot {
      margin-top: auto; display: flex; justify-content: space-between; align-items: center;
      padding-top: 10px; border-top: 1px solid var(--border);
    }
    .cm-card-actions { display: flex; gap: 4px; }
    .cm-empty {
      grid-column: 1 / -1; text-align: center; padding: 48px 20px;
      border: 1px dashed var(--border); border-radius: 16px; color: var(--muted);
    }
    .cm-detail-hero {
      display: flex; gap: 16px; align-items: center; margin-bottom: 20px; flex-wrap: wrap;
    }
    .cm-detail-hero .cm-avatar { width: 64px; height: 64px; font-size: 1.4rem; border-radius: 18px; }
    .cm-detail-kpis {
      display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px;
    }
    .cm-detail-kpi {
      background: #0f172a; border: 1px solid var(--border); border-radius: 12px; padding: 12px;
    }
    .cm-detail-kpi .lbl { font-size: 0.7rem; text-transform: uppercase; color: var(--muted); font-weight: 600; }
    .cm-detail-kpi .val { font-size: 1.1rem; font-weight: 700; margin-top: 4px; }
    .cm-detail-kpi .val.warn { color: #fbbf24; }
    .cm-detail-kpi .val.ok { color: #4ade80; }
    @media (max-width: 640px) {
      .cm-stats { grid-template-columns: 1fr; }
      .cm-detail-kpis { grid-template-columns: 1fr; }
    }
    @container paymodal (max-width: 560px) {
      .cm-detail-kpis { grid-template-columns: 1fr; }
    }


    /* Client Master modal — fixed layout (Fold / wide / phone) */
    #cmModal.modal-overlay {
      align-items: center;
      justify-content: center;
    }
    #cmModal .modal {
      width: min(640px, calc(100vw - 24px)) !important;
      max-width: 640px !important;
      margin: 12px auto;
      max-height: calc(100dvh - 24px);
      overflow-x: hidden;
      overflow-y: auto;
      box-sizing: border-box;
    }
    #cmModal .pay-section {
      width: 100%;
      margin-bottom: 18px;
    }
    #cmModal .pay-section-title {
      width: 100%;
      text-align: left;
    }
    #cmModal .cm-form-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px 14px;
      width: 100%;
    }
    #cmModal .cm-form-grid .fld {
      display: flex;
      flex-direction: column;
      gap: 4px;
      min-width: 0;
      width: 100%;
      flex: none;
    }
    #cmModal .cm-form-grid .fld.full {
      grid-column: 1 / -1;
    }
    #cmModal .cm-form-grid label {
      font-size: 0.75rem;
      color: var(--muted);
      font-weight: 500;
      text-align: left;
    }
    #cmModal .cm-form-grid input,
    #cmModal .cm-form-grid select,
    #cmModal .cm-form-grid textarea {
      width: 100% !important;
      min-width: 0 !important;
      max-width: 100% !important;
      box-sizing: border-box;
      margin: 0;
    }
    #cmModal .modal-actions {
      display: flex;
      flex-direction: row;
      justify-content: flex-end;
      gap: 10px;
      flex-wrap: wrap;
      width: 100%;
    }
    #cmModal .modal-actions button {
      width: auto;
      min-width: 120px;
    }
    @media (max-width: 560px) {
      #cmModal .cm-form-grid { grid-template-columns: 1fr; }
      #cmModal .modal-actions {
        flex-direction: column-reverse;
        align-items: stretch;
      }
      #cmModal .modal-actions button { width: 100%; }
    }


    /* Client autocomplete for payments */
    .ac-wrap { position: relative; flex: 1; min-width: 0; width: 100%; }
    .ac-wrap input { width: 100%; }
    .ac-list {
      position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 4000;
      background: #0f172a; border: 1px solid var(--border); border-radius: 12px;
      box-shadow: 0 12px 28px rgba(0,0,0,0.45); max-height: 280px; overflow-y: auto;
      display: none;
    }
    #payForm .ac-wrap { z-index: 5; }
    #payModal .ac-list { z-index: 4100; }
    .ac-list.open { display: block; }
    .ac-item {
      padding: 10px 12px; cursor: pointer; border-bottom: 1px solid rgba(51,65,85,0.6);
      display: flex; flex-direction: column; gap: 2px;
    }
    .ac-item:last-child { border-bottom: none; }
    .ac-item:hover, .ac-item.active { background: rgba(56,189,248,0.12); }
    .ac-item .ac-name { font-weight: 600; color: var(--text); font-size: 0.92rem; }
    .ac-item .ac-sub { font-size: 0.78rem; color: var(--muted); }
    .ac-empty { padding: 12px; color: var(--muted); font-size: 0.85rem; }


    /* Edit Payment modal layout (Fold / wide) */
    #payModal .modal {
      width: min(640px, calc(100vw - 24px)) !important;
      max-width: 640px !important;
      margin: 12px auto;
      max-height: calc(100dvh - 24px);
      overflow-x: hidden;
      overflow-y: auto;
      box-sizing: border-box;
    }
    #payModal .pay-form-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px 14px;
      width: 100%;
    }
    #payModal .pay-form-grid .fld {
      display: flex;
      flex-direction: column;
      gap: 4px;
      min-width: 0;
      width: 100%;
      flex: none;
    }
    #payModal .pay-form-grid .fld.full { grid-column: 1 / -1; }
    #payModal .pay-form-grid label {
      font-size: 0.75rem;
      color: var(--muted);
      font-weight: 500;
      text-align: left;
    }
    #payModal .pay-form-grid input,
    #payModal .pay-form-grid select,
    #payModal .pay-form-grid textarea,
    #payModal .pay-form-grid .ac-wrap {
      width: 100% !important;
      min-width: 0 !important;
      max-width: 100% !important;
      box-sizing: border-box;
    }
    #payModal .pay-section { width: 100%; }
    #payModal .pay-section-title { text-align: left; width: 100%; }
    #payModal .modal-actions {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: flex-end;
      gap: 10px;
      width: 100%;
    }
    #payModal .modal-actions .btn-secondary { margin-right: auto !important; width: auto; }
    #payModal .modal-actions button { width: auto; min-width: 110px; }
    #payModal .rcpt-add {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
      width: 100%;
    }
    #payModal .rcpt-add .full,
    #payModal .rcpt-add .rcpt-add-title { grid-column: 1 / -1; }
    @media (max-width: 560px) {
      #payModal .pay-form-grid { grid-template-columns: 1fr; }
      #payModal .rcpt-add { grid-template-columns: 1fr; }
      #payModal .modal-actions {
        flex-direction: column-reverse;
        align-items: stretch;
      }
      #payModal .modal-actions .btn-secondary { margin-right: 0 !important; }
      #payModal .modal-actions button { width: 100%; }
    }


    /* Dark theme form controls — no bright white fields */
    .fld input, .fld select, .fld textarea,
    .cm-form-grid input, .cm-form-grid select, .cm-form-grid textarea,
    .pay-form-grid input, .pay-form-grid select, .pay-form-grid textarea,
    .rcpt-add input, .rcpt-add select, .rcpt-add textarea,
    .ac-wrap input,
    #cmModal input, #cmModal select, #cmModal textarea,
    #payModal input, #payModal select, #payModal textarea,
    #payViewModal input, #payViewModal select, #payViewModal textarea {
      background: #0f172a !important;
      background-color: #0f172a !important;
      border: 1px solid #334155 !important;
      color: #e2e8f0 !important;
      border-radius: 10px;
      color-scheme: dark;
    }
    .fld input::placeholder, .fld textarea::placeholder,
    .cm-form-grid input::placeholder, .cm-form-grid textarea::placeholder,
    .pay-form-grid input::placeholder, .pay-form-grid textarea::placeholder,
    #cmModal input::placeholder, #cmModal textarea::placeholder,
    #payModal input::placeholder, #payModal textarea::placeholder {
      color: #64748b !important;
      opacity: 1;
    }
    .fld select, .cm-form-grid select, .pay-form-grid select,
    #cmModal select, #payModal select {
      background: #0f172a !important;
      color: #e2e8f0 !important;
    }
    .fld input:focus, .fld select:focus, .fld textarea:focus,
    .cm-form-grid input:focus, .cm-form-grid select:focus, .cm-form-grid textarea:focus,
    .pay-form-grid input:focus, .pay-form-grid select:focus, .pay-form-grid textarea:focus,
    #cmModal input:focus, #cmModal select:focus, #cmModal textarea:focus,
    #payModal input:focus, #payModal select:focus, #payModal textarea:focus {
      border-color: #38bdf8 !important;
      outline: none;
      box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
    }
    /* Browser autofill stays dark */
    input:-webkit-autofill,
    input:-webkit-autofill:hover,
    input:-webkit-autofill:focus,
    textarea:-webkit-autofill,
    select:-webkit-autofill {
      -webkit-text-fill-color: #e2e8f0 !important;
      -webkit-box-shadow: 0 0 0 1000px #0f172a inset !important;
      box-shadow: 0 0 0 1000px #0f172a inset !important;
      transition: background-color 99999s ease-out 0s;
      caret-color: #e2e8f0;
    }


        /* ===== Notes / Trello-style boards ===== */
    .nb-boards {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
      gap: 16px;
    }
    .nb-board-card {
      background: linear-gradient(160deg, #1e293b 0%, #0f172a 100%);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 18px;
      cursor: pointer;
      min-height: 140px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
      position: relative;
      overflow: hidden;
    }
    .nb-board-card::before {
      content: '';
      position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
      background: var(--nb-accent, #38bdf8);
    }
    .nb-board-card:hover {
      transform: translateY(-3px);
      border-color: rgba(56,189,248,0.35);
      box-shadow: 0 14px 32px rgba(0,0,0,0.35);
    }
    .nb-board-card h3 { margin: 0; font-size: 1.1rem; font-weight: 650; padding-left: 8px; }
    .nb-board-meta { padding-left: 8px; font-size: 0.82rem; color: var(--muted); margin-top: auto; }
    .nb-board-actions { display: flex; gap: 4px; justify-content: flex-end; }
    .nb-new-board {
      border: 2px dashed #334155;
      background: transparent;
      border-radius: 16px;
      min-height: 140px;
      display: flex; align-items: center; justify-content: center;
      color: var(--muted); font-weight: 600; cursor: pointer;
      transition: border-color 0.15s, color 0.15s, background 0.15s;
    }
    .nb-new-board:hover { border-color: var(--accent); color: var(--accent); background: rgba(56,189,248,0.06); }

    #view-notes-board { display: flex; flex-direction: column; height: calc(100dvh - 100px); min-height: 420px; }
    .nb-board-bar {
      display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
      margin-bottom: 14px; flex-shrink: 0;
    }
    .nb-board-bar h2 { margin: 0; font-size: 1.25rem; flex: 1; min-width: 120px; }
    .nb-lists {
      display: flex; gap: 14px; overflow-x: auto; overflow-y: hidden;
      flex: 1; align-items: flex-start;
      padding-bottom: 12px;
      -webkit-overflow-scrolling: touch;
    }
    .nb-list {
      flex: 0 0 288px;
      width: 288px;
      background: #0b1220;
      border: 1px solid #1e293b;
      border-radius: 14px;
      display: flex; flex-direction: column;
      max-height: 100%;
      box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    }
    .nb-list-head {
      display: flex; align-items: center; gap: 8px;
      padding: 12px 12px 8px;
      flex-shrink: 0;
    }
    .nb-list-title {
      flex: 1; font-weight: 700; font-size: 0.92rem; color: var(--text);
      background: transparent; border: none; color: inherit;
      padding: 4px 6px; border-radius: 6px; min-width: 0;
    }
    .nb-list-title:focus { background: #1e293b; outline: 1px solid var(--accent); }
    .nb-list-count {
      font-size: 0.75rem; color: var(--muted);
      background: #1e293b; padding: 2px 8px; border-radius: 999px;
    }
    .nb-cards {
      flex: 1; overflow-y: auto; padding: 4px 10px 10px;
      display: flex; flex-direction: column; gap: 8px;
      min-height: 40px;
      max-height: calc(100dvh - 260px);
    }
    .nb-card {
      background: #1e293b;
      border: 1px solid #334155;
      border-radius: 10px;
      padding: 10px 12px;
      cursor: pointer;
      transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
      position: relative;
    }
    .nb-card:hover {
      border-color: rgba(56,189,248,0.4);
      box-shadow: 0 6px 16px rgba(0,0,0,0.3);
      transform: translateY(-1px);
    }
    .nb-card-label {
      height: 6px; border-radius: 4px; margin-bottom: 8px; width: 40%;
    }
    .nb-card-title { font-size: 0.9rem; font-weight: 550; line-height: 1.35; color: #f1f5f9; }
    .nb-card-desc {
      font-size: 0.78rem; color: var(--muted); margin-top: 6px;
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    }
    .nb-card-footer {
      display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
      gap: 6px; margin-top: 8px;
    }
    .nb-card-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
    .nb-badge {
      display: inline-flex; align-items: center; gap: 4px;
      font-size: 0.72rem; font-weight: 600; color: #cbd5e1;
      padding: 2px 7px; border-radius: 5px;
      background: #334155;
    }
    .nb-badge-due.overdue { background: #7f1d1d; color: #fecaca; }
    .nb-badge-check.complete { background: #14532d; color: #86efac; }
    .nb-card-avatars { display: flex; align-items: center; }
    .nb-card-avatar {
      width: 22px; height: 22px; border-radius: 50%;
      background: linear-gradient(135deg, #8ab4f8, #c58af9);
      color: #202124;
      display: flex; align-items: center; justify-content: center;
      font-size: 0.65rem; font-weight: 700;
      border: 2px solid #1e293b;
      margin-left: -8px;
    }
    .nb-card-avatar:first-child { margin-left: 0; }
    .nb-add-card, .nb-add-list {
      margin: 0 10px 12px;
      background: transparent;
      border: none;
      color: var(--muted);
      text-align: left;
      padding: 10px 12px;
      border-radius: 10px;
      cursor: pointer;
      font-size: 0.88rem;
      font-weight: 600;
    }
    .nb-add-card:hover, .nb-add-list:hover {
      background: rgba(255,255,255,0.05);
      color: var(--text);
    }
    .nb-add-list-col {
      flex: 0 0 288px;
      width: 288px;
    }
    .nb-add-list-btn {
      width: 100%;
      background: rgba(30,41,59,0.6);
      border: 1px dashed #334155;
      border-radius: 14px;
      padding: 16px;
      color: var(--muted);
      font-weight: 600;
      cursor: pointer;
    }
    .nb-add-list-btn:hover { border-color: var(--accent); color: var(--accent); }
    .nb-composer {
      margin: 0 10px 12px;
      display: flex; flex-direction: column; gap: 8px;
    }
    .nb-composer textarea, .nb-composer input {
      width: 100%; background: #0f172a; border: 1px solid #334155;
      border-radius: 8px; padding: 10px; color: var(--text); font-size: 0.9rem;
      resize: vertical; min-height: 60px; box-sizing: border-box;
    }
    .nb-composer-actions { display: flex; gap: 8px; }
    .nb-label-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
    .nb-label-swatch {
      width: 28px; height: 28px; border-radius: 6px; border: 2px solid transparent;
      cursor: pointer;
    }
    .nb-label-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }


    /* Trello-like card detail — polished dark UI */
    #nbCardModal.modal-overlay {
      align-items: flex-start;
      padding-top: 24px;
      background: rgba(0,0,0,0.72);
    }
    #nbCardModal .nb-trello-card {
      background: #242528 !important;
      border: none !important;
      border-radius: 12px !important;
      max-width: 560px !important;
      width: min(560px, calc(100vw - 16px)) !important;
      margin: 0 auto 40px;
      box-shadow: 0 20px 50px rgba(0,0,0,0.55);
      max-height: calc(100dvh - 40px);
      overflow-x: hidden;
      overflow-y: auto;
      padding: 0 !important;
    }
    .nb-cover {
      height: 0;
      transition: height 0.2s ease;
      background: linear-gradient(120deg, #5c6bc0, #7e57c2);
      border-radius: 12px 12px 0 0;
      position: relative;
    }
    .nb-cover.has-cover { height: 120px; }
    .nb-trello-body { padding: 12px 16px 20px; }
    .nb-trello-top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 8px;
      margin-bottom: 10px;
    }
    .nb-icon-btn {
      width: 36px; height: 36px;
      border-radius: 8px;
      border: none;
      background: rgba(255,255,255,0.08);
      color: #cfd3dc;
      font-size: 1rem;
      cursor: pointer;
      display: inline-flex; align-items: center; justify-content: center;
    }
    .nb-cover-btn {
      border: none;
      background: rgba(255,255,255,0.1);
      color: #e8eaed;
      border-radius: 8px;
      padding: 8px 12px;
      font-size: 0.82rem;
      font-weight: 600;
      cursor: pointer;
    }
    .nb-trello-title {
      width: 100%;
      background: transparent !important;
      border: none !important;
      box-shadow: none !important;
      color: #f1f3f4 !important;
      font-size: 1.4rem !important;
      font-weight: 700 !important;
      padding: 6px 4px !important;
      margin: 0 0 4px !important;
      line-height: 1.3;
      outline: none;
      border-radius: 8px;
    }
    .nb-trello-title:focus {
      background: rgba(0,0,0,0.35) !important;
      padding: 8px 10px !important;
    }
    .nb-trello-context {
      font-size: 0.82rem;
      color: #9aa0a6;
      margin: 0 4px 16px;
      line-height: 1.4;
    }
    .nb-trello-context strong { color: #8ab4f8; font-weight: 600; }

    .nb-quick {
      background: transparent;
      margin-bottom: 18px;
    }
    .nb-quick-title {
      font-size: 0.75rem;
      color: #9aa0a6;
      margin-bottom: 10px;
      font-weight: 600;
      letter-spacing: 0.02em;
    }
    .nb-quick-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
    }
    .nb-quick-btn {
      background: #3c4043 !important;
      border: none !important;
      border-radius: 24px !important;
      padding: 14px 16px !important;
      color: #e8eaed !important;
      text-align: left;
      cursor: pointer;
      font-size: 0.88rem;
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .nb-quick-btn:hover { background: #4a4e52 !important; }

    .nb-section {
      margin-bottom: 4px;
      padding: 14px 4px;
      border-top: 1px solid rgba(255,255,255,0.06);
    }
    .nb-sec-label {
      font-size: 0.9rem;
      font-weight: 600;
      color: #e8eaed;
      margin-bottom: 10px;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .nb-section textarea,
    .nb-section input[type="text"],
    .nb-section input[type="date"],
    .nb-comment-bar input,
    #nbCardModal input,
    #nbCardModal textarea,
    #nbCardModal select {
      width: 100%;
      background: #3c4043 !important;
      background-color: #3c4043 !important;
      border: none !important;
      border-radius: 10px !important;
      padding: 12px 14px !important;
      color: #e8eaed !important;
      -webkit-text-fill-color: #e8eaed !important;
      box-sizing: border-box;
      font-size: 0.92rem !important;
      outline: none;
      box-shadow: none !important;
      color-scheme: dark;
    }
    .nb-section textarea::placeholder,
    .nb-section input::placeholder,
    .nb-comment-bar input::placeholder {
      color: #9aa0a6 !important;
      -webkit-text-fill-color: #9aa0a6 !important;
      opacity: 1;
    }
    .nb-section textarea:focus,
    .nb-section input:focus {
      background: #45494d !important;
      box-shadow: 0 0 0 2px rgba(138,180,248,0.35) !important;
    }
    .nb-dates {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      border-top: 1px solid rgba(255,255,255,0.06);
      padding: 14px 4px;
      margin-bottom: 0;
    }
    .nb-date-field label {
      display: block;
      font-size: 0.8rem;
      color: #9aa0a6;
      margin-bottom: 6px;
      font-weight: 600;
    }
    .nb-plus {
      background: transparent;
      border: none;
      color: #8ab4f8;
      font-size: 1.4rem;
      cursor: pointer;
      font-weight: 400;
      line-height: 1;
      padding: 0 4px;
    }
    .nb-label-row { display: flex; gap: 8px; flex-wrap: wrap; }
    .nb-label-swatch {
      width: 36px; height: 28px;
      border-radius: 6px;
      border: 2px solid transparent;
      cursor: pointer;
    }
    .nb-label-swatch.active {
      border-color: #fff;
      box-shadow: 0 0 0 2px #8ab4f8;
    }
    .nb-progress {
      display: flex; align-items: center; gap: 8px;
      margin-bottom: 10px;
    }
    .nb-progress-pct { font-size: 0.78rem; color: #9aa0a6; font-weight: 600; width: 34px; }
    .nb-progress-track { flex: 1; height: 8px; border-radius: 999px; background: #3c4043; overflow: hidden; }
    .nb-progress-fill { height: 100%; background: #8ab4f8; border-radius: 999px; transition: width 0.2s ease; }
    .nb-progress-fill.complete { background: #81c995; }
    .nb-check-list, .nb-attach-list {
      display: flex; flex-direction: column; gap: 8px;
    }
    .nb-check-item, .nb-attach-item {
      display: flex; align-items: center; gap: 12px;
      padding: 12px 14px;
      background: #3c4043;
      border-radius: 10px;
      border: none;
    }
    .nb-check-item input[type="checkbox"] {
      width: 18px; height: 18px;
      accent-color: #81c995;
      flex-shrink: 0;
    }
    .nb-check-item span { flex: 1; font-size: 0.9rem; color: #e8eaed; }
    .nb-check-item.done span { text-decoration: line-through; color: #9aa0a6; }
    .nb-attach-item a { color: #8ab4f8; flex: 1; text-decoration: none; font-size: 0.88rem; }
    .nb-members { display: flex; flex-wrap: wrap; gap: 8px; }
    .nb-member-chip {
      display: flex; align-items: center; gap: 8px;
      padding: 8px 12px 8px 8px;
      background: #3c4043;
      border: 2px solid transparent;
      border-radius: 999px;
      font-size: 0.85rem;
      color: #e8eaed;
      cursor: pointer;
    }
    .nb-member-chip.on { border-color: #8ab4f8; }
    .nb-member-av {
      width: 28px; height: 28px; border-radius: 50%;
      background: linear-gradient(135deg, #8ab4f8, #c58af9);
      display: flex; align-items: center; justify-content: center;
      font-size: 0.75rem; font-weight: 700; color: #202124;
    }
    .nb-comments {
      max-height: 160px; overflow-y: auto;
      display: flex; flex-direction: column; gap: 10px;
      margin-bottom: 12px;
    }
    .nb-comment {
      background: #3c4043;
      border-radius: 12px;
      padding: 10px 14px;
      font-size: 0.88rem;
      color: #e8eaed;
    }
    .nb-comment .who { font-weight: 600; color: #8ab4f8; font-size: 0.8rem; }
    .nb-comment .when { color: #9aa0a6; font-size: 0.72rem; margin-left: 8px; }
    .nb-comment-bar {
      display: flex; gap: 8px; align-items: center;
      background: #3c4043;
      border-radius: 999px;
      padding: 4px 4px 4px 4px;
    }
    .nb-comment-bar input {
      flex: 1;
      background: transparent !important;
      border-radius: 999px !important;
      padding: 10px 14px !important;
    }
    .nb-comment-bar .btn-save {
      border-radius: 999px !important;
      min-width: 72px;
      min-height: 40px;
      padding: 8px 16px;
    }
    #nbCardModal .modal-actions {
      display: flex;
      flex-direction: column-reverse;
      gap: 10px;
      padding: 16px 4px 4px !important;
      border-top: 1px solid rgba(255,255,255,0.08) !important;
      margin-top: 8px !important;
    }
    #nbCardModal .modal-actions button {
      width: 100%;
      border-radius: 24px !important;
      min-height: 48px;
      font-weight: 600;
    }
    #nbCardModal .modal-actions .btn-save {
      background: #8ab4f8 !important;
      color: #202124 !important;
      border: none;
    }
    #nbCardModal .modal-actions .btn-secondary {
      background: transparent !important;
      border: 1px solid #5f6368 !important;
      color: #f28b82 !important;
      margin-right: 0 !important;
    }
    .nb-empty-hint { color: #9aa0a6; font-size: 0.85rem; padding: 4px 0; }
    @media (max-width: 560px) {
      .nb-quick-grid, .nb-dates { grid-template-columns: 1fr; }
      #nbCardModal.modal-overlay { padding-top: 8px; }
    }


/* Board zoom controls */
    .nb-zoom-fab {
      position: fixed;
      right: max(16px, env(safe-area-inset-right));
      bottom: max(20px, env(safe-area-inset-bottom));
      z-index: 80;
      display: none;
      flex-direction: column;
      gap: 8px;
      align-items: center;
    }
    body.nb-board-open .nb-zoom-fab { display: flex; }
    .nb-zoom-btn {
      width: 52px; height: 52px;
      border-radius: 50%;
      border: none;
      background: #c8e6c9;
      color: #1b5e20;
      font-size: 1.35rem;
      font-weight: 700;
      cursor: pointer;
      box-shadow: 0 6px 18px rgba(0,0,0,0.35);
      display: flex; align-items: center; justify-content: center;
      line-height: 1;
    }
    .nb-zoom-btn:active { transform: scale(0.96); }
    .nb-zoom-btn.secondary {
      width: 44px; height: 44px;
      background: #e8f5e9;
      font-size: 1.15rem;
    }
    .nb-zoom-level {
      font-size: 0.72rem;
      color: #c8e6c9;
      background: rgba(15,23,42,0.85);
      padding: 2px 8px;
      border-radius: 999px;
      border: 1px solid rgba(200,230,201,0.35);
    }
    #nbLists {
      transform-origin: top left;
      transition: transform 0.2s ease;
    }
    #view-notes-board.nb-zooming .nb-lists-wrap {
      overflow: auto;
      flex: 1;
      min-height: 0;
      -webkit-overflow-scrolling: touch;
    }


    /* Card modal MUST scroll on mobile / Fold */
    #nbCardModal.modal-overlay {
      align-items: flex-start !important;
      justify-content: center !important;
      overflow-y: auto !important;
      overflow-x: hidden !important;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior: contain;
      padding: 12px 8px 32px !important;
      height: 100% !important;
      max-height: 100dvh !important;
    }
    #nbCardModal .nb-trello-card.modal,
    #nbCardModal .modal.nb-trello-card {
      max-height: none !important;
      height: auto !important;
      overflow: visible !important;
      margin: 0 auto 24px !important;
      position: relative !important;
    }
    #nbCardModal .nb-trello-body {
      overflow: visible !important;
      max-height: none !important;
    }
    /* Fallback: if overlay can't scroll, body scrolls */
    #nbCardModal .nb-trello-card {
      display: flex !important;
      flex-direction: column !important;
      max-height: calc(100dvh - 24px) !important;
      overflow: hidden !important;
    }
    #nbCardModal .nb-cover { flex-shrink: 0; }
    #nbCardModal .nb-trello-body {
      flex: 1 1 auto !important;
      overflow-y: auto !important;
      overflow-x: hidden !important;
      -webkit-overflow-scrolling: touch !important;
      overscroll-behavior: contain;
      max-height: none !important;
      padding-bottom: 28px !important;
    }


    /* Dashboard payments chart */
    .dash-chart-card {
      margin-top: 16px;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 18px 16px 16px;
    }
    .dash-chart-card h3 {
      font-size: 0.95rem;
      font-weight: 650;
      margin: 0 0 14px;
      color: var(--text);
    }
    .dash-chart-layout {
      display: grid;
      grid-template-columns: minmax(140px, 200px) 1fr;
      gap: 18px;
      align-items: center;
    }
    @media (max-width: 560px) {
      .dash-chart-layout { grid-template-columns: 1fr; justify-items: center; }
    }
    .dash-donut-wrap { position: relative; width: 160px; height: 160px; }
    .dash-donut-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }
    .dash-donut-center {
      position: absolute; inset: 0;
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      pointer-events: none;
    }
    .dash-donut-center .amt {
      font-size: 0.95rem; font-weight: 700; color: var(--text);
    }
    .dash-donut-center .lbl {
      font-size: 0.7rem; color: var(--muted); margin-top: 2px;
    }
    .dash-chart-legend { width: 100%; display: flex; flex-direction: column; gap: 12px; }
    .dash-leg-row {
      display: flex; align-items: center; gap: 10px;
      background: rgba(15,23,42,0.45);
      border-radius: 12px;
      padding: 10px 12px;
    }
    .dash-leg-dot {
      width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0;
    }
    .dash-leg-meta { flex: 1; min-width: 0; }
    .dash-leg-meta .name { font-size: 0.82rem; color: var(--muted); }
    .dash-leg-meta .val { font-size: 1.05rem; font-weight: 700; color: var(--text); }
    .dash-leg-pct { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
    .dash-bars { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
    .dash-bar-row { display: flex; flex-direction: column; gap: 4px; }
    .dash-bar-label { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); }
    .dash-bar-track {
      height: 10px; border-radius: 999px; background: #0f172a; overflow: hidden;
      border: 1px solid #1e293b;
    }
    .dash-bar-fill { height: 100%; border-radius: 999px; width: 0; transition: width 0.6s ease; }


    /* App-native confirm dialog */
    #appConfirmModal.modal-overlay {
      z-index: 9999;
      background: rgba(2, 6, 23, 0.72);
      backdrop-filter: blur(4px);
      align-items: center;
      justify-content: center;
    }
    #appConfirmModal .app-confirm-box {
      width: min(420px, calc(100vw - 28px));
      background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
      border: 1px solid #334155;
      border-radius: 16px;
      box-shadow: 0 24px 48px rgba(0,0,0,0.5);
      padding: 22px 20px 18px;
      animation: appConfirmIn 0.18s ease-out;
    }
    @keyframes appConfirmIn {
      from { opacity: 0; transform: translateY(8px) scale(0.98); }
      to { opacity: 1; transform: none; }
    }
    .app-confirm-icon {
      width: 44px; height: 44px; border-radius: 12px;
      background: rgba(56,189,248,0.12);
      color: #38bdf8;
      display: flex; align-items: center; justify-content: center;
      font-size: 1.25rem; margin-bottom: 12px;
    }
    .app-confirm-title {
      font-size: 1.1rem; font-weight: 700; color: #f1f5f9;
      margin: 0 0 8px;
    }
    .app-confirm-body {
      font-size: 0.92rem; color: #94a3b8; line-height: 1.55;
      margin: 0 0 18px; white-space: pre-line;
    }
    .app-confirm-body strong { color: #e2e8f0; font-weight: 600; }
    .app-confirm-actions {
      display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
    }
    .app-confirm-actions button {
      min-width: 100px; min-height: 42px; border-radius: 10px;
      font-weight: 600; font-size: 0.9rem; cursor: pointer; border: none;
    }
    .app-confirm-actions .ac-cancel {
      background: #1e293b; color: #cbd5e1; border: 1px solid #334155 !important;
    }
    .app-confirm-actions .ac-cancel:hover { background: #334155; }
    .app-confirm-actions .ac-ok {
      background: #38bdf8; color: #0f172a;
    }
    .app-confirm-actions .ac-ok:hover { background: #7dd3fc; }
    .app-confirm-actions .ac-ok.danger { background: #f87171; color: #0f172a; }


    /* Client Master — ERP edit modal */
    #cmModal.modal-overlay {
      align-items: flex-start;
      padding: 24px 12px 40px;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
    }
    #cmModal .cm-erp-modal {
      max-width: 720px !important;
      width: min(720px, calc(100vw - 20px)) !important;
      padding: 0 !important;
      overflow: hidden;
      border: 1px solid #334155;
      border-radius: 18px;
      background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
      box-shadow: 0 28px 64px rgba(0,0,0,0.55);
      display: flex;
      flex-direction: column;
      max-height: calc(100dvh - 32px);
    }
    .cm-erp-header {
      display: flex;
      align-items: center;
      gap: 14px;
      padding: 18px 20px;
      border-bottom: 1px solid rgba(148,163,184,0.12);
      background: linear-gradient(135deg, rgba(56,189,248,0.08), rgba(99,102,241,0.06));
      flex-shrink: 0;
    }
    .cm-erp-avatar {
      width: 52px; height: 52px; border-radius: 14px;
      background: linear-gradient(135deg, #38bdf8, #818cf8);
      color: #0f172a; font-weight: 800; font-size: 1.25rem;
      display: flex; align-items: center; justify-content: center;
      flex-shrink: 0;
      box-shadow: 0 8px 20px rgba(56,189,248,0.25);
    }
    .cm-erp-head-text { flex: 1; min-width: 0; }
    .cm-erp-kicker {
      font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em;
      color: #7dd3fc; font-weight: 700; margin-bottom: 2px;
    }
    .cm-erp-header h2 {
      margin: 0; font-size: 1.2rem; font-weight: 700; color: #f8fafc;
    }
    .cm-erp-sub { font-size: 0.8rem; color: #94a3b8; margin-top: 2px; }
    .cm-erp-status-pill {
      font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
      letter-spacing: 0.04em; padding: 6px 12px; border-radius: 999px;
      background: rgba(52,211,153,0.15); color: #34d399;
      border: 1px solid rgba(52,211,153,0.35);
      flex-shrink: 0;
    }
    .cm-erp-status-pill.inactive {
      background: rgba(148,163,184,0.12); color: #94a3b8;
      border-color: rgba(148,163,184,0.3);
    }
    .cm-erp-body {
      padding: 14px 16px 8px;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      flex: 1;
    }
    .cm-erp-card {
      background: rgba(15,23,42,0.65);
      border: 1px solid #1e293b;
      border-radius: 14px;
      padding: 14px 14px 6px;
      margin-bottom: 12px;
    }
    .cm-erp-card-title {
      display: flex; align-items: center; gap: 10px;
      font-size: 0.82rem; font-weight: 700; color: #e2e8f0;
      margin-bottom: 12px; letter-spacing: 0.02em;
    }
    .cm-erp-ico {
      width: 26px; height: 26px; border-radius: 8px;
      background: rgba(56,189,248,0.12); color: #38bdf8;
      display: inline-flex; align-items: center; justify-content: center;
      font-size: 0.7rem; font-weight: 800;
    }
    #cmModal .cm-form-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px 14px;
    }
    #cmModal .cm-form-grid .fld.full { grid-column: 1 / -1; }
    #cmModal .cm-form-grid label {
      display: block; font-size: 0.72rem; font-weight: 600;
      color: #94a3b8; text-transform: uppercase; letter-spacing: 0.04em;
      margin-bottom: 6px;
    }
    #cmModal .cm-form-grid input,
    #cmModal .cm-form-grid select,
    #cmModal .cm-form-grid textarea {
      width: 100%;
      background: #0f172a !important;
      border: 1px solid #334155 !important;
      border-radius: 10px !important;
      padding: 11px 12px !important;
      color: #e2e8f0 !important;
      font-size: 0.92rem !important;
      box-sizing: border-box;
    }
    #cmModal .cm-form-grid input:focus,
    #cmModal .cm-form-grid select:focus,
    #cmModal .cm-form-grid textarea:focus {
      border-color: #38bdf8 !important;
      box-shadow: 0 0 0 3px rgba(56,189,248,0.15);
      outline: none;
    }
    .cm-erp-footer {
      flex-shrink: 0;
      padding: 14px 18px 16px !important;
      border-top: 1px solid rgba(148,163,184,0.12);
      background: rgba(15,23,42,0.9);
      display: flex; gap: 10px; justify-content: flex-end;
      margin: 0 !important;
    }
    .cm-erp-footer .btn-save {
      min-width: 140px; border-radius: 10px !important; min-height: 44px;
      font-weight: 700;
    }
    .cm-erp-footer .btn-cancel {
      border-radius: 10px !important; min-height: 44px;
    }
    @media (max-width: 640px) {
      #cmModal .cm-form-grid { grid-template-columns: 1fr; }
      .cm-erp-header { flex-wrap: wrap; }
      .cm-erp-footer { flex-direction: column-reverse; }
      .cm-erp-footer button { width: 100%; }
    }


    /* Proforma view — ERP parties */
    .pfv-card { max-width: 820px !important; width: min(820px, calc(100vw - 20px)) !important; max-height: calc(100dvh - 40px); overflow-y: auto; }
    .pfv-parties {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      margin: 14px 0 6px;
    }
    .pfv-party {
      background: rgba(15, 23, 42, 0.7);
      border: 1px solid #1e293b;
      border-radius: 14px;
      overflow: hidden;
    }
    .pfv-party-hd {
      padding: 10px 12px 0;
    }
    .pfv-party-badge {
      display: inline-block;
      font-size: 0.7rem;
      font-weight: 800;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      padding: 4px 10px;
      border-radius: 999px;
    }
    .pfv-party-badge.buyer {
      background: rgba(0, 150, 170, 0.18);
      color: #2dd4bf;
      border: 1px solid rgba(45, 212, 191, 0.35);
    }
    .pfv-party-badge.seller {
      background: rgba(56, 189, 248, 0.12);
      color: #7dd3fc;
      border: 1px solid rgba(56, 189, 248, 0.3);
    }
    .pfv-party-body { padding: 10px 12px 12px; }
    .pfv-dl-row {
      display: grid;
      grid-template-columns: 88px 1fr;
      gap: 8px;
      padding: 6px 0;
      border-bottom: 1px solid rgba(148, 163, 184, 0.08);
      font-size: 0.86rem;
    }
    .pfv-dl-row:last-child { border-bottom: none; }
    .pfv-dl-k {
      color: #64748b;
      font-size: 0.72rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.03em;
      padding-top: 2px;
    }
    .pfv-dl-v {
      color: #e2e8f0;
      font-weight: 500;
      line-height: 1.4;
      word-break: break-word;
    }
    .pfv-empty { color: #64748b; font-size: 0.85rem; }
    .pfv-section-label {
      font-size: 0.72rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: #94a3b8;
      margin: 14px 0 8px;
    }
    .pfv-notes-body {
      background: rgba(15, 23, 42, 0.6);
      border: 1px solid #1e293b;
      border-radius: 10px;
      padding: 10px 12px;
      color: #cbd5e1;
      font-size: 0.88rem;
      line-height: 1.45;
    }
    .pfv-tpl {
      text-transform: capitalize;
      background: rgba(148, 163, 184, 0.12);
      padding: 1px 8px;
      border-radius: 999px;
      font-size: 0.75rem;
    }
    .pfv-num { color: #64748b; font-variant-numeric: tabular-nums; width: 36px; }
    @media (max-width: 700px) {
      .pfv-parties { grid-template-columns: 1fr; }
      .pfv-dl-row { grid-template-columns: 1fr; gap: 2px; }
    }


    #view-proforma .ac-wrap { position: relative; }
    #view-proforma .ac-list {
      position: absolute; left: 0; right: 0; top: calc(100% + 4px);
      z-index: 50; max-height: 240px; overflow-y: auto;
      background: #0f172a; border: 1px solid #334155; border-radius: 10px;
      box-shadow: 0 12px 28px rgba(0,0,0,0.45);
    }
    #view-proforma .ac-list.open { display: block; }


    /* ===== M365 Tenants Management ===== */
    .lic-tenant-card {
      border: 1px solid rgba(0, 120, 212, 0.35) !important;
      background: linear-gradient(145deg, rgba(0,120,212,0.12), rgba(15,23,42,0.9)) !important;
    }
    .lic-tenant-card-ico {
      font-size: 1.6rem; margin-bottom: 8px;
    }
    .m365-tenants { margin-top: 8px; }
    .m365-hero {
      display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
      flex-wrap: wrap;
      padding: 20px 20px;
      border-radius: 16px;
      background: linear-gradient(120deg, #0c1929 0%, #0f2744 45%, #0b1a2e 100%);
      border: 1px solid rgba(0, 120, 212, 0.35);
      box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
      margin-bottom: 18px;
      position: relative;
      overflow: hidden;
    }
    .m365-hero::after {
      content: '';
      position: absolute; right: -40px; top: -40px;
      width: 180px; height: 180px; border-radius: 50%;
      background: radial-gradient(circle, rgba(0,120,212,0.25), transparent 70%);
      pointer-events: none;
    }
    .m365-hero-badge {
      display: inline-block;
      font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
      color: #60cdff; background: rgba(0,120,212,0.18);
      border: 1px solid rgba(96,205,255,0.35);
      padding: 4px 10px; border-radius: 999px; margin-bottom: 8px;
    }
    .m365-hero-title {
      margin: 0 0 6px; font-size: 1.45rem; font-weight: 700; color: #f3f2f1;
    }
    .m365-hero-sub {
      margin: 0; color: #9ca3af; font-size: 0.9rem; max-width: 480px; line-height: 1.45;
    }
    .m365-primary-btn {
      background: #0078d4 !important; color: #fff !important; border: none !important;
      border-radius: 8px !important; padding: 11px 18px !important;
      font-weight: 650 !important; font-size: 0.92rem !important;
      cursor: pointer; box-shadow: 0 4px 14px rgba(0,120,212,0.35);
      white-space: nowrap; width: auto !important; margin: 0 !important;
    }
    .m365-primary-btn:hover { background: #106ebe !important; }
    .m365-tenant-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 14px;
    }
    .m365-tenant-card {
      background: linear-gradient(180deg, #1b2332 0%, #121826 100%);
      border: 1px solid #2b3548;
      border-radius: 14px;
      padding: 16px;
      transition: border-color 0.15s, transform 0.15s;
      cursor: default;
    }
    .m365-tenant-card:hover {
      border-color: rgba(0,120,212,0.55);
      transform: translateY(-2px);
    }
    .m365-tenant-top {
      display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
    }
    .m365-tenant-avatar {
      width: 44px; height: 44px; border-radius: 10px;
      background: linear-gradient(135deg, #0078d4, #00bcf2);
      color: #fff; font-weight: 800; font-size: 1rem;
      display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    }
    .m365-tenant-name {
      font-weight: 700; color: #f3f2f1; font-size: 0.98rem;
      word-break: break-all;
    }
    .m365-tenant-meta { font-size: 0.8rem; color: #9ca3af; margin-top: 2px; }
    .m365-tenant-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
    .m365-tenant-row {
      display: flex; justify-content: space-between; gap: 10px;
      font-size: 0.82rem; padding: 6px 8px; border-radius: 8px;
      background: rgba(15,23,42,0.55);
    }
    .m365-tenant-row span:first-child { color: #8a93a6; font-weight: 600; }
    .m365-tenant-row span:last-child { color: #e5e7eb; text-align: right; word-break: break-all; }
    .m365-tenant-actions { display: flex; gap: 8px; justify-content: flex-end; }
    .m365-tenant-actions button {
      width: auto !important; margin: 0 !important; min-height: 36px;
      border-radius: 8px !important; font-size: 0.82rem !important; padding: 0 12px !important;
    }
    .m365-empty {
      grid-column: 1 / -1;
      text-align: center; padding: 40px 20px;
      border: 1px dashed #334155; border-radius: 14px; color: #9ca3af;
    }
    /* Modal */
    #licTenantModal .m365-modal {
      max-width: 520px !important; width: min(520px, calc(100vw - 20px)) !important;
      padding: 0 !important; border-radius: 14px !important;
      border: 1px solid #2b3548; overflow: hidden;
      background: #1b2332 !important;
    }
    .m365-modal-hd {
      display: flex; align-items: center; gap: 12px;
      padding: 16px 18px; border-bottom: 1px solid #2b3548;
      background: linear-gradient(90deg, rgba(0,120,212,0.15), transparent);
    }
    .m365-modal-ico {
      width: 40px; height: 40px; border-radius: 10px;
      background: #0078d4; display: flex; align-items: center; justify-content: center;
      font-size: 1.2rem;
    }
    .m365-modal-kicker {
      font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
      color: #60cdff; font-weight: 700;
    }
    .m365-modal-hd h2 { margin: 0; font-size: 1.1rem; color: #f3f2f1; }
    .m365-modal-body { padding: 16px 18px; max-height: min(60vh, 480px); overflow-y: auto; }
    .m365-field { margin-bottom: 14px; }
    .m365-field label {
      display: block; font-size: 0.78rem; font-weight: 650; color: #c8c6c4;
      margin-bottom: 6px;
    }
    .m365-field input, .m365-field textarea {
      width: 100%; box-sizing: border-box;
      background: #0f172a !important; border: 1px solid #3b4455 !important;
      border-radius: 8px !important; padding: 11px 12px !important;
      color: #f3f2f1 !important; font-size: 0.92rem !important;
    }
    .m365-field input:focus, .m365-field textarea:focus {
      border-color: #0078d4 !important; outline: none;
      box-shadow: 0 0 0 2px rgba(0,120,212,0.25);
    }
    .m365-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
    .m365-pass-wrap { position: relative; }
    .m365-pass-wrap input { padding-right: 44px !important; }
    .m365-eye {
      position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
      background: transparent; border: none; cursor: pointer; font-size: 1rem;
      width: auto !important; margin: 0 !important; padding: 6px !important;
    }
    .m365-modal-ft {
      display: flex; justify-content: flex-end; gap: 10px;
      padding: 14px 18px; border-top: 1px solid #2b3548; background: #151b27;
    }
    @media (max-width: 560px) {
      .m365-field-row { grid-template-columns: 1fr; }
      .m365-hero { flex-direction: column; }
      .m365-primary-btn { width: 100% !important; }
    }


    .m365-modal-lg { max-width: 640px !important; width: min(640px, calc(100vw - 16px)) !important; }
    .m365-tabs {
      display: flex; gap: 4px; padding: 0 16px;
      border-bottom: 1px solid #2b3548; background: #151b27;
    }
    .m365-tab {
      background: transparent; border: none; color: #9ca3af;
      padding: 12px 14px; font-size: 0.88rem; font-weight: 650;
      cursor: pointer; border-bottom: 2px solid transparent;
      width: auto !important; margin: 0 !important; border-radius: 0 !important;
    }
    .m365-tab.active { color: #60cdff; border-bottom-color: #0078d4; }
    .m365-tab-panel { display: none; }
    .m365-tab-panel.active { display: block; }
    .m365-domain-add {
      background: rgba(15,23,42,0.55); border: 1px solid #2b3548;
      border-radius: 12px; padding: 14px; margin-bottom: 14px;
    }
    .m365-domain-add-title {
      font-size: 0.8rem; font-weight: 700; color: #60cdff;
      text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 10px;
    }
    .m365-domain-list { display: flex; flex-direction: column; gap: 10px; }
    .m365-domain-card {
      background: #121826; border: 1px solid #2b3548; border-radius: 12px; padding: 12px 14px;
    }
    .m365-domain-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
    .m365-domain-name { font-weight: 700; color: #f3f2f1; font-size: 0.95rem; }
    .m365-domain-exp { font-size: 0.75rem; font-weight: 650; padding: 3px 8px; border-radius: 999px; background: rgba(0,120,212,0.15); color: #60cdff; }
    .m365-domain-exp.warn { background: rgba(248,113,113,0.15); color: #f87171; }
    .m365-domain-meta { font-size: 0.8rem; color: #9ca3af; line-height: 1.45; }
    .m365-domain-actions { display: flex; gap: 6px; margin-top: 10px; justify-content: flex-end; }
    .m365-domain-actions button { width: auto !important; margin: 0 !important; min-height: 32px; font-size: 0.78rem !important; padding: 0 10px !important; }
    .m365-coming-soon { text-align: center; padding: 36px 16px; color: #9ca3af; border: 1px dashed #334155; border-radius: 14px; }
    .m365-coming-ico { font-size: 2rem; margin-bottom: 8px; }
    .m365-coming-title { font-size: 1.1rem; font-weight: 700; color: #e5e7eb; }
    .m365-coming-sub { display: inline-block; margin: 8px 0 12px; padding: 4px 12px; border-radius: 999px; background: rgba(0,120,212,0.15); color: #60cdff; font-size: 0.8rem; font-weight: 700; }
    .m365-view-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
    .m365-view-item { background: rgba(15,23,42,0.55); border-radius: 10px; padding: 10px 12px; }
    .m365-view-item.full { grid-column: 1 / -1; }
    .m365-view-k { font-size: 0.7rem; color: #8a93a6; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
    .m365-view-v { color: #e5e7eb; margin-top: 4px; word-break: break-word; font-size: 0.9rem; }
    @media (max-width: 560px) { .m365-view-grid { grid-template-columns: 1fr; } }


    .m365-search-wrap {
      position: relative;
      margin-bottom: 14px;
      max-width: 520px;
    }
    .m365-search-wrap input {
      width: 100%;
      box-sizing: border-box;
      background: #0f172a !important;
      border: 1px solid #2b3548 !important;
      border-radius: 12px !important;
      padding: 12px 40px 12px 42px !important;
      color: #f3f2f1 !important;
      font-size: 0.95rem !important;
    }
    .m365-search-wrap input:focus {
      border-color: #0078d4 !important;
      outline: none;
      box-shadow: 0 0 0 2px rgba(0,120,212,0.25);
    }
    .m365-search-ico {
      position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
      pointer-events: none; font-size: 0.95rem; opacity: 0.7;
    }
    .m365-search-clear {
      position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
      background: transparent; border: none; color: #9ca3af; cursor: pointer;
      width: auto !important; margin: 0 !important; padding: 6px 8px !important;
      font-size: 0.9rem; display: none;
    }
    .m365-search-wrap.has-value .m365-search-clear { display: block; }
    .m365-search-meta {
      font-size: 0.82rem; color: #9ca3af; margin: -6px 0 12px;
    }


    .m365-modal-xl { max-width: 860px !important; width: min(860px, calc(100vw - 16px)) !important; }
    .m365-lic-hero {
      display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap;
      padding: 18px 20px;
      background: linear-gradient(120deg, #0c1929 0%, #0f2744 50%, #0b1a2e 100%);
      border-bottom: 1px solid rgba(0,120,212,0.3);
    }
    .m365-lic-avatar {
      width: 52px; height: 52px; border-radius: 12px;
      background: linear-gradient(135deg, #0078d4, #00bcf2);
      color: #fff; font-weight: 800; font-size: 1.2rem;
      display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    }
    .m365-lic-hero-text { flex: 1; min-width: 0; }
    .m365-lic-hero-text h2 {
      margin: 0 0 4px; font-size: 1.25rem; color: #f3f2f1; font-weight: 700;
      word-break: break-word;
    }
    .m365-lic-hero-sub { color: #9ca3af; font-size: 0.88rem; }
    .m365-lic-pill {
      font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
      padding: 6px 12px; border-radius: 999px;
      background: rgba(0,120,212,0.2); color: #60cdff;
      border: 1px solid rgba(96,205,255,0.35); white-space: nowrap;
    }
    .m365-lic-kpis {
      display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
      padding: 14px 16px 6px;
    }
    .m365-lic-kpi {
      background: rgba(15,23,42,0.7); border: 1px solid #2b3548;
      border-radius: 12px; padding: 12px 14px;
    }
    .m365-lic-kpi .k {
      font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
      letter-spacing: 0.05em; color: #8a93a6; margin-bottom: 4px;
    }
    .m365-lic-kpi .v { font-size: 0.95rem; font-weight: 650; color: #e5e7eb; word-break: break-word; }
    .m365-lic-kpi .v.big { font-size: 1.35rem; color: #60cdff; font-weight: 800; }
    .m365-lic-section { padding: 8px 16px 16px; }
    .m365-lic-section-title {
      font-size: 0.75rem; font-weight: 800; text-transform: uppercase;
      letter-spacing: 0.06em; color: #60cdff; margin: 8px 0 10px;
    }
    .m365-lic-table-wrap {
      border: 1px solid #2b3548; border-radius: 12px; overflow: hidden;
      background: #121826;
    }
    .m365-lic-table {
      width: 100%; border-collapse: collapse; font-size: 0.88rem;
    }
    .m365-lic-table thead th {
      text-align: left; padding: 10px 12px;
      background: #1a2332; color: #9ca3af;
      font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
      letter-spacing: 0.04em; border-bottom: 1px solid #2b3548;
      white-space: nowrap;
    }
    .m365-lic-table tbody td {
      padding: 11px 12px; border-bottom: 1px solid rgba(43,53,72,0.8);
      color: #e5e7eb; vertical-align: middle;
    }
    .m365-lic-table tbody tr:last-child td { border-bottom: none; }
    .m365-lic-table tbody tr:hover td { background: rgba(0,120,212,0.08); }
    .m365-lic-emp {
      display: flex; align-items: center; gap: 10px;
    }
    .m365-lic-emp-av {
      width: 32px; height: 32px; border-radius: 8px;
      background: rgba(0,120,212,0.2); color: #60cdff;
      font-weight: 700; font-size: 0.8rem;
      display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    }
    .m365-lic-emp-name { font-weight: 650; color: #f3f2f1; }
    .m365-lic-muted { color: #6b7280; }
    .m365-lic-empty {
      text-align: center; padding: 28px 16px; color: #9ca3af;
      border: 1px dashed #334155; border-radius: 12px;
    }
    @media (max-width: 700px) {
      .m365-lic-kpis { grid-template-columns: 1fr 1fr; }
    }
    @media (max-width: 480px) {
      .m365-lic-kpis { grid-template-columns: 1fr; }
    }


    .lic-product-stats {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 12px;
      margin: 12px 0 16px;
    }
    .lic-product-stat {
      background: linear-gradient(145deg, rgba(0,120,212,0.1), rgba(15,23,42,0.9));
      border: 1px solid rgba(0,120,212,0.28);
      border-radius: 14px;
      padding: 16px 18px;
      box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    }
    .lic-product-stat-label {
      font-size: 0.72rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: #9ca3af;
      margin-bottom: 6px;
    }
    .lic-product-stat-value {
      font-size: 1.55rem;
      font-weight: 800;
      color: #60cdff;
      font-variant-numeric: tabular-nums;
      line-height: 1.1;
    }
    @media (max-width: 640px) {
      .lic-product-stats { grid-template-columns: 1fr; }
    }

