:root {
    --primary: #0077b6;
    --primary-light: #caf0f8;
    --secondary: #00b4d8;
    --accent: #ffb703;
    --text-main: #2b2d42;
    --text-muted: #8d99ae;
    --bg-main: #f8f9fa;
    --bg-card: #ffffff;
    --border: #edf2f4;
    --success: #2ecc71;
    --danger: #e74c3c;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Auth Screen */
#auth-screen {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--primary-light) 0%, #ffffff 100%);
}

.auth-card {
    background: var(--bg-card);
    padding: 3rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 2rem;
}

.logo-img {
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

.sidebar .logo {
    justify-content: center;
    padding: 0;
}

.sidebar .logo-img {
    width: 100%;
}

.auth-card h2 {
    margin-bottom: 0.5rem;
}

.auth-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.input-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.input-group input, .input-group select {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus, .input-group select:focus {
    border-color: var(--primary);
}

.btn {
    width: 100%;
    padding: 0.8rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
}

.btn:active {
    transform: translateY(1px);
}

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

.primary-btn:hover {
    background: #005f92;
    box-shadow: 0 4px 12px rgba(0, 119, 182, 0.3);
}

.cancel-btn {
    background: #f1f2f6;
    color: var(--text-main);
}

.icon-btn {
    width: auto;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
}

.error-text {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 1rem;
}

/* Main Layout */
#main-layout {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.sidebar .logo {
    justify-content: flex-start;
}

.nav-links {
    list-style: none;
    margin-top: 2rem;
    flex: 1;
}

.nav-links li {
    margin-bottom: 0.5rem;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.8rem 1rem;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: 8px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}

.nav-links a:hover, .nav-links a.active {
    background: var(--primary-light);
    color: var(--primary);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

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

.details {
    display: flex;
    flex-direction: column;
}

#user-role-label {
    font-weight: 600;
    font-size: 0.9rem;
}

#logout-btn {
    font-size: 0.8rem;
    color: var(--danger);
    text-decoration: none;
}

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    background: var(--bg-card);
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.header-actions select, .header-actions input {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
}

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

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-header h2 {
    margin-bottom: 0;
}

.sort-select {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    background: white;
    cursor: pointer;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

.data-table, .schedule-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th, .schedule-table th {
    text-align: left;
    padding: 1rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
}

.data-table td, .schedule-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.schedule-table td {
    padding: 0.15rem;
    vertical-align: top;
    height: 1px; /* Trick to make inner height 100% work */
}

.schedule-grid-container.card {
    padding-left: 0;
    padding-right: 0;
    padding-bottom: 0;
}

.schedule-grid-container {
    overflow-x: auto;
    position: relative;
    max-width: 100%;
}

.schedule-table {
    table-layout: fixed;
    width: max-content; /* Allow table to expand beyond container */
    min-width: 100%;
}

/* Base column styles */
.schedule-table th, .schedule-table td {
    width: calc((100vw - 320px) / 9); /* Fits roughly 9 therapists on standard screens */
    min-width: 160px; /* Ensures readability on smaller screens */
    box-sizing: border-box;
}

/* Time column specific styles */
.time-col {
    width: 85px !important;
    min-width: 85px !important;
    position: sticky;
    left: 0;
    background: white;
    z-index: 10;
    font-weight: 600;
    color: var(--text-muted);
    text-align: right;
    padding-right: 1rem;
    font-size: 0.85rem;
    border-right: 2px solid var(--border);
}

.schedule-table thead th.time-col {
    z-index: 11;
}

.schedule-table tbody td.time-col {
    background: #f8fafc;
}

/* Schedule Slots */
.slot {
    border-radius: 4px;
    padding: 0.4rem;
    min-height: 25px;
    height: 100%;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
}

.slot.available {
    background: #ecfdf5;
    border: 1px dashed #6ee7b7;
    color: #059669;
}

.slot.available:hover {
    background: #d1fae5;
    border-color: #10b981;
    color: #047857;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.leave-cell {
    background-color: #f1f5f9 !important;
    opacity: 0.8;
}

.roster-grid-container {
    max-height: 70vh;
}

.roster-select {
    padding: 0.2rem;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.roster-select:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    background-color: #e2e8f0 !important;
    color: #64748b;
}

.roster-select:hover:not(:disabled) {
    border-color: var(--primary);
    background: white !important;
}

.roster-select:focus {
    outline: 2px solid var(--primary);
    background: white !important;
}

.badge.danger {
    background: var(--danger);
    color: white;
}

.badge.success {
    background: var(--success);
    color: white;
}

.slot.booked {
    background: #fdf2f8;
    color: #db2777;
    border: 1px solid #fbcfe8;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.slot.booked:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.slot.home-physio {
    background: #fce7f3;
    color: #be185d;
    border: 1px solid #f9a8d4;
    min-height: 130px; /* Legacy floor, safe to keep */
}

.slot-title {
    font-weight: 600;
    margin-bottom: 0.1rem;
    font-size: 0.85rem;
}

.slot-details {
    font-size: 0.75rem;
    opacity: 0.9;
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.view-toggles {
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
}

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

.calendar-controls select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    min-width: 200px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.session-info {
    background: var(--bg-main);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Loader */
.loader {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--primary-light);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading-overlay {
    flex-direction: column;
    background: rgba(0, 0, 0, 0.75);
}

/* Tabs */
.tab-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
    overflow-x: auto;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--primary);
    background: #f0f7ff;
}

.tab-btn.active {
    color: var(--primary);
    background: #e0efff;
}

.tab-content {
    display: flex;
    flex-direction: column;
}

.settings-card {
    display: flex;
    flex-direction: column;
}

.settings-card .card-header h3 {
    font-size: 1.1rem;
    margin-bottom: 0;
}

.settings-body {
    margin-top: 1rem;
}

.settings-form-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.settings-form-row input,
.settings-form-row select {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
}

.settings-form-row input:focus,
.settings-form-row select:focus {
    border-color: var(--primary);
}

.settings-form-row .btn {
    width: auto;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

.compact-table th,
.compact-table td {
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.btn-delete {
    width: auto;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: #fee2e2;
    color: var(--danger);
    border: 1px solid #fecaca;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-delete:hover {
    background: #fecaca;
}

/* Calendar Roster */
.roster-calendar-container {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
}

.calendar-header {
    background: var(--bg-card);
    padding: 0.8rem;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
}

.calendar-day {
    background: white;
    min-height: 120px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.calendar-day.other-month {
    background: #f8fafc;
    color: #cbd5e1;
}

.calendar-day-num {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.calendar-therapist-entry {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px;
    border-radius: 4px;
    background: #f1f5f9;
    font-size: 0.75rem;
}

.calendar-therapist-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.calendar-select {
    width: 100%;
    font-size: 0.7rem;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: white;
    min-width: 0;
}

.calendar-select:disabled {
    background: #e2e8f0;
    cursor: not-allowed;
    opacity: 0.8;
}

.status-w { 
    background-color: #dcfce7 !important; 
    border-color: #bbf7d0 !important;
    color: #166534 !important; 
}

.status-leave { 
    background-color: #fce7f3 !important; 
    border-color: #fbcfe8 !important;
    color: #9d174d !important; 
}

@media (max-width: 1024px) {
    .roster-calendar-container {
        grid-template-columns: repeat(1, 1fr);
    }
    .calendar-header {
        display: none;
    }
}
