/* ============================================
   HEC SACCO — Professional Design System
   Matches reference dashboard screenshot
   ============================================ */

/* --- CSS Variables --- */
:root {
    --primary: #1e3a8a;
    --primary-hover: #172554;
    --primary-soft: rgba(30, 58, 138, 0.08);
    --accent: #05cd99;

    --bg-body: #f4f7fe;
    --bg-card: #ffffff;
    --bg-sidebar: #1e3a8a;
    --sidebar-text: rgba(255, 255, 255, 0.7);
    --sidebar-hover: rgba(255, 255, 255, 0.1);

    --text-main: #1b2559;
    --text-muted: #a3aed0;

    --border: #e9edf7;
    --input-bg: #ffffff;

    --success: #05cd99;
    --warning: #ffb547;
    --danger: #ee5d50;
    --info: #4318ff;

    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1.25rem;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] {
    --bg-body: #0b1437;
    --bg-card: #111c44;
    --bg-sidebar: #0b1437;
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
    --border: #1b254b;
    --input-bg: #111c44;
}

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

body {
    background: var(--bg-body);
    color: var(--text-main);
    font-family: 'DM Sans', 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

/* --- Layout --- */
.layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 220px;
    background: var(--bg-sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 50;
}

.sidebar-header {
    padding: 1.25rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header h1 {
    font-size: 0.95rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.logo-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.sidebar nav {
    flex: 1;
    padding: 0.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 1rem 0.75rem 0.4rem;
    font-weight: 700;
    opacity: 0.6;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    color: var(--sidebar-text);
    font-weight: 600;
    font-size: 0.85rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.sidebar nav a i,
.sidebar nav a svg {
    width: 18px;
    height: 18px;
}

.sidebar nav a:hover {
    color: #fff;
    background: var(--sidebar-hover);
}

.sidebar nav a.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    font-weight: 700;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.sidebar-footer a:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* --- Main Content --- */
.main-content {
    margin-left: 220px;
    padding: 0;
    min-height: 100vh;
    width: calc(100% - 220px);
    background: var(--bg-body);
}

/* --- Top Bar --- */
.top-bar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 40;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-main);
    padding: 0.25rem;
}

.currency-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.6rem;
    border-radius: 8px;
    background: var(--bg-body);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-main);
}

.currency-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    z-index: 100;
    min-width: 120px;
    margin-top: 0.25rem;
}

.currency-dropdown.show {
    display: block;
}

.currency-dropdown a {
    display: block;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    color: var(--text-main);
}

.currency-dropdown a:hover {
    background: var(--bg-body);
}

.currency-dropdown a.active {
    background: var(--bg-body);
    font-weight: 700;
}

.top-bar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem;
    border-radius: 8px;
    background: var(--bg-body);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
}

.user-avatar {
    width: 30px;
    height: 30px;
    background: var(--warning);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.75rem;
}

/* ================================
   Dashboard Page Styles
   ================================ */

/* Stat Cards Row — exactly like the reference: 7 cards in a scrollable row */
.dash-stats {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.dash-stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    min-width: 150px;
    flex: 1;
    box-shadow: var(--shadow-sm);
}

.dash-stat .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.dash-stat .label i {
    width: 14px;
    height: 14px;
}

.dash-stat .value {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-main);
    white-space: nowrap;
}

.dash-stat .trend {
    font-size: 0.65rem;
    font-weight: 700;
    margin-top: 0.2rem;
}

.trend-up {
    color: var(--success);
}

.trend-down {
    color: var(--danger);
}

/* Dashboard Content Container */
.dash-content {
    padding: 1rem 1.5rem;
}

/* Two-column: Charts top row */
.dash-row {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

.dash-row-2 {
    grid-template-columns: 2.5fr 1fr;
}

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

.dash-row-split {
    grid-template-columns: 2.5fr 1fr;
}

/* Card */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.card h3 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-filters {
    display: flex;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.card-filters span {
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 600;
}

.card-filters span.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

/* Chart Container */
.chart-box {
    position: relative;
    width: 100%;
}

/* Tables */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    padding: 0.6rem 0.75rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    text-align: left;
    border-bottom: 1px solid var(--border);
    background: transparent;
}

td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-main);
}

