*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #0f172a;
    --gray-900: #1e293b;
    --gray-700: #334155;
    --gray-600: #475569;
    --gray-500: #64748b;
    --gray-400: #94a3b8;
    --gray-300: #cbd5e1;
    --gray-200: #e2e8f0;
    --gray-100: #f1f5f9;
    --gray-50: #f8fafc;
    --gradient: linear-gradient(135deg, #2563eb 0%, #06b6d4 100%);
    --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
    --shadow-md: 0 4px 12px rgba(15,23,42,.08);
    --shadow-lg: 0 12px 40px rgba(15,23,42,.10);
}
body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--gray-50);
    color: var(--dark);
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; }
ul { list-style: none; }
h1,h2,h3,h4,h5 { font-family: 'Plus Jakarta Sans', sans-serif; letter-spacing: -0.02em; }

/* LAYOUT */
.layout { display: grid; grid-template-columns: 284px 1fr; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
    background:
        radial-gradient(circle at top left, rgba(37,99,235,.18), transparent 34%),
        linear-gradient(180deg, #0f172a 0%, #111b34 100%);
    color: white;
    padding: 20px 14px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    border-right: 1px solid rgba(148,163,184,0.12);
    box-shadow: inset -1px 0 0 rgba(255,255,255,0.03);
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px 18px;
    color: white;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 16px;
    flex-shrink: 0;
}
.brand strong {
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.brand-icon {
    width: 36px; height: 36px;
    background: var(--gradient);
    border-radius: 10px;
    display: grid;
    place-items: center;
}
.brand-icon svg { width: 20px; height: 20px; color: white; }
.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 6px;
    margin-right: -6px;
}
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
.nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
    color: #c8d3e5;
    font-weight: 600;
    font-size: 0.88rem;
    line-height: 1.2;
    transition: all 0.15s;
    min-height: 42px;
}
.nav-item span {
    flex: 1;
    min-width: 0;
}
.nav-item:hover {
    background: rgba(148,163,184,0.10);
    border-color: rgba(148,163,184,0.12);
    color: white;
}
.nav-item.active {
    background: rgba(37,99,235,0.18);
    border-color: rgba(96,165,250,0.28);
    color: white;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
.nav-item.active svg { color: white; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.88; }
.nav-item.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
    color: #93a4bf;
}
.nav-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    color: #8ea4c7;
    padding: 16px 10px 6px;
    font-weight: 700;
    margin-top: 4px;
}
.nav-group-title::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: #60a5fa;
    box-shadow: 0 0 0 4px rgba(37,99,235,0.15);
}
.nav-group-title:first-child { margin-top: 0; padding-top: 4px; }
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 14px;
    margin-top: 12px;
    flex-shrink: 0;
}
.user-card {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 14px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(148,163,184,0.10);
}
.user-avatar {
    width: 38px; height: 38px;
    background: var(--gradient);
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.85rem;
}
.user-info strong { display: block; font-size: 0.88rem; }
.user-info small { color: var(--gray-400); font-size: 0.75rem; }
.logout-btn {
    width: 100%;
    background: rgba(255,255,255,0.04);
    color: var(--gray-300);
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid rgba(148,163,184,0.10);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
}
.logout-btn:hover {
    background: rgba(239,68,68,0.15);
    border-color: rgba(248,113,113,0.20);
    color: #fca5a5;
}

/* MAIN */
.main { padding: 0 32px 32px; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 28px;
}
.topbar h1 { font-size: 1.7rem; font-weight: 800; }
.topbar-actions { display: flex; gap: 10px; }
.content { padding-bottom: 30px; }

/* COMPONENTS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.15s;
    cursor: pointer;
    border: 1.5px solid transparent;
}
.btn-primary { background: var(--gradient); color: white; box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(37,99,235,0.4); }
.btn-secondary { background: white; color: var(--dark); border-color: var(--gray-200); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-block { width: 100%; justify-content: center; }

.card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.flash {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-weight: 500;
    font-size: 0.93rem;
}
.flash-ok { background: rgba(16,185,129,0.1); color: #047857; border: 1px solid rgba(16,185,129,0.3); }
.flash-error { background: rgba(239,68,68,0.1); color: #b91c1c; border: 1px solid rgba(239,68,68,0.3); }
.flash ul { padding-left: 20px; list-style: disc; }

/* STATS GRID */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
    margin-bottom: 32px;
}
.stat-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: 14px;
    padding: 22px;
    position: relative;
    overflow: hidden;
}
.stat-card .stat-icon {
    width: 42px; height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    margin-bottom: 14px;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 800; color: var(--dark); line-height: 1.1; }
.stat-card .stat-label { color: var(--gray-500); font-size: 0.88rem; margin-top: 4px; }

/* TABLE */
.table-wrap { background: white; border: 1px solid var(--gray-200); border-radius: 14px; overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 14px 18px; text-align: left; border-bottom: 1px solid var(--gray-100); font-size: 0.92rem; }
table.data th { background: var(--gray-50); font-weight: 600; color: var(--gray-700); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--gray-50); }

