:root {
    --bg-color: #F9F7F3;
    --card-bg: #FFFFFF;
    --primary-color: #6B4E2E;
    --accent-color: #CBB89D;
    --text-color: #333333;
    --border-color: #EAEAEA;
    --danger-color: #e53e3e;
    --danger-bg: #fed7d7;
    --font-family: 'Poppins', sans-serif;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.08);
    --border-radius: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* --- Login Page Styles --- */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}
.login-form {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
}
.login-form h1 {
    color: var(--primary-color);
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}
.login-form h2 {
    font-size: 1.1rem;
    font-weight: 400;
    margin-bottom: 2rem;
    color: #777;
}
.login-form .form-group {
    text-align: left;
    margin-bottom: 1.5rem;
}
.login-form .form-group label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    display: block;
}
.login-form .form-group input {
     width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 1rem;
    background-color: #fff;
}
.login-form .primary-btn {
    width: 100%;
}
.error-message {
    color: var(--danger-color);
    background-color: var(--danger-bg);
    padding: 0.8rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}


/* --- General App Styles --- */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.hidden {
    display: none !important;
}

/* --- Header & Controls --- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
}
.main-title {
    color: var(--primary-color);
    font-size: 2rem;
    font-weight: 700;
}
.controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}
.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.control-group label {
    font-size: 0.9rem;
    font-weight: 500;
}
.control-group select {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--card-bg);
    font-family: var(--font-family);
    cursor: pointer;
}
.logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background-color: var(--danger-bg);
    color: var(--danger-color);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.2s;
}
.logout-btn:hover {
    background-color: #fbd5d5;
}


/* --- Dashboard --- */
.selection-step h2, #invoice-form-container h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    margin-top: 2rem;
    color: var(--primary-color);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}
#invoice-form-container h3:first-of-type {
    margin-top: 0;
}
.client-type-selector {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}
.client-type-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 2rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--card-bg);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.1rem;
    font-weight: 500;
}
.client-type-btn i {
    font-size: 2rem;
    color: var(--accent-color);
    transition: color 0.2s;
}
.client-type-btn:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow);
}
.client-type-btn.selected {
    border-color: var(--primary-color);
    background-color: #fdfaf5;
    box-shadow: var(--shadow);
}
.client-type-btn.selected i {
    color: var(--primary-color);
}
.riad-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.5rem;
}
.riad-card {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid transparent;
}
.riad-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}
.riad-card.selected {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}
.riad-card h3 {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 1.1rem;
}


/* --- Buttons --- */
.primary-btn, .secondary-btn, .back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    justify-content: center;
}
.primary-btn {
    background-color: var(--primary-color);
    color: white;
}
.primary-btn:hover {
    background-color: #523a20;
}
.secondary-btn {
    background-color: #E9E4DB;
    color: var(--primary-color);
}
.secondary-btn:hover {
    background-color: #dcd4c7;
}
.back-btn {
    background: none;
    color: var(--primary-color);
    padding: 0.5rem 0;
    font-weight: 600;
}
.back-btn:hover {
    text-decoration: underline;
}


/* --- Invoice Form --- */
#invoice-form-container {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}
#agency-fields {
    grid-column: 1 / -1;
}
.form-grid-inner {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}
.form-group {
    display: flex;
    flex-direction: column;
}
.form-group label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 1rem;
    background-color: #fff;
}
.form-group textarea {
    resize: vertical;
}
.form-bottom-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 2rem;
    align-items: flex-start;
}
.form-group-inline {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.form-actions {
    margin-top: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-top: 2px solid var(--border-color);
    padding-top: 2rem;
}
.totals-summary {
    text-align: right;
}
.totals-summary p {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.grand-total-summary {
    font-size: 1.3rem !important;
    font-weight: 700 !important;
    color: var(--primary-color);
}


/* Stay Periods & Service Items Table */
#stay-periods, #service-items {
    margin: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.stay-period-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem;
    align-items: flex-end;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: #fdfdfd;
}
.service-item-row {
    display: grid;
    grid-template-columns: 4fr 1fr 1fr 1.5fr 1.5fr auto;
    gap: 1rem;
    align-items: flex-end;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: #fdfdfd;
}
.service-item-row .form-group, .stay-period-row .form-group {
    margin-bottom: 0;
}
.service-item-row input, .stay-period-row input {
    padding: 0.6rem;
    font-size: 0.9rem;
}
.item-total {
    font-weight: 600;
    text-align: right;
    padding: 0.6rem 0.5rem;
    background-color: #f8f9fa;
    border-radius: 8px;
    white-space: nowrap;
}
.remove-item-btn {
    background: #fde2e2;
    color: #c53030;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: bold;
    line-height: 1;
    transition: background-color 0.2s;
}
.remove-item-btn:hover {
    background-color: #f8caca;
}

/* Tax Toggle Switch */
.tax-toggle-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
}
.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}
.switch input { display: none; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 26px; width: 26px;
    left: 4px; bottom: 4px;
    background-color: white;
    transition: .4s;
}
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before { transform: translateX(26px); }
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }


