:root {
    --primary: #0f766e;
    --primary-dark: #0d5f59;
    --primary-light: #14b8a6;
    --accent: #f59e0b;
    --accent-soft: #fef3c7;
    --success: #059669;
    --danger: #dc2626;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --sidebar-width: 280px;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Cairo', sans-serif;
    color: var(--text);
    background: #eef2f7;
    min-height: 100vh;
}

.loading-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: linear-gradient(135deg, #ecfeff 0%, #f8fafc 100%);
}

/* App shell */
.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #115e59 0%, #0f766e 45%, #134e4a 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1040;
    box-shadow: var(--shadow-lg);
    transition: transform 0.25s ease;
}

.sidebar-brand {
    padding: 1.5rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
}

.sidebar-brand p {
    margin: 0.35rem 0 0;
    font-size: 0.82rem;
    opacity: 0.78;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.nav-section-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.65;
    padding: 0.75rem 0.75rem 0.35rem;
    font-weight: 700;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.72rem 0.85rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.88);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.sidebar-link.active {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.sidebar-link .bi {
    font-size: 1.05rem;
    opacity: 0.9;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: grid;
    place-items: center;
    font-weight: 700;
}

.main-area {
    flex: 1;
    margin-right: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.page-content {
    padding: 1.5rem;
    flex: 1;
}

/* Page header */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h2 {
    margin: 0;
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--text);
}

.page-header p {
    margin: 0.35rem 0 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: center;
}

/* Cards & panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.panel-body {
    padding: 1.5rem;
}

.panel-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
    box-shadow: var(--shadow-sm);
}

.filter-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.15rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: var(--primary-light);
}

.stat-card.accent::before { background: var(--accent); }
.stat-card.success::before { background: var(--success); }

.stat-card span {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.stat-card strong {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text);
}

.stat-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: rgba(15, 118, 110, 0.1);
    color: var(--primary);
    display: grid;
    place-items: center;
    margin-bottom: 0.65rem;
    font-size: 1.1rem;
}

.stat-card.accent .stat-card-icon {
    background: var(--accent-soft);
    color: var(--accent);
}

.stat-card.success .stat-card-icon {
    background: rgba(5, 150, 105, 0.12);
    color: var(--success);
}

/* Dashboard */
.dashboard-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 220px;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.dashboard-charts {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 1rem;
}

.dashboard-split {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 1rem;
}

.stats-grid-sm {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chart-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.chart-panel-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
}

.chart-panel-header p {
    margin: 0.25rem 0 0;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.chart-canvas-wrap {
    position: relative;
    height: 280px;
    margin-top: 1rem;
}

.chart-empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.chart-empty .bi {
    font-size: 2rem;
    opacity: 0.45;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.panel-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
}

.panel-subtitle {
    margin: 0.2rem 0 0;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.table-total-row td {
    background: var(--surface-muted);
    border-top: 2px solid var(--border);
    font-weight: 700;
}

.clickable-row {
    cursor: pointer;
}

.clickable-row:hover td {
    background: rgba(15, 118, 110, 0.04);
}

.mobile-card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.mobile-card-link:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
}

/* Forms */
.form-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.4rem;
}

.form-control,
.form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    background: #fff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 0.2rem rgba(20, 184, 166, 0.15);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

/* Buttons */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 700;
    padding: 0.62rem 1.1rem;
    transition: transform 0.12s, box-shadow 0.12s;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border: none;
    box-shadow: 0 4px 14px rgba(15, 118, 110, 0.25);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2dd4bf, var(--primary-dark));
}

.btn-outline-secondary {
    border-color: var(--border);
    color: var(--text-muted);
}

.btn-danger-soft {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.btn-danger-soft:hover {
    background: #fee2e2;
    color: #b91c1c;
}

.btn-logout {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

/* Tables */
.table-panel {
    overflow: hidden;
}

.data-table {
    width: 100%;
    margin: 0;
}

.data-table thead th {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    padding: 0.9rem 1rem;
    white-space: nowrap;
}

.data-table tbody td {
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.money {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--primary-dark);
}

/* Badges */
.badge-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-in {
    background: #ecfdf5;
    color: #047857;
}

.badge-out {
    background: #fef2f2;
    color: #b91c1c;
}

/* Alerts */
.app-alert {
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.app-alert-danger {
    background: #fef2f2;
    color: #991b1b;
}

.app-alert-success {
    background: #ecfdf5;
    color: #065f46;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state .bi {
    font-size: 2.5rem;
    opacity: 0.35;
    margin-bottom: 0.75rem;
}

/* Mobile cards */
.mobile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-sm);
}

.mobile-card + .mobile-card {
    margin-top: 0.85rem;
}

/* Login */
.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
}

.login-hero {
    background: linear-gradient(145deg, #0f766e 0%, #115e59 40%, #134e4a 100%);
    color: #fff;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-hero::after {
    content: "";
    position: absolute;
    width: 420px;
    height: 420px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    top: -120px;
    left: -120px;
}

.login-hero h1 {
    font-size: 2.4rem;
    font-weight: 800;
    margin-bottom: 1rem;
    position: relative;
}

.login-hero p {
    font-size: 1.05rem;
    opacity: 0.88;
    max-width: 420px;
    line-height: 1.8;
    position: relative;
}

.login-features {
    margin-top: 2rem;
    display: grid;
    gap: 0.85rem;
    position: relative;
}

.login-feature {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
}

.login-form-area {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: #f8fafc;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border-radius: calc(var(--radius) + 4px);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    border: 1px solid var(--border);
}

.login-card h2 {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 0.35rem;
}

.login-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 1.75rem;
}

.sidebar-overlay {
    display: none;
}

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        z-index: 1035;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s;
    }

    .sidebar-overlay.show {
        opacity: 1;
        pointer-events: auto;
    }

    .main-area {
        margin-right: 0;
    }

    .topbar {
        display: flex;
    }

    .page-content {
        padding: 1rem;
    }

    .login-shell {
        grid-template-columns: 1fr;
    }

    .login-hero {
        display: none;
    }
}

@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    .btn {
        min-height: 44px;
    }

    .page-header h2 {
        font-size: 1.35rem;
    }

    .dashboard-charts {
        grid-template-columns: 1fr;
    }

    .dashboard-split {
        grid-template-columns: 1fr;
    }

    .stats-grid-sm {
        grid-template-columns: 1fr;
    }
}