/* BADGE */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-pendiente { background: rgba(245,158,11,0.15); color: #b45309; }
.badge-confirmada { background: rgba(59,130,246,0.15); color: #1d4ed8; }
.badge-atendida { background: rgba(16,185,129,0.15); color: #047857; }
.badge-cancelada { background: rgba(239,68,68,0.15); color: #b91c1c; }
.badge-no_asistio { background: rgba(107,114,128,0.15); color: #374151; }
.badge-online { background: rgba(6,182,212,0.15); color: #0e7490; }
.badge-interna { background: var(--gray-100); color: var(--gray-700); }

/* FORMS */
.form-grid { display: grid; gap: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: 10px;
    font-size: 0.93rem;
    font-family: inherit;
    background: white;
    transition: border 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.field textarea { min-height: 90px; resize: vertical; }

/* AGENDA */
.agenda-wrap {
    background: white;
    border-radius: 14px;
    border: 1px solid var(--gray-200);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}
.fc { font-family: 'Inter', sans-serif; }
.fc .fc-toolbar-title { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 1.3rem !important; }
.fc-button-primary { background: var(--gradient) !important; border: none !important; box-shadow: var(--shadow-sm); }
.fc-event { border-radius: 6px !important; padding: 2px 6px !important; font-size: 0.78rem !important; cursor: pointer; }

/* MODAL */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 999; }
.modal-backdrop.open { display: flex; }
.modal {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    padding: 28px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}
.modal h3 { margin-bottom: 18px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* AUTH */
.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f0f7ff, #ffffff);
    padding: 24px;
}
.auth-card {
    background: white;
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}
.auth-card .brand {
    border: none;
    margin-bottom: 24px;
    padding: 0 0 18px;
    color: var(--dark);
}
.auth-card h2 { font-size: 1.5rem; margin-bottom: 6px; }
.auth-card .sub { color: var(--gray-500); margin-bottom: 24px; font-size: 0.93rem; }

/* RESERVA PUBLICA */
.public-shell {
    min-height: 100vh;
    background: linear-gradient(135deg, #f0f7ff, #ffffff);
    padding: 40px 20px;
}
.public-card {
    max-width: 760px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.public-header {
    background: var(--gradient);
    color: white;
    padding: 32px 36px;
}
.public-header h1 { font-size: 1.6rem; }
.public-header p { opacity: 0.9; font-size: 0.95rem; margin-top: 4px; }
.public-body { padding: 36px; }

.medico-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.medico-card {
    border: 2px solid var(--gray-200);
    border-radius: 14px;
    padding: 18px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}
.medico-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.medico-card.selected { border-color: var(--primary); background: rgba(37,99,235,0.05); }
.medico-card .doc-avatar {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--gradient);
    color: white;
    display: grid;
    place-items: center;
    font-weight: 700;
    margin-bottom: 10px;
}
.medico-card strong { display: block; font-size: 0.95rem; }
.medico-card small { color: var(--gray-500); font-size: 0.82rem; }
.medico-card .precio { color: var(--primary); font-weight: 700; margin-top: 6px; font-size: 0.9rem; }

.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; margin-top: 14px; }
.slot-btn {
    padding: 10px;
    border-radius: 10px;
    border: 1.5px solid var(--gray-200);
    background: white;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s;
}
.slot-btn:hover { border-color: var(--primary); color: var(--primary); }
.slot-btn.selected { background: var(--gradient); color: white; border-color: transparent; }

.step-tag { display: inline-block; background: rgba(37,99,235,0.1); color: var(--primary); padding: 4px 12px; border-radius: 100px; font-size: 0.78rem; font-weight: 700; margin-bottom: 10px; }

/* CONFIRMACION */
.confirm-icon {
    width: 80px; height: 80px;
    background: var(--success);
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin: 0 auto 20px;
    color: white;
}
.confirm-detail { background: var(--gray-50); padding: 20px; border-radius: 12px; margin: 22px 0; }
.confirm-detail dt { font-size: 0.78rem; color: var(--gray-500); text-transform: uppercase; font-weight: 600; letter-spacing: 0.05em; }
.confirm-detail dd { font-size: 1rem; margin-bottom: 12px; font-weight: 500; }

/* RESPONSIVE */
@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; max-height: none; overflow: visible; padding: 16px; }
    .sidebar .nav { max-height: none; overflow: visible; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .main { padding: 16px; }
    .page-header { align-items: flex-start; gap: 12px; }
    .page-header h1 { font-size: 1.35rem; line-height: 1.2; }
    .stats-grid { grid-template-columns: 1fr; }
    .modal { width: calc(100vw - 24px); max-height: calc(100vh - 24px); overflow-y: auto; padding: 18px; border-radius: 14px; }
    .public-shell { padding: 18px 12px; }
    .public-card { border-radius: 14px; }
    .public-header { padding: 24px 20px; }
    .public-body { padding: 22px 18px; }
    .medico-grid { grid-template-columns: 1fr; }
    .slot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .btn { white-space: normal; text-align: center; }
    .table-wrap { overflow-x: auto; }
}