tr:hover td {
    background: var(--primary-soft);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: capitalize;
}

.badge-success {
    background: var(--success);
    color: white;
}

.badge-warning {
    background: var(--warning);
    color: white;
}

.badge-info {
    background: var(--info);
    color: white;
}

.badge-danger {
    background: var(--danger);
    color: white;
}

.badge-online {
    background: rgba(5, 205, 153, 0.1);
    color: var(--success);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
}

.badge-offline {
    background: rgba(163, 174, 208, 0.1);
    color: var(--text-muted);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
}

/* Export Buttons */
.export-btns {
    display: flex;
    gap: 0.35rem;
}

.export-btns button {
    background: var(--bg-body);
    border: 1px solid var(--border);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.export-btns button:hover {
    background: var(--border);
}

/* Action buttons in table */
.action-btn {
    background: var(--bg-sidebar);
    color: white;
    border: none;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.6rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

/* Alerts Section */
.alert-item {
    padding: 0.6rem;
    font-size: 0.75rem;
    line-height: 1.4;
    border-bottom: 1px solid var(--border);
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.35rem;
}

.dot-danger {
    background: var(--danger);
}

.dot-warning {
    background: var(--warning);
}

/* Financial Health Card */
.health-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Footer Alerts Bar */
.footer-alerts {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.footer-alerts .fa-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-sidebar);
    color: white;
}

.btn-success {
    background: var(--success);
}

.btn-danger {
    background: var(--danger);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-body);
}

/* Form Inputs */
input,
select,
textarea {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 100%;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 0.85rem;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Container */
.container {
    max-width: 100%;
    padding: 1.25rem 1.5rem;
}

/* Grid utility */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-weight: 500;
    font-size: 0.85rem;
}

.alert-success {
    background: rgba(5, 205, 153, 0.1);
    color: #059669;
    border: 1px solid rgba(5, 205, 153, 0.2);
}

.alert-error {
    background: rgba(238, 93, 80, 0.1);
    color: #dc2626;
    border: 1px solid rgba(238, 93, 80, 0.2);
}

.alert-warning {
    background: rgba(255, 181, 71, 0.1);
    color: #d97706;
    border: 1px solid rgba(255, 181, 71, 0.2);
}

/* Auth Pages */
.auth-page {
    background: #0f172a;
    background-image:
        radial-gradient(at 0% 0%, hsla(243, 75%, 59%, 0.15) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(263, 90%, 66%, 0.1) 0, transparent 50%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    padding: 2rem;
}

.auth-wrapper {
    width: 100%;
    max-width: 450px;
}

.auth-wrapper .card {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    color: white;
}

.auth-wrapper h1,
.auth-wrapper h2 {
    color: #fff;
    font-weight: 800;
}

.auth-wrapper .text-muted {
    color: #94a3b8;
}

.auth-wrapper input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
}

.auth-wrapper .btn {
    width: 100%;
    padding: 0.8rem;
    margin-top: 0.75rem;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
}

.auth-header-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.auth-logo-circle {
    min-width: 64px;
    height: 64px;
    padding: 0 1.5rem;
    background: var(--primary);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
    box-shadow: 0 10px 25px -5px rgba(79, 70, 229, 0.5);
}

/* App Footer */
.app-footer {
    display: flex;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}

/* Center utility */
.center {
    text-align: center;
}

/* Stat (legacy support) */
.stat {
    background: var(--bg-card);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.stat .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.stat .label i {
    width: 16px;
    height: 16px;
}

.stat .value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main);
}

/* Badge online (legacy) */
.badge-online {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    background: rgba(5, 205, 153, 0.15);
    color: #05cd99;
    font-size: 0.65rem;
    border-radius: 1rem;
    font-weight: 700;
    text-transform: uppercase;
}

/* Chart container */
.chart-container {
    position: relative;
    height: 250px;
}

/* Card h2 (legacy) */
.card h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Landing Page */
.landing-page {
    background: var(--bg-body);
}

