/* Qina Billing - Design System (PayPal Minimalist)
   Chunk 9: CSS variables, components, responsive grid, typography
   WCAG 2.1 AA compliant */

:root {
    --qina-bg: #f5f7fa;
    --qina-card: #ffffff;
    --qina-primary: #0070ba;
    --qina-primary-hover: #005a9e;
    --qina-primary-light: #e5f0fa;
    --qina-text: #1a1a1a;
    --qina-text-secondary: #5f6b7a;
    --qina-border: #e1e4e8;
    --qina-border-strong: #cfd8e3;
    --qina-radius: 12px;
    --qina-radius-sm: 8px;
    --qina-radius-btn: 6px;
    --qina-radius-tag: 2px;
    --qina-radius-pill: 999px;
    --qina-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --qina-shadow-sm: 0 1px 2px rgba(16,24,40,0.05);
    --qina-shadow: 0 1px 3px rgba(16,24,40,0.06), 0 1px 2px rgba(16,24,40,0.04);
    --qina-shadow-hover: 0 12px 24px -12px rgba(0,112,186,0.18), 0 2px 6px rgba(16,24,40,0.06);
    --qina-shadow-md: 0 2px 4px rgba(16,24,40,0.04), 0 12px 32px -12px rgba(16,24,40,0.12);
    --qina-shadow-lg: 0 4px 8px rgba(16,24,40,0.04), 0 24px 48px -12px rgba(16,24,40,0.18);
    --qina-danger: #d32f2f;
    --qina-success: #2e7d32;
    --qina-warning: #f57c00;
    --qina-info: #0288d1;
    /* Safe area insets for notched/home-indicator devices */
    --sa-top: env(safe-area-inset-top, 0px);
    --sa-right: env(safe-area-inset-right, 0px);
    --sa-bottom: env(safe-area-inset-bottom, 0px);
    --sa-left: env(safe-area-inset-left, 0px);
}

/* Dark mode — toggled via documentElement.dataset.theme, persisted in localStorage */
[data-theme="dark"] {
    --qina-bg: #0f141b;
    --qina-card: #1a2230;
    --qina-primary: #2f9fe0;
    --qina-primary-hover: #5cb3e8;
    --qina-primary-light: #14324a;
    --qina-text: #e8edf3;
    --qina-text-secondary: #9aa7b8;
    --qina-border: #2a3444;
    --qina-border-strong: #3a4658;
    --qina-shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --qina-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.25);
    --qina-shadow-hover: 0 12px 24px -12px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
    --qina-shadow-md: 0 2px 4px rgba(0,0,0,0.3), 0 12px 32px -12px rgba(0,0,0,0.4);
    --qina-shadow-lg: 0 4px 8px rgba(0,0,0,0.3), 0 24px 48px -12px rgba(0,0,0,0.5);
    color-scheme: dark;
}
[data-theme="dark"] .topbar {
    background: rgba(26, 34, 48, 0.92);
}
[data-theme="dark"] .dropdown-menu,
[data-theme="dark"] .modal-content,
[data-theme="dark"] .receiver-preview {
    background: var(--qina-card);
}
[data-theme="dark"] .bottom-nav {
    background: rgba(26, 34, 48, 0.96);
}
[data-theme="dark"] .bottom-nav-fab {
    border-color: var(--qina-card);
}
[data-theme="dark"] .data-table tr:hover { background: #222d3f; }
[data-theme="dark"] .dropdown-item:hover { background: #222d3f; }
[data-theme="dark"] .topbar-search input { background: #222d3f; }
[data-theme="dark"] .topbar-search input:focus { background: var(--qina-card); }
[data-theme="dark"] img:not(.doc-logo) { filter: none; }
/* Dashboard dark-mode readability: brighten semantic values, soften pastel chips */
[data-theme="dark"] .chart-info-value.pos { color: #66bb6a; }
[data-theme="dark"] .chart-info-value.neg { color: #ef5350; }
[data-theme="dark"] .dash-stat-icon { filter: brightness(0.92); }
[data-theme="dark"] .badge-paid { background: #14331c; color: #7bd88a; }
[data-theme="dark"] .badge-overdue { background: #3d1f1a; color: #f0968a; }
[data-theme="dark"] .badge-sent { background: #14324a; color: #6db9e8; }
[data-theme="dark"] .badge-draft { background: #2a3444; color: #b9c4d4; }
@media print {
    [data-theme="dark"] body, [data-theme="dark"] .main-content, [data-theme="dark"] .card {
        background: #fff !important;
        color: #1a1a1a !important;
    }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; overflow-x: hidden; }

body {
    font-family: var(--qina-font);
    background: var(--qina-bg);
    color: var(--qina-text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    padding-top: var(--sa-top);
    padding-right: var(--sa-right);
    padding-bottom: var(--sa-bottom);
    padding-left: var(--sa-left);
}

a { color: var(--qina-primary); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--qina-primary-hover); }

img { max-width: 100%; height: auto; }

/* Typography */
h1 { font-size: clamp(1.35rem, 4.5vw, 1.75rem); font-weight: 600; margin-bottom: 0.25rem; }
h2 { font-size: clamp(1.15rem, 3.5vw, 1.35rem); font-weight: 600; margin-bottom: 0.75rem; }
h3 { font-size: clamp(1rem, 2.5vw, 1.1rem); font-weight: 600; margin-bottom: 0.5rem; }
h4 { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; }
p { margin-bottom: 0.5rem; color: var(--qina-text-secondary); }

/* Cards */
.card {
    background: var(--qina-card);
    border-radius: 16px;
    box-shadow: var(--qina-shadow-md);
    padding: clamp(1rem, 3vw, 1.5rem);
    margin-bottom: 1.25rem;
    transition: box-shadow 0.2s ease;
}

/* Navigation */
.navbar {
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border-bottom: 1px solid var(--qina-border);
    box-shadow: var(--qina-shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    padding: 0.8rem clamp(0.75rem, 4vw, 1.5rem);
    gap: clamp(0.5rem, 2vw, 1rem);
}

.nav-left {
    flex-shrink: 0;
}

.nav-brand {
    text-decoration: none !important;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.brand-bold {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--qina-primary);
    letter-spacing: 1px;
}

.brand-light {
    font-weight: 400;
    font-size: 1.1rem;
    color: var(--qina-text-secondary);
    letter-spacing: 0.5px;
}

.nav-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.nav-links {
    display: flex;
    gap: 0.15rem;
}

.nav-link {
    color: var(--qina-text-secondary) !important;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.4rem 0.85rem;
    border-radius: var(--qina-radius-pill);
    white-space: nowrap;
    transition: color 150ms ease, background 150ms ease;
    position: relative;
}

.nav-link:hover {
    color: var(--qina-primary) !important;
    background: var(--qina-primary-light);
    text-decoration: none;
}

.nav-link.active {
    color: var(--qina-primary) !important;
    background: var(--qina-primary-light);
    text-decoration: none;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 2px;
    background: var(--qina-primary);
    border-radius: 1px;
}

.nav-right {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Quick-add button */
.btn-add {
    border-radius: var(--qina-radius-btn);
    font-weight: 600;
    padding: 0.4rem 0.9rem;
    box-shadow: none;
    background: var(--qina-primary);
    border-color: var(--qina-primary);
}
.btn-add:hover {
    background: var(--qina-primary-hover);
    border-color: var(--qina-primary-hover);
    box-shadow: var(--qina-shadow-hover);
    transform: translateY(-1px);
}

/* User chip (avatar + name) */
.user-chip {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--qina-radius-btn);
    padding: 0.25rem 0.55rem 0.25rem 0.25rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 150ms ease, box-shadow 150ms ease;
}
.user-chip:hover {
    background: var(--qina-card);
    border-color: var(--qina-border);
    box-shadow: var(--qina-shadow-sm);
}
/* Static footer chip: display only, actions live on the sign-out icon */
.user-chip-static { cursor: default; }
.user-chip-static:hover {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}
.signout-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    margin-left: auto;
    border: 1px solid transparent;
    border-radius: var(--qina-radius-btn);
    background: transparent;
    color: var(--qina-text-secondary, #57606a);
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease;
}
.signout-icon svg { width: 20px; height: 20px; }
.signout-icon:hover { background: #fbe9e7; color: var(--qina-danger, #dc2626); }
/* Sidebar section label (e.g. Admin Tools) */
.sidebar-section {
    padding: 0.9rem 0.9rem 0.3rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--qina-text-secondary);
}
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--qina-primary), #003087);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: 0.5px;
}
.user-chip-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.25;
    min-width: 0;
}
.user-chip-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--qina-text);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-chip-role {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--qina-text-secondary);
}
.user-chip-role-label { text-transform: capitalize; }
.user-chip-role .tier-badge {
    font-size: 0.6rem;
    padding: 0 0.4rem;
    letter-spacing: 0.04em;
}

/* Dropdown menu inside navbar */
.nav-right .dropdown-menu {
    top: calc(100% + 8px);
    min-width: 210px;
}
.dropdown-menu-left { right: auto; left: 0; }
.quick-add-menu { min-width: 180px; }

.nav-user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.3;
}

.nav-user-info .nav-user-name {
    font-size: 0.85rem;
    color: var(--qina-text);
    font-weight: 500;
}

.nav-user-info .nav-user-role {
    font-size: 0.7rem;
    color: var(--qina-text-secondary);
    text-transform: capitalize;
    margin-bottom: 1px;
}

.nav-user-info .badge {
    font-size: 9px;
    padding: 1px 6px;
    text-transform: uppercase;
    border-radius: 8px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--qina-text-secondary);
    white-space: nowrap;
}

.nav-user .badge {
    font-size: 10px;
    padding: 2px 8px;
    text-transform: uppercase;
    border-radius: 10px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

/* Hide nav-user inside collapse on desktop (nav-right is used instead) */
.nav-center .nav-user { display: none; }

/* Nav toggle (hamburger) - hidden on desktop */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    flex-direction: column;
    gap: 4px;
    z-index: 110;
}
.nav-toggle-bar {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--qina-text-secondary);
    border-radius: 2px;
    transition: all 0.25s;
}
.nav-toggle.open .nav-toggle-bar:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}
.nav-toggle.open .nav-toggle-bar:nth-child(2) {
    opacity: 0;
}
.nav-toggle.open .nav-toggle-bar:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* Nav collapse - mobile dropdown */
.nav-collapse {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.5rem;
}

/* Main content */
.main-content {
    max-width: 1280px;
    margin: clamp(0.75rem, 2.5vw, 1.5rem) auto;
    padding: 0 clamp(0.75rem, 4vw, 1.5rem) clamp(2rem, 5vw, 3rem);
}

/* Fluid wrapper – use on any block needing consistent horizontal padding */
.responsive-wrapper {
    padding: 0 clamp(0.75rem, 4vw, 1.5rem);
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: clamp(1rem, 3vw, 1.5rem);
    border-top: 1px solid var(--qina-border);
    color: var(--qina-text-secondary);
    font-size: 0.8rem;
}
.app-footer p { margin: 0; }

/* View container (shared page wrapper) */
.view-container {
    width: 100%;
    animation: viewIn 0.25s ease;
}
@keyframes viewIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* View header (title + Import/Export buttons + logo) */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.view-header-left h1 {
    margin: 0;
    font-size: clamp(1.25rem, 4vw, 1.5rem);
}

.view-header-left p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--qina-text-secondary);
}

