:root {
    --primary: #1a6b2f;
    --primary-dark: #14532d;
    --primary-soft: #f0f7f2;
    --primary-border: #c4dfc9;
    --border: #e2e8f0;
    --muted: #64748b;
    --surface: #ffffff;
    --canvas: #f8fafc;
    --warning: #d97706;
    --danger: #dc2626;
    --ink: #0f172a;
    --sidebar: #11351f;
    --sidebar-text: #d7eadc;
    --radius: 1rem;
    --shadow: 0 18px 50px rgba(31, 50, 81, .09);
}

* { box-sizing: border-box; }

html { font-size: 14px; }

body {
    min-height: 100vh;
    margin: 0;
    background: var(--canvas);
    color: var(--ink);
    font-family: "Inter", system-ui, -apple-system, sans-serif;
}

a { color: var(--primary); }

.app {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    width: 268px;
    min-height: 100vh;
    padding: 1.25rem 1rem;
    background: linear-gradient(180deg, var(--sidebar) 0%, #0c2416 100%);
    color: #fff;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .35rem .45rem 1.15rem;
    color: #fff;
    text-decoration: none;
}

.app-brand__mark {
    display: grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    overflow: hidden;
    border-radius: .8rem;
    background: #1f7a3a;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}

.app-brand__mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.app-brand__name {
    display: block;
    font-size: 1.02rem;
    font-weight: 750;
    letter-spacing: -.02em;
}

.app-brand__tag {
    display: block;
    color: var(--sidebar-text);
    font-size: .75rem;
}

.app-nav {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    margin-top: .35rem;
}

.app-nav a {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .72rem .8rem;
    border-radius: .75rem;
    color: var(--sidebar-text);
    font-weight: 650;
    text-decoration: none;
}

.app-nav a:hover,
.app-nav a.is-active {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.app-nav a.is-active {
    background: #1a6b2f;
}

.app-sidebar__foot {
    margin-top: auto;
    padding-top: 1rem;
}

.app-main {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .9rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(10px);
}

.app-header__user {
    display: flex;
    align-items: center;
    gap: .7rem;
}

.app-header__avatar {
    display: grid;
    place-items: center;
    width: 2.3rem;
    height: 2.3rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 750;
}

.app-header__meta small {
    display: block;
    color: var(--muted);
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    border: 1px solid var(--border);
    border-radius: .7rem;
    background: #fff;
}

.page-shell {
    width: min(80vw, 1760px);
    max-width: calc(100% - 2rem);
    margin: 0 auto;
    padding: 2rem 0 3rem;
    flex: 1;
}

.page-shell--wide {
    width: min(92vw, 1760px);
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.15rem;
}

.eyebrow {
    margin-bottom: .5rem;
    color: var(--primary);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    color: #15233b;
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    font-weight: 750;
    letter-spacing: -.03em;
}

.page-description {
    max-width: 680px;
    margin: .55rem 0 0;
    color: var(--muted);
}

.app-footer {
    padding: 1rem 1.5rem 1.4rem;
    color: var(--muted);
    font-size: .82rem;
}

.table-card,
.form-card,
.stat-card,
.filter-card {
    overflow: hidden;
    border: 1px solid rgba(227, 233, 242, .9);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.table-card__header,
.form-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .9rem 1.1rem;
    border-bottom: 1px solid var(--border);
}

.table-card__title,
.form-card__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.table-card__body,
.form-card__body,
.filter-card {
    padding: 1rem 1.1rem 1.15rem;
}

.table {
    --bs-table-striped-bg: #f8faff;
    --bs-table-hover-bg: #eef4fd;
    margin-bottom: 0;
}

.table thead th {
    padding: .55rem .7rem;
    border-bottom: 0;
    background-color: var(--primary-dark) !important;
    color: #fff !important;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.table thead th:first-child { border-radius: .65rem 0 0 .65rem; }
.table thead th:last-child { border-radius: 0 .65rem .65rem 0; }

.table tbody td {
    padding: .55rem .7rem;
    border-color: var(--border);
    font-size: .86rem;
    vertical-align: middle;
}

.btn-app,
.btn-ghost,
.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .55rem .9rem;
    border-radius: .55rem;
    font-size: .86rem;
    font-weight: 700;
    line-height: 1.25;
    text-decoration: none;
    border: 1px solid transparent;
}

.btn-app {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.btn-app:hover {
    border-color: var(--primary-dark);
    background: var(--primary-dark);
    color: #fff;
}

.btn-ghost {
    border-color: var(--primary-border);
    background: #fff;
    color: var(--primary-dark);
}

.btn-ghost:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.btn-danger {
    border-color: #b42318;
    background: #fff;
    color: #b42318;
}

.btn-danger:hover {
    background: #b42318;
    color: #fff;
}

.btn-icon {
    padding: .35rem .5rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: .3rem .65rem;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 750;
    white-space: nowrap;
}

.badge-success { background: #e7f7ed; color: #146c43; }
.badge-danger { background: #fde8e8; color: #b42318; }
.badge-warning { background: #fff3cd; color: #7a4b00; }
.badge-info { background: #e8f1ff; color: #1d4ed8; }
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge-muted { background: #eef2f6; color: #475569; }

.field-error {
    margin: .35rem 0 0;
    color: var(--danger);
    font-size: .8rem;
    font-weight: 650;
}

.form-label {
    color: var(--primary-dark);
    font-size: .8rem;
    font-weight: 750;
}

.form-control,
.form-select {
    min-height: 2.45rem;
    border-color: #cfd8e6;
    border-radius: .6rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 .2rem rgba(26, 107, 47, .14);
}

.app-alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    margin-bottom: 1rem;
    padding: .85rem 1rem;
    border-radius: .8rem;
    font-weight: 650;
}

.alert-success { background: #e7f7ed; color: #146c43; }
.alert-danger { background: #fde8e8; color: #b42318; }
.alert-warning { background: #fff8e8; color: #7a4b00; }
.alert-info { background: #e8f1ff; color: #1d4ed8; }

.app-alert__close {
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 1.2rem;
    line-height: 1;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1.15rem;
}

.stats-grid--agenda {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stats-period {
    margin: 0 0 .85rem;
    color: var(--muted);
    font-size: .86rem;
}

.stat-card {
    padding: 1.1rem 1.15rem;
}

.stat-card span {
    color: var(--muted);
    font-size: .8rem;
    font-weight: 750;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.stat-card strong {
    display: block;
    margin-top: .35rem;
    color: #15233b;
    font-size: 2rem;
    letter-spacing: -.04em;
}

.stat-card small {
    display: block;
    margin-top: .25rem;
    color: var(--muted);
    font-size: .78rem;
}

.stat-card--pendiente { border-top: 4px solid #2563eb; }
.stat-card--activa { border-top: 4px solid #1a6b2f; }
.stat-card--atendida { border-top: 4px solid #0f766e; }
.stat-card--cancelada { border-top: 4px solid #dc2626; }

.empty-state {
    padding: 2.2rem 1rem;
    color: var(--muted);
    text-align: center;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.logo-preview {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: .8rem;
}

.login-page {
    display: grid;
    grid-template-columns: 1.05fr .95fr;
    min-height: 100vh;
}

.login-hero {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2.5rem;
    background:
        radial-gradient(circle at top left, rgba(255,255,255,.12), transparent 28%),
        linear-gradient(160deg, #14532d 0%, #1a6b2f 48%, #0c2416 100%);
    color: #fff;
}

.login-hero h2 {
    max-width: 12ch;
    margin: 1.2rem 0 .7rem;
    font-size: clamp(2rem, 5vw, 3.4rem);
    font-weight: 750;
    letter-spacing: -.04em;
}

.login-hero p {
    max-width: 38ch;
    color: #d7eadc;
}

.login-panel {
    display: grid;
    place-items: center;
    padding: 2rem;
    background: var(--canvas);
}

.login-card {
    width: min(440px, 100%);
    padding: 1.6rem;
    border: 1px solid rgba(227, 233, 242, .9);
    border-radius: 1.1rem;
    background: #fff;
    box-shadow: var(--shadow);
}

.sidebar-backdrop {
    display: none;
}

.calendar-card__header {
    align-items: flex-start;
}

.calendar-card__hint {
    margin: .35rem 0 0;
    color: var(--muted);
    font-size: .86rem;
}

.calendar-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .55rem .8rem;
}

.calendar-legend__item {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    color: #334155;
    font-size: .78rem;
    font-weight: 700;
}

.calendar-legend__item i {
    width: .7rem;
    height: .7rem;
    border-radius: 999px;
}

.calendar-modal .modal-header {
    align-items: flex-start;
    border-bottom-color: var(--border);
}

.detalle-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .35rem 1rem;
    margin-bottom: 1rem;
    padding: .85rem 1rem;
    border: 1px solid var(--primary-border);
    border-radius: .8rem;
    background: var(--primary-soft);
}

.detalle-meta p {
    margin: 0;
}

#agenda-calendario .fc {
    --fc-border-color: #e2e8f0;
    --fc-today-bg-color: #f0f7f2;
    --fc-page-bg-color: #fff;
    --fc-neutral-bg-color: #f8fafc;
    --fc-button-bg-color: #1a6b2f;
    --fc-button-border-color: #1a6b2f;
    --fc-button-hover-bg-color: #14532d;
    --fc-button-hover-border-color: #14532d;
    --fc-button-active-bg-color: #14532d;
    --fc-button-active-border-color: #14532d;
    --fc-event-border-color: transparent;
    font-family: "Inter", system-ui, sans-serif;
}

#agenda-calendario .fc .fc-toolbar-title {
    font-size: 1.15rem;
    font-weight: 750;
    color: #15233b;
}

#agenda-calendario .fc .fc-button {
    border-radius: .55rem;
    font-weight: 700;
    text-transform: capitalize;
}

#agenda-calendario .fc .fc-col-header-cell-cushion,
#agenda-calendario .fc .fc-daygrid-day-number {
    color: #14532d;
    font-weight: 700;
    text-decoration: none;
}

#agenda-calendario .fc .fc-event {
    border: 0;
    border-radius: .45rem;
    padding: .1rem .25rem;
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
}

#agenda-calendario .fc .fc-timegrid-slot {
    height: 2.1rem;
}

#agenda-calendario .fc .fc-timegrid-slot:hover {
    background: rgba(26, 107, 47, .04);
}

.app-toasts {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1080;
    display: grid;
    gap: .55rem;
}

.app-toast {
    min-width: min(320px, calc(100vw - 2rem));
    padding: .8rem 1rem;
    border-radius: .8rem;
    color: #fff;
    font-weight: 700;
    box-shadow: var(--shadow);
}

.expediente-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.timeline {
    margin: 0;
    padding: 0;
    list-style: none;
}

.timeline__item {
    position: relative;
    padding: 0 0 1.15rem 1.1rem;
    border-left: 2px solid var(--primary-border);
}

.timeline__item:last-child {
    padding-bottom: 0;
}

.timeline__item::before {
    position: absolute;
    top: .35rem;
    left: -.42rem;
    width: .7rem;
    height: .7rem;
    border-radius: 999px;
    background: var(--primary);
    content: "";
}

.timeline__item h3 {
    margin: .35rem 0 .3rem;
    font-size: 1rem;
}

.timeline__item p {
    margin: 0;
    color: #334155;
}

.timeline__meta,
.timeline__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.timeline__foot {
    margin-top: .55rem;
}

.app-toast--success { background: #146c43; }
.app-toast--error { background: #b42318; }
.app-toast--info { background: #1d4ed8; }

.odonto-banner {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--primary-border);
    border-radius: 1rem;
    background: linear-gradient(135deg, #f0f7f2, #fff);
    text-decoration: none;
    color: inherit;
}

.odonto-banner__icon {
    display: grid;
    place-items: center;
    width: 2.8rem;
    height: 2.8rem;
    border-radius: .8rem;
    background: var(--primary);
    color: #fff;
    font-size: 1.2rem;
}

.odonto-app {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 320px;
    gap: 1rem;
}

.odonto-pills {
    display: flex;
    gap: .35rem;
}

.odonto-pills button,
.odonto-num,
.odonto-version {
    border: 1px solid var(--border);
    border-radius: .55rem;
    background: #fff;
    color: #334155;
    font-weight: 700;
}

.odonto-pills button {
    flex: 1;
    padding: .4rem .5rem;
    font-size: .78rem;
}

.odonto-pills button.is-active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.odonto-switch {
    margin: .9rem 0;
}

.odonto-legend {
    display: grid;
    gap: .35rem;
    margin: 1rem 0;
    font-size: .78rem;
    font-weight: 700;
}

.odonto-legend span {
    display: flex;
    align-items: center;
    gap: .4rem;
}

.odonto-legend i {
    width: .7rem;
    height: .7rem;
    border: 1px solid #cbd5e1;
    border-radius: .2rem;
}

.odonto-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .35rem;
}

.odonto-arco {
    margin-bottom: 1.2rem;
}

.odonto-arco__label {
    display: block;
    margin-bottom: .45rem;
    color: var(--muted);
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    text-align: center;
}

.odonto-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 3.4rem;
}

.odonto-tooth {
    width: 3.3rem;
    height: 4.1rem;
    overflow: visible;
    filter: drop-shadow(0 6px 10px rgba(15, 23, 42, .08));
}

.odonto-tooth polygon {
    stroke: #334155;
    stroke-width: 1;
    cursor: pointer;
    transition: fill .15s ease, stroke .15s ease;
}

.odonto-tooth polygon:hover {
    stroke: #1a6b2f;
    stroke-width: 1.8;
}

.odonto-tooth line {
    stroke: #7f1d1d;
    stroke-width: 3;
}

.odonto-num {
    min-width: 1.8rem;
    margin: .15rem 0;
    padding: .1rem .3rem;
    font-size: .72rem;
}

.odonto-midline {
    width: 1px;
    margin: 0 .15rem;
    background: #94a3b8;
}

.odonto-menu {
    position: fixed;
    z-index: 1080;
    min-width: 180px;
    padding: .55rem;
    border: 1px solid var(--border);
    border-radius: .8rem;
    background: #fff;
    box-shadow: var(--shadow);
}

.odonto-menu p {
    margin: 0 0 .4rem;
    color: var(--primary-dark);
    font-size: .75rem;
    font-weight: 750;
}

.odonto-menu button {
    display: block;
    width: 100%;
    margin-bottom: .25rem;
    padding: .4rem .5rem;
    border: 0;
    border-radius: .45rem;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 700;
    text-align: left;
}

.odonto-menu button:hover {
    background: var(--primary);
    color: #fff;
}

.odonto-explain {
    margin-top: 1rem;
    padding: 1rem;
    border: 1px solid #bfdbfe;
    border-radius: .9rem;
    background: #eff6ff;
}

.odonto-explain h3 {
    margin: 0 0 .5rem;
    font-size: 1rem;
}

.is-paciente .odonto-tooth {
    width: 3.8rem;
    height: 4.7rem;
}

.is-paciente .odonto-tooth polygon {
    stroke: #1e3a5f;
}

.odonto-versions {
    display: grid;
    gap: .55rem;
}

.odonto-version {
    width: 100%;
    padding: .55rem .65rem;
    text-align: left;
}

.odonto-version small,
.odonto-version em {
    display: block;
    font-style: normal;
    font-weight: 500;
    color: var(--muted);
}

.odonto-total {
    margin: .6rem 0 0;
    text-align: right;
    font-size: 1.05rem;
}

.odonto-aceptados {
    margin-top: 1rem;
    padding-top: .85rem;
    border-top: 1px dashed var(--border);
}

.odonto-note {
    margin: 0 0 .45rem;
    padding: .5rem .65rem;
    border-radius: .55rem;
    background: var(--canvas);
}

@media (max-width: 1100px) {
    .page-shell { width: calc(100% - 2rem); }
    .stats-grid,
    .stats-grid--agenda { grid-template-columns: 1fr 1fr; }
    .login-page { grid-template-columns: 1fr; }
    .login-hero { min-height: 280px; }
    .calendar-card__header { flex-direction: column; }
    .calendar-legend { justify-content: flex-start; }
    .detalle-meta { grid-template-columns: 1fr; }
    .expediente-grid { grid-template-columns: 1fr; }
    .odonto-app,
    .odonto-banner { grid-template-columns: 1fr; display: grid; }
}

@media (max-width: 860px) {
    .menu-toggle { display: inline-flex; }
    .app-sidebar {
        position: fixed;
        left: 0;
        z-index: 30;
        transform: translateX(-105%);
        transition: transform .2s ease;
    }
    .app-sidebar.is-open { transform: translateX(0); }
    .sidebar-backdrop.is-visible {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 20;
        background: rgba(15, 23, 42, .4);
    }
    .page-header { flex-direction: column; align-items: flex-start; }
}
