:root {
    --bg-color: #f4f4f9;
    --sidebar-bg: #2c3e50;
    --sidebar-text: #ecf0f1;
    --primary-color: #3498db;
    --text-color: #333;
    --card-bg: #fff;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
}

.app-container {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 20px;
}

.sidebar h2 {
    margin-top: 0;
    margin-bottom: 30px;
    text-align: center;
}

.sidebar nav ul {
    list-style: none;
    padding: 0;
}

.sidebar nav li {
    margin-bottom: 10px;
}

.sidebar nav a {
    display: block;
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 10px;
    border-radius: 4px;
    transition: background 0.2s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background-color: var(--primary-color);
}

.content {
    flex: 1;
    padding: 20px 40px;
    overflow-y: auto;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.stat-card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.stat-card h3 {
    margin-top: 0;
    color: #7f8c8d;
}

.stat-card p {
    font-size: 2em;
    font-weight: bold;
    margin: 10px 0 0;
    color: var(--primary-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    margin-top: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

th,
td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    background-color: #f8f9fa;
    font-weight: 600;
}

.actions-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 15px;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

button:hover {
    background-color: #2980b9;
}

dialog {
    border: none;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 20px;
    width: 400px;
    z-index: 1000;
    /* Ensure dialog is above backdrop */
    pointer-events: auto;
    /* Allow clicks on dialog */
    position: fixed;
    /* Ensure proper positioning */
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    /* Backdrop below dialog */
    pointer-events: auto;
    /* Allow backdrop to receive clicks for closing */
}

form {
    pointer-events: auto;
    /* Ensure form receives clicks */
}

form label {
    display: block;
    margin-bottom: 15px;
    pointer-events: auto;
    /* Ensure labels receive clicks */
}

form input,
form textarea,
form select {
    width: 100%;
    padding: 8px;
    margin-top: 5px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    pointer-events: auto;
    /* CRITICAL: Allow inputs to receive clicks and focus */
    position: relative;
    /* Ensure inputs are in normal flow */
    z-index: 1;
    /* Ensure inputs are above any potential overlays */
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    pointer-events: auto;
    /* Ensure buttons receive clicks */
}

#btn-cancel-car,
.btn-cancel {
    background-color: #95a5a6;
}

/* Modal Improvements */
.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    pointer-events: auto;
    /* Ensure form rows receive clicks */
}

.form-row label {
    flex: 1;
}

textarea {
    width: 100%;
    height: 60px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {

    /* ===== PREVENT HORIZONTAL SCROLL ===== */
    html,
    body {
        overflow-x: hidden !important;
        width: 100% !important;
    }

    .app-container {
        flex-direction: column;
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* ===== SIDEBAR ===== */
    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        width: 250px;
        z-index: 1000;
        transition: left 0.3s ease, visibility 0.3s ease;
        box-shadow: none;
        visibility: hidden;
    }

    .sidebar.active {
        left: 0;
        visibility: visible;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar.active+.sidebar-overlay {
        display: block;
    }

    /* ===== HAMBURGER BUTTON (small floating) ===== */
    #menu-toggle {
        display: block !important;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 1001;
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 8px 12px;
        border-radius: 8px;
        cursor: pointer;
        font-size: 20px;
        min-height: 40px;
        min-width: 40px;
        line-height: 1;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
        opacity: 0.9;
    }

    #menu-toggle:active {
        opacity: 1;
        transform: scale(0.95);
    }

    /* ===== MAIN CONTENT ===== */
    .content {
        padding: 55px 12px 20px 12px;
        width: 100%;
        box-sizing: border-box;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .content header h1 {
        font-size: 1.3em;
        text-align: center;
    }

    /* ===== ACTIONS BAR ===== */
    .actions-bar {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .actions-bar button {
        width: 100%;
    }

    .actions-bar input[type="text"] {
        width: 100%;
    }

    /* ===== STATS & CHARTS GRID ===== */
    .stats-grid,
    .charts-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-card p {
        font-size: 1.6em;
    }

    /* ===== RESPONSIVE TABLES → CARD VIEW ===== */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    table {
        border: none;
        box-shadow: none;
        background: transparent;
    }

    tr {
        margin-bottom: 16px;
        border: 1px solid #ddd;
        border-radius: 10px;
        background: #fff;
        padding: 14px 16px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    }

    /* ===== RENTAL CARD TEXT ALIGNMENT ===== */
    td {
        border: none;
        border-bottom: 1px solid #f0f0f0;
        position: relative;
        padding: 10px 0;
        padding-left: 0;
        text-align: center;
        min-height: 28px;
        font-size: 15px;
        word-break: break-word;
    }

    td:last-child {
        border-bottom: none;
    }

    td:before {
        display: block;
        position: static;
        width: 100%;
        padding: 0;
        margin-bottom: 2px;
        text-align: center;
        font-weight: 600;
        content: attr(data-label);
        color: #888;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    /* ===== BUTTONS IN CARDS: STACK VERTICALLY ===== */
    td:last-child {
        text-align: center;
        padding-left: 0;
        padding-top: 12px;
        display: flex;
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    td:last-child:before {
        display: none;
    }

    td:last-child button {
        width: 100%;
        padding: 12px 16px;
        font-size: 14px;
        border-radius: 6px;
        min-height: 44px;
    }

    /* Danger button styling */
    td:last-child button.btn-danger {
        background-color: #e74c3c;
    }

    /* ===== DIALOGS / MODALS ===== */
    dialog {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 92vw !important;
        max-width: none !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        box-sizing: border-box;
        margin: 0 !important;
        padding: 20px 16px;
        border-radius: 12px;
    }

    dialog h3 {
        font-size: 1.2em;
        margin-bottom: 15px;
    }

    /* ===== FORM LAYOUT IN MODALS ===== */
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row label {
        width: 100%;
        margin-bottom: 12px;
    }

    form label {
        margin-bottom: 14px;
        font-size: 14px;
    }

    form label span {
        display: block;
        margin-bottom: 4px;
        font-weight: 600;
        color: #333;
    }

    /* ===== FORM INPUTS: 16px MIN TO PREVENT iOS ZOOM ===== */
    form input,
    form textarea,
    form select,
    dialog input,
    dialog textarea,
    dialog select {
        width: 100% !important;
        font-size: 16px !important;
        padding: 10px !important;
        box-sizing: border-box;
        border: 1px solid #ccc;
        border-radius: 6px;
        min-height: 44px;
        -webkit-appearance: none;
        appearance: none;
    }

    form textarea,
    dialog textarea {
        min-height: 60px;
        resize: vertical;
    }

    /* ===== MODAL ACTION BUTTONS ===== */
    .modal-actions {
        flex-direction: column;
        gap: 8px;
        margin-top: 16px;
    }

    .modal-actions button {
        width: 100%;
        padding: 12px;
        font-size: 15px;
        min-height: 46px;
        border-radius: 6px;
    }

    /* ===== GENERAL TOUCH TARGETS ===== */
    button,
    input,
    select,
    textarea {
        min-height: 44px;
    }

    button {
        font-size: 14px;
        padding: 10px 16px;
    }

    /* ===== SEARCH INPUT ===== */
    #search-customer {
        width: 100% !important;
        font-size: 16px !important;
        margin-bottom: 10px;
    }

    /* ===== ACCOUNTING MONTH INPUT ===== */
    #accounting-month {
        width: 100%;
        font-size: 16px;
    }

    /* ===== EXPENSES HEADER ===== */
    #expenses-view>div:first-child {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    #expenses-view .stat-card {
        min-width: unset;
        width: 100%;
    }
}

/* Base styles - hidden on desktop */
#menu-toggle {
    display: none;
}

.mobile-header {
    display: none;
}

.mobile-header-title {
    display: none;
}