/* ===== CSS Variables ===== */
:root {
    --primary: #0891b2;
    --primary-dark: #0e7490;
    --primary-light: #22d3ee;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #f43f5e;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #1e293b;
    --light: #f8fafc;
    --white: #ffffff;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 20px;
    --transition: all 0.3s ease;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Roboto', sans-serif;
    min-height: 100vh;
    color: var(--dark);
    line-height: 1.6;
    background: linear-gradient(135deg, #f0fdfa 0%, #ecfeff 50%, #f0f9ff 100%);
    background-attachment: fixed;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

/* ===== Navbar ===== */
.navbar {
    background: var(--white);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 65px;
    box-shadow: 0 2px 20px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
}

.nav-brand i {
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 0.3rem;
}

.nav-menu a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    color: var(--gray-600);
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
}

.nav-menu a:hover,
.nav-menu a.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: var(--white);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.user-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--gray-600);
    font-weight: 500;
    font-size: 0.9rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: var(--gray-500);
    background: var(--gray-100);
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--primary);
    color: var(--white);
    transform: translateY(-2px);
}

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

/* ===== Mobile Menu Button ===== */
.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: var(--transition);
}

.nav-toggle:hover {
    background: var(--gray-100);
}

.nav-toggle span {
    display: block;
    width: 24px;
    height: 2.5px;
    background: var(--gray-600);
    border-radius: 2px;
    transition: var(--transition);
}

.nav-mobile-only {
    display: none;
}

/* ===== Container ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ===== Cards ===== */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    overflow: hidden;
}

.card-header {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
}

.card-header h2 {
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
}

.card-body {
    padding: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    background: var(--gray-100);
    border-top: 1px solid var(--gray-200);
}

/* ===== Stats Cards ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.2rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.3rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}

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

.stat-icon {
    width: 55px;
    height: 55px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: var(--white);
    flex-shrink: 0;
}

.stat-icon.blue { background: linear-gradient(135deg, #3b82f6, #60a5fa); }
.stat-icon.green { background: linear-gradient(135deg, #10b981, #34d399); }
.stat-icon.orange { background: linear-gradient(135deg, #f97316, #fb923c); }
.stat-icon.purple { background: linear-gradient(135deg, #0891b2, #22d3ee); }
.stat-icon.red { background: linear-gradient(135deg, #f43f5e, #fb7185); }
.stat-icon.teal { background: linear-gradient(135deg, #14b8a6, #2dd4bf); }

.stat-info h3 {
    font-size: 0.8rem;
    color: var(--gray-500);
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.stat-info .stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--dark);
}

.stat-info .stat-change {
    font-size: 0.75rem;
    margin-top: 0.2rem;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.stat-change.positive { color: var(--success); background: rgba(16, 185, 129, 0.1); }
.stat-change.negative { color: var(--danger); background: rgba(244, 63, 94, 0.1); }

.stat-card-success { border-left: 4px solid var(--success); }
.stat-card-danger { border-left: 4px solid var(--danger); }
.stat-card-primary { border-left: 4px solid var(--primary); }
.stat-card-warning { border-left: 4px solid var(--warning); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.3rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: var(--white);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: var(--white);
    box-shadow: 0 4px 15px rgba(8, 145, 178, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #34d399);
    color: var(--white);
}

.btn-success:hover {
    background: linear-gradient(135deg, #059669, #10b981);
    color: var(--white);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #f43f5e, #fb7185);
    color: var(--white);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #e11d48, #f43f5e);
    color: var(--white);
    box-shadow: 0 4px 15px rgba(244, 63, 94, 0.4);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-600);
}

.btn-secondary:hover {
    background: var(--gray-300);
    color: var(--gray-700);
}

.btn-sm {
    padding: 0.45rem 0.9rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.9rem 1.8rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1.2rem;
}

.form-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--gray-600);
    font-size: 0.85rem;
}

.form-control {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--white);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.1);
}

.form-control::placeholder {
    color: var(--gray-400);
}

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

/* ===== Tables ===== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 0.9rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.table th {
    background: var(--gray-100);
    font-weight: 600;
    color: var(--gray-600);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.table tbody tr {
    transition: var(--transition);
}

.table tbody tr:hover {
    background: var(--gray-100);
}

.table .amount {
    font-weight: 600;
    color: var(--danger);
}

.table .actions {
    display: flex;
    gap: 0.4rem;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.7rem;
    border-radius: 50px;
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-primary { background: rgba(8, 145, 178, 0.1); color: var(--primary); }
.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-danger { background: rgba(244, 63, 94, 0.1); color: var(--danger); }
.badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-admin { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: var(--white); }

.category-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.7rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
}

.category-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* ===== Alerts ===== */
.alert {
    padding: 1rem 1.2rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    position: relative;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    color: #065f46;
    border-left: 4px solid var(--success);
}

.alert-error {
    background: rgba(244, 63, 94, 0.1);
    color: #9f1239;
    border-left: 4px solid var(--danger);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #92400e;
    border-left: 4px solid var(--warning);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    color: #1e40af;
    border-left: 4px solid var(--info);
}

.alert-close {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.5;
    transition: var(--transition);
}

.alert-close:hover {
    opacity: 1;
}

