/* =========================================
   DiBlue - Design System
   ========================================= */
   :root {
    /* Paleta Base (Consistent with Mobile App) */
    --primary: #3498db;
    --primary-dark: #2980b9;
    --primary-light: #f0f7ff;
    --secondary: #2c3e50;
    --accent: #8e44ad;
    
    /* Estados */
    --success: #2ecc71;
    --warning: #f1c40f;
    --danger: #e74c3c;
    --danger-dark: #c0392b;
    --info: #34495e;

    /* Fondos y Texto */
    --bg-body: #F5F7FA;
    --bg-card: #FFFFFF;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --border-color: #ecf0f1;

    /* Sombras y Bordes */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50px;

    /* Disciplinas */
    --color-to: #e67e22; 
    --color-fono: #16a085; 
    --color-psico: #9b59b6;
    --color-ped: #f39c12;
    --color-kinesio: #2980b9;
    --color-edu-dif: #e74c3c;
    --color-nutri: #16a085;
}

.disc-to { background-color: var(--color-to); color: white; }
.disc-fono { background-color: var(--color-fono); color: white; }
.disc-psico { background-color: var(--color-psico); color: white; }
.disc-ped { background-color: var(--color-ped); color: white; }


.text-dark { color: var(--text-main) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-danger { color: var(--danger) !important; }


.patient-card-interactive {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.patient-card-interactive:hover {
    transform: translateX(5px);
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--primary);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* =========================================
   Sidebar Layout
   ========================================= */
.sidebar {
    width: 260px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    padding: 1.5rem;
    z-index: 1000;
}

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

.brand div {
    margin-left: 3rem;
    display: flex;
    flex-direction: column;
    font-size: 1.4rem;
}
.brand small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.logoimg {
    position: absolute;
    max-width: 46px;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-item:hover, .nav-item.active {
    background-color: #eaf6fc;
    color: var(--primary);
}

.user-profile {
    position: absolute;
    bottom: 1rem;
    left: .5rem;
    right: 1rem;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    gap: 1rem;
    border-top: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 1rem;
    margin: 0 -1rem -1rem -1rem; /* Negative margin to fill width */
}

.user-profile:hover {
    background-color: #f8f9fa;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info h4 {
    font-size: 0.9rem;
    margin-bottom: 0;
}

.user-info span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* =========================================
   Main Content Area
   ========================================= */
.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 1rem;
}

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

.patients .header {
    display: grid;
    grid-template-columns: 1fr 180px;
    gap: 20px;
}

.header.fixed {
    position: fixed;
    top: 0;
    left: 16rem;
    right: 0;
    margin-bottom: 0;
    padding: 1rem;
    background: var(--bg-body);
    z-index: 11;
}

.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--secondary);
}

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

.patients .actions {
    justify-items: end;
}

/* =========================================
   Components
   ========================================= */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

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


.stat-card {
    background: white;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--border-color);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-info h3 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--secondary);
}

.stat-info span {
    font-size: 0.85rem;
    color: var(--text-muted);
}





.btn {
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    transition: opacity 0.2s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary-disabled { background: #d0dcef; color: white; }
.btn-secondary { background: white; border: 1px solid var(--border-color); color: var(--secondary); }
.btn:hover { opacity: 0.9; }


.btn-outline-primary {
    background: white;
    border: 1px solid var(--primary);
    color: var(--primary);
}

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

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: #f0f0f0;
    color: var(--primary);
}
.mx-0 { margin-left: 0 !important; margin-right: 0 !important; }
.mx-1 { margin-left: 0.25rem !important; margin-right: 0.25rem !important; }
.mx-2 { margin-left: 0.5rem !important; margin-right: 0.5rem !important; }

.mt-1 { margin-top: 0.25rem !important; }

.mt-2 {
    margin-top: 0.5rem !important;
}
.mt-4 {
    margin-top: 1rem !important;
}
.mt-8 {
    margin-top: 2rem !important;
}

.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 {
    margin-bottom: 1rem !important;
}

.my-4 {
    margin-top: 1rem !important;
    margin-bottom: 1rem !important;
}

.p-0 { padding: 0 !important; }
.p-2 { padding: 0.5rem !important; }
.p-3 { padding: 1rem !important; }





/* Grid de Pacientes */
.patient-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.patient-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.patient-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.patient-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.patient-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
}