.view-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.company-name {
    font-size: 0.875rem;
    color: var(--qina-text-secondary);
    font-weight: 500;
}

.header-logo {
    max-height: 36px;
    border-radius: var(--qina-radius-sm);
}

.company-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.company-info .badge {
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 8px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1.15rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--qina-radius-btn);
    border: 1px solid var(--qina-border);
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--qina-card);
    color: var(--qina-text);
    white-space: nowrap;
    gap: 0.35rem;
    font-family: inherit;
    line-height: 1.4;
    box-shadow: var(--qina-shadow-sm);
}

.btn:hover { box-shadow: var(--qina-shadow-md); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: var(--qina-shadow-sm); }

.btn-primary {
    background: var(--qina-primary);
    color: #fff;
    border-color: var(--qina-primary);
    box-shadow: 0 2px 8px rgba(0,112,186,0.22);
}
.btn-primary:hover { background: var(--qina-primary-hover); border-color: var(--qina-primary-hover); color: #fff; box-shadow: 0 6px 16px -4px rgba(0,112,186,0.35); }

.btn-secondary { background: var(--qina-card); color: var(--qina-text); }
.btn-secondary:hover { background: var(--qina-bg); color: var(--qina-text); }
.btn-ghost { background: none; color: var(--qina-text-secondary); border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--qina-bg); color: var(--qina-text); border-color: transparent; box-shadow: none; transform: none; }

