/* ============================================
   Room Management System - Modern Dark Theme
   ============================================ */

:root {
    /* Colors */
    --bg-primary: #231e0f;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1f3460;
    --accent-primary: #3b82f6;
    --accent-secondary: #06b6d4;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.4);

    /* Sizes */
    --sidebar-width: 260px;
    --header-height: 70px;
    --border-radius: 12px;
    --border-radius-lg: 20px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans Thai', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ============ Sidebar ============ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo i {
    font-size: 1.8rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--glass-bg);
    color: var(--text-primary);
    transform: translateX(4px);
}

.nav-item.active {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
}

.nav-item i {
    width: 24px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.current-date {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ============ Main Content ============ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px;
    min-height: 100vh;
}

.content-container {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Page Structure */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-header h1 i {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.5);
}

.btn-secondary {
    background: var(--glass-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.btn-warning:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 16px 28px;
    font-size: 1.05rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-radius: 10px;
}

/* ============ Form Controls ============ */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-control::placeholder {
    color: var(--text-muted);
}

select.form-control {
    cursor: pointer;
}

/* Month Selector */
.month-selector {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.month-selector .form-control {
    width: auto;
    min-width: 140px;
}

/* ============ Cards ============ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--accent-primary);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.card-title {
    font-size: 1.2rem;
    font-weight: 600;
}

/* ============ Floors Grid ============ */
.floors-grid {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.floor-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.floor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1) 0%, rgba(124, 58, 237, 0.1) 100%);
    border-bottom: 1px solid var(--border-color);
}

.floor-name {
    font-size: 1.3rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.floor-name i {
    color: var(--accent-primary);
}

.floor-actions {
    display: flex;
    gap: 8px;
}

.rooms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 24px;
}

.room-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.room-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-primary);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.2);
}

.room-card.occupied {
    border-left: 4px solid var(--success);
}

.room-card.empty {
    border-left: 4px solid #f87171;
    /* Bright Red-400 */
    background: rgba(239, 68, 68, 0.05);
    opacity: 1;
}

.room-number {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.room-price {
    color: var(--success);
    font-weight: 600;
    margin-bottom: 12px;
}

.room-tenant {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-status {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.room-status.occupied {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.room-status.empty {
    background: #ef4444;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
}

/* ============ Meters Page ============ */
.meter-floor-section {
    margin-bottom: 32px;
}

.meter-floor-header {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1) 0%, rgba(124, 58, 237, 0.1) 100%);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    gap: 10px;
}

.meter-floor-header i {
    color: var(--accent-primary);
}

.meters-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.meters-table th,
.meters-table td {
    padding: 16px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.meters-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.meters-table tr:last-child td {
    border-bottom: none;
}

.meters-table tr:hover td {
    background: var(--glass-bg);
}

.meters-table input {
    width: 100px;
    padding: 10px;
    text-align: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
}

.meters-table input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.meter-label {
    /* display: flex; Removed to fix colspan rendering */
    text-align: center;
    vertical-align: middle;
}

.meter-label i {
    margin-right: 8px;
    vertical-align: middle;
}

.meter-label.water {
    color: var(--info);
}

.meter-label.electric {
    color: var(--warning);
}

/* Vertical Divider */
.border-right-separator {
    border-right: 2px solid #ffd700 !important;
    /* Gold color for visibility */
}

/* Usage Badges */
.usage-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-weight: 600;
    min-width: 60px;
    transition: all 0.3s ease;
}

.usage-badge.negative {
    background: #ef4444;
    color: white;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.2);
}

.form-control.is-invalid {
    border-color: #ef4444 !important;
    background-color: rgba(239, 68, 68, 0.12) !important;
    color: #f87171 !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3) !important;
}

.usage-badge.positive {
    background: #10b981;
    /* Green */
    color: white;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.2);
}

/* ============ Bills Grid ============ */
.bills-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
}

.bill-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    transition: all 0.3s ease;
    color: #111827;
    /* Global dark text for the card */
}

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

.bill-header {
    padding: 20px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.15) 0%, rgba(124, 58, 237, 0.15) 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bill-room {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1a1a2e;
    /* Dark fallback */
}

.bill-card.vacant .bill-room {
    color: #991b1b;
    /* Dark red for vacant room number */
}