.patient-info h3 { font-size: 1.1rem; margin-bottom: 0.2rem; }
.patient-info p { font-size: 0.85rem; color: var(--text-muted); }

.tag {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    background: #f0f0f0;
    color: var(--text-muted);
}

.tag-diagnosis { background: #e8f4f8; color: var(--primary); }
.tag-discipline { color: white; }

/* Calendario Mini */
.calendar-view {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.calendar-header {
    background: #f8f9fa;
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    color: var(--secondary);
}

.calendar-day {
    background: white;
    min-height: 120px;
    padding: 0.5rem;
}

.calendar-day.today {
    background: #fcfcfc;
}

.calendar-date {
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: block;
    color: var(--text-muted);
}

.appt-pill {
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
    display: block;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    transition: opacity 0.2s;
}
.appt-pill:hover { opacity: 0.9; }

/* Patient Detail */
.detail-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
}

.timeline {
    border-left: 2px solid var(--border-color);
    padding-left: 2rem;
    margin-left: 1rem;
}

.timeline-item {
    position: relative;
    margin-bottom: 2rem;
}

.timeline-dot {
    position: absolute;
    left: -2.6rem;
    top: 0;
    width: 20px;
    height: 20px;
    background: white;
    border: 4px solid var(--primary);
    border-radius: 50%;
}

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

/* Tabs */
.tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.tab-link {
    padding: 0.8rem 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    border-bottom: 3px solid transparent;
}

.tab-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Forms */
.form-invalid-feedback {
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 0.25rem;
    margin-left: 2px;
}



.form-col{
    display: grid;
    gap: 1rem;
    padding: 1rem;
    margin: 1rem;
    border: solid 1px var(--border-color);
    border-radius: var(--radius-sm);
}

.form-cols{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1rem;
    margin: 1rem;
    border: solid 1px var(--border-color);
    border-radius: var(--radius-sm);
}


.form-cols.alt {
    background: #f0f7ff;
}
.form-2y1-cols{
    grid-template-columns: 2fr 1fr;
}
.form-3y1-cols{
    grid-template-columns: 3fr 1fr;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 25px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary-light);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 25px;
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1rem;
}
.form-grid .form-group {
    margin-bottom: 0;
}

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

.form-control {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-control-sm {
    padding: 0.7rem;
    font-size: 0.9rem;
}

.input-icon-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
}

.input-icon-wrapper .input-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
    font-size: 1rem;
    pointer-events: none;
    top: .9rem;
}

.input-icon-wrapper .form-control {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.75rem; /* Space for icon */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s;
    background: #f8fafc;
}

/* Toggle Button */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 25px;
    background: #f8f9fa;
    padding: 15px;
    border-radius: var(--radius-sm);
}

.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(22px); }


/* Tabs Override */
.nav-tabs {
    display: flex;
    gap: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-tab {
    padding: 0.75rem 0;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}
.patient-grid.active{
    display: grid;
}

/* Table Styles */
.table-responsive { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 12px 15px; border-bottom: 2px solid var(--border-color); color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; }
td { padding: 15px; border-bottom: 1px solid var(--border-color); font-size: 0.95rem; }

.status-pill {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}
.status-enviada { background: var(--primary-light); color: var(--primary-color); }
.status-pendiente { background: #fff8e1; color: var(--warning); }
.status-completada { background: #e8f5e9; color: var(--success); }



/* =========================================
   Global Modal Styles
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}


.error-modal .modal-content {
    border-left: 4px solid var(--danger);
}
.error-modal .modal-header h3 {
    color: var(--danger);
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    width: 500px;
    max-width: 90%;
    /* Remove padding from main container to control header/body/footer separately */
    padding: 0; 
    box-shadow: var(--shadow-md);
    position: relative;
    transform: translateY(0);
    animation: slideUpFade 0.3s ease-out;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.modal-content.sm{
    width: 300px;
}
.modal-overlay.active.lg .modal-content, .modal-content.lg{
    width: 800px;
    max-width: 800px !important;
}
.modal-content.xl{
    width: 1140px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: white;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-shrink: 0; /* Prevent shrinking */
}

#global-dialog-container .modal-header {
    padding-bottom: 1rem;
}


.modal-body {
    padding: 1rem 1.5rem;
    overflow-y: auto; /* Scroll only here */
    flex: 1; /* Take available space */
    padding-bottom: 0;
}

#global-dialog-container .modal-body {
    padding-bottom: 1.2rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: white;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    text-align: right;
    flex-shrink: 0; /* Prevent shrinking */
    display: flex;
    justify-content: space-between;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--secondary);
}

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

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

