/* CSS Variables for Themes */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #f3f4f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

body.dark-mode {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --secondary: #1e293b;
    --success: #34d399;
    --danger: #f87171;
    --warning: #fbbf24;
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Tajawal', sans-serif;
    color: var(--text-main);
    background-color: var(--bg-color);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--card-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    color: var(--primary);
}

.sidebar-header h2 {
    margin-top: 10px;
    font-weight: 800;
}

.nav-links {
    list-style: none;
    flex: 1;
    padding: 1rem 0;
}

.nav-links li a {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-links li a i {
    width: 30px;
    font-size: 1.2rem;
}

.nav-links li a:hover,
.nav-links li a.active {
    background-color: var(--secondary);
    color: var(--primary);
    border-right: 4px solid var(--primary);
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.company-badge {
    background-color: var(--card-bg);
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    font-weight: 700;
    box-shadow: var(--shadow-sm);
}

.section-title {
    margin: 2rem 0 1rem;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-warning {
    background-color: var(--warning);
    color: white;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: var(--secondary);
}

.w-100 {
    width: 100%;
    justify-content: center;
}

/* Grid Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-card.primary {
    border-right: 4px solid var(--primary);
}

.stat-card.success {
    border-right: 4px solid var(--success);
}

.stat-icon {
    width: 60px;
    height: 60px;
    background: var(--secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--primary);
}

.accounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.account-box {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    text-align: center;
}

.account-box h4 {
    margin-bottom: 5px;
    color: var(--text-muted);
}

/* Table Container */
.table-container {
    background: var(--card-bg);
    border-radius: 12px;
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: var(--secondary);
    font-weight: 700;
}

.data-table tbody tr:hover {
    background-color: var(--bg-color);
}

/* Action Bar */
.action-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: center;
}

.search-input {
    flex: 1;
    max-width: 400px;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--card-bg);
    width: 100%;
    max-width: 500px;
    border-radius: 12px;
    padding: 2rem;
    animation: modalSlideIn 0.3s ease-out forwards;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.close {
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text-muted);
}

.close:hover {
    color: var(--danger);
}

/* Forms */
.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.form-control {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    background: var(--bg-color);
}

.form-control:focus {
    outline: 2px solid var(--primary);
}

/* Ledger Specific Styles */
.ledger-info-card {
    background: var(--primary);
    color: white;
    padding: 2rem;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}

.ledger-actions {
    display: flex;
    gap: 0.5rem;
}

.ledger-balances {
    display: flex;
    gap: 2rem;
    text-align: left;
}

.balance-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 1rem 1.5rem;
    border-radius: 8px;
}

.wallet-box {
    border: 1px dashed rgba(255, 255, 255, 0.5);
}

.wallet-actions {
    margin-top: 10px;
    display: flex;
    gap: 5px;
}

/* Helpers */
.text-danger {
    color: var(--danger);
    font-weight: bold;
}

.text-success {
    color: var(--success);
    font-weight: bold;
}

.text-muted {
    color: var(--text-muted);
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.settings-card {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    max-width: 600px;
    box-shadow: var(--shadow-sm);
}

/* Printable View */
@media print {
    body {
        background: white;
        color: black;
        display: block;
    }

    .no-print {
        display: none !important;
    }

    .main-content {
        padding: 0;
        margin: 0;
    }

    .ledger-info-card {
        background: none;
        color: black;
        border: 1px solid black;
        box-shadow: none;
        align-items: flex-start;
    }

    .balance-box {
        background: none;
        border: 1px solid #ccc;
        color: black;
    }

    .print-brand-header {
        display: flex;
        align-items: center;
        flex-direction: column;
        text-align: center;
        margin-bottom: 2rem;
        padding-bottom: 1rem;
        border-bottom: 2px solid black;
    }

    .print-brand-footer {
        margin-top: 3rem;
        text-align: center;
        font-size: 0.9rem;
    }

    .data-table th {
        background-color: #eee !important;
        color: black !important;
    }

    .data-table th,
    .data-table td {
        border: 1px solid #ddd;
    }
}

/* Bottom Nav - hidden on desktop */
.mobile-bottom-nav {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    #mobile-menu-btn {
        display: inline-flex !important;
    }

    .hide-sm {
        display: none;
    }

    body {
        flex-direction: column;
        overflow-x: hidden;
    }

    /* Sidebar as overlay drawer (slides in from right for RTL) */
    .sidebar {
        position: fixed !important;
        top: 0;
        right: -290px;
        width: 270px !important;
        height: 100vh !important;
        z-index: 1000;
        transition: right 0.3s ease;
        overflow-y: auto;
        flex-direction: column;
    }

    .sidebar.open {
        right: 0;
    }

    /* Overlay backdrop */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Main content full width + space for bottom bar */
    .main-content {
        width: 100%;
        padding: 0.75rem;
        padding-bottom: 75px;
        margin-left: 0 !important;
        overflow-y: auto;
    }

    .top-header {
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 6px;
        margin-bottom: 1rem;
    }

    .top-header h1 {
        font-size: 0.9rem;
        white-space: normal;
        line-height: 1.2;
    }

    .company-badge {
        font-size: 0.78rem;
        padding: 4px 8px;
    }

    .stats-grid,
    .accounts-grid {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }

    .stat-card {
        padding: 1rem;
        gap: 0.8rem;
    }

    .stat-card h2 {
        font-size: 1.3rem;
    }

    .ledger-info-card {
        flex-direction: column;
        gap: 1rem;
        padding: 1.5rem 1rem;
        text-align: center;
        align-items: center;
    }

    .ledger-header {
        flex-direction: column;
        gap: 10px;
    }

    .ledger-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        width: 100%;
    }

    .ledger-actions .btn {
        width: 100%;
        margin: 0;
        justify-content: center;
        font-size: 0.85rem;
    }

    .ledger-balances {
        flex-direction: column;
        gap: 0.6rem;
    }

    .balance-box {
        padding: 0.8rem 1rem;
    }

    .action-bar {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .action-bar .btn {
        flex: 1;
        min-width: 100px;
        justify-content: center;
    }

    .data-table {
        min-width: 480px;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem;
        font-size: 0.82rem;
    }

    .modal-content {
        width: 95%;
        max-width: none;
        margin: 8px;
        padding: 1.2rem;
    }

    .settings-card {
        padding: 1rem;
        max-width: 100%;
    }

    /* Show bottom nav on mobile */
    .mobile-bottom-nav {
        display: flex !important;
    }
}

/* Bottom Navigation Bar */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -3px 15px rgba(0, 0, 0, 0.12);
    z-index: 900;
    height: 62px;
    align-items: stretch;
    justify-content: space-around;
}

.mob-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 3px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.62rem;
    font-weight: 600;
    padding: 6px 2px;
    transition: color 0.2s;
    border-top: 3px solid transparent;
    cursor: pointer;
}

.mob-nav-item i {
    font-size: 1.15rem;
}

.mob-nav-item.active {
    color: var(--primary);
    border-top-color: var(--primary);
}

.mob-nav-item:hover {
    color: var(--primary);
}

/* Responsive Table Adjustments */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .data-table th,
    .data-table td {
        padding: 0.6rem 0.4rem;
        font-size: 0.82rem;
    }

    .stat-card {
        padding: 1rem;
        gap: 1rem;
    }

    .stat-icon {
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
    }
}