.bill-card.occupied .bill-room {
    color: #3b82f6;
    /* Indigo for occupied room number */
}

.bill-tenant {
    color: #4b5563;
    /* Darker gray for better contrast on light Bg */
    font-size: 0.95rem;
    font-weight: 500;
}

.bill-invoice {
    color: #6b7280;
    font-size: 0.85rem;
}

.bill-body {
    padding: 20px;
}

.bill-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    /* Softer dark border */
}

.bill-row:last-child {
    border-bottom: none;
}

.bill-row.total {
    font-size: 1.2rem;
    font-weight: 700;
    color: #059669;
    /* Solid green for legibility */
    padding-top: 16px;
    margin-top: 8px;
    border-top: 2px solid rgba(0, 0, 0, 0.05);
}

.bill-label {
    color: #374151;
    /* Dark gray for labels */
}

.bill-value {
    font-weight: 600;
    color: #111827;
    /* Near black for values */
}

.bill-detail {
    font-size: 0.85rem;
    color: #6b7280;
}

.bill-footer {
    padding: 16px 20px;
    background: var(--bg-secondary);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ============ Tenants Table ============ */
.tenants-table-container {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.tenants-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    /* Ensures column widths are respected */
}

.tenants-table th,
.tenants-table td {
    padding: 16px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
}

.tenants-table th:last-child,
.tenants-table td:last-child {
    border-right: none;
}

.tenants-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Specific Column Widths for Desktop */
.tenants-table th:nth-child(1),
.tenants-table td:nth-child(1) {
    width: 30%;
}

/* Name */
.tenants-table th:nth-child(2),
.tenants-table td:nth-child(2) {
    width: 10%;
    text-align: center;
}

/* Room */
.tenants-table th:nth-child(3),
.tenants-table td:nth-child(3) {
    width: 20%;
}

/* Phone */
.tenants-table th:nth-child(4),
.tenants-table td:nth-child(4) {
    width: 15%;
    text-align: center;
}

/* Status */
.tenants-table th:nth-child(5),
.tenants-table td:nth-child(5) {
    width: 25%;
}

/* Actions */

.tenants-table tr:hover td {
    background: var(--glass-bg);
}

.tenant-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.tenant-status.active {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.tenant-status.inactive {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

/* Upload Button Row */
.upload-btn-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.upload-btn-row .btn {
    flex-shrink: 0;
}

.file-name-display {
    color: var(--success);
    font-size: 0.9rem;
}

/* ============ Settings ============ */
.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    margin-bottom: 20px;
}

.settings-card h3 {
    font-size: 1.1rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-card h3 i {
    color: var(--accent-primary);
}

/* ============ Modal ============ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.modal-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ============ Toast Notifications ============ */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px 20px;
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    animation: toastSlide 0.3s ease;
}

@keyframes toastSlide {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast i {
    font-size: 1.2rem;
}

.toast.success i {
    color: var(--success);
}

.toast.error i {
    color: var(--danger);
}

.toast.warning i {
    color: var(--warning);
}

/* ============ Action Bar ============ */
.action-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 16px 24px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: flex;
    gap: 16px;
    align-items: center;
}

/* ============ Print Styles (User Template) ============ */
@media print {
    body * {
        visibility: hidden;
    }

    #print-container,
    #print-container * {
        visibility: visible;
    }

    #print-container {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: white;
    }

    @page {
        size: A4;
        margin: 0;
    }
}

.bill-container {
    width: 210mm;
    margin: 0 auto;
    background: white;
    color: #000;
}

.bill-section {
    height: 142mm;
    width: 210mm;
    padding: 5mm 12mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    color: #000 !important;
}

.dashed-line {
    border-top: 2px dashed #666;
    position: relative;
    margin: 2mm 0;
    width: 100%;
}


.dashed-line::before {
    content: '✂';
    position: absolute;
    left: 2mm;
    top: -12px;
    font-size: 18px;
    color: #666;
}

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

.bill-table th,
.bill-table td {
    border: 1px solid #000;
    padding: 4px 8px;
    text-align: center;
    color: #000;
}

.bill-table th {
    background-color: #f9f9f9;
    font-weight: bold;
    color: #000;
}

.bill-table tfoot tr {
    background-color: transparent;
    font-weight: bold;
}

