:root {
    /* BizNexa brand blue, sampled from the logo's gradient */
    --primary: #0066fc;
    --primary-hover: #0050c8;
    --primary-tint: #e5f0ff;
    --primary-tint-border: #b8d9ff;
    --brand-accent: #69d702; /* logo's lime-green accent (arrow, chart bars) */
    --danger: #a32d2d;
    --danger-hover: #791f1f;
    --success: #16a34a;
    --success-dark: #15803d;
    --warning: #ba7517;
    --info: #185fa5;
    --muted-status: #888780;
    --background: #f4f3ef;
    --surface: #fff;
    --surface-muted: var(--background);
    --border: #ddd;
    --border-light: #eee;
    --text-primary: #222;
    --text-secondary: #555;
    --text-muted: #888;
    --sidebar-bg: #0a1f44;
    --sidebar-bg-hover: #14305e;
    --radius: 6px;
    --radius-lg: 10px;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    overflow-x: hidden;
}
.center-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 32px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.04);
}
.card h1 {
    font-size: 20px;
    margin: 0 0 4px;
    text-align: center;
}
.login-logo {
    display: block;
    max-width: 220px;
    width: 100%;
    height: auto;
    margin: 0 auto;
}
.app-credit-line {
    text-align: center;
    font-size: 11px;
    color: #999;
    margin: 18px 0 0;
}
.app-credit-line-footer {
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #fff;
    padding: 12px 24px;
    background: linear-gradient(90deg, var(--sidebar-bg), var(--primary));
    position: fixed;
    bottom: 0;
    left: 220px;
    right: 0;
    z-index: 40;
}
.card p.subtitle {
    text-align: center;
    color: #777;
    font-size: 13px;
    margin: 0 0 24px;
}
label {
    display: block;
    font-size: 13px;
    color: #444;
    margin-bottom: 6px;
}
input[type=text], input[type=password] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
}
input[type=text]:focus, input[type=password]:focus {
    outline: none;
    border-color: var(--primary);
}
/* Stacked-field spacing belongs to login-style centered forms only — everywhere
   else (search bars, inline form rows) already manages its own spacing, and this
   bare rule used to leak a stray margin-bottom onto those, breaking alignment
   with sibling buttons (e.g. .search-bar). */