#global-dialog-container .modal-footer{
    justify-content: flex-end;
}

.space-between .modal-footer{
    justify-content: space-between !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Toast Notification (Simple version for Web) */
.web-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    border-left: 4px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 3000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.web-toast.active {
    transform: translateY(0);
    opacity: 1;
}

.web-toast.success { border-left-color: var(--success); }
.web-toast.error { border-left-color: var(--danger); top: 2rem;bottom: unset; }


.loadingStripe {
  border: 1px solid white;
  width: 70%;
  height: 1.6rem;
  background-color: #babbbc;
  animation: hintloading 1s ease-in-out 0s infinite reverse;
  -webkit-animation: hintloading 1s ease-in-out 0s infinite reverse;
}
.loadingStripe.fullwidth {
    width: 100%;
}
.loadingStripe.fullheight {
    height: 100%;
}

/* Lightbox Styles */
.lightbox-overlay {
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s;
}

.lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 90%;
}

.lightbox-content img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.lightbox-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    z-index: 10000;
}

.lightbox-close:hover,
.lightbox-close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

.lightbox-prev,
.lightbox-next {
    cursor: pointer;
    position: absolute;
    top: 50%;
    width: auto;
    padding: 16px;
    margin-top: -50px;
    color: white;
    font-weight: bold;
    font-size: 20px;
    transition: 0.6s ease;
    border-radius: 0 3px 3px 0;
    user-select: none;
    -webkit-user-select: none;
    z-index: 10001;
}

.lightbox-next {
    right: 0;
    border-radius: 3px 0 0 3px;
}

.lightbox-prev {
    left: 0;
    border-radius: 0 3px 3px 0;
}

.lightbox-prev:hover,
.lightbox-next:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

.delete-icon {
    color: var(--danger);
    cursor: pointer;
    transition: color 0.3s ease;
    border:none;
}
.delete-icon:hover {
    color: var(--danger-dark);
}

.d-none {
    display: none !important;
}

.d-flex {
    display: flex !important;
}
.gap-2 {
    gap: 0.5rem;
}

.bg-danger {
    background-color: var(--danger);
}
.bg-card {
    background-color: var(--bg-card);
}
.bg-light { background-color: #f8f9fa; }
.bg-primary { background-color: var(--primary); }
.bg-primary-light { background-color: var(--primary-light); }


@keyframes hintloading
{
  0%   { opacity: 0.3; }
  50%  { opacity: 0.6; }
  100% { opacity: 0.3; }
}

@-webkit-keyframes hintloading
{
  0%   { opacity: 0.3; }
  50%  { opacity: 0.6; }
  100% { opacity: 0.3; }
}

.strong{
    font-weight: 600;
}

/* Banner de Ayuda/Contexto */
.context-banner {
    background-color: var(--primary-light);
    border-radius: var(--radius-sm);
    padding: 20px;
    display: flex;
    gap: 15px;
    margin-bottom: 1.5rem;
}

.context-banner i { color: var(--primary); font-size: 1.5rem; }
.context-banner p { font-size: 0.85rem; color: var(--secondary); line-height: 1.5; }


        .institution-selector {
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-weight: 600;
            font-size: 1.2rem;
            justify-content: space-between;
        }
        .institution-menu {
            position: absolute;
            top: 100%;
            left: -100px;
            background: white;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            box-shadow: var(--shadow-md);
            min-width: 200px;
            z-index: 1000;
            padding: 0.5rem 0;
            margin-top: 0.5rem;
        }
        .institution-item {
            display: flex;
            font-size: .9rem;
            justify-content: space-between;
            align-items: center;
            padding: 0.75rem 1rem;
            text-decoration: none;
            color: var(--text-color);
            transition: background 0.2s;
        }
        .institution-item:hover {
            background: var(--border-color);
        }
        .institution-item.active {
            font-weight: 600;
            color: var(--primary);
            background: var(--primary-light);
        }