.btn-danger { background: var(--qina-danger); color: #fff; border-color: var(--qina-danger); }
.btn-danger:hover { color: #fff; }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* Kebab (⋯) icon-only action trigger */
.btn-icon-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--qina-border, #d0d7de);
    border-radius: var(--qina-radius-btn);
    background: #fff;
    color: var(--qina-text-secondary, #57606a);
    cursor: pointer;
    transition: all 150ms ease;
}
.btn-icon-action:hover { background: var(--qina-bg, #f6f8fa); color: var(--qina-text, #1f2328); }
.btn-icon-action svg { width: 20px; height: 20px; }

/* Flat PayPal-style action button */
.btn-action {
    background: var(--qina-primary);
    color: #fff;
    border: 1px solid var(--qina-primary);
    border-radius: var(--qina-radius-btn);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,112,186,0.22);
    transition: all 150ms ease;
}
.btn-action:hover {
    background: var(--qina-primary-hover);
    border-color: var(--qina-primary-hover);
    box-shadow: 0 6px 16px -4px rgba(0,112,186,0.4);
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
}
.btn-action:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0,112,186,0.2);
}

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.35rem; color: var(--qina-text); }
.form-input {
    width: 100%;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    border: 1px solid var(--qina-border);
    border-radius: 10px;
    background: var(--qina-card);
    color: var(--qina-text);
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:hover { border-color: var(--qina-border-strong); }
.form-input:focus { outline: none; border-color: var(--qina-primary); box-shadow: 0 0 0 3px var(--qina-primary-light); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235f6b7a' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.85rem center; padding-right: 2rem; }
.form-textarea { min-height: 80px; resize: vertical; }
.form-help { font-size: 0.75rem; color: var(--qina-text-secondary); margin-top: 0.25rem; }
.form-checkbox { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; cursor: pointer; }
.form-checkbox input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.form-container { max-width: 800px; margin: 0 auto; }

/* File input (receipt upload, CSV import, logo) */
.form-file {
    padding: 0.5rem 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}
.form-file::file-selector-button {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--qina-border);
    border-radius: var(--qina-radius-sm);
    background: var(--qina-bg);
    color: var(--qina-text);
    font-size: 0.8rem;
    cursor: pointer;
    margin-right: 0.5rem;
    transition: background 0.15s;
}
.form-file::file-selector-button:hover { background: #e8eaed; }

.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.search-bar .form-input { max-width: 320px; }
.search-bar .form-select { max-width: 200px; }

/* Data table */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.data-table th {
    text-align: left;
    padding: 0.7rem 0.8rem;
    font-weight: 600;
    color: var(--qina-text-secondary);
    border-bottom: 2px solid var(--qina-border);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.data-table td {
    padding: 0.7rem 0.8rem;
    border-bottom: 1px solid var(--qina-border);
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}
.data-table tr { transition: background 100ms ease; }
.data-table tr:hover { background: #f8f9fb; }
.data-table .empty-cell { text-align: center; padding: 2.5rem 1rem; color: var(--qina-text-secondary); font-size: 0.9rem; }
.data-table tbody {
    content-visibility: auto;
    contain-intrinsic-size: 200px;
}

.actions-cell { white-space: nowrap; }
.text-center { text-align: center; }
.data-table th.text-center { text-align: center; }
.data-table td.text-center { text-align: center; }
.text-right { text-align: right; }
.data-table th.text-right { text-align: right; }
.text-nowrap { white-space: nowrap; }

/* Scroll wrapper for wide tables on mobile */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Actions Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-toggle { cursor: pointer; user-select: none; }
.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: #fff;
    border-radius: 14px;
    box-shadow: var(--qina-shadow-lg);
    min-width: 180px;
    z-index: 100;
    padding: 6px;
    margin-top: 4px;
    border: 1px solid rgba(225,228,232,0.7);
}
.dropdown.open .dropdown-menu { display: block; animation: dropdownIn 120ms ease; }
@keyframes dropdownIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.dropdown-item {
    display: block;
    padding: 0.5rem 0.7rem;
    font-size: 0.82rem;
    color: var(--qina-text, #1a1a1a);
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    border-radius: 8px;
}
.dropdown-item:hover { background: #f0f2f5; text-decoration: none; }
.dropdown-item.danger { color: var(--qina-danger, #dc2626); }
.dropdown-item.danger:hover { background: #fbe9e7; color: var(--qina-danger); }
.dropdown-menu a.dropdown-item,
.dropdown-menu a.dropdown-item:link,
.dropdown-menu a.dropdown-item:visited,
.dropdown-menu a.dropdown-item:hover,
.dropdown-menu a.dropdown-item:active,
.dropdown-menu a.dropdown-item:focus {
    color: var(--qina-text, #1a1a1a) !important;
    text-decoration: none !important;
    background: none !important;
}
.dropdown-menu a.dropdown-item:hover { background: #f0f2f5 !important; }
.dropdown-menu a.dropdown-item.danger:hover { background: #fbe9e7 !important; color: var(--qina-danger) !important; }
.dropdown-divider { height: 1px; background: var(--qina-border, #e1e4e8); margin: 5px 0; }

/* ─── Invoice Actions – Desktop dropdown + Mobile bottom sheet ─── */
.actions-dropdown { position: relative; display: inline-block; }
/* Backdrop for mobile bottom sheet (hidden on desktop) - below modals to avoid ghost over payment modal */
.actions-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16,24,40,0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.22s ease;
    pointer-events: none;
}
.actions-sheet-backdrop.open {
    display: block;
    opacity: 1;
    pointer-events: auto;
}
/* Desktop: backdrop never shows — only mobile bottom-sheet uses faint overlay */
@media (min-width:768px){
  .actions-sheet-backdrop, .actions-sheet-backdrop.open {
    display:none !important;
    opacity:0 !important;
    pointer-events:none !important;
  }
}
/* Sheet handle (drag indicator) – only visible on mobile */
.sheet-handle {
    display: none;
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: #d0d7de;
    margin: 0 auto 12px;
}
.sheet-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px 10px;
    border-bottom: 1px solid var(--qina-border);
    margin-bottom: 10px;
}
.sheet-header span { font-size: 0.95rem; font-weight: 700; color: var(--qina-text); }
.sheet-close-btn {
    background: var(--qina-bg);
    border: 1px solid var(--qina-border);
    border-radius: var(--qina-radius-btn);
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--qina-text-secondary);
}
/* Desktop: keep absolute dropdown with proper spacing and z-index (Tailwind: sm:relative md:absolute right-0 mt-2 w-48 z-50) */
.actions-dropdown .dropdown-menu {
    z-index: 200;
    margin-top: 8px;
    min-width: 192px;
    right: 0;
    left: auto;
}
/* Mobile bottom sheet – overrides absolute positioning below 768px (Option A) - z-index below modal (1000) to prevent ghost over modals */
@media (max-width: 767.98px) {
    .actions-dropdown .dropdown-menu {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 20px 20px 0 0 !important;
        padding: 12px 12px calc(14px + var(--sa-bottom)) !important;
        box-shadow: 0 -8px 32px rgba(16,24,40,0.18), 0 -2px 8px rgba(16,24,40,0.08) !important;
        z-index: 999 !important;
        border: 1px solid var(--qina-border) !important;
        border-bottom: none !important;
        background: var(--qina-card) !important;
        /* hidden by transform – never overlaps header/logo */
        display: block !important;
        visibility: hidden;
        opacity: 0;
        transform: translateY(100%);
        transition: transform 0.32s cubic-bezier(0.32,0.72,0,1), opacity 0.25s ease, visibility 0s linear 0.32s;
        max-height: min(78vh, 520px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .actions-dropdown.open .dropdown-menu {
        visibility: visible;
        opacity: 1;
        transform: translateY(0);
        transition: transform 0.32s cubic-bezier(0.32,0.72,0,1), opacity 0.2s ease;
        animation: none;
    }
    .actions-dropdown .sheet-handle,
    .actions-dropdown .sheet-header { display: flex; }
    .actions-dropdown .sheet-handle { display: block; }
    /* Touch-friendly stacked buttons – full-width, 44px min, 8px gap */
    .actions-dropdown .dropdown-item {
        min-height: 44px;
        display: flex;
        align-items: center;
        font-size: 0.95rem;
        font-weight: 500;
        padding: 0.75rem 1rem;
        margin-bottom: 8px;
        border-radius: 12px;
        background: #f8f9fb;
        border: 1px solid rgba(225,228,232,0.7);
        white-space: normal;
        width: 100%;
        justify-content: flex-start;
        gap: 0.6rem;
        transition: background 0.15s, transform 0.1s, border-color 0.15s;
    }
    .actions-dropdown .dropdown-item:last-of-type { margin-bottom: 0; }
    .actions-dropdown .dropdown-item:hover { background: #eef2f7; border-color: #d0d7de; transform: none; }
    .actions-dropdown .dropdown-item:active { background: #e3e8ee; transform: scale(0.99); }
    .actions-dropdown .dropdown-item.danger { background: #fef2f2; border-color: #fecaca; color: #dc2626; }
    .actions-dropdown .dropdown-item.danger:hover { background: #fee2e2; }
    .actions-dropdown .dropdown-divider { margin: 10px 0; height: 1px; background: var(--qina-border); }
    .actions-dropdown .dropdown-item + .dropdown-divider,
    .actions-dropdown .dropdown-divider + .dropdown-divider { display: none; }
    @keyframes sheetSlideIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
    @keyframes sheetFadeIn { from { opacity: 0; } to { opacity: 1; } }
}

/* Pagination */
.pagination {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    padding: 1rem 0;
}
.page-link {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--qina-border);
    border-radius: var(--qina-radius-btn);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    color: var(--qina-text);
}
.page-link:hover, .page-link.active {
    background: var(--qina-primary);
    color: #fff;
    border-color: var(--qina-primary);
    text-decoration: none;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.18rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--qina-radius-tag);
    text-transform: capitalize;
    line-height: 1.5;
    white-space: nowrap;
}
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
    flex-shrink: 0;
}
.badge-draft { background: #eef1f5; color: #444; }
.badge-sent { background: #e3f0fa; color: #005a9e; }
.badge-viewed { background: #e3f0fa; color: #005a9e; }
.badge-accepted { background: #e6f7e6; color: #0d7c0d; }
.badge-converted_to_invoice { background: #e6f7e6; color: #0d7c0d; }
.badge-partial { background: #fff3e0; color: #e65100; }
.badge-paid { background: #e6f7e6; color: #0d7c0d; }
.badge-expired { background: #fbe9e7; color: #bf360c; }
.badge-overdue { background: #fbe9e7; color: #bf360c; }
.badge-cancelled { background: #f5f5f5; color: #666; }
.badge-refunded { background: #f3e5f5; color: #7b1fa2; }
.badge-director { background: #e3f0fa; color: #005a9e; }
.badge-manager { background: #e6f7e6; color: #0d7c0d; }
.badge-officer { background: #f5f5f5; color: #666; }
.badge-recurring { background: #fff3e0; color: #e65100; font-size: 0.7rem; margin-left: 4px; }
.badge-primary { background: #e3f0fa; color: #005a9e; }
.badge-secondary { background: #eef1f5; color: #444; }
.badge-success { background: #e6f7e6; color: #0d7c0d; }
.badge-danger { background: #fbe9e7; color: #bf360c; }
.badge-void { background: #fde8e8; color: #b91c1c; }
.badge-warning { background: #fff3e0; color: #e65100; }
.badge-sm { font-size: 0.65rem; padding: 0.12rem 0.5rem; }
.badge-sm::before { width: 5px; height: 5px; }

/* Neutral badges (draft/cancelled/officer etc.) keep dot but subtle */
.badge-draft::before,
.badge-cancelled::before,
.badge-officer::before,
.badge-secondary::before { opacity: 0.5; }

/* Tier badge — single source of truth for per-tier colours.
   Shared by the account menu and the super admin Clients list. */
.tier-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.12rem 0.5rem;
    border-radius: var(--qina-radius-tag);
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.5;
    letter-spacing: 0.03em;
    white-space: nowrap;
}
.tier-starter, .tier-default {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #475569;
}
.tier-business {
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    color: #0070ba;
}
.tier-enterprise {
    background: #fdf3d7;
    border: 1px solid #e8c75a;
    color: #8a6d0a;
}
[data-theme="dark"] .tier-badge { background: #232c38; border-color: #364153; color: #cbd5e1; }
[data-theme="dark"] .tier-business { background: #0d2740; border-color: #16537d; color: #6cc0f0; }
[data-theme="dark"] .tier-enterprise { background: #2b2412; border-color: #5f4e1c; color: #e6c96a; }

/* Stats grid - KPI Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Admin panel: 6 cards must fit the available window width */
.stats-grid.admin-panel-stats {
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}
@media (min-width: 1400px) {
    .stats-grid.admin-panel-stats {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}
@media (min-width: 1100px) and (max-width: 1399px) {
    .stats-grid.admin-panel-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
@media (max-width: 640px) {
    .stats-grid.admin-panel-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem;
    }
}
.stats-grid.admin-panel-stats .stat-card {
    min-width: 0;
}
.stats-grid.admin-panel-stats .stat-value {
    font-size: clamp(1rem, 1.8vw, 1.35rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stats-grid.admin-panel-stats .stat-card-body {
    padding: 16px 14px 18px;
}
@media (max-width: 640px) {
    .stats-grid.admin-panel-stats .stat-card-body {
        padding: 12px 10px 14px;
    }
    .stats-grid.admin-panel-stats .stat-icon {
        width: 32px;
        height: 32px;
    }
}
.stat-card {
    background: var(--qina-card);
    border-radius: 16px;
    box-shadow: var(--qina-shadow-md);
    padding: 0;
    overflow: hidden;
    text-align: left;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid rgba(225,228,232,0.55);
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--qina-shadow-lg);
}
.stat-accent {
    height: 4px;
    width: 100%;
}
.stat-card-body {
    padding: 20px 24px 24px;
}
.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    margin-bottom: 12px;
    opacity: 0.85;
}
.stat-icon svg {
    width: 20px;
    height: 20px;
}
.stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--qina-text);
    line-height: 1.2;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}
.stat-label {
    font-size: 0.72rem;
    color: var(--qina-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    font-weight: 600;
}

/* Dashboard grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}
.modal.open { display: flex; }
.modal-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    background: #fff;
    padding: 1.5rem;
    border-radius: 16px;
    box-shadow: var(--qina-shadow-lg);
    border: 1px solid rgba(225,228,232,0.6);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--qina-border);
}
.modal-header h2 { margin: 0; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--qina-text-secondary);
    padding: 0.25rem;
    line-height: 1;
}

/* Toast notifications */
.toast {
    position: fixed;
    top: 1rem;
    right: 1rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--qina-radius);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 300;
    animation: slideIn 0.3s ease;
    box-shadow: var(--qina-shadow-hover);
}
.toast-success { background: var(--qina-success); color: #fff; }
.toast-error { background: var(--qina-danger); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Auth */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 60px);
    padding: 2rem 1rem 3rem;
    background:
        radial-gradient(900px 420px at 85% -10%, rgba(0,112,186,0.08), transparent 60%),
        radial-gradient(700px 380px at -10% 110%, rgba(0,48,135,0.07), transparent 60%),
        var(--qina-bg);
}
.auth-card {
    max-width: 420px;
    width: 100%;
    padding: 2.5rem 2.25rem;
    border-radius: 20px;
    box-shadow: var(--qina-shadow-lg);
}
.auth-header { text-align: center; margin-bottom: 1.75rem; }
.auth-logo {
    width: 52px;
    height: 52px;
    margin: 0 auto 0.75rem;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--qina-primary), #003087);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: 0.5px;
    box-shadow: 0 8px 20px -6px rgba(0,112,186,0.4);
}
.auth-logo-img {
    width: 52px;
    height: 52px;
    margin: 0 auto 0.75rem;
    border-radius: 14px;
    display: block;
    box-shadow: 0 8px 20px -6px rgba(0,112,186,0.4);
}
.pw-wrap { position: relative; }
.pw-wrap .form-input { padding-right: 2.75rem; }
.pw-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--qina-text-secondary);
    line-height: 0;
}
.pw-toggle:hover { color: var(--qina-primary); }
.pw-toggle svg { width: 18px; height: 18px; }
.auth-header h1 { color: var(--qina-text); font-size: 1.6rem; margin: 0 0 0.25rem; }
.auth-header p { color: var(--qina-text-secondary); font-size: 0.875rem; }
.auth-links { display: flex; justify-content: space-between; margin-top: 1rem; font-size: 0.85rem; }
.auth-links a { font-weight: 500; }
.auth-trust {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--qina-border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--qina-text-secondary);
    font-size: 0.75rem;
}
.auth-trust svg { color: var(--qina-success); }

/* Setup */
.setup-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    padding: 2rem 1rem;
}
.setup-card { max-width: 540px; width: 100%; padding: 2rem; }
.setup-header { text-align: center; margin-bottom: 1.5rem; }
.setup-steps { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin-bottom: 1rem; }
.step {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--qina-border);
    color: var(--qina-text-secondary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.875rem;
}
.step.active { background: var(--qina-primary); color: #fff; }
.step-separator { width: 60px; height: 2px; background: var(--qina-border); }

/* Document view */
.doc-view .doc-content { padding: 2rem; }
.doc-header { display: flex; justify-content: space-between; margin-bottom: 1.5rem; }
.doc-brand { max-width: 50%; }
.doc-logo { max-height: 60px; margin-bottom: 0.75rem; }
.doc-meta { text-align: right; }
.doc-meta h3 { font-size: 1.25rem; color: var(--qina-primary); letter-spacing: 1px; }
.doc-bill-to { margin-bottom: 1.5rem; padding: 1rem; background: var(--qina-bg); border-radius: var(--qina-radius); }
.doc-items { margin-bottom: 1.5rem; table-layout: fixed; }
.doc-items th, .doc-items td { overflow: hidden; text-overflow: ellipsis; }
.doc-items th:nth-child(1), .doc-items td:nth-child(1) { width: 45%; }
.doc-items th:nth-child(2), .doc-items td:nth-child(2) { width: 100px; text-align: right; }
.doc-items th:nth-child(3), .doc-items td:nth-child(3) { width: 130px; text-align: right; }
.doc-items th:nth-child(4), .doc-items td:nth-child(4) { width: 140px; text-align: right; }
.doc-totals { text-align: right; margin-bottom: 1rem; font-variant-numeric: tabular-nums; }
.doc-totals .total-row { margin: 0.35rem 0; font-size: 0.95rem; }
.doc-totals .total-final { font-size: 1.25rem; color: var(--qina-primary); border-top: 2px solid var(--qina-primary); padding-top: 0.5rem; }
.doc-totals .total-due { font-size: 1.1rem; color: var(--qina-danger); }
.doc-notes, .doc-terms { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--qina-border); }
.doc-notes p, .doc-terms p { font-size: 0.875rem; }
.doc-banking { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--qina-border); }
.doc-banking h4 { margin-bottom: 0.5rem; color: var(--qina-primary); }
.banking-table { width: auto; }
.banking-table td { padding: 2px 12px 2px 0; font-size: 0.875rem; }

/* Totals box on forms */
.totals-box {
    background: var(--qina-bg);
    border-radius: 14px;
    padding: 1rem;
    margin-bottom: 1rem;
    font-variant-numeric: tabular-nums;
}
.totals-box .total-row { display: flex; justify-content: space-between; margin: 0.25rem 0; font-size: 0.9rem; }
.totals-box .total-final { font-weight: 700; font-size: 1.1rem; color: var(--qina-primary); border-top: 2px solid var(--qina-primary); padding-top: 0.5rem; margin-top: 0.25rem; }
.totals-box .tax-detail-row { font-size: 0.85em; color: var(--qina-text-secondary, #5f6b7a); }
.tax-checkbox-group { display: flex; flex-wrap: wrap; gap: 6px 14px; border: 1px solid var(--qina-border, #e3e8ee); border-radius: 8px; padding: 0.5rem 0.75rem; background: var(--qina-bg); }
.tax-checkbox-group .tax-cb { margin: 2px 0; padding: 2px 4px; border-radius: 6px; }
.tax-checkbox-group .tax-cb:hover { background: var(--qina-bg-soft, #f5f7fa); }

/* Logo preview */
.logo-preview img { border: 1px solid var(--qina-border); border-radius: var(--qina-radius-sm); padding: 4px; background: var(--qina-card); }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
}
.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    border-radius: 18px;
    background: var(--qina-primary-light);
    color: var(--qina-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}
.empty-state-icon svg { width: 32px; height: 32px; }
.empty-state h1 { font-size: 3rem; color: var(--qina-primary); }
.empty-state p { font-size: 1rem; margin: 0.5rem 0 1.5rem; }
.empty-text { text-align: center; padding: 1.5rem; color: var(--qina-text-secondary); font-size: 0.875rem; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }

/* Dashboard stats row — always a single line (e.g. Invoiced / Collected / Expenses) */
.stats-grid.dash-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stats-grid.dash-stats .stat-card-body {
    padding: 16px 14px 18px;
    min-width: 0;
}
.stats-grid.dash-stats .stat-value {
    font-size: clamp(0.95rem, 2.4vw, 1.35rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
@media (max-width: 700px) {
    .stats-grid.dash-stats { gap: 0.6rem; }
    .stats-grid.dash-stats .stat-card-body { padding: 12px 10px 14px; }
    .stats-grid.dash-stats .stat-label { font-size: 0.65rem; }
}

/* Dashboard layout: chart + stacked stats */
.dash-layout {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    align-items: stretch;
}
.dash-layout .card:first-child {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.dash-layout .card:first-child canvas {
    flex: 1;
    max-height: 260px;
}
.dash-layout .stacked-stats {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 230px;
    flex-shrink: 0;
}
.dash-layout .stacked-stats .stat-card {
    padding: 0;
    margin: 0;
    flex: 1;
}
.dash-layout .stacked-stats .stat-card-body {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.dash-layout .stacked-stats .stat-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 8px;
}
.dash-layout .stacked-stats .stat-icon svg {
    width: 16px;
    height: 16px;
}
.dash-layout .stacked-stats .stat-value {
    font-size: 1rem;
}

/* Responsive */
@media (max-width: 900px) {
    .dash-layout { flex-direction: column; }
    .dash-layout .stacked-stats { width: 100%; flex-direction: row; flex-wrap: wrap; }
    .dash-layout .stacked-stats .stat-card { flex: 1; min-width: 120px; }
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    /* Nav: hamburger visible, collapse becomes dropdown */
    .navbar { height: auto; position: relative; }
    .nav-container { flex-wrap: wrap; padding: 0 1rem; position: relative; min-height: 64px; }
    .nav-toggle { display: flex; position: absolute; right: 1rem; top: 50%; transform: translateY(-50%); }
    /* The topbar hamburger shares .nav-toggle: keep it in flow so it never
       collides with the centered brand or the dark-mode toggle. */
    .topbar-left .nav-toggle.sidebar-toggle { position: static; transform: none; }
    .nav-center { order: 3; flex: 1 1 100%; }
    .nav-right { display: none; }

    .nav-collapse {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--qina-card);
        border-bottom: 1px solid var(--qina-border);
        box-shadow: 0 4px 16px rgba(0,0,0,0.12);
        padding: 0.5rem 1rem 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        z-index: 99;
        max-height: calc(100vh - 64px);
        overflow-y: auto;
    }
    .nav-collapse.open { display: flex; }
    .nav-collapse .nav-links {
        flex-direction: column;
        overflow: visible;
        gap: 0;
        flex: none;
    }
    .nav-collapse .nav-link {
        padding: 0.75rem 0.75rem;
        font-size: 0.95rem;
        border-radius: var(--qina-radius);
        border-bottom: 1px solid var(--qina-border);
    }
    .nav-collapse .nav-link:last-child { border-bottom: none; }
    .nav-collapse .nav-link.active::after { display: none; }
    .nav-center .nav-user { display: flex; }
    .nav-collapse .nav-user {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding-top: 0.75rem;
        margin-top: 0.25rem;
        border-top: 1px solid var(--qina-border);
    }
    .nav-collapse .nav-user .btn { text-align: center; }

    .settings-grid .view-header { flex-direction: column; gap: 8px; }
    .settings-grid { grid-template-columns: 1fr; }
    .view-header-right { width: 100%; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.65rem; }
    .stat-value { font-size: 1.35rem; }
    .stat-label { font-size: 0.7rem; }
    .form-row { grid-template-columns: 1fr; }
    .search-bar .form-input, .search-bar .form-select { max-width: 100%; }
    .doc-header { flex-direction: column; }
    .doc-brand, .doc-meta { max-width: 100%; text-align: left; }
    /* Tables: stacked cards on mobile */
    .data-table thead { display: none; }
    .data-table tr {
        display: block;
        margin-bottom: 0.75rem;
        border: 1px solid var(--qina-border);
        border-radius: 8px;
        background: var(--qina-card);
        padding: 0.5rem 0.75rem;
    }
    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--qina-border);
        gap: 0.5rem;
        text-align: left;
        white-space: normal;
    }
    .data-table td:last-child { border-bottom: none; }
    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--qina-text-secondary);
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        flex-shrink: 0;
        min-width: 30%;
    }
    .data-table td.actions-cell,
    .data-table td.td-actions,
    .data-table td.th-actions {
        justify-content: flex-end;
        border-bottom: none;
        padding-top: 0.25rem;
        gap: 0.35rem;
    }
    .data-table td.actions-cell::before,
    .data-table td.td-actions::before,
    .data-table td.th-actions::before {
        display: none;
    }
    .data-table td.text-right { text-align: left; }
    .data-table td.text-center { text-align: left; }

    /* Banking tables: stack rows vertically */
    .banking-table { width: 100%; display: block; }
    .banking-table tr { display: flex; flex-wrap: wrap; gap: 0 0.5rem; }
    .banking-table td { padding: 2px 0; }

    /* Touch-friendly form controls: 44px min tap target, 16px to prevent iOS zoom */
    input, select, textarea { font-size: 16px; }
    .form-input, .form-select, .btn, .form-file {
        min-height: 44px;
    }
    .btn { padding: 0.6rem 1rem; }
    .btn-sm { min-height: 36px; padding: 0.4rem 0.7rem; font-size: 0.85rem; }
    .form-input, .form-select, .form-file { padding: 0.65rem 0.75rem; }
    .form-textarea { min-height: 88px; }
    .form-checkbox input[type="checkbox"] { width: 20px; height: 20px; }
    .theme-selector-wrapper { flex-direction: column; }
    .theme-preview-panel { min-height: 200px; }
    .theme-selector { grid-template-columns: 1fr 1fr; }

    /* Modal: full-width on mobile */
    .modal-content {
        max-width: 92vw !important;
        margin: 0 auto;
        padding: 1.25rem;
        border-radius: 8px;
    }

    /* Buttons: make primary action full-width */
    .view-header-right .btn-primary { flex: 1; }

    /* Toasts: reposition */
    .toast { top: 0.5rem; right: 0.5rem; left: 0.5rem; text-align: center; }
}

@media (max-width: 480px) {

    h1 { font-size: 1.35rem; }
    h2 { font-size: 1.15rem; }

    .main-content { padding: 0 0.75rem 2rem; margin: 0.75rem auto; }
    .card { padding: 1rem; }

    .view-header {
        flex-direction: column;
        gap: 0.5rem;
    }
    .view-header-left h1 { font-size: 1.25rem; }
    .view-header-right {
        width: 100%;
        gap: 0.35rem;
    }
    .view-header-right .btn { font-size: 0.8rem; padding: 0.4rem 0.65rem; flex: 1; text-align: center; }
    .view-header-right .btn-primary { flex: 1; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .stat-value { font-size: 1.35rem; }
    .stat-label { font-size: 0.7rem; }

    .stats-grid.dash-stats { grid-template-columns: 1fr 1fr; }

    .data-table { font-size: 0.75rem; }
    .data-table th, .data-table td { padding: 0.45rem 0.5rem; }
    .actions-cell .btn-sm { padding: 0.25rem 0.4rem; font-size: 0.7rem; }

    .search-bar { flex-direction: column; }
    .search-bar .form-input { max-width: 100%; }
    .search-bar .btn { width: 100%; }

    .pagination { gap: 0.15rem; }
    .page-link { padding: 0.3rem 0.55rem; font-size: 0.8rem; }

    .modal-content { max-width: 96vw !important; padding: 1rem; border-radius: 6px; }
    .modal-header h2 { font-size: 1.1rem; }

    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; }

    .dashboard-grid { gap: 0.75rem; }

    .auth-card { padding: 1.5rem; }
    .setup-card { padding: 1.5rem; }

    .dash-layout .stacked-stats .stat-card { min-width: 100px; padding: 0.75rem; }

    .badge { font-size: 0.65rem; padding: 0.1rem 0.4rem; }
}

/* Stationery / Theme Selector */
.theme-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-option { cursor: pointer; padding: 8px; border: 2px solid var(--qina-border); border-radius: var(--qina-radius); text-align: center; transition: border-color .15s; }
.theme-option.selected { border-color: var(--qina-primary); }
.theme-option input[type="radio"] { display: none; }
.theme-preview { height: 80px; border-radius: 4px; overflow: hidden; margin-bottom: 6px; background: #fff; border: 1px solid #e1e4e8; display: flex; flex-direction: column; }
.tp-header { height: 24px; }
.tp-body { padding: 6px 8px; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.tp-line { height: 5px; background: #d0d7de; border-radius: 3px; }
.tp-line-short { width: 50%; }
.tp-line-half { width: 70%; }
/* Colour pickers */
.theme-colours { display: flex; flex-direction: column; gap: 8px; min-width: 110px; }
.theme-colours .colour-row { display: flex; flex-direction: column; gap: 2px; }
.theme-colours .colour-row .form-label { font-size: .7rem; font-weight: 600; color: var(--qina-muted); text-transform: uppercase; letter-spacing: .5px; }
.theme-colours .color-picker { display: flex; align-items: center; gap: 4px; }
.theme-colours input[type="color"] { width: 32px; height: 32px; padding: 1px; border: 1px solid var(--qina-border); border-radius: 4px; cursor: pointer; }

/* Stationery 2-Column Layout */
.stationery-layout { display: flex; gap: 24px; align-items: flex-start; }
.stationery-preview { flex: 0 0 auto; width: 360px; }
.stationery-controls { flex: 1; min-width: 280px; }
.theme-preview-panel { width: 100%; height: 520px; border: 2px solid var(--qina-border); border-radius: var(--qina-radius); background: #d1d5db; display: flex; justify-content: center; padding: 20px 0; overflow: hidden; box-shadow: inset 0 1px 4px rgba(0,0,0,0.1); }
.theme-preview-panel .a4-page { width: 320px; min-height: 450px; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,0.18); overflow-y: auto; flex-shrink: 0; }
.theme-preview-panel .a4-page::-webkit-scrollbar { width: 5px; }
.theme-preview-panel .a4-page::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* Color Picker */
.color-picker { display: flex; align-items: center; gap: 8px; }
.color-picker input[type="color"] { width: 40px; height: 40px; padding: 2px; border: 1px solid var(--qina-border); border-radius: 4px; cursor: pointer; }

/* WCAG 2.1 AA: Focus indicators */
:focus-visible {
    outline: 2px solid var(--qina-primary);
    outline-offset: 2px;
}

/* Dashboard layout (InvoiceShelf-inspired) */
.dash-stats-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}
.dash-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--qina-card);
    border-radius: 14px;
    box-shadow: var(--qina-shadow-md);
    border: 1px solid rgba(225, 228, 232, 0.55);
    padding: 1.25rem 1.5rem;
    text-decoration: none !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.dash-stat:hover {
    transform: translateY(-2px);
    box-shadow: var(--qina-shadow-lg);
}
.dash-stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--qina-text);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}
.dash-stat-label {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--qina-text-secondary);
    font-weight: 500;
}
.dash-stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--qina-primary);
    background: var(--qina-primary-light);
    flex-shrink: 0;
}
.dash-stat-icon svg { width: 24px; height: 24px; }
@media (min-width: 1024px) {
    .dash-stats-row { grid-template-columns: repeat(9, minmax(0, 1fr)); }
    .dash-stat { grid-column: span 2; padding: 1.5rem 1.75rem; }
    .dash-stat.dash-stat-lg { grid-column: span 3; }
    .dash-stat.dash-stat-lg .dash-stat-value { font-size: 2rem; }
}

/* Chart panel: chart (left) + info rail (right) */
.chart-panel {
    display: grid;
    grid-template-columns: 1fr;
    background: var(--qina-card);
    border-radius: 16px;
    box-shadow: var(--qina-shadow-md);
    border: 1px solid rgba(225, 228, 232, 0.55);
    overflow: hidden;
    margin-bottom: 2.5rem;
}
@media (min-width: 1024px) {
    .chart-panel { grid-template-columns: repeat(10, minmax(0, 1fr)); }
    .chart-main { grid-column: span 7; }
    .chart-info { grid-column: span 3; }
}
.chart-main { padding: 1.5rem; min-width: 0; }
.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.chart-header h3 {
    margin: 0;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.chart-year-form { margin: 0; }
.year-select {
    width: auto;
    padding: 0.45rem 2.2rem 0.45rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--qina-text);
}
.chart-wrap {
    position: relative;
    height: 260px;
    width: 100%;
    overflow: hidden;
}
.chart-wrap canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

.chart-info {
    border-top: 1px solid var(--qina-border);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (min-width: 1024px) {
    .chart-info {
        border-top: none;
        border-left: 1px solid var(--qina-border);
        grid-template-columns: 1fr;
    }
}
.chart-info-item { padding: 1.25rem 1.5rem; text-align: center; }
.chart-info-item + .chart-info-item { border-left: 1px solid var(--qina-border); }
@media (min-width: 1024px) {
    .chart-info-item { text-align: right; }
    .chart-info-item + .chart-info-item { border-left: none; }
    .chart-info-item:not(:last-child) { border-bottom: 1px solid var(--qina-border); }
}
.chart-info-item:nth-child(4) { grid-column: span 3; }
@media (min-width: 1024px) {
    .chart-info-item:nth-child(4) { grid-column: span 1; }
}
.chart-info-label {
    display: block;
    font-size: 0.72rem;
    color: var(--qina-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}
.chart-info-value {
    display: block;
    margin-top: 0.35rem;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--qina-text);
    font-variant-numeric: tabular-nums;
}
.chart-info-value.pos { color: var(--qina-success); }
.chart-info-value.neg { color: var(--qina-danger); }
.chart-info-value.primary { color: var(--qina-primary); }

/* Dashboard recent tables */
.dash-tables {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 1280px) {
    .dash-tables { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.table-card {
    background: var(--qina-card);
    border-radius: 16px;
    box-shadow: var(--qina-shadow-md);
    border: 1px solid rgba(225, 228, 232, 0.55);
    padding: 1.25rem 1.5rem;
}
.table-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.table-card-header h3 { margin: 0; font-size: 1.15rem; }

/* Outline button (View All) */
.btn-outline {
    background: transparent;
    color: var(--qina-primary);
    border-color: var(--qina-primary);
}
.btn-outline:hover {
    background: var(--qina-primary-light);
    color: var(--qina-primary-hover);
    border-color: var(--qina-primary-hover);
}

/* Responsive */
@media (max-width: 640px) {
    .dash-stats-row { gap: 0.75rem; }
    .dash-stat { padding: 1rem 1.1rem; }
    .dash-stat-value { font-size: 1.25rem; }
    .dash-stat.dash-stat-lg .dash-stat-value { font-size: 1.5rem; }
    .dash-stat-icon { width: 38px; height: 38px; }
    .chart-main { padding: 1.1rem; }
    .chart-info-item { padding: 1rem 0.9rem; }
    .chart-info-value { font-size: 1.1rem; }
}

/* Top bar (InvoiceShelf-style) */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px) saturate(160%);
    -webkit-backdrop-filter: blur(14px) saturate(160%);
    border-bottom: 1px solid var(--qina-border);
    z-index: 300;
    display: flex;
    align-items: center;
}
.topbar-inner {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 clamp(0.75rem, 4vw, 1.5rem);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: relative;
}
.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    flex: 1 1 auto;
}
/* QINA Billing wordmark pinned to the true center of the top bar */
.topbar-brand-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    white-space: nowrap;
}
.topbar-wordmark {
    height: 21px;
    width: auto;
    display: block;
    object-fit: contain;
}
@media (max-width: 899.98px) {
    .topbar-wordmark {
        height: 13px;
        max-width: 52vw;
    }
    .trial-banner {
        display: none !important;
    }
    .topbar-brand-center {
        max-width: calc(100vw - 132px);
        overflow: hidden;
    }
}

.topbar-left .btn-add { white-space: nowrap; flex-shrink: 0; }
.topbar-left .nav-brand .brand-bold,
.topbar-left .nav-brand .brand-light,
.topbar-brand-center .brand-bold,
.topbar-brand-center .brand-light {
    font-size: 1.1rem;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.topbar-right .dropdown-menu {
    top: calc(100% + 8px);
}

/* Sidebar layout (left navigation) */
.sidebar {
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    width: 248px;
    background: var(--qina-card);
    border-right: 1px solid var(--qina-border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: transform 0.25s ease;
}
.sidebar-header {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--qina-border);
}
.sidebar-brand {
    display: flex;
    align-items: center;
    min-height: 56px;
    text-decoration: none !important;
}
.sidebar-brand .brand-bold {
    font-size: 1.4rem;
    color: var(--qina-text);
    letter-spacing: 0.5px;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-logo {
    max-height: 56px;
    max-width: 200px;
    width: auto;
    object-fit: contain;
}
.sidebar-nav {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}
.sidebar-footer {
    flex-shrink: 0;
}
/* + New action block under the sidebar header */
.sidebar-create {
    padding: 0.85rem 0.75rem 0.25rem;
}
.sidebar-create .dropdown { display: block; }
.sidebar-create .btn-add { width: 100%; padding: 0.65rem 1rem; font-size: 0.95rem; }
.sidebar-create .dropdown-menu {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    min-width: 0;
}
/* Logged-in user pinned to the bottom of the sidebar */
.sidebar-footer {
    border-top: 1px solid var(--qina-border);
    padding: 0.75rem;
}
.sidebar-footer .user-chip { width: 100%; }
.sidebar-footer .user-chip-info { display: flex; flex: 1 1 auto; min-width: 0; }
/* Topbar search */
.topbar-search {
    flex: 0 1 400px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    min-width: 0;
    padding: 0;
}
.search-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--qina-border);
    border-radius: var(--qina-radius-btn);
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--qina-text-secondary);
    flex-shrink: 0;
}
.search-toggle svg { width: 19px; height: 19px; }
.topbar-search form {
    width: 100%;
    max-width: 100%;
    position: relative;
    margin: 0;
}
.topbar-search input {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--qina-border);
    border-radius: var(--qina-radius-pill);
    background: var(--qina-bg);
    color: var(--qina-text);
    font-size: 0.85rem;
    font-family: inherit;
    padding: 0.45rem 2.4rem 0.45rem 1rem;
}
.topbar-search input:focus {
    outline: none;
    border-color: var(--qina-primary);
    box-shadow: 0 0 0 3px var(--qina-primary-light);
    background: var(--qina-card);
}
.topbar-search button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--qina-radius-btn);
    background: transparent;
    color: var(--qina-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.topbar-search button svg { width: 17px; height: 17px; }
/* Dashboard header actions: search + New (replaces logo + plan badge) */
.dash-header-actions {
    gap: 0.75rem;
    flex-wrap: nowrap;
    flex: 1 1 auto;
    justify-content: flex-end;
}
.dash-search {
    flex: 1 1 auto;
    max-width: 420px;
    min-width: 0;
    display: flex;
    align-items: center;
}
.dash-search form {
    width: 100%;
    position: relative;
    margin: 0;
}
.dash-search input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--qina-border);
    border-radius: var(--qina-radius-pill);
    background: var(--qina-card);
    color: var(--qina-text);
    font-size: 0.875rem;
    font-family: inherit;
    padding: 0.55rem 2.4rem 0.55rem 1rem;
}
.dash-search input:focus {
    outline: none;
    border-color: var(--qina-primary);
    box-shadow: 0 0 0 3px var(--qina-primary-light);
}
.dash-search button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--qina-radius-btn);
    background: transparent;
    color: var(--qina-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dash-search button svg { width: 18px; height: 18px; }
.dash-header-actions .btn-add { white-space: nowrap; flex-shrink: 0; }
@media (max-width: 640px) {
    .dash-header-actions { width: 100%; gap: 0.5rem; flex-wrap: nowrap; }
    .dash-search { flex: 1 1 auto; max-width: none; min-width: 0; }
    .dash-header-actions .btn-add .new-label { display: none; }
    .dash-header-actions .btn-add { padding: 0.5rem 0.9rem; font-size: 1.1rem; line-height: 1; flex-shrink: 0; }
}
/* Dark-mode toggle */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--qina-border);
    border-radius: var(--qina-radius-btn);
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--qina-text-secondary);
    transition: background 150ms ease, color 150ms ease;
}
.theme-toggle:hover {
    background: var(--qina-card);
    color: var(--qina-primary);
    border-color: var(--qina-primary-light);
}
.theme-toggle svg { width: 19px; height: 19px; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--qina-text-secondary);
    text-decoration: none !important;
    transition: background 150ms ease, color 150ms ease;
}
.sidebar-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-link:hover { background: var(--qina-primary-light); color: var(--qina-primary); }
.sidebar-link.active { background: var(--qina-primary-light); color: var(--qina-primary); font-weight: 600; }

/* Sidebar hamburger lives inside the top bar on mobile */
.sidebar-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--qina-border);
    border-radius: 10px;
    cursor: pointer;
    padding: 0.4rem;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.45);
    z-index: 190;
}
.sidebar-backdrop.open { display: block; }

/* Shift main content right of the fixed sidebar + below the top bar */
body.has-sidebar .main-content {
    margin-left: 248px;
    max-width: 1600px;
    min-height: 100vh;
    padding: 76px clamp(1rem, 2.5vw, 1.75rem) clamp(2rem, 5vw, 3rem);
}

@media (min-width: 900px) {
    .sidebar-toggle { display: none !important; }
}

@media (max-width: 899.98px) {
    .topbar { height: 56px; }
    .sidebar-toggle {
        display: flex;
    }
    .sidebar-toggle.open .nav-toggle-bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
    .sidebar-toggle.open .nav-toggle-bar:nth-child(2) { opacity: 0; }
    .sidebar-toggle.open .nav-toggle-bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

    .sidebar {
        top: 56px;
        bottom: 72px;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--qina-shadow-lg);
    }
    .sidebar.open .sidebar-footer .user-chip-info { display: flex; }
    .sidebar.open .user-chip { padding: 0.5rem; }

    .user-chip-info { display: none; }
    .user-chip { padding: 0.25rem; }

    body.has-sidebar .main-content {
        margin-left: 0;
        max-width: none;
        padding: 72px 0.75rem clamp(1.5rem, 5vw, 3rem);
    }
}

@media (max-width: 480px) {
    .topbar-left .nav-brand .brand-light { display: inline; }
    .topbar-inner { padding: 0 0.75rem; gap: 0.5rem; }
    .topbar-right { gap: 0.35rem; }
    .topbar-search { padding: 0; }
    .topbar-search input { padding-left: 0.8rem; }
}
/* Small screens: brand keeps center, search collapses to an icon, + New shrinks to "+" */
@media (max-width: 760px) {
    .topbar-brand-center .brand-light { display: inline; }
    .topbar-brand-center .brand-bold { font-size: 1.2rem; }
}
@media (max-width: 640px) {
    .topbar-left { gap: 0.5rem; }
    .topbar-search { flex: 0 0 auto; }
    .topbar-search form { display: none; }
    .topbar-search .search-toggle { display: inline-flex; }
    .topbar-search.open form {
        display: block;
        position: absolute;
        top: calc(100% + 6px);
        left: 0.75rem;
        right: 0.75rem;
        z-index: 320;
        background: var(--qina-card);
        border: 1px solid var(--qina-border);
        border-radius: 14px;
        padding: 8px;
        box-shadow: var(--qina-shadow-lg);
    }
    .topbar-search.open form input { max-width: none; }
    .topbar-left .btn-add .new-label { display: none; }
    .topbar-left .btn-add { padding: 0.4rem 0.8rem; font-size: 1.1rem; line-height: 1; }
    .bottom-nav-link { font-size: 0.72rem; }
}

@media print {
    .topbar, .sidebar, .sidebar-toggle, .sidebar-backdrop, .bottom-nav { display: none !important; }
    body.has-sidebar .main-content { margin-left: 0 !important; max-width: none !important; padding: 0 !important; }
}

/* Mobile bottom tab bar (PWA-first): visible below 900px, replaces sidebar */
.bottom-nav {
    display: none;
}
@media (max-width: 899.98px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 300;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(14px) saturate(160%);
        -webkit-backdrop-filter: blur(14px) saturate(160%);
        border-top: 1px solid var(--qina-border);
        box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.08);
        padding: 6px 8px calc(6px + var(--sa-bottom));
        align-items: stretch;
        justify-content: space-around;
        gap: 2px;
    }
    .bottom-nav-link {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-width: 44px;
        min-height: 52px;
        padding: 6px 4px 4px;
        border-radius: 12px;
        color: var(--qina-text-secondary);
        font-size: 0.72rem;
        font-weight: 600;
        text-decoration: none !important;
        letter-spacing: 0.2px;
    }
    .bottom-nav-link svg {
        width: 22px;
        height: 22px;
        flex-shrink: 0;
    }
    .bottom-nav-link.active {
        color: var(--qina-primary);
        background: var(--qina-primary-light);
        text-decoration: none !important;
    }
    .bottom-nav-fab {
        align-self: center;
        flex-shrink: 0;
        width: 52px;
        height: 52px;
        min-width: 52px;
        min-height: 52px;
        border-radius: 999px;
        background: var(--qina-primary);
        color: #fff !important;
        font-size: 1.75rem;
        font-weight: 400;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        text-decoration: none !important;
        box-shadow: 0 4px 12px rgba(0, 112, 186, 0.4);
        margin-top: -20px;
        border: 3px solid #fff;
    }
    .bottom-nav-fab:active { transform: scale(0.96); }
    /* Keep content/footer clear of the fixed tab bar */
    body.has-sidebar .main-content {
        padding-bottom: calc(clamp(1.5rem, 5vw, 3rem) + 76px);
    }
    .app-footer {
        padding-bottom: calc(clamp(1rem, 3vw, 1.5rem) + 76px);
    }
}

/* Print */
@media print {
    .navbar, .nav-container, .btn, .view-header-right, .search-bar, .pagination { display: none !important; }
    .card { box-shadow: none; border: none; }
    .main-content { margin: 0; padding: 0; }
}

/* PWA: installed as standalone (no browser chrome) */
@media (display-mode: standalone) {
    .navbar { padding-top: calc(0.8rem + var(--sa-top)); }
    .nav-container { min-height: 56px; }
    body { -webkit-user-select: none; user-select: none; }
    input, textarea { -webkit-user-select: text; user-select: text; }
}

/* Shared PayPal-theme utilities (extracted from inline styles) */
.w-100 { width: 100px; }
.w-80 { width: 80px; }
.logo-preview img { max-height: 60px; }
.form-mono { font-family: monospace; font-size: 13px; }
.version-footer { text-align: center; color: var(--qina-text-secondary); font-size: 13px; }
.version-footer p { margin: 0; }
.template-tabs { display: flex; gap: 0; margin-bottom: 1rem; }
.template-tab { flex: 1; padding: 0.5rem; border: 1px solid var(--qina-border, #e1e4e8); background: var(--qina-card, #fff); color: var(--qina-text, #1a1a1a); cursor: pointer; font-weight: 500; font-family: inherit; font-size: 0.875rem; min-height: 44px; }
.template-tab:first-child { border-radius: 4px 0 0 4px; }
.template-tab:last-child { border-radius: 0 4px 4px 0; }
.template-tab.active { background: var(--qina-primary, #2563eb); border-color: var(--qina-primary, #2563eb); color: #fff; }
.template-tabs a.template-tab { text-decoration: none; text-align: center; display: flex; align-items: center; justify-content: center; }
.template-tabs a.template-tab:hover { text-decoration: none; }
.sender-preview { padding: 14px 16px; background: #f8f9fb; border-left: 4px solid var(--qina-primary); margin-bottom: 14px; }
.sender-preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 640px) { .sender-preview-grid { grid-template-columns: 1fr; } }
.sender-preview-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--qina-primary); margin-bottom: 4px; }
.sender-preview-name { font-weight: 700; color: var(--qina-text); }
.sender-preview-name .badge { margin-left: 6px; }
.sender-preview-line { font-size: 0.85rem; color: var(--qina-text-secondary); }
.sender-preview-line.mt { margin-top: 4px; }
.receiver-preview { display: none; padding: 10px 12px; background: var(--qina-card); border: 1px solid var(--qina-border); border-radius: 8px; }
.receiver-preview-content { font-size: 0.85rem; color: var(--qina-text-secondary); line-height: 1.4; }
.form-note { font-size: 0.75rem; color: var(--qina-text-secondary); margin-top: 8px; }
.form-note-sm { margin-top: 4px; }
.option-add { color: var(--qina-primary); font-weight: 600; }
.form-actions.tight { margin-top: 8px; gap: 8px; }
.form-actions.start { justify-content: flex-start; }
.modal-sm { max-width: 400px; }
.backup-status { font-size: 0.875rem; color: var(--qina-text-secondary); margin-left: 0.75rem; }
.mt-1 { margin-top: 1rem; }
.mt-3 { margin-top: 0.75rem; }
.sample-preview { margin: 0.75rem 0; }
.sample-preview-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--qina-text-secondary); margin-bottom: 0.35rem; }
.sample-table { font-size: 0.72rem; }
.sample-table th, .sample-table td { padding: 0.35rem 0.5rem; white-space: nowrap; }
.inline-details { margin-bottom: 1rem; }
.inline-details summary { cursor: pointer; font-size: 0.85rem; color: var(--qina-primary); font-weight: 600; padding: 10px 0; min-height: 44px; }
.dropdown-section-label { padding: 4px 12px 2px; font-size: 0.68rem; font-weight: 600; color: var(--qina-text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

/* Inactivity session lock overlay (blur hides sensitive data, esp. on mobile) */
#sessionLockOverlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 5000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
#sessionLockOverlay .lock-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 15, 25, 0.72);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
}
#sessionLockOverlay .lock-card {
    position: relative;
    width: 100%;
    max-width: 380px;
    background: var(--qina-card);
    border: 1px solid var(--qina-border);
    border-radius: 20px;
    box-shadow: var(--qina-shadow-lg);
    padding: 1.75rem 1.5rem;
    text-align: center;
}
#sessionLockOverlay .lock-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--qina-primary), #003087);
    color: #fff;
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem;
}
#sessionLockOverlay h2 { margin: 0 0 0.25rem; font-size: 1.25rem; }
#sessionLockOverlay .lock-sub { font-size: 0.85rem; color: var(--qina-text-secondary); margin-bottom: 1rem; }
#sessionLockOverlay .form-group { text-align: left; }
#sessionLockOverlay input { min-height: 48px; font-size: 1.05rem; text-align: center; letter-spacing: 1px; }
#sessionLockOverlay .btn { width: 100%; min-height: 48px; }
#sessionLockOverlay .lock-err { display: none; color: var(--qina-danger); font-size: 0.85rem; margin-top: 0.5rem; }
@media print {
    #sessionLockOverlay { display: none !important; }
}

/* Accessibility: reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
    .card:hover, .stat-card:hover { transform: none !important; }
    .btn-action:active { transform: none; }
    .nav-toggle-bar { transition: none; }
}

/* Compact mobile document lists (invoices / quotations / receipts).
   Desktop keeps the regular data-table; below 768px the table hides and
   this list shows instead. Dropdown open/close reuses .dropdown behaviour. */
.mobile-list-view { display: none; }
@media (min-width: 768px) {
    .mobile-list-view { display: none !important; }
}
@media (max-width: 767px) {
    table.data-table.mobile-compact { display: none; }
    .documents-list {
        display: block;
        background: var(--qina-card, #fff);
        border: 1px solid var(--qina-border, #e5e7eb);
        border-radius: 12px;
    }
    .documents-list-header {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 16px;
        background: #f9fafb;
        border-bottom: 1px solid #e5e7eb;
        border-radius: 12px 12px 0 0;
        font-weight: 600;
        font-size: 12px;
        text-transform: uppercase;
        color: #6b7280;
        letter-spacing: 0.04em;
    }
    .documents-list-header-doc { flex: 1 1 auto; min-width: 0; }
    .documents-list-header-amt { flex: none; text-align: right; }
    .documents-list-header-act { flex: none; width: 44px; }
    .document-row {
        display: flex;
        align-items: center;
        gap: 12px;
        min-height: 44px;
        padding: 16px;
        border-bottom: 1px solid #f3f4f6;
        background: #fff;
        cursor: pointer;
        transition: background-color 150ms ease;
    }
    .document-row:last-child { border-bottom: none; }
    .document-row:hover, .document-row:active { background: #f9fafb; }
    .document-row:focus-visible { outline: 2px solid var(--qina-primary, #0070ba); outline-offset: -2px; }
    .document-main { flex: 1 1 auto; min-width: 0; }
    .document-top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        margin-bottom: 4px;
    }
    .document-number {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
        font-weight: 700;
        font-size: 1rem;
        color: #111827;
        text-decoration: none;
    }
    .document-number:hover { text-decoration: underline; }
    .document-number .badge { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
    .document-amount {
        flex: none;
        font-weight: 700;
        font-size: 1rem;
        color: #111827;
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
    }
    .document-bottom { display: flex; align-items: center; }
    .document-meta {
        font-size: 0.875rem;
        color: #6b7280;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .document-actions { flex: none; align-self: center; text-align: right; }
    /* Touch-friendly kebab: 44px target, 24px icon */
    .kebab-menu { position: relative; display: inline-block; }
    .kebab-menu .btn-icon-action { min-width: 44px; min-height: 44px; }
    .kebab-menu .btn-icon-action svg { width: 24px; height: 24px; }
    .kebab-dropdown { animation: dropdownIn 120ms ease; }
    /* Last rows open upward so the menu never clips off-screen */
    .document-row:nth-last-child(-n+3) .kebab-dropdown {
        top: auto;
        bottom: calc(100% + 4px);
        margin-top: 0;
        margin-bottom: 4px;
    }
    .documents-empty { padding: 2rem 1rem; text-align: center; color: var(--qina-text-secondary, #6b7280); font-size: 0.9rem; }
    [data-theme="dark"] .documents-list { background: var(--qina-card); }
    [data-theme="dark"] .documents-list-header { background: #1c2534; border-bottom-color: var(--qina-border); color: #9aa7b8; }
    [data-theme="dark"] .document-row { background: var(--qina-card); border-bottom-color: var(--qina-border); }
    [data-theme="dark"] .document-row:hover, [data-theme="dark"] .document-row:active { background: #222d3f; }
    [data-theme="dark"] .document-number, [data-theme="dark"] .document-amount { color: var(--qina-text); }
    [data-theme="dark"] .document-meta { color: #9aa7b8; }
}

/* Screen-reader-only helper */.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* On-screen document preview (invoice / quotation / receipt view pages).
   The actual document HTML (?format=html) is fetch-injected here because
   mobile browsers will not render PDFs inside iframes. In normal flow, so
   the bottom nav is never covered. */
.preview-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 12px; }
.invoice-preview-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    margin: 0 0 16px;
    min-height: 320px;
}
.invoice-preview-frame {
    display: block;
    width: 100%;
    min-height: 320px;
    border: 0;
    border-radius: 4px;
    background: #fff;
}
.invoice-preview-frame[hidden] { display: none; }
.invoice-preview-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 64px 16px;
    color: #6b7280;
    font-size: 0.9rem;
}
.invoice-preview-loading[hidden], .invoice-preview-error[hidden], .invoice-preview-doc[hidden] { display: none; }
.spinner {
    width: 22px;
    height: 22px;
    flex: none;
    border-radius: 50%;
    border: 3px solid #e5e7eb;
    border-top-color: var(--qina-primary, #0070ba);
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.invoice-preview-error { text-align: center; padding: 48px 16px; }
.invoice-preview-error p { margin: 0 0 12px; }
@media (max-width: 767px) {
    .invoice-preview-container { padding: 8px; border-radius: 8px; }
}
[data-theme="dark"] .invoice-preview-container { background: #1c2534; border-color: var(--qina-border); }
[data-theme="dark"] .invoice-preview-loading { color: #9aa7b8; }
