:root {
    --bg-main: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #334155;
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --accent-primary: #8b5cf6;
    --accent-hover: #7c3aed;
    --accent-light: rgba(139, 92, 246, 0.2);
    
    --border-color: #334155;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
}

.app-container {
    width: 100%;
    max-width: 1400px;
    min-height: 100vh;
    height: auto;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 1.25rem;
}

/* =========================================================
   🔑 ESTILOS DEL LOGIN Y ACCESO DENEGADO
   ========================================================= */

/* Contenedor principal de login centrado */
#login-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.login-header .logo-emoji {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.5rem;
}

.login-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Botón de Google */
.google-btn-container {
    width: 100%;
    margin-top: 2rem;
}

.btn-google {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background-color: #ffffff;
    color: #1f2937;
    border: none;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.1s ease, background-color 0.2s ease;
}

.btn-google:hover {
    background-color: #f8fafc;
}

.btn-google:active {
    transform: scale(0.98);
}

/* Cartel de error integrado */
.unauthorized-card {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 10px;
    padding: 16px;
    margin-top: 1.5rem;
    text-align: center;
    animation: fadeIn 0.3s ease-in-out;
}

.unauthorized-icon {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.unauthorized-card h4 {
    color: #ef4444;
    margin: 4px 0;
    font-size: 1rem;
    font-weight: 600;
}

.unauthorized-card p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0 0 12px 0;
}

.btn-retry {
    background-color: #ef4444;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s ease;
}

.btn-retry:hover {
    background-color: #dc2626;
}

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

/* Header de la App */
.app-header {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding: 1rem;
    background-color: #1a202c;
    border-radius: 12px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand h2 {
    color: #ffffff;
    font-size: 1.3rem;
    margin: 0;
}

.logo-icon {
    font-size: 1.75rem;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent-primary), #d946ef);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
}

.header-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 0.6rem;
}

.user-name {
    color: #e9d5ff;
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-btn {
    background-color: #ffffff;
    color: #6b21a8;
    border: none;
    padding: 0.4rem 0.9rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
}

.nav-btn:hover {
    background-color: var(--accent-light);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.logout-btn {
    background: rgba(147, 51, 234, 0.15);
    color: #d8b4fe;
    border: 1px solid rgba(168, 85, 247, 0.4);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: rgba(147, 51, 234, 0.3);
    color: #ffffff;
}

/* Layout */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    flex: 1;
    min-height: 0;
}

/* Panels */
.panel {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
}

.panel-header {
    margin-bottom: 1.5rem;
}

.panel-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* Calendar */
.calendar-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
}

.calendar-controls h3 {
    font-size: 1.1rem;
    font-weight: 500;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background-color: var(--bg-surface-hover);
}

.calendar {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-top: 1rem;
}

.weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
    flex: 1;
}

.day {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    min-height: 80px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.day:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.day.selected {
    background-color: var(--accent-light);
    border-color: var(--accent-primary);
}

.day.empty {
    background-color: transparent;
    border: none;
    cursor: default;
}

.day.empty:hover {
    transform: none;
}

.day-number {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: auto;
}

.day.today .day-number {
    color: var(--accent-primary);
}

.appointments-indicator {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--accent-primary);
}

.appointments-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.appointments-list {
    flex: 1;
    overflow-y: auto;
    max-height: calc(100vh - 350px);
}

.main-layout .appointments-panel div[style*="display: flex"] {
    margin-top: auto;
    padding-top: 1rem;
    background-color: var(--bg-surface);
    position: sticky;
    bottom: 0;
}

/* Custom Scrollbar */
.appointments-list::-webkit-scrollbar {
    width: 6px;
}
.appointments-list::-webkit-scrollbar-track {
    background: transparent;
}
.appointments-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}

.appointment-card {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    transition: transform 0.2s;
    cursor: pointer;
}

.appointment-card:hover {
    transform: translateX(4px);
    border-color: var(--accent-primary);
}

