:root {
    --bg: #eef2f7;
    --surface: #ffffff;
    --ink: #1a2332;
    --muted: #5c6b7a;
    --line: #dce3ec;
    --accent: #2f6fed;
    --accent-soft: rgba(47, 111, 237, 0.12);
    --accent-2: #c45c26;
    --sidebar: #0f2744;
    --sidebar-2: #163556;
    --sidebar-text: rgba(255, 255, 255, 0.78);
    --sidebar-active: #3d7cf0;
    --warn: #8a5a00;
    --danger: #9b2c2c;
    --ok: #1f8a5b;
    --shadow: 0 8px 24px rgba(15, 39, 68, 0.08);
    --radius: 16px;
    --sidebar-w: 260px;
    --font: "Segoe UI", "Candara", "Trebuchet MS", sans-serif;
    --tone-green: #1f8a5b;
    --tone-blue: #2f6fed;
    --tone-purple: #6b5ce7;
    --tone-amber: #c47a1a;
    --tone-rose: #c44b6a;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* —— App shell + sidebar —— */
.app-body {
    display: flex;
    min-height: 100vh;
    background:
        radial-gradient(ellipse 80% 50% at 100% 0%, rgba(47, 111, 237, 0.06), transparent 50%),
        var(--bg);
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--sidebar) 0%, #0b1e35 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 40;
    padding: 1.1rem 0.85rem 1rem;
    box-shadow: 4px 0 24px rgba(15, 39, 68, 0.18);
}

.sidebar-brand {
    padding: 0.5rem 0.45rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.85rem;
}
.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: inherit;
    text-decoration: none;
}
.sidebar-brand-link:hover { text-decoration: none; }
.sidebar-brand-link.has-logo {
    display: block;
    width: 100%;
    padding: 0.65rem 0.7rem;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.sidebar-logo {
    display: block;
    width: 100%;
    height: auto;
    max-height: 88px;
    object-fit: contain;
    border-radius: 0;
    background: transparent;
    padding: 0;
}
.sidebar-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background:
        radial-gradient(circle at 35% 35%, #7eb6ff 0 28%, transparent 29%),
        radial-gradient(circle at 65% 60%, #3d7cf0 0 34%, transparent 35%),
        rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-name {
    font-weight: 700;
    font-size: 0.98rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-sub {
    font-size: 0.72rem;
    color: var(--sidebar-text);
    font-weight: 400;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    overflow-y: auto;
    padding: 0.15rem 0;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
}
.sidebar-link.active {
    background: var(--sidebar-active);
    color: #fff;
    box-shadow: 0 6px 16px rgba(61, 124, 240, 0.35);
}
.sidebar-ico {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.sidebar-ico svg { width: 20px; height: 20px; display: block; }

.sidebar-foot {
    margin-top: auto;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: grid;
    gap: 0.5rem;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.45rem;
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
}
.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.06);
    text-decoration: none;
}
.sidebar-user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}
.sidebar-user-meta strong {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-meta span {
    font-size: 0.75rem;
    color: var(--sidebar-text);
    text-transform: capitalize;
}
.sidebar-logout {
    color: var(--sidebar-text);
    font-size: 0.85rem;
    padding: 0.35rem 0.55rem;
    text-decoration: none;
}
.sidebar-logout:hover { color: #fff; }

.sidebar-backdrop {
    display: none;
}

.app-shell {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.5rem;
    background: rgba(255, 255, 255, 0.85);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.app-topbar-title { flex: 1; }
.sidebar-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    cursor: pointer;
    padding: 0 11px;
}
.sidebar-toggle span {
    display: block;
    height: 2px;
    background: var(--ink);
    border-radius: 2px;
}

.userbox {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--muted);
    font-size: 0.9rem;
}
.userchip {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.25rem 0.65rem 0.25rem 0.25rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}
.userchip-text {
    font-size: 0.85rem;
    color: var(--ink);
    font-weight: 600;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.avatar {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}
.avatar-sm { width: 34px; height: 34px; font-size: 0.75rem; }
.avatar-tone-1 { background: rgba(31, 138, 91, 0.15); color: var(--tone-green); }
.avatar-tone-2 { background: rgba(47, 111, 237, 0.15); color: var(--tone-blue); }
.avatar-tone-3 { background: rgba(107, 92, 231, 0.15); color: var(--tone-purple); }
.avatar-tone-4 { background: rgba(196, 122, 26, 0.15); color: var(--tone-amber); }

.container {
    width: min(1180px, calc(100% - 2.5rem));
    margin: 1.35rem auto 2.5rem;
    flex: 1;
}

.footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    padding: 1rem 1.5rem 1.5rem;
}

/* Legacy brand bits (login / config) */
.brand a {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--ink);
    text-decoration: none;
}
.brand-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
    color: inherit;
}
.brand-link:hover { text-decoration: none; }
.brand-logo {
    height: 48px;
    width: auto;
    max-width: 220px;
    object-fit: contain;
    display: block;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.brand-sub {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 400;
}
.login-logo { margin-bottom: 0.85rem; }
.login-logo img {
    max-height: 72px;
    max-width: 220px;
    width: auto;
    object-fit: contain;
    display: block;
}
.brand-preview {
    margin: 0.75rem 0 1rem;
    padding: 1rem;
    background: #f4f7fb;
    border-radius: 12px;
    border: 1px dashed var(--line);
    display: inline-flex;
}
.brand-preview img {
    max-height: 80px;
    max-width: 240px;
    object-fit: contain;
}
.brand-preview-favicon img {
    max-height: 48px;
    max-width: 48px;
}

h1, h2, h3 { margin: 0 0 0.75rem; line-height: 1.2; }
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.35rem;
    flex-wrap: wrap;
}
.page-head h1 {
    font-size: clamp(1.55rem, 2.4vw, 1.9rem);
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
}
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.15rem 1.25rem;
    margin-bottom: 1rem;
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}
.card-head h2 {
    margin: 0;
    font-size: 1.05rem;
}
.card-link {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
}