/* ===== Auth Pages ===== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #f0fdfa 0%, #ecfeff 50%, #f0f9ff 100%);
}

.auth-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
}

.auth-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 2rem;
    text-align: center;
    color: var(--white);
}

.auth-header h1 {
    font-size: 1.5rem;
    margin-bottom: 0.4rem;
}

.auth-header p {
    opacity: 0.9;
    font-size: 0.9rem;
}

.auth-body {
    padding: 2rem;
}

.auth-footer {
    text-align: center;
    padding: 1.2rem;
    background: var(--gray-100);
    border-top: 1px solid var(--gray-200);
    font-size: 0.9rem;
}

/* ===== Charts ===== */
.chart-container {
    position: relative;
    height: 280px;
    width: 100%;
}

/* ===== Grid Layout ===== */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

/* ===== Filters ===== */
.filters {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    align-items: flex-end;
}

.filters .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 140px;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--gray-500);
}

.empty-state i {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--gray-600);
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 0.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
}

.pagination a {
    background: var(--white);
    color: var(--gray-600);
    box-shadow: var(--shadow);
}

.pagination a:hover,
.pagination a.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: var(--white);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--gray-500);
    margin-top: 2rem;
    font-size: 0.85rem;
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray-500); }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ===== RESPONSIVE - Tablet ===== */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-2, .grid-3 {
        grid-template-columns: 1fr;
    }
    
    .nav-menu a {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
    }
    
    .nav-menu a span {
        display: none;
    }
}

/* ===== RESPONSIVE - Mobile ===== */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }
    
    .navbar {
        padding: 0 1rem;
        height: 60px;
    }
    
    .nav-brand {
        font-size: 1.2rem;
    }
    
    .nav-toggle {
        display: flex;
    }
    
    .nav-menu {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--white);
        flex-direction: column;
        padding: 1rem;
        gap: 0.5rem;
        box-shadow: var(--shadow-lg);
        transform: translateY(-100%);
        opacity: 0;
        visibility: hidden;
        transition: var(--transition);
        z-index: 999;
    }
    
    .nav-menu.active {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }
    
    .nav-menu a {
        padding: 0.9rem 1rem;
        font-size: 1rem;
        border-radius: var(--radius-sm);
    }
    
    .nav-menu a span {
        display: inline;
    }
    
    .nav-mobile-only {
        display: block;
    }
    
    .user-name span {
        display: none;
    }
    
    .nav-user {
        display: none;
    }
    
    .container {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.8rem;
    }
    
    .stat-card {
        padding: 1rem;
        flex-direction: column;
        text-align: center;
        gap: 0.6rem;
    }
    
    .stat-icon {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
    
    .stat-info .stat-value {
        font-size: 1.2rem;
    }
    
    .stat-info h3 {
        font-size: 0.7rem;
    }
    
    .card {
        border-radius: var(--radius);
    }
    
    .card-header {
        padding: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .filters-row {
        flex-direction: column;
    }
    
    .filters .form-group {
        width: 100%;
        min-width: auto;
    }
    
    .table th,
    .table td {
        padding: 0.7rem 0.5rem;
        font-size: 0.85rem;
    }
    
    .table .actions {
        flex-direction: column;
        gap: 0.3rem;
    }
    
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }
    
    .btn-sm {
        padding: 0.4rem 0.7rem;
        font-size: 0.75rem;
    }
    
    .pagination a,
    .pagination span {
        min-width: 34px;
        height: 34px;
        font-size: 0.85rem;
    }
    
    .chart-container {
        height: 220px;
    }
    
    .auth-card {
        max-width: 100%;
    }
    
    .auth-header {
        padding: 1.5rem;
    }
    
    .auth-body {
        padding: 1.5rem;
    }
    
    .empty-state {
        padding: 2rem 1rem;
    }
    
    .empty-state i {
        font-size: 2.5rem;
    }
}

/* ===== RESPONSIVE - Small Mobile ===== */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.6rem;
    }
    
    .stat-card {
        flex-direction: row;
        text-align: left;
        padding: 0.9rem;
    }
    
    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .nav-brand span {
        display: none;
    }
    
    .table {
        font-size: 0.8rem;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.4rem;
    }
    
    .btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .card-header h2 {
        font-size: 0.9rem;
    }
    
    h1 {
        font-size: 1.4rem;
    }
}

/* ===== Touch Improvements ===== */
@media (hover: none) and (pointer: coarse) {
    .btn, .nav-menu a, .btn-icon {
        min-height: 44px;
    }
    
    .form-control {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    select.form-control {
        font-size: 16px;
    }
    
    .table tbody tr:hover {
        background: transparent;
    }
    
    .stat-card:hover {
        transform: none;
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

.slide-up {
    animation: slideUp 0.4s ease;
}

/* ===== Safe Area for notched devices ===== */
@supports (padding: max(0px)) {
    .navbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .container {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .nav-menu {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* ===== Print Styles ===== */
@media print {
    .navbar, .filters, .btn, .actions, .footer, .pagination, .nav-toggle {
        display: none !important;
    }
    
    body {
        background: white;
    }
    
    .container {
        max-width: 100%;
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===== Dark Mode Support (optional) ===== */
@media (prefers-color-scheme: dark) {
    /* Can be enabled if needed */
}
