/* ============================================================
   TRAVEL HEALTH — Estilos principales
   ============================================================ */

:root {
    --color-primary:    #1a6fb5;
    --color-primary-dk: #0d4f8a;
    --color-bg:         #f4f6fa;
    --color-card:       #ffffff;
    --color-border:     #dde2ec;
    --color-text:       #1e2532;
    --color-muted:      #6b7694;
    --color-success:    #1a8a4a;
    --color-warning:    #c47f00;
    --color-danger:     #b92d2d;
    --color-info:       #1a6fb5;

    /* Colores de citas — nomenclatura Travel Health */
    --cita-nuevo:       #ff6d00;  /* Naranja — paciente nuevo */
    --cita-subsecuente: #2979ff;  /* Azul — paciente subsecuente */
    --cita-factura:     #757575;  /* Gris — factura */
    --cita-atendido:    #2e7d32;  /* Verde — paciente atendido */
    --cita-pagado:      #7b1fa2;  /* Morado — paciente ya pagado */
    --cita-domicilio:   #f9a825;  /* Amarillo — visita a domicilio */
    --cita-cancelado:   #d32f2f;  /* Rojo — cancelado */

    --sidebar-width: 230px;
    --topbar-height: 56px;
    --radius: 8px;
    --shadow: 0 1px 4px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
}

/* ---- LOGIN ---- */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1a6fb5 0%, #0d4f8a 100%);
}
.login-container {
    background: var(--color-card);
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 100%; max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.login-logo { text-align: center; margin-bottom: 1.8rem; }
.login-logo h1 { font-size: 1.6rem; color: var(--color-primary); margin-top: .5rem; }
.login-logo p  { color: var(--color-muted); font-size: .85rem; }

/* ---- LAYOUT PRINCIPAL ---- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: #1e2532;
    color: #c8cfe0;
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; height: 100vh;
    z-index: 100;
}
.sidebar-logo {
    padding: 1.2rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    text-align: center;
}
.sidebar-nav { flex: 1; padding: .75rem 0; overflow-y: auto; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: .6rem 1.2rem;
    color: #c8cfe0; text-decoration: none;
    font-size: .875rem; border-radius: 6px;
    margin: 2px 8px; transition: background .15s;
}
.sidebar-nav a:hover,
.sidebar-nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-nav .nav-icon { width: 18px; text-align: center; }
.sidebar-user {
    padding: .8rem 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .8rem; color: #9aa3b8;
}
.sidebar-user strong { display: block; color: #fff; font-size: .85rem; }

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex; flex-direction: column;
}
.topbar {
    height: var(--topbar-height);
    background: var(--color-card);
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center;
    padding: 0 1.5rem; gap: 1rem;
    position: sticky; top: 0; z-index: 90;
}
.topbar h2 { font-size: 1rem; font-weight: 600; flex: 1; }
.page-body { padding: 1.5rem; }

/* ---- TARJETAS ---- */
.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--color-border);
}
.card-title { font-size: .95rem; font-weight: 600; }

/* ---- ESTADÍSTICAS ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--color-primary); }
.stat-card .stat-label { font-size: .78rem; color: var(--color-muted); margin-top: .25rem; }

/* ---- FORMULARIOS ---- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .35rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: .04em; }
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: .55rem .8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: .9rem; color: var(--color-text);
    background: var(--color-card);
    transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26,111,181,.12);
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ---- BOTONES ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: .5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: .875rem; font-weight: 500;
    cursor: pointer; text-decoration: none;
    transition: all .15s;
}
.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dk); }
.btn-secondary { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-danger    { background: var(--color-danger); color: #fff; }
.btn-success   { background: var(--color-success); color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; padding: .7rem; }

/* ---- TABLAS ---- */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { background: var(--color-bg); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-muted); padding: .6rem .9rem; text-align: left; border-bottom: 2px solid var(--color-border); }
td { padding: .65rem .9rem; border-bottom: 1px solid var(--color-border); }
tr:hover td { background: rgba(26,111,181,.04); }