.grid {
    display: grid;
    gap: 1rem;
}
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.dash-main {
    grid-template-columns: 1.35fr 1fr;
    align-items: start;
}
.dash-ops {
    grid-template-columns: 1.2fr 1fr;
    align-items: start;
    margin-top: 0.25rem;
}
.page-head-compact {
    margin-bottom: 0.85rem;
}
.page-head-compact h1 {
    font-size: 1.35rem;
    margin-bottom: 0.15rem;
}
.page-head-compact .muted {
    margin: 0;
}
a.dash-stat-link {
    text-decoration: none;
    color: inherit;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
a.dash-stat-link:hover {
    text-decoration: none;
    transform: translateY(-1px);
}
.dash-pendientes-all {
    margin-top: 0.75rem;
}
.dash-pendientes-all summary {
    cursor: pointer;
    color: var(--primary, #2f6fed);
    font-size: 0.9rem;
    font-weight: 600;
}
.dash-secondary-ok {
    margin: 0.5rem 0 0;
}

@media (max-width: 980px) {
    .dash-main { grid-template-columns: 1fr; }
    .dash-ops { grid-template-columns: 1fr; }
    .dash-ops.role-coord .dash-pendientes { order: 1; }
    .dash-ops.role-coord .dash-proximos { order: 2; }
    .dash-ops.role-recepcion .dash-proximos { order: 1; }
    .dash-ops.role-recepcion .dash-pendientes { order: 2; }
    .dash-ops.role-terapeuta .dash-proximos { order: 1; }
    .dash-ops.role-terapeuta .dash-pendientes { order: 2; }
}
@media (max-width: 800px) {
    .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .sidebar {
        transform: translateX(-105%);
        transition: transform 0.22s ease;
    }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 39, 68, 0.45);
        z-index: 35;
    }
    .sidebar-backdrop[hidden] { display: none !important; }
    .app-shell { margin-left: 0; }
    .sidebar-toggle { display: flex; }
    .container { width: calc(100% - 1.5rem); }
}