.landing-header {
    background: var(--bg-card);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--border);
}

.hero {
    padding: 6rem 0;
    background: linear-gradient(135deg, var(--bg-sidebar), #1e293b);
    color: #fff;
    position: relative;
    overflow: hidden;
}

.hero::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: url('https://www.transparenttextures.com/patterns/cubes.png');
    opacity: 0.05;
}

.hero-content {
    max-width: 800px;
}

.hero h1 {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 1.5rem;
    background: linear-gradient(to right, #fff, var(--sidebar-text));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero p {
    font-size: 1.15rem;
    color: var(--sidebar-text);
    margin-bottom: 2rem;
    line-height: 1.6;
}

.section {
    padding: 5rem 0;
}

.section-header {
    text-align: center;
    max-width: 600px;
    margin: 0 auto 3rem;
}

.section-header h2 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1rem;
}

.service-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.service-card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: all 0.3s;
}

.service-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.service-icon {
    width: 48px;
    height: 48px;
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.service-card h3 {
    font-size: 1.15rem;
    margin-bottom: 0.75rem;
    font-weight: 700;
}

.service-card p {
    color: var(--text-muted);
    line-height: 1.6;
}

.cta-section {
    background: var(--primary);
    color: #fff;
    text-align: center;
    border-radius: 1.5rem;
    padding: 3rem;
    margin: 3rem 0;
}

.cta-section h2 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1rem;
}

.landing-footer {
    background: var(--bg-sidebar);
    color: var(--sidebar-text);
    padding: 3rem 0 1.5rem;
}

.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-col h4 {
    color: #fff;
    margin-bottom: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
}

.footer-col ul {
    list-style: none;
}

.footer-col ul li {
    margin-bottom: 0.5rem;
}