.time-badge {
    background-color: var(--accent-light);
    color: #a78bfa;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 65px;
    text-align: center;
}

.patient-info h4 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.patient-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-indicator {
    margin-left: auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.pending { background-color: var(--warning); }
.status-indicator.completed { background-color: var(--success); }
.status-indicator.cancelled { background-color: var(--danger); }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 0;
    font-size: 0.95rem;
}

/* Buttons */
.primary-btn {
    background: linear-gradient(135deg, var(--accent-primary), #6d28d9);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    box-shadow: 0 4px 14px 0 rgba(139, 92, 246, 0.39);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
    background: linear-gradient(135deg, var(--accent-hover), #5b21b6);
}

.primary-btn:active {
    transform: translateY(0);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-md);
    transform: translateY(0);
    transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal-content {
    transform: translateY(20px);
}

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

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

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

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

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
    color-scheme: dark;
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23cbd5e1' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: calc(100% - 1rem) center;
    cursor: pointer;
}

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

/* Modal Actions */
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

.modal-actions .primary-btn {
    width: auto;
    padding: 0.75rem 1.5rem;
}

.secondary-btn {
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* Buscador de pacientes */
#search-patient-input {
    margin-bottom: 0.5rem;
}

.patient-directory-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
}

.patient-directory-row:hover {
    border-color: var(--accent-primary);
}

/* Tarjetas del Historial Clínico */
.history-card {
    background-color: var(--bg-main);
    border-left: 4px solid var(--accent-primary);
    padding: 1rem;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.history-card em {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

/* 🔝 Prioridad de capas para los modales */
#appointment-modal {
    z-index: 1000;
}

#patient-modal {
    z-index: 2000 !important; 
}

/* 🖨️ ESTILOS EXCLUSIVOS PARA IMPRESIÓN */
@media print {
    body, .app-container, .main-layout, html {
        background: white !important;
        color: black !important;
        height: auto !important;
        overflow: visible !important;
    }
    .app-header, .calendar-panel, #print-day-btn, .primary-btn, .secondary-btn, .modal-overlay, .status-indicator, #login-container {
        display: none !important;
    }
    .appointments-panel {
        width: 100% !important;
        border: none !important;
        padding: 0 !important;
        background: white !important;
    }
    .panel-header h2 {
        font-size: 24pt !important;
        color: black !important;
        border-bottom: 2px solid black;
        padding-bottom: 10px;
    }
    #selected-date-text {
        color: #333 !important;
        font-size: 14pt !important;
        margin-bottom: 30px !important;
    }
    .appointment-card {
        background: white !important;
        border: 1px solid #ccc !important;
        color: black !important;
        box-shadow: none !important;
        margin-bottom: 15px !important;
        padding: 15px !important;
        page-break-inside: avoid;
    }
    .time-badge {
        background: #eee !important;
        color: black !important;
        border: 1px solid #aaa !important;
        font-size: 12pt !important;
    }
    .patient-info h4 {
        font-size: 14pt !important;
        color: black !important;
    }
    .patient-info p {
        color: #444 !important;
        font-size: 11pt !important;
    }
}

/* 📱 RESPONSIVIDAD PARA CELULARES (Menos de 768px) */
@media (max-width: 768px) {
    .app-container {
        padding: 0.75rem;
        gap: 1rem;
    }

    .app-header {
        padding: 0.75rem 1rem;
    }

    .logo h1 {
        font-size: 1.1rem;
    }

    .main-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .days {
        gap: 0.25rem;
    }

    .day {
        min-height: 58px;
        padding: 0.35rem;
    }

    .day-number {
        font-size: 0.8rem;
    }

    .weekdays {
        font-size: 0.75rem;
    }

    .panel {
        padding: 1rem;
    }

    .appointments-list {
        max-height: none;
    }

    @media (max-width: 400px) {
        .user-name {
            display: none;
        }
    }
}