/* Stats */
.stat {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.stat strong { font-size: 1.8rem; color: var(--accent); }
.stat.warn strong { color: var(--accent-2); }
.stat.danger strong { color: var(--danger); }

.stat-card {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 1rem 1.15rem;
}
.stat-ico {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.stat-ico svg { width: 24px; height: 24px; }
.stat-ico.blue { background: rgba(47, 111, 237, 0.12); color: var(--tone-blue); }
.stat-ico.green { background: rgba(31, 138, 91, 0.12); color: var(--tone-green); }
.stat-ico.amber { background: rgba(196, 122, 26, 0.14); color: var(--tone-amber); }
.stat-ico.rose { background: rgba(196, 75, 106, 0.12); color: var(--tone-rose); }
.stat-body { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.stat-body strong {
    font-size: 1.65rem;
    line-height: 1.1;
    color: var(--ink);
    letter-spacing: -0.02em;
}
.stat-body span { color: var(--muted); font-size: 0.9rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    padding: 0.55rem 0.95rem;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn-secondary {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}
.btn-ghost {
    background: transparent;
    color: var(--muted);
    border-color: var(--line);
}
.btn-danger { background: var(--danger); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

.alert {
    padding: 0.8rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
    border: 1px solid;
}
.alert-success { background: #e8f5ef; border-color: #b7dfcb; color: var(--ok); }
.alert-error { background: #fdecec; border-color: #f0c2c2; color: var(--danger); }
.alert-warning { background: #fff5e6; border-color: #f0d7a8; color: var(--warn); }

.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    text-align: left;
    padding: 0.7rem 0.55rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
tr:hover td { background: rgba(47, 111, 237, 0.03); }

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
    border: 1px solid var(--line);
    background: #f4f7fb;
}
.badge-ok { background: #e8f5ef; color: var(--ok); border-color: #b7dfcb; }
.badge-warn { background: #fff5e6; color: var(--warn); border-color: #f0d7a8; }
.badge-danger { background: #fdecec; color: var(--danger); border-color: #f0c2c2; }
.badge-muted { color: var(--muted); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.9rem;
}
.form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}
.form-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 1100px) {
    .form-grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
    .form-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
    .form-grid,
    .form-grid-3,
    .form-grid-4 { grid-template-columns: 1fr; }
}
.form-grid .full { grid-column: 1 / -1; }
.agenda-filters .card-head {
    margin-bottom: 0.75rem;
}
.agenda-filters .actions {
    margin-top: 1rem;
}
#nuevo-turno {
    scroll-margin-top: 5.25rem;
}

/* Planilla consultorios: hora × consultorio, tipo planilla */
.planilla-board { padding: 0.85rem; }
.planilla-leyenda {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.9rem;
    margin-bottom: 0.75rem;
}
.planilla-leyenda-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    font-weight: 600;
}
.planilla-swatch {
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 3px;
    border: 2px solid transparent;
    flex-shrink: 0;
}
.planilla-excel-wrap {
    overflow: auto;
    max-height: calc(100vh - 210px);
    border: 1px solid var(--line);
    border-radius: 12px;
}
.planilla-excel {
    width: 100%;
    min-width: 760px;
    border-collapse: separate;
    border-spacing: 0;
    background: #fff;
}
.planilla-excel th,
.planilla-excel td {
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    vertical-align: top;
}
.planilla-excel th:last-child,
.planilla-excel td:last-child { border-right: 0; }
.planilla-col-h {
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: left;
    padding: 0.65rem 0.7rem;
    font-size: 0.95rem;
}
.planilla-col-h span { display: block; margin-bottom: 0.35rem; }
.planilla-col-h.col-1 { background: #e7f0ff; }
.planilla-col-h.col-2 { background: #e5f6ee; }
.planilla-col-h.col-3 { background: #fff3df; }
.planilla-hora {
    position: sticky;
    left: 0;
    z-index: 1;
    width: 4.4rem;
    min-width: 4.4rem;
    background: #f6f8fb;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    text-align: left;
    padding: 0.45rem 0.55rem;
    font-size: 0.85rem;
}
.planilla-excel thead .planilla-hora {
    top: 0;
    z-index: 3;
    background: #eef2f7;
}
.planilla-td { min-width: 210px; background: #fff; }
.planilla-td-libre { background: #fbfcfe; }
.planilla-libre {
    display: block;
    padding: 0.45rem 0.6rem;
    color: #b7c2ce;
    font-size: 0.78rem;
}
.planilla-vacia {
    padding: 1rem;
    color: var(--muted);
}
.planilla-chip {
    margin: 0.3rem;
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    border-left: 4px solid var(--tone-blue);
    background: rgba(47, 111, 237, 0.08);
}
.planilla-chip strong { display: block; font-size: 0.92rem; line-height: 1.25; }
.planilla-bloque strong { font-size: 1.02rem; }
.planilla-bloque-item {
    margin-top: 0.45rem;
    padding-top: 0.4rem;
    border-top: 1px solid rgba(15, 39, 68, 0.08);
}
.planilla-chip a { font-size: 0.86rem; }
.planilla-hora-rango {
    font-size: 0.75rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    margin: 0.1rem 0 0.2rem;
}
.planilla-chip-sigue {
    margin-top: 0;
    padding: 0.2rem 0.55rem 0.28rem;
    border-radius: 0 0 8px 8px;
    font-size: 0.78rem;
    font-weight: 600;
}
.planilla-chip.tone-0 { border-left-color: #1f8a5b; background: rgba(31, 138, 91, 0.12); }
.planilla-chip.tone-1 { border-left-color: #2f6fed; background: rgba(47, 111, 237, 0.12); }
.planilla-chip.tone-2 { border-left-color: #6b5ce7; background: rgba(107, 92, 231, 0.12); }
.planilla-chip.tone-3 { border-left-color: #c47a1a; background: rgba(196, 122, 26, 0.14); }
.planilla-chip.tone-4 { border-left-color: #c44b6a; background: rgba(196, 75, 106, 0.12); }
.planilla-chip.tone-5 { border-left-color: #0e7c8a; background: rgba(14, 124, 138, 0.12); }
.planilla-chip.tone-6 { border-left-color: #c45c26; background: rgba(196, 92, 38, 0.12); }
.planilla-chip.tone-7 { border-left-color: #3d5a80; background: rgba(61, 90, 128, 0.12); }
.planilla-chip.tone-8 { border-left-color: #7a5af8; background: rgba(122, 90, 248, 0.12); }
.planilla-chip.tone-9 { border-left-color: #2f7d4a; background: rgba(47, 125, 74, 0.14); }
.planilla-swatch.tone-0 { background: rgba(31, 138, 91, 0.35); border-color: #1f8a5b; }
.planilla-swatch.tone-1 { background: rgba(47, 111, 237, 0.35); border-color: #2f6fed; }
.planilla-swatch.tone-2 { background: rgba(107, 92, 231, 0.35); border-color: #6b5ce7; }
.planilla-swatch.tone-3 { background: rgba(196, 122, 26, 0.4); border-color: #c47a1a; }
.planilla-swatch.tone-4 { background: rgba(196, 75, 106, 0.35); border-color: #c44b6a; }
.planilla-swatch.tone-5 { background: rgba(14, 124, 138, 0.35); border-color: #0e7c8a; }
.planilla-swatch.tone-6 { background: rgba(196, 92, 38, 0.35); border-color: #c45c26; }
.planilla-swatch.tone-7 { background: rgba(61, 90, 128, 0.35); border-color: #3d5a80; }
.planilla-swatch.tone-8 { background: rgba(122, 90, 248, 0.35); border-color: #7a5af8; }
.planilla-swatch.tone-9 { background: rgba(47, 125, 74, 0.35); border-color: #2f7d4a; }
.planilla-recepcion,
.planilla-swatch-recepcion {
    border-left-color: #5c6b7a;
    background-color: #eef2f6;
    background-image: repeating-linear-gradient(
        -45deg,
        rgba(92, 107, 122, 0.16),
        rgba(92, 107, 122, 0.16) 4px,
        transparent 4px,
        transparent 8px
    );
}
.planilla-swatch-recepcion {
    border: 2px solid #5c6b7a;
    border-left-width: 2px;
}
.planilla-chip.planilla-conflicto {
    outline: 2px solid #e7b4b4;
}
.planilla-suspendido { opacity: 0.72; }
.planilla-slot {
    border-top: 1px solid var(--line);
    padding: 0.7rem 0;
}
.planilla-slot:first-of-type { border-top: 0; padding-top: 0; }
.planilla-sin { margin-bottom: 0.85rem; }
.planilla-sin-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
}
.inline-consultorio select {
    min-width: 5.5rem;
    padding: 0.3rem 0.45rem;
}
label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}
input, select, textarea {
    font: inherit;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; }

/* Editor de texto básico (objetivos) */
.editor-basico {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}
.editor-basico-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.35rem 0.45rem;
    border-bottom: 1px solid var(--line);
    background: #f7f9fc;
}
.editor-basico-btn {
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.45rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
}
.editor-basico-btn:nth-child(2) { font-style: italic; font-weight: 500; }
.editor-basico-btn:nth-child(3) { text-decoration: underline; font-weight: 500; }
.editor-basico-btn:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.editor-basico-area {
    min-height: 120px;
    padding: 0.65rem 0.75rem;
    color: var(--ink);
    outline: none;
    line-height: 1.45;
}
.editor-basico-area:focus {
    box-shadow: inset 0 0 0 2px var(--accent-soft);
}
.editor-basico-area ul,
.editor-basico-area ol,
.richtext ul,
.richtext ol {
    margin: 0.35rem 0 0.35rem 1.25rem;
    padding: 0;
}
.editor-basico-area p,
.richtext p {
    margin: 0 0 0.45rem;
}
.editor-basico-area p:last-child,
.richtext p:last-child {
    margin-bottom: 0;
}
.editor-basico-source {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    border: 0 !important;
}
.richtext {
    color: var(--ink);
    font-size: 1.05rem;
    font-weight: 650;
    line-height: 1.45;
}
.richtext.richtext-sm {
    display: inline-block;
    font-size: inherit;
    font-weight: 400;
    vertical-align: top;
}
.richtext strong,
.richtext b { font-weight: 700; }

.tabs {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.tabs a {
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    text-decoration: none;
    background: var(--surface);
}
.tabs a.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.reportes-subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0 0 1rem;
}
.reportes-filtros {
    margin-bottom: 1rem;
}
.reportes-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.85rem;
}
.reportes-pager-actions {
    display: flex;
    gap: 0.4rem;
}
@media (max-width: 800px) {
    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
    }
    .tabs a {
        white-space: nowrap;
    }
}

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background:
        radial-gradient(circle at top left, rgba(47, 111, 237, 0.1), transparent 40%),
        radial-gradient(circle at bottom right, rgba(15, 39, 68, 0.08), transparent 40%),
        var(--bg);
}
.login-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 1.75rem;
}
.login-card h1 { margin-bottom: 0.25rem; }
.stack { display: grid; gap: 0.85rem; }
.hint {
    margin-top: 1rem;
    padding: 0.8rem;
    background: #f4f7fb;
    border-radius: 10px;
    color: var(--muted);
    font-size: 0.85rem;
}
.empty {
    color: var(--muted);
    padding: 1rem 0;
}

/* Timeline agenda */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}
.timeline-item {
    display: grid;
    grid-template-columns: 52px 1fr;
    gap: 0.75rem;
    align-items: stretch;
}
.timeline-time {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--ink);
    padding-top: 0.85rem;
}
.timeline-card {
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    background: #f4f7fb;
    border-left: 4px solid var(--tone-blue);
    min-width: 0;
}
.timeline-card.tone-0 { border-left-color: var(--tone-green); background: rgba(31, 138, 91, 0.08); }
.timeline-card.tone-1 { border-left-color: var(--tone-blue); background: rgba(47, 111, 237, 0.08); }
.timeline-card.tone-2 { border-left-color: var(--tone-purple); background: rgba(107, 92, 231, 0.08); }
.timeline-card.tone-3 { border-left-color: var(--tone-amber); background: rgba(196, 122, 26, 0.1); }
.timeline-card strong {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 0.15rem;
}
.timeline-card span {
    color: var(--muted);
    font-size: 0.85rem;
}

/* Person / note lists */
.list-rows {
    display: flex;
    flex-direction: column;
}
.list-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 0.15rem;
    border-bottom: 1px solid var(--line);
    color: inherit;
    text-decoration: none;
}
.list-row:last-child { border-bottom: 0; }
a.list-row:hover {
    background: rgba(47, 111, 237, 0.04);
    text-decoration: none;
    border-radius: 10px;
    margin: 0 -0.35rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}
.list-row-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.list-row-body strong {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-row-body span {
    color: var(--muted);
    font-size: 0.82rem;
}
.list-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}
.list-chevron {
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
}
.note-ico {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: rgba(47, 111, 237, 0.1);
    color: var(--tone-blue);
}
.note-ico.warn { background: rgba(196, 122, 26, 0.12); color: var(--tone-amber); }
.note-ico.danger { background: rgba(155, 44, 44, 0.1); color: var(--danger); }
.note-ico.ok { background: rgba(31, 138, 91, 0.12); color: var(--tone-green); }
.note-ico svg { width: 18px; height: 18px; }

.progress-list { display: flex; flex-direction: column; gap: 0.95rem; }
.progress-row { display: grid; gap: 0.35rem; }
.progress-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.9rem;
}
.progress-meta span { color: var(--muted); }
.progress-bar {
    height: 8px;
    background: #e8eef7;
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar > i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--tone-blue);
}
.progress-bar.green > i { background: var(--tone-green); }
.progress-bar.purple > i { background: var(--tone-purple); }
.progress-bar.amber > i { background: var(--tone-amber); }

.agenda-week {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.85rem;
}
.agenda-day h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}
.agenda-today {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px rgba(47, 111, 237, 0.2), var(--shadow);
}
.agenda-slot {
    border-top: 1px solid var(--line);
    padding: 0.7rem 0;
}
.agenda-slot:first-of-type { border-top: 0; padding-top: 0; }
.agenda-slot-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    margin-bottom: 0.25rem;
}
.agenda-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.55rem;
}

/* Tarjetas compactas de agenda */
.agenda-slot-compact {
    padding: 0.55rem 0;
}
.agenda-slot-compact .agenda-slot-head {
    margin-bottom: 0.15rem;
}
.agenda-slot-time {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}
.agenda-slot-body {
    margin-bottom: 0.3rem;
}
.agenda-slot-paciente {
    font-weight: 600;
    text-decoration: none;
}
.agenda-slot-paciente:hover {
    text-decoration: underline;
}
.agenda-slot-states {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.35rem;
}
.agenda-slot-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}
.agenda-slot-compact.has-borrador {
    box-shadow: inset 3px 0 0 var(--tone-amber, #c9852a);
    padding-left: 0.55rem;
}
.agenda-slot-compact.sin-consultorio .agenda-slot-head .badge-muted {
    outline: 1px dashed rgba(47, 111, 237, 0.35);
}
.agenda-asist-menu {
    position: relative;
}
.agenda-asist-menu > summary {
    list-style: none;
    cursor: pointer;
}
.agenda-asist-menu > summary::-webkit-details-marker {
    display: none;
}
.agenda-asist-form {
    position: absolute;
    z-index: 5;
    left: 0;
    top: calc(100% + 0.25rem);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 11rem;
    padding: 0.45rem;
    background: var(--surface, #fff);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.agenda-inline-form {
    display: inline;
    margin: 0;
}
.bitacora-cancel-resumen {
    margin: 0.35rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    font-size: 0.78rem;
    line-height: 1.35;
}
.bitacora-cancel-meta {
    color: var(--warn);
    font-weight: 650;
}
.bitacora-cancel-relato {
    color: var(--muted);
}
label.check-line {
    flex-direction: row;
    align-items: center;
    gap: 0.45rem;
    font-weight: 600;
    color: var(--ink);
}
label.check-line input {
    width: auto;
    margin: 0;
}

/* Modal de sesión (popup centrado sobre toda la pantalla) */
.agenda-drawer-root,
.agenda-modal-root {
    position: fixed !important;
    inset: 0 !important;
    left: 0 !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    z-index: 9999 !important;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    box-sizing: border-box;
    /* Fuera del flex de .app-body */
    flex: none !important;
    align-self: auto !important;
}
.agenda-drawer-root.is-open,
.agenda-modal-root.is-open {
    display: flex !important;
}
.agenda-drawer-root[hidden],
.agenda-modal-root[hidden] {
    display: none !important;
}
.agenda-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    cursor: pointer;
}
.agenda-drawer {
    position: relative;
    z-index: 1;
    width: min(680px, calc(100vw - 2rem));
    max-height: min(88vh, 820px);
    margin: 0 auto;
    background: var(--surface, #fff);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 28px 64px rgba(15, 23, 42, 0.35);
    overflow: auto;
    outline: none;
    animation: agenda-modal-in 0.18s ease-out;
    flex: none;
}
body.agenda-drawer-open {
    overflow: hidden !important;
}
.agenda-drawer-loading {
    padding: 1.25rem;
    color: var(--muted);
}
.agenda-panel {
    padding: 1.15rem 1.25rem 1.5rem;
}
@keyframes agenda-modal-in {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.agenda-panel-head {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 0.85rem;
}
.agenda-panel-head h2 {
    font-size: 1.2rem;
    margin: 0.15rem 0;
}
.agenda-panel-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 1rem;
}
.agenda-panel-section {
    margin-bottom: 1.15rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
}
.agenda-panel-section h3 {
    font-size: 0.95rem;
    margin: 0 0 0.5rem;
}
.agenda-panel-list {
    margin: 0 0 0.65rem;
    padding-left: 1.1rem;
}
.agenda-panel-list li {
    margin-bottom: 0.25rem;
}
.agenda-panel textarea {
    width: 100%;
    min-height: 10rem;
    resize: vertical;
}
.agenda-panel .editor-basico {
    margin-top: 0.25rem;
}
.agenda-panel .editor-basico-area {
    min-height: 10rem;
}
.agenda-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.65rem;
}
.agenda-panel-status {
    margin: 0.45rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}
.agenda-panel-status.is-error {
    color: var(--danger, #b42318);
}
.agenda-panel-status.is-warning {
    color: var(--warn, #b54708);
    font-weight: 600;
}
.agenda-panel-nota-ro {
    white-space: pre-wrap;
    font-size: 0.95rem;
}
.agenda-panel-anteriores {
    list-style: none;
    margin: 0;
    padding: 0;
}
.agenda-panel-anteriores li {
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--line);
}
.agenda-panel-ant-head {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-bottom: 0.25rem;
}
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
@media (max-width: 720px) {
    .agenda-drawer-root {
        padding: 0.5rem;
        align-items: stretch;
    }
    .agenda-drawer {
        width: 100%;
        max-height: calc(100vh - 1rem);
        border-radius: 10px;
        margin: auto 0;
    }
}

@keyframes dash-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.dash-animate > * {
    animation: dash-in 0.4s ease both;
}
.dash-animate > *:nth-child(2) { animation-delay: 0.05s; }
.dash-animate > *:nth-child(3) { animation-delay: 0.1s; }
.dash-animate > *:nth-child(4) { animation-delay: 0.15s; }

/* DataTables */
table.dataTable {
    border-collapse: collapse !important;
    width: 100% !important;
}
table.dataTable thead th {
    border-bottom: 1px solid var(--line) !important;
    background: transparent;
}
table.dataTable tbody td {
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}
table.dataTable.no-footer {
    border-bottom: 1px solid var(--line);
}
.dataTables_wrapper {
    padding-top: 0.25rem;
}
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0.65rem 0;
}
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.4rem 0.65rem;
    font: inherit;
    color: var(--ink);
    background: #fff;
    margin-left: 0.35rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 8px !important;
    border: 1px solid transparent !important;
    padding: 0.3rem 0.65rem !important;
    margin: 0 0.1rem !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--accent) !important;
    color: #fff !important;
    border-color: var(--accent) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: var(--accent-soft) !important;
    color: var(--accent) !important;
    border-color: transparent !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    background: transparent !important;
    color: var(--muted) !important;
}

/* Modal */
body.modal-open { overflow: hidden; }
.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.is-open,
.modal:not([hidden]) {
    display: flex;
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 39, 68, 0.55);
    backdrop-filter: blur(2px);
}
.modal-dialog {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: min(88vh, 720px);
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 24px 48px rgba(15, 39, 68, 0.28);
    padding: 1.15rem 1.25rem 1.25rem;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}
.modal-head h2 { margin: 0; font-size: 1.2rem; }
.modal-close {
    border: 1px solid var(--line);
    background: #fff;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1.35rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
}
.modal-close:hover { color: var(--ink); background: #f4f7fb; }
.modal-body .list-rows { margin-bottom: 1rem; }
.modal-form {
    margin-top: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
}
.modal-form h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

/* Tom Select (paciente en agenda) */
.ts-wrapper.single .ts-control {
    font: inherit;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
    background: #fff;
    box-shadow: none;
    min-height: 2.55rem;
}
.ts-wrapper.single .ts-control input {
    font: inherit;
}
.ts-wrapper.focus .ts-control {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.ts-dropdown {
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 80;
}
.ts-dropdown .option {
    padding: 0.5rem 0.75rem;
}
.ts-dropdown .active {
    background: var(--accent-soft);
    color: var(--ink);
}
.ts-dropdown .option.selected {
    background: var(--accent);
    color: #fff;
}

/* Reportes de agenda */
.report-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 1rem;
}
.filter-actions {
    display: flex;
    align-items: flex-end;
}
.filter-actions .btn {
    width: 100%;
}