.footer-col ul li a:hover {
    color: #fff;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Quick Insight */
.quick-insight {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 1rem;
}

.insight-up {
    color: #05cd99;
    background: rgba(5, 205, 153, 0.1);
}

.insight-down {
    color: #ee5d50;
    background: rgba(238, 93, 80, 0.1);
}

/* Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ================================
   Responsive
   ================================ */

@media (max-width: 1200px) {
    .dash-row-4 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 70px;
    }

    .sidebar-header h1,
    .sidebar nav a span,
    .sidebar-footer span,
    .nav-section-label {
        display: none;
    }

    .sidebar-header {
        justify-content: center;
        padding: 1rem 0.5rem;
    }

    .sidebar nav a {
        justify-content: center;
        padding: 0.6rem;
    }

    .main-content {
        margin-left: 70px;
        width: calc(100% - 70px);
    }

    .dash-row-2,
    .dash-row-split {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
        width: 220px;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-header h1,
    .sidebar nav a span,
    .sidebar-footer span,
    .nav-section-label {
        display: block;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .mobile-menu-btn {
        display: block;
    }

    .dash-stats {
        padding: 0.75rem;
    }

    .dash-content {
        padding: 0.75rem;
    }

    .dash-row-2,
    .dash-row-4,
    .dash-row-split {
        grid-template-columns: 1fr;
    }

    .top-bar {
        padding: 0.5rem 0.75rem;
    }

    .app-footer {
        flex-direction: column;
        gap: 0.25rem;
        text-align: center;
    }
}

/* ============================================================
   RESPONSIVE HARDENING — Full device coverage (320px → 4K)
   ============================================================ */

/* Global: prevent horizontal overflow on any screen size */
html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

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

/* Ensure grid / flex children never force their parent wider */
.dash-row > *,
.grid > *,
.dash-stats > * {
    min-width: 0;
}

/* Prevent main area from overflowing */
.main-content {
    overflow-x: hidden;
}

/* ── Sidebar overlay (mobile) ─────────────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 49;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    cursor: pointer;
}
.sidebar-overlay.show {
    display: block;
}

/* ── 1025px + (full desktop) ──────────────────────────────────────────── */
@media (min-width: 1025px) {
    .dash-row-2  { grid-template-columns: 2.5fr 1fr; }
    .dash-row-split { grid-template-columns: 2.5fr 1fr; }
}

/* ── 768px – 1024px (tablet, sidebar is icon-only 70px) ──────────────── */
@media (min-width: 768px) and (max-width: 1024px) {
    /* Restore 2-column layout on tablet */
    .dash-row-2,
    .dash-row-split {
        grid-template-columns: 1fr 1fr;
    }
    .dash-stat {
        min-width: 110px;
    }
    .dash-stat .value {
        font-size: 1rem;
    }
    .card-filters span {
        font-size: 0.7rem;
    }
}

/* ── Below 768px (phones) ─────────────────────────────────────────────── */
@media (max-width: 767px) {

    /* Stat cards: 2-column grid (no horizontal scroll) */
    .dash-stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
        overflow-x: unset;
        -webkit-overflow-scrolling: unset;
        padding: 0.75rem 0.75rem 0;
    }
    .dash-stat {
        min-width: 0;
        flex: none;
    }

    /* Dashboard rows → single column */
    .dash-row-2,
    .dash-row-4,
    .dash-row-split {
        grid-template-columns: 1fr;
    }

    /* Reduce chart heights on phones */
    .chart-box {
        height: 200px !important;
    }

    /* Card header: wrap filter tabs */
    .card-header {
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    .card-filters {
        flex-wrap: wrap;
        gap: 0.2rem;
    }

    /* Padding reduction */
    .dash-content { padding: 0.75rem; }
    .container    { padding: 0.75rem; }
    .card         { padding: 0.875rem; }

    /* Top bar — hide non-critical icons (feather replaces <i> with <svg>) */
    .top-bar { padding: 0.5rem 0.75rem; }
    .top-bar-right > svg          { display: none; }   /* bell & moon direct SVG children */
    .top-bar-user > span          { display: none; }   /* username text */
    .currency-toggle > span       { display: none; }   /* currency code text */
    .top-bar-right                { gap: 0.5rem; }

    /* General grid → 1 column */
    .grid { grid-template-columns: 1fr; }

    /* Footer */
    .app-footer {
        flex-direction: column;
        gap: 0.25rem;
        text-align: center;
    }

    /* Tables: always scrollable */
    .table-scroll-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Auth page */
    .auth-page  { padding: 1rem; }
    .hero h1    { font-size: 2rem; }
    .hero p     { font-size: 1rem; }
    .section    { padding: 3rem 0; }
}

/* ── Below 480px (small phones: iPhone SE, Galaxy A series) ──────────── */
@media (max-width: 479px) {
    .top-bar          { padding: 0.4rem 0.5rem; }
    .dash-content     { padding: 0.5rem; }
    .container        { padding: 0.5rem; }
    .card             { padding: 0.75rem; }
    .card h3          { font-size: 0.8rem; }

    .dash-stat        { padding: 0.6rem 0.75rem; }
    .dash-stat .value { font-size: 0.88rem; white-space: normal; word-break: break-word; }
    .dash-stat .label { font-size: 0.62rem; }
    .dash-stat .trend { font-size: 0.6rem; }

    .chart-box { height: 170px !important; }

    .export-btns button { font-size: 0.6rem; padding: 0.15rem 0.35rem; }

    /* Tables: min-width so columns are still readable when scrolled */
    table { min-width: 520px; }
}

/* ── Touch / hover improvements for all mobile ───────────────────────── */
@media (hover: none) and (pointer: coarse) {
    .sidebar nav a  { padding: 0.75rem; }   /* larger tap targets */
    .action-btn     { padding: 0.35rem 0.6rem; }
    .btn            { min-height: 44px; }   /* Apple/Google touch target min */
    input, select, textarea { min-height: 44px; font-size: 16px; } /* prevent iOS zoom on focus */
}

/* ── Mobile menu button — always visible, prominent tap target ── */
.mobile-menu-btn {
    display: none;          /* hidden on desktop (overridden at 768px) */
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: var(--bg-body);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-main);
    padding: 0;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn:active {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex !important;  /* force-override any conflicting rule */
    }
}