.input-line {
    border-bottom: 1px dotted #333;
    min-width: 80px;
    display: inline-block;
    text-align: center;
    padding: 0 5px;
}

.copy-badge {
    background: #dc2626;
    color: white;
    padding: 2px 12px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 4px;
}

.original-badge {
    background: #16a34a;
    color: white;
    padding: 2px 12px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 4px;
}

.header-flex h1 {
    font-size: 24px;
    margin: 0;
}


.room-status-badge {
    font-size: 0.85rem;
    padding: 3px 12px;
    border-radius: 14px;
    font-weight: 700;
    margin-left: 10px;
    vertical-align: middle;
    text-transform: uppercase;
}

.room-status-badge.occupied {
    background: var(--accent-primary);
    color: white;
    border: 1px solid var(--accent-primary);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.room-status-badge.vacant {
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.bill-card.vacant {
    opacity: 1;
    /* Removed opacity for better readability */
    border: 2px dashed #fecaca;
    background: #fffafa;
}

.bill-card.occupied {
    border: 2px solid var(--accent-primary);
    background: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}

.bill-card.occupied .bill-room {
    color: var(--accent-primary);
}

/* ============ Sidebar Footer Refinement ============ */
.sidebar-credit {
    font-size: 0.65rem;
    color: var(--text-muted);
    opacity: 0.6;
    margin-top: 8px;
    text-align: center;
    width: 100%;
}

/* ============ Print Section ============ */
@media print {
    body>*:not(#print-container) {
        display: none !important;
    }

    #print-container {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }

    .page-break {
        page-break-after: always;
        break-after: page;
    }

    @page {
        size: A4;
        margin: 0;
    }
}

.signature-section {
    display: flex;
    justify-content: flex-end;
    /* Align signature block to the right */
    margin-top: auto;
    padding-bottom: 5mm;
    color: #000 !important;
}

.signature-box {
    text-align: center;
    color: #000 !important;
    min-width: 200px;
    /* Ensure enough space for the line */
}

.signature-line {
    border-top: 1px solid #000;
    padding-top: 4px;
    width: 180px;
    margin: 20px auto 0 auto;
    /* Center line within the box */
    color: #000 !important;
}

.bill-section h2,
.bill-section p,
.bill-section span,
.bill-section td,
.bill-section th {
    color: #000 !important;
}

/* ============ Edit Bill Modal ============ */
.edit-bill-modal .modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.edit-bill-modal .form-group.full-width {
    grid-column: span 2;
}

.edit-bill-modal label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}


.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}


/* ============ Empty State ============ */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.3rem;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

