:root {
    --primary-color: #111827;
    --primary-dark: #000000;
    --secondary-color: #4b5563;
    --bg-color: #f9fafb;
    --sidebar-bg: #ffffff;
    --text-color: #1f2937;
    --border-color: #e5e7eb;
    --success-color: #059669;
    --warning-color: #d97706;
    --danger-color: #dc2626;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
    min-height: 100dvh;
    /* Ensure full viewport height */
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 3rem;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-menu a {
    text-decoration: none;
    color: var(--secondary-color);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-menu a:hover,
.nav-menu a.active {
    background-color: #f3f4f6;
    color: var(--primary-color);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    height: 70px;
    background-color: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.content-area {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* Cards & Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background-color: #f3f4f6;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--secondary-color);
    margin-bottom: 0.25rem;
}

.stat-info p {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
}

/* Tables */
.table-container {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

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

th,
td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: #f8fafc;
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 0.875rem;
}

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

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

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

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

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: inherit;
}

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

/* Custom Time Slot Picker */
.appointment-picker-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.flatpickr-calendar.inline {
    margin: 0 auto;
    box-shadow: none;
    border: 1px solid var(--border-color);
}

.time-slots-container {
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 1rem;
    background: #fff;
    max-height: 320px;
    /* Match approximate height of flatpickr */
    overflow-y: auto;
}

.time-slots-header {
    text-align: center;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

.slots-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.time-slot-btn {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    color: var(--text-color);
    font-size: 0.9rem;
}

.time-slot-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background-color: #f3f4f6;
}

.time-slot-btn.selected {
    background-color: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.time-slot-btn:disabled {
    background-color: #f1f5f9;
    color: #cbd5e1;
    cursor: not-allowed;
    border-color: #e2e8f0;
}

/* Mobile Sidebar & Toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.5rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Landing Page Styles */
.hero {
    background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('../images/cabinet-bg.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: white;
    padding: 6rem 2rem;
    text-align: center;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.hero p {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.features {
    padding: 4rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.feature-card {
    text-align: center;
    padding: 2rem;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.feature-icon {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: white;
}

/* Media Queries */
/* Media Queries */
@media (max-width: 1024px) {
    .appointment-picker-container {
        grid-template-columns: 1fr;
    }

    /* Fix Tablet Button Visibility */
    .nav-header {
        flex-wrap: wrap;
        /* Allow wrapping if space is tight */
        height: auto;
        /* Allow expansion */
        gap: 1rem;
        /* Spacing between wrapped items */
    }

    .page-header-flex {
        flex-wrap: wrap;
        gap: 1rem;
    }

    /* Ensure bottom buttons (Cancel/Save) aren't cut off */
    .content-area {
        padding-bottom: 250px !important;
        /* NUCLEAR OPTION: Extra padding for bottom safe area/scroll */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Force margin at bottom of cards to push buttons up */
    .card {
        margin-bottom: 5rem !important;
    }

    .menu-toggle {
        display: block !important;
    }

    .sidebar {
        position: fixed !important;
        top: 0;
        left: -280px !important;
        /* Hide sidebar */
        width: 260px;
        height: 100vh;
        z-index: 2000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        left: 0 !important;
        /* Show sidebar */
    }

    .user-profile span {
        display: none !important;
    }

    .top-bar {
        padding: 0 1rem;
    }

    .content-area {
        padding: 1rem;
    }
}

/* Mobile Improvements */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
        /* Stack cards on mobile */
    }

    .modal-content {
        width: 95% !important;
        /* Full width modals */
        margin: 5% auto !important;
    }

    .nav-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        padding: 1rem;
    }

    .nav-header>div {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }

    .nav-header .btn {
        width: 100%;
        margin: 0 !important;
        text-align: center;
    }

    .hero {
        padding: 3rem 1rem;
        background-attachment: scroll;
        /* Fix for mobile browsers */
    }

    .hero h1 {
        font-size: 2rem;
    }

    .features {
        grid-template-columns: 1fr;
        padding: 2rem 1rem;
    }

    /* Global Mobile Adjustments */
    .btn {
        min-height: 44px;
        /* Touch friendly */
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .form-control {
        min-height: 44px;
    }

    /* Stack flex containers on mobile */
    .mobile-stack {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1rem !important;
    }

    .mobile-full-width {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
    }

    /* Login Card Specific */
    .login-card {
        width: 90% !important;
        margin: 1rem auto !important;
        padding: 1.5rem !important;
    }
}

/* Responsive Table */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: 1rem;
    /* Match card radius */
    border: 1px solid var(--border-color);
}

.table-responsive table {
    white-space: nowrap;
    /* Prevent wrapping inside cells */
    margin: 0;
}

.table-responsive th,
.table-responsive td {
    border-bottom: 1px solid var(--border-color);
}

/* Auth Page Styles */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url('../images/cabinet-bg.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

.auth-card {
    background-color: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px);
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

/* Mobile Content Adjustments */
@media (max-width: 768px) {
    .content-area {
        padding: 0.5rem !important;
    }

    .card {
        padding: 1rem !important;
        margin-bottom: 1rem;
    }

    h1 {
        font-size: 1.5rem !important;
    }

    h2 {
        font-size: 1.25rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

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

    .patient-tabs {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 5px;
    }

    .patient-tab {
        flex-shrink: 0;
    }
}

/* Desktop Fixes */
@media (min-width: 769px) {
    .auth-card {
        max-width: 400px !important;
        width: 100% !important;
        margin: auto;
    }
}

/* Z-Index Fixes for Sidebar Toggle */
.top-bar {
    position: relative;
    z-index: 100;
}

.menu-toggle {
    position: relative;
    z-index: 101;
    cursor: pointer;
}

/* Mobile Viewport Fixes */
body {
    height: 100vh;
    /* Fallback */
    height: 100dvh;
}

@media (max-width: 768px) {
    .content-area {
        padding-bottom: 100px !important;
        /* Ensure bottom content is visible */
    }

    /* Ensure sidebar toggle is always clickable */
    .menu-toggle {
        pointer-events: auto !important;
    }
}

/* Nuclear Option for Sidebar Toggle */
@media (max-width: 768px) {
    .menu-toggle {
        display: block !important;
        position: fixed !important;
        top: 15px !important;
        left: 15px !important;
        z-index: 9999 !important;
        background: white !important;
        border-radius: 50% !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
        width: 40px !important;
        height: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Adjust top bar title to not overlap with fixed toggle */
    .top-bar h2 {
        margin-left: 40px !important;
    }
}

/* Invoice Page Specific Responsiveness */
.page-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.header-left {
    margin-bottom: 0;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

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

    .header-left {
        width: 100%;
        text-align: center;
    }

    .header-left>div {
        justify-content: center;
    }

    .header-actions {
        flex-direction: column;
        width: 100%;
    }

    .header-actions .btn {
        width: 100%;
        text-align: center;
        margin-bottom: 0.5rem;
    }
}