/* ---- BADGES / COLORES CITAS (nomenclatura Travel Health) ---- */
.badge {
    display: inline-block; padding: .2rem .6rem;
    border-radius: 20px; font-size: .72rem; font-weight: 600;
}
.badge-nuevo       { background: #fff0e0; color: #8a4500; } /* Naranja */
.badge-subsecuente { background: #e3edff; color: #1a4fa0; } /* Azul */
.badge-factura     { background: #f2f2f2; color: #4a4a4a; } /* Gris */
.badge-atendido    { background: #e4f5eb; color: #1a5c34; } /* Verde */
.badge-pagado      { background: #f5e8ff; color: #5a0a8a; } /* Morado */
.badge-domicilio   { background: #fffbe0; color: #7a6000; } /* Amarillo */
.badge-cancelado   { background: #fde8e8; color: #8a2020; } /* Rojo */

/* ---- ALERTAS ---- */
.alert {
    padding: .75rem 1rem; border-radius: var(--radius);
    margin-bottom: 1rem; font-size: .875rem;
}
.alert-error   { background: #fde8e8; border: 1px solid #f5b8b8; color: #8a2020; }
.alert-success { background: #e4f5eb; border: 1px solid #b8e0c8; color: #1a5c34; }
.alert-warning { background: #fffbe0; border: 1px solid #ffe08a; color: #7a6000; }
.alert-info    { background: #e3edff; border: 1px solid #b8d0f5; color: #1a4fa0; }

/* ---- LEYENDA COLORES CALENDARIO ---- */
.legend { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: .78rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* ---- MODAL ---- */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 500;
    align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--color-card); border-radius: 12px;
    padding: 1.5rem; width: 100%; max-width: 560px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0,0,0,.2);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.25rem;
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--color-muted); }

/* ---- INVENTARIO ALERTAS ---- */
.stock-bajo { color: var(--color-danger); font-weight: 600; }
.stock-ok   { color: var(--color-success); }

/* ---- UTILIDADES ---- */
.text-muted    { color: var(--color-muted); }
.text-right    { text-align: right; }
.text-center   { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }
.fw-600 { font-weight: 600; }
.fs-sm { font-size: .8rem; }

/* ---- CALENDARIO (FullCalendar overrides) ---- */
#calendar { background: var(--color-card); border-radius: var(--radius); }
.fc-toolbar-title { font-size: 1rem !important; font-weight: 600 !important; }
.fc-event { cursor: pointer; border-radius: 4px !important; font-size: .78rem !important; }
.fc-event-nuevo       { background: var(--cita-nuevo)       !important; border-color: var(--cita-nuevo)       !important; }
.fc-event-subsecuente { background: var(--cita-subsecuente) !important; border-color: var(--cita-subsecuente) !important; }
.fc-event-factura     { background: var(--cita-factura)     !important; border-color: var(--cita-factura)     !important; }
.fc-event-atendido    { background: var(--cita-atendido)    !important; border-color: var(--cita-atendido)    !important; }
.fc-event-pagado      { background: var(--cita-pagado)      !important; border-color: var(--cita-pagado)      !important; }
.fc-event-domicilio   { background: var(--cita-domicilio)   !important; border-color: var(--cita-domicilio)   !important; color: #333 !important; }
.fc-event-cancelado   { background: var(--cita-cancelado)   !important; border-color: var(--cita-cancelado)   !important; }

/* ---- RESPONSIVE MÓVIL ---- */
@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    .sidebar { position: fixed; left: -260px; width: 260px; transition: left .25s ease; z-index: 200; }
    .sidebar.open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,.3); }
    .main-content { margin-left: 0 !important; }
    .topbar { padding: 0 1rem; }
    .topbar #menu-btn { display: flex !important; }
    .page-body { padding: 1rem .75rem; }
    .stats-grid { grid-template-columns: 1fr 1fr !important; gap: .6rem; }
    .stat-card { padding: .75rem; }
    .stat-card .stat-value { font-size: 1.4rem; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr !important; }
    .card { padding: 1rem .75rem; }
    .card-header { flex-wrap: wrap; gap: .5rem; }
    #calendar .fc-toolbar { flex-direction: column; gap: .5rem; }
    #calendar .fc-toolbar-title { font-size: .9rem !important; }
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 600px; }
    .modal { width: 95vw; max-width: 95vw; padding: 1rem; margin: 0 auto; }
    .d-flex.gap-2 { flex-direction: column; }
    .fc-event { font-size: .72rem !important; }
    div[style*="width:260px"] { width: 100% !important; }
    .btn { padding: .55rem 1rem; font-size: .9rem; }
    .btn-sm { padding: .4rem .75rem; font-size: .82rem; }
    table th:nth-child(4), table td:nth-child(4),
    table th:nth-child(7), table td:nth-child(7) { display: none; }
}

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 199; }
.sidebar-overlay.active { display: block; }