.center-screen input[type=text], .center-screen input[type=password] {
    margin-bottom: 16px;
}
.center-screen button {
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.center-screen button:hover { background: var(--primary-hover); }
.error-box {
    background: #fbe9e9;
    color: var(--danger);
    border: 1px solid #f0c7c7;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}
.success-box {
    background: #e8f0fe;
    color: var(--primary-hover);
    border: 1px solid #bfdbfe;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* App shell: sidebar + main area */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    color: #eee;
    flex-shrink: 0;
    padding: 20px 0;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    margin: 14px 16px 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.sidebar-logo { width: 75%; max-width: 190px; min-width: 120px; height: auto; display: block; margin: 0 auto; }

.sidebar nav { display: flex; flex-direction: column; padding: 0 10px; }
.nav-icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-link {
    color: #ccc;
    text-decoration: none;
    padding: 10px 12px;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 8px;
    margin-bottom: 2px;
    position: relative;
}
.nav-link:hover { background: var(--sidebar-bg-hover); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link.active .nav-icon { opacity: 1; }

/* Collapsible nav groups (native <details>/<summary> — no JS needed) */
.nav-group { margin-bottom: 2px; }
.nav-group summary {
    list-style: none;
    cursor: pointer;
    color: #ccc;
    padding: 10px 12px;
    font-size: 13.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 8px;
    user-select: none;
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after {
    content: '';
    width: 6px;
    height: 6px;
    border-right: 1.6px solid currentColor;
    border-bottom: 1.6px solid currentColor;
    transform: rotate(-45deg);
    margin-left: auto;
    opacity: 0.6;
    transition: transform 0.15s;
}
.nav-group[open] summary::after { transform: rotate(45deg); }
.nav-group summary:hover { background: var(--sidebar-bg-hover); color: #fff; }
.nav-subgroup { display: flex; flex-direction: column; padding: 2px 0 4px 14px; }
.nav-subgroup .nav-link { padding: 8px 12px; font-size: 13px; color: #b8b8b2; }
.nav-subgroup .nav-link:hover { color: #fff; }
.nav-subgroup .nav-link.active { color: #fff; background: var(--sidebar-bg-hover); box-shadow: inset 2px 0 0 var(--primary); }

.nav-section-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #6f6f68;
    padding: 16px 12px 6px;
}

.nav-badge {
    background: var(--danger);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1;
    padding: 2.5px 6px;
    border-radius: 10px;
    margin-left: auto;
}

.main-area { flex: 1; min-width: 0; }
.topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.topbar a { color: var(--text-secondary); text-decoration: none; font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-bell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text-secondary);
}
.topbar-bell:hover { background: var(--background); }
.topbar-bell svg { width: 19px; height: 19px; }
.topbar-bell-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    background: var(--danger);
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    line-height: 1;
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}
.topbar-user { display: flex; align-items: center; gap: 10px; padding-left: 4px; border-left: 1px solid #e5e5e0; }
.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.topbar-avatar-sa { background: var(--sidebar-bg); }
.topbar-user-text { line-height: 1.3; }
.topbar-user-name { font-size: 13px; font-weight: 600; color: #222; }
.topbar-user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.topbar-logout { padding: 8px 4px; }

.topbar-user-menu { position: relative; }
.topbar-user-trigger { background: none; border: none; cursor: pointer; padding: 0; font: inherit; }
.topbar-user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    z-index: 30;
    overflow: hidden;
}
.topbar-user-dropdown.open { display: block; }
.topbar-user-dropdown-header { padding: 12px 14px; border-bottom: 1px solid var(--border-light); }
.topbar-user-dropdown-name { font-size: 13px; font-weight: 600; color: #222; }
.topbar-user-dropdown-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; margin-top: 2px; }
.topbar-user-dropdown a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
}
.topbar-user-dropdown a .nav-icon { width: 16px; height: 16px; opacity: 1; }
.topbar-user-dropdown a:hover { background: var(--background); }
.topbar-user-dropdown a.danger { color: var(--danger); }
.container { max-width: 1100px; padding: 24px; padding-bottom: 56px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-top: 20px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.stat-card .label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 22px; font-weight: 700; }

/* Tables */
.table-wrap { background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-top: 16px; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
    background: var(--background);
    text-align: left;
    padding: 10px 14px;
    font-size: 12px;
    color: #666;
    border-bottom: 1px solid var(--border);
}
table.data-table td { padding: 10px 14px; border-bottom: 1px solid #eee; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover { background: #fafaf8; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.page-header h2 { margin: 0; }

.btn {
    display: inline-block;
    padding: 8px 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.65; cursor: not-allowed; }
.btn-secondary { background: #fff; color: #333; border: 1px solid #ccc; }
.btn-secondary:hover { background: var(--background); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.badge { font-size: 11px; padding: 3px 9px; border-radius: 10px; color: #fff; }
.badge-draft { background: var(--muted-status); }
.badge-pending_approval { background: var(--warning); }
.badge-approved { background: var(--info); }
.badge-rejected { background: var(--danger); }
.badge-sent { background: #3b6d11; }
.badge-viewed { background: var(--info); }
.badge-accepted { background: var(--success); }
.badge-expired { background: var(--muted-status); }
.badge-cancelled { background: #6b6b66; }
.badge-converted { background: var(--success-dark); }

.form-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 24px; margin-top: 16px; max-width: 640px; }
.form-row { margin-bottom: 16px; }
.form-row label { display:block; font-size: 13px; color:#444; margin-bottom:6px; }
.form-row input[type=text], .form-row input[type=number], .form-row input[type=email],
.form-row input[type=password], .form-row input[type=date], .form-row select, .form-row textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.form-row textarea { min-height: 90px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.layout-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.layout-option {
    display: block;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
}
.layout-option:hover { border-color: var(--primary); }
.layout-option.selected { border-color: var(--primary); background: #eef4ff; }
.layout-option input[type=radio] { position: absolute; top: 12px; right: 12px; }
.layout-option-name { font-weight: 600; font-size: 13.5px; margin-bottom: 4px; padding-right: 18px; }
.layout-option-desc { font-size: 11.5px; color: #777; line-height: 1.4; }

.template-form-layout { display: flex; gap: 20px; align-items: flex-start; margin-top: 16px; }
.template-form-layout .form-card { margin-top: 0; flex: 1 1 480px; }
.template-preview-pane { flex: 1 1 420px; position: sticky; top: 16px; }
.template-preview-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }
.template-preview-frame-wrap { background: #e5e5e0; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.template-preview-frame { width: 100%; height: 640px; border: none; background: #fff; border-radius: 4px; box-shadow: 0 1px 6px rgba(0,0,0,0.12); }

@media (max-width: 1100px) {
    .template-form-layout { flex-direction: column; }
    .template-preview-pane { position: static; width: 100%; }
}
.checkbox-row { display:flex; align-items:center; gap:8px; font-size: 13px; }
.perm-matrix-wrap { max-width: 640px; }
.perm-matrix th, .perm-matrix td { padding: 8px 10px; }
.perm-matrix input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.search-bar { margin: 16px 0 0; display:flex; gap:8px; }
.search-bar input { padding: 8px 12px; border:1px solid #ccc; border-radius:6px; font-size:13px; width:260px; }
.tab-row { display:flex; gap:6px; margin-top: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tab-row::-webkit-scrollbar { display: none; }
.tab-link { padding: 6px 14px; border-radius: 16px; font-size: 12px; text-decoration:none; color:var(--text-secondary); border:1px solid var(--border); white-space: nowrap; flex-shrink: 0; }
.tab-link.active { background:var(--sidebar-bg); color:#fff; border-color:var(--sidebar-bg); }
.detail-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top:16px; }
.detail-card { background:#fff; border:1px solid var(--border); border-radius:10px; padding:16px 18px; }
.detail-card h4 { margin: 0 0 10px; font-size: 13px; color:var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.action-row { display:flex; gap:8px; margin-top:16px; flex-wrap: wrap; }

/* Super Admin authentication screens */
.sa-auth-body {
    margin: 0;
    min-height: 100vh;
    background: #14140f;
    background-image: radial-gradient(circle at 50% 0%, #24241d 0%, #14140f 60%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.sa-auth-wrap { width: 100%; max-width: 400px; }
.sa-auth-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px 36px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.35);
    text-align: center;
}
.sa-auth-logo { max-width: 200px; margin-bottom: 16px; }
.sa-auth-eyebrow {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
    margin: 0 0 8px;
}
.sa-auth-title { font-size: 22px; font-weight: 700; color: var(--sidebar-bg); margin: 0 0 6px; }
.sa-auth-subtitle { font-size: 13px; color: #777; line-height: 1.5; margin: 0 0 28px; }
.sa-field { text-align: left; margin-bottom: 18px; }
.sa-field label { display: block; font-size: 13px; font-weight: 600; color: #333; margin-bottom: 6px; }
.sa-field input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.sa-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29,158,117,0.14);
}
.sa-auth-card .btn { width: 100%; padding: 12px; font-size: 14px; margin-top: 6px; }
.sa-auth-footnote { font-size: 11px; color: #999; line-height: 1.5; margin: 24px 0 0; }
.sa-auth-error {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    text-align: left;
}
.sa-auth-error svg { flex-shrink: 0; margin-top: 1px; }

/* Charts */
.chart-card { background:#fff; border:1px solid var(--border); border-radius:10px; padding:18px 20px; margin-top:16px; }
.chart-card h4 { margin: 0 0 4px; font-size: 14px; }
.chart-card .chart-subtitle { margin: 0 0 12px; font-size: 12px; color: var(--text-muted); }
.bar-chart { width: 100%; height: 160px; overflow: visible; }
.chart-value { font-size: 10px; fill: var(--text-secondary); font-weight: 600; }
.chart-label { font-size: 10px; fill: var(--text-muted); }
.chart-empty { padding: 40px 0; text-align: center; color: #999; font-size: 13px; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.pagination-info { font-size: 12px; color: #777; }
.pagination-disabled { opacity: 0.4; pointer-events: none; }

/* Filter bar (search + selects on list pages) */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 0; align-items: center; }
.filter-bar input[type=text] { padding: 8px 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; width: 220px; }
.filter-bar select { padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; }
.sortable-th a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 4px; }
.sortable-th a:hover { color: var(--primary); }

/* Empty state */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state h4 { margin: 0 0 6px; color: var(--text-secondary); font-size: 15px; }
.empty-state p { margin: 0; font-size: 13px; }

/* Breadcrumb */
.breadcrumb { font-size: 12px; color: #999; margin: 4px 0 12px; }
.breadcrumb a { color: #999; text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); }

/* Detail page header */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-top: 4px; }
.detail-header h2 { margin: 0 0 6px; }
.detail-header-meta { display: flex; gap: 8px; align-items: center; }

/* Mobile navigation (hidden on desktop) */
.mobile-bottom-nav { display: none; }
.mobile-drawer-overlay { display: none; }
.mobile-drawer { display: none; }

/* ------------------------------------------------------------
   Responsive: tablet/mobile — the same app is later opened inside
   a staff WebView, so this must stay comfortably usable on a phone.
   ------------------------------------------------------------ */
@media (max-width: 860px) {
    .container { padding: 16px; padding-bottom: 76px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .form-grid-2 { grid-template-columns: 1fr; }
    .table-wrap { overflow-x: auto; }
    .table-wrap table.data-table { min-width: 640px; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .action-row { width: 100%; }
    .action-row .btn, .action-row form { flex: 1 1 auto; }

    /* Sidebar becomes a slide-out "More" panel instead of a fixed column */
    .app-shell { flex-direction: column; }
    .sidebar { display: none; }
    .main-area { width: 100%; }

    /* The fixed bottom nav already owns the bottom of the screen here — the
       credit line would otherwise sit behind it. */
    .app-credit-line-footer { display: none; }

    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--sidebar-bg);
        border-top: 1px solid #333;
        z-index: 50;
        padding: 6px 0;
    }
    .mobile-bottom-nav a {
        flex: 1;
        text-align: center;
        color: #ccc;
        text-decoration: none;
        font-size: 11px;
        padding: 6px 2px;
    }
    .mobile-bottom-nav a.active { color: var(--primary); }
    .mobile-bottom-nav a .mnav-icon { display: block; margin: 0 auto 2px; width: 20px; height: 20px; }
    .mobile-bottom-nav a .mnav-icon .nav-icon { width: 20px; height: 20px; opacity: 1; }
    .mobile-bottom-nav a.mnav-fab .mnav-icon {
        background: var(--primary); color: #fff; width: 30px; height: 30px; border-radius: 50%;
        display: flex; align-items: center; justify-content: center; margin: 0 auto 2px;
    }
    .mobile-bottom-nav a.mnav-fab .mnav-icon .nav-icon { width: 18px; height: 18px; }

    /* Off-canvas drawer: slides in from the left, covers the bottom nav while open */
    .mobile-drawer-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 60;
        opacity: 0;
        visibility: hidden;
        transition: opacity 200ms ease;
    }
    .mobile-drawer-overlay.open { opacity: 1; visibility: visible; }

    .mobile-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0; bottom: 0; left: 0;
        width: 82vw;
        max-width: 300px;
        background: var(--sidebar-bg);
        z-index: 61;
        transform: translateX(-100%);
        transition: transform 220ms ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    }
    .mobile-drawer.open { transform: translateX(0); }

    .mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 18px 16px;
        border-bottom: 1px solid rgba(255,255,255,0.1);
        flex-shrink: 0;
    }
    .mobile-drawer-close {
        background: none;
        border: none;
        color: #ccc;
        padding: 6px;
        border-radius: 6px;
        cursor: pointer;
        display: flex;
    }
    .mobile-drawer-close:hover { background: var(--sidebar-bg-hover); color: #fff; }
    .mobile-drawer-close svg { width: 20px; height: 20px; }

    .mobile-drawer-body { flex: 1; overflow-y: auto; padding: 10px 10px 20px; }
    .mobile-drawer-body nav { display: flex; flex-direction: column; }
    .mobile-drawer-body .nav-section-label { padding-left: 12px; }
}