/* ============ File Upload ============ */
.file-upload {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.file-upload:hover {
    border-color: var(--accent-primary);
    background: var(--glass-bg);
}

.file-upload i {
    font-size: 2rem;
    color: var(--accent-primary);
    margin-bottom: 10px;
}

.file-upload input {
    display: none;
}

.file-preview {
    margin-top: 16px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.file-preview-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.file-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-preview-item .remove-file {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: var(--danger);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

/* ============ Mobile Header ============ */
.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 90;
}

.mobile-header .logo {
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-header .logo i {
    color: var(--accent-primary);
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px;
}

/* ============ Sidebar Overlay ============ */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 98;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ============ Tenant Detail & Documents ============ */
.tenant-name-link {
    color: var(--accent-primary);
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tenant-name-link:hover {
    color: var(--accent-secondary);
    text-decoration: underline;
    transform: translateX(4px);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.detail-item {
    background: var(--glass-bg);
    padding: 16px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.detail-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-value {
    display: block;
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.document-gallery {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 24px;
}

.document-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    transition: transform 0.3s ease;
}

.document-card:hover {
    transform: translateY(-5px);
}

.document-header {
    padding: 12px 16px;
    background: var(--glass-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.document-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.document-preview {
    width: 100%;
    aspect-ratio: 4/3;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.document-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.document-preview .no-doc {
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.document-preview .no-doc i {
    font-size: 2.5rem;
    opacity: 0.3;
}

@media (max-width: 768px) {

    .detail-grid,
    .document-gallery {
        grid-template-columns: 1fr;
    }
}

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

@media (max-width: 768px) {

    .table thead,
    .tenants-table thead {
        display: none;
        /* Hide table headers on mobile */
    }

    .table,
    .tenants-table,
    .table tbody,
    .tenants-table tbody,
    .table tr,
    .tenants-table tr,
    .table td,
    .tenants-table td {
        display: block;
        width: 100%;
    }

    .table tr,
    .tenants-table tr {
        margin-bottom: 20px;
        background: var(--bg-card);
        border-radius: var(--border-radius);
        padding: 16px;
        box-shadow: var(--shadow);
        border: 1px solid var(--border-color);
    }

    .table td,
    .tenants-table td {
        text-align: right;
        padding: 12px 0;
        position: relative;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 15px;
        border-right: none !important;
        /* Remove desktop vertical grid on mobile cards */
    }

    .table td:last-child,
    .tenants-table td:last-child {
        border-bottom: none;
        padding-top: 16px;
        justify-content: flex-end;
    }

    .table td::before,
    .tenants-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 0.85rem;
        text-align: left;
    }

    .table-responsive {
        overflow: visible;
        /* Disable horizontal scroll if cards are used */
    }

    .tenant-name-link {
        font-size: 1.1rem;
    }
}

/* ============ Responsive ============ */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        overflow-x: hidden;
    }

    .mobile-header {
        display: flex;
        width: 100%;
        position: sticky;
        top: 0;
        z-index: 90;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 99;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
        width: 100%;
        padding: 16px;
        /* Reduced padding */
        padding-top: 0;
    }

    /* Scaling Content Down */
    .room-card {
        padding: 16px;
    }

    .room-number {
        font-size: 1.5rem;
        /* Smaller than desktop 1.8rem */
    }

    .room-price {
        font-size: 1rem;
    }

    .page-header h1 {
        font-size: 1.4rem;
    }

    .btn {
        padding: 8px 16px;
        font-size: 0.9rem;
    }

    /* iOS Input Zoom Fix */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-actions {
        width: 100%;
    }

    .month-selector {
        width: 100%;
    }

    .month-selector .form-control {
        flex: 1;
    }

    .rooms-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .bills-grid {
        grid-template-columns: 1fr;
    }

    .meters-table {
        font-size: 0.85rem;
    }

    .meters-table th,
    .meters-table td {
        padding: 10px 8px;
    }

    .meters-table input {
        width: 70px;
        padding: 8px 4px;
    }
}

/* ============ Login Page ============ */
.login-body {
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.login-logo {
    font-size: 3rem;
    margin-bottom: 20px;
    display: inline-block;
}

.login-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: white;
}

.login-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form .form-control {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    font-size: 1.2rem;
    letter-spacing: 2px;
    margin-bottom: 24px;
    height: 60px;
}

.login-form .form-control:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.login-footer {
    margin-top: 32px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ============ Badges & Status ============ */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-primary {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-light {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.tenant-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
}

.tenant-status.active {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.tenant-status.inactive {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

/* ============ Quick Stats ============ */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.stat-icon.blue {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.stat-icon.green {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.stat-icon.purple {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
}

.stat-icon.orange {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.stat-info .stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-info .stat-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============ Search UI ============ */
.search-container {
    position: relative;
    max-width: 400px;
    width: 100%;
}

.search-container i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input {
    padding-left: 44px !important;
}

.no-results {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-color);
    margin-top: 20px;
}

.no-results i {
    font-size: 3rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-results h3 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.no-results p {
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .search-container {
        max-width: 100%;
        margin-top: 8px;
    }
}

/* ============ Table Sorting ============ */
.tenants-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.tenants-table th.sortable:hover {
    background-color: var(--glass-bg);
}

.sort-container {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sort-icon {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.4;
    transition: all 0.2s;
}

.tenants-table th.active-sort .sort-icon {
    opacity: 1;
    color: var(--accent-primary);
}

/* ============ Print Layout ============ */
.print-only {
    display: none !important;
}

@media print {
    body * {
        visibility: hidden;
    }

    .print-only,
    .print-only * {
        visibility: visible;
    }

    .print-only {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: white;
    }

    .page-break {
        page-break-after: always;
        height: 0;
    }

    /* Reset some styles for print */
    .bill-container {
        padding: 0;
        margin: 0;
        box-shadow: none;
        border: none;
    }

    .dashed-line {
        border-top: 1px dashed #ccc;
        margin: 20px 0;
    }
}

.login-footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
}