/* --- Invoice History --- */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}
.history-tabs {
    display: flex;
    flex-wrap: wrap;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 2rem;
}
.tab-link {
    padding: 0.8rem 1.5rem;
    cursor: pointer;
    background: none;
    border: none;
    font-size: 1rem;
    font-weight: 500;
    color: #888;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
}
.tab-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}
.history-month-group {
    margin-bottom: 2rem;
}
.history-month-header {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1rem;
}
.table-responsive {
    overflow-x: auto;
}
.history-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.history-table th, .history-table td {
    padding: 1rem;
    text-align: left;
    white-space: nowrap;
}
.history-table thead {
    background-color: #f8f9fa;
}
.history-table th {
    font-weight: 600;
    font-size: 0.9rem;
    color: #555;
}
.history-table tbody tr {
    border-bottom: 1px solid var(--border-color);
}
.history-table tbody tr:last-child {
    border-bottom: none;
}
.actions-cell {
    display: flex;
    gap: 0.5rem;
}
.edit-btn, .view-btn, .delete-btn {
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
}
.edit-btn {
    background-color: #e2e8f0;
    color: #4a5568;
}
.edit-btn:hover { background-color: #cbd5e0; }
.view-btn {
    background-color: #dbeafe;
    color: #2563eb;
}
.view-btn:hover { background-color: #bfdbfe; }
.delete-btn {
    background-color: var(--danger-bg);
    color: var(--danger-color);
}
.delete-btn:hover { background-color: #fbd5d5; }

/* --- Invoice Preview --- */
.preview-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}
.preview-actions {
    display: flex;
    gap: 1rem;
}
#invoice-preview {
    background: white;
    padding: 3rem;
    box-shadow: var(--shadow);
    font-size: 12px;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--primary-color);
}
.company-details { position: relative; }
.logo {
    max-width: 150px;
    max-height: 70px;
    margin-bottom: 1rem;
}
.company-details h1 { font-size: 24px; color: var(--primary-color); font-weight: 700;}
.company-details h2 { font-size: 16px; color: var(--text-color); font-weight: 500;}
.invoice-meta { text-align: right; }
.invoice-meta h2 { font-size: 28px; color: #999; margin-bottom: 10px; font-weight: 600; }
.invoice-meta p { margin-bottom: 5px; }

.client-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin: 30px 0;
    font-size: 13px;
}
.client-info .bill-to { display: flex; flex-direction: column; gap: 4px; }
.client-info .bill-to strong { display: inline-block; min-width: 60px; }
.pax-info { text-align: right; }

.stay-periods-preview {
    margin-bottom: 30px;
}
.stay-periods-preview p {
    font-size: 13px;
    margin-bottom: 4px;
}
.stay-periods-preview strong {
    display: inline-block;
    min-width: 100px;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}
.invoice-table thead {
    background-color: var(--primary-color);
    color: white;
}
.invoice-table th, .invoice-table td {
    padding: 12px 15px;
    text-align: left;
    vertical-align: top;
}
.invoice-table th { font-weight: 600; }
.invoice-table tbody tr {
    border-bottom: 1px solid var(--border-color);
}
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.invoice-summary {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: auto;
}
.notes-payment { flex: 1; }
#preview-notes-section { margin-bottom: 1rem; }
.totals {
    width: 280px;
    text-align: right;
}
.totals p {
    margin-bottom: 10px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
}
.totals p span { font-weight: 400; }
.grand-total {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: var(--primary-color);
    padding-top: 10px;
    border-top: 2px solid var(--border-color);
}
#tax-included-label {
    justify-content: flex-end;
    font-style: italic;
    color: #555;
    font-size: 12px;
}
.invoice-footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    font-size: 10px;
    color: #777;
}

/* --- Print Styles --- */
@media print {
    body {
        padding: 0;
        background-color: white;
    }
    .app-header, .preview-controls, .view:not(#invoice-preview-container), .logout-btn, #history-btn {
        display: none;
    }
    .app-container {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }
    #invoice-preview-container {
        display: block !important;
    }
    #invoice-preview {
        width: 100%;
        min-height: auto;
        box-shadow: none;
        padding: 0;
        margin: 0;
    }
}

/* --- Responsive Styles --- */
@media (max-width: 992px) {
    .form-grid, .form-bottom-section {
        grid-template-columns: 1fr;
    }
    #invoice-preview {
        width: 100%;
        height: auto;
        min-height: auto;
        padding: 1.5rem;
    }
    .service-item-row {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
    .service-item-row .form-group:nth-child(1) {
        grid-column: 1 / -1;
    }
    .service-item-row .form-group:nth-child(4) {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    body { padding: 1rem; }
    .app-container { padding: 1rem; }
    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .controls {
        width: 100%;
        justify-content: space-between;
    }
    .client-type-selector {
        flex-direction: column;
    }
}

