/* ============================================================
   Historia Clínica — sistema visual
   Paleta clínica cálida: verde profundo, marfil y terracota.
   ============================================================ */

:root {
    --hc-ink: #1f2a28;
    --hc-muted: #6f7772;
    --hc-canvas: #f6f3ec;
    --hc-surface: #ffffff;
    --hc-line: #e7e2d7;
    --hc-brand: #146b60;
    --hc-brand-dark: #0b3b38;
    --hc-brand-soft: #e8f3ef;
    --hc-accent: #d97757;
    --hc-accent-soft: #fbede7;
    --hc-shadow: 0 18px 45px -28px rgba(15, 59, 56, 0.38);
    --hc-shadow-sm: 0 8px 24px -18px rgba(15, 59, 56, 0.35);
}

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    background-color: var(--hc-canvas);
    color: var(--hc-ink);
    font-family: "Manrope", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection {
    background: rgba(20, 107, 96, 0.18);
    color: var(--hc-brand-dark);
}

[x-cloak] {
    display: none !important;
}

body.hc-sidebar-open {
    overflow: hidden;
}

@media (min-width: 768px) {
    body.hc-sidebar-open {
        overflow: auto;
    }
}

/* Un fondo muy sutil para que las tarjetas blancas tengan profundidad. */
.hc-canvas {
    background:
        radial-gradient(1100px 520px at 88% -10%, rgba(20, 107, 96, 0.075), transparent 62%),
        radial-gradient(900px 480px at -8% 8%, rgba(217, 119, 87, 0.055), transparent 58%),
        var(--hc-canvas);
}

/* Pantalla de acceso: fondo oscuro con una luz verde muy contenida. */
.hc-login-shell {
    color-scheme: dark;
    background:
        radial-gradient(900px 560px at 8% -12%, rgba(33, 150, 128, 0.18), transparent 62%),
        radial-gradient(760px 460px at 100% 108%, rgba(217, 119, 87, 0.07), transparent 58%),
        #04100f;
}

/* Evita que el autocompletado del navegador rompa la paleta oscura. */
.hc-login-input:-webkit-autofill,
.hc-login-input:-webkit-autofill:hover,
.hc-login-input:-webkit-autofill:focus,
.hc-login-input:-webkit-autofill:active {
    -webkit-text-fill-color: #ffffff;
    caret-color: #ffffff;
    -webkit-box-shadow: 0 0 0 1000px #0f2421 inset;
    box-shadow: 0 0 0 1000px #0f2421 inset;
    transition: background-color 9999s ease-out 0s;
}

.hc-card {
    border: 1px solid var(--hc-line);
    border-radius: 1.25rem;
    background: var(--hc-surface);
    box-shadow: var(--hc-shadow-sm);
}

.hc-card-hover {
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.hc-card-hover:hover {
    transform: translateY(-2px);
    border-color: #d8d1c3;
    box-shadow: var(--hc-shadow);
}

.hc-divider {
    border-color: var(--hc-line);
}

/* ------------------------------------------------------------
   Componentes compartidos de páginas internas
   ------------------------------------------------------------ */

.hc-page {
    width: 100%;
    max-width: 80rem;
    margin-inline: auto;
}

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

.hc-page-kicker {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.35rem;
    color: var(--hc-brand);
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.2em;
    line-height: 1.2;
    text-transform: uppercase;
}

.hc-page-title {
    margin: 0;
    color: var(--hc-ink);
    font-family: "Fraunces", ui-serif, Georgia, serif;
    font-size: clamp(1.65rem, 2.4vw, 2.15rem);
    font-weight: 600;
    letter-spacing: -0.025em;
    line-height: 1.15;
}

/* Los títulos principales de todas las vistas comparten la misma voz editorial. */
main h1 {
    font-family: "Fraunces", ui-serif, Georgia, serif;
    font-weight: 600 !important;
    letter-spacing: -0.025em;
    line-height: 1.15;
}

.hc-page-subtitle {
    max-width: 46rem;
    margin-top: 0.4rem;
    color: var(--hc-muted);
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.6;
}

.hc-page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.hc-panel {
    overflow: hidden;
    border: 1px solid var(--hc-line);
    border-radius: 1.25rem;
    background: var(--hc-surface);
    box-shadow: var(--hc-shadow-sm);
}

.hc-panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem 1.4rem;
    border-bottom: 1px solid var(--hc-line);
}

.hc-panel-body {
    padding: 1.4rem;
}

.hc-panel-title {
    color: var(--hc-ink);
    font-size: 0.92rem;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.hc-panel-text {
    margin-top: 0.2rem;
    color: var(--hc-muted);
    font-size: 0.75rem;
    font-weight: 500;
}

.hc-back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--hc-muted);
    font-size: 0.72rem;
    font-weight: 700;
    transition: color 160ms ease;
}

.hc-back-link:hover {
    color: var(--hc-brand-dark);
}

.hc-btn {
    display: inline-flex;
    min-height: 2.45rem;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.62rem 1rem;
    border: 1px solid transparent;
    border-radius: 0.8rem;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.hc-btn:hover {
    transform: translateY(-1px);
}

.hc-btn:active {
    transform: translateY(0);
}

.hc-btn-primary {
    background: var(--hc-brand);
    color: #ffffff;
    box-shadow: 0 10px 20px -14px rgba(11, 59, 56, 0.8);
}

.hc-btn-primary:hover {
    background: var(--hc-brand-dark);
    color: #ffffff;
}

.hc-btn-secondary {
    border-color: var(--hc-line);
    background: #ffffff;
    color: #45413b;
}

.hc-btn-secondary:hover {
    border-color: #d6cfc1;
    background: #fbfaf7;
    color: var(--hc-ink);
}

.hc-btn-ghost {
    background: transparent;
    color: var(--hc-brand);
}

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

.hc-btn-danger {
    border-color: #fecdd3;
    background: #fff7f7;
    color: #b42318;
}

.hc-btn-danger:hover {
    border-color: #fda4af;
    background: #ffecee;
    color: #9f1c14;
}

.hc-btn-warning {
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
}

.hc-btn-warning:hover {
    border-color: #fcd34d;
    background: #fef3c7;
    color: #78350f;
}

.hc-btn-sm {
    min-height: 2rem;
    padding: 0.4rem 0.7rem;
    border-radius: 0.65rem;
    font-size: 0.68rem;
}

.hc-icon-btn {
    display: inline-flex;
    height: 2.1rem;
    width: 2.1rem;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--hc-line);
    border-radius: 0.65rem;
    background: #ffffff;
    color: var(--hc-muted);
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.hc-icon-btn:hover {
    border-color: #d6cfc1;
    background: #fbfaf7;
    color: var(--hc-brand-dark);
}

.hc-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.hc-label {
    display: block;
    color: #575148;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    line-height: 1.3;
    text-transform: uppercase;
}

.hc-input,
.hc-select,
.hc-textarea {
    width: 100%;
    border: 1px solid #d9d3c6;
    border-radius: 0.8rem;
    background: #fbfaf7;
    color: var(--hc-ink);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1.4;
    outline: none;
    transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.hc-input,
.hc-select {
    min-height: 2.65rem;
    padding: 0.62rem 0.85rem;
}

.hc-textarea {
    min-height: 7rem;
    padding: 0.7rem 0.85rem;
    resize: vertical;
}

.hc-input::placeholder,
.hc-textarea::placeholder {
    color: #a39b8d;
    font-weight: 500;
}

.hc-input:focus,
.hc-select:focus,
.hc-textarea:focus {
    border-color: rgba(20, 107, 96, 0.65);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(20, 107, 96, 0.13);
}

.hc-form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.7rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--hc-line);
}

.hc-search-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.hc-search-bar .hc-input {
    min-width: min(100%, 18rem);
    flex: 1 1 16rem;
}

.hc-table-shell {
    overflow-x: auto;
    border: 1px solid var(--hc-line);
    border-radius: 1rem;
    background: #ffffff;
}

main .hc-table {
    min-width: 100%;
    border-spacing: 0;
    font-size: 0.8rem;
}

main .hc-table thead th {
    padding: 0.72rem 1rem;
    border-bottom: 1px solid var(--hc-line);
    background: #f8f6f1;
    color: #6f7772;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

main .hc-table tbody td {
    padding: 0.82rem 1rem;
    border-bottom: 1px solid #efebe3;
    color: #45413b;
    font-size: 0.8rem;
    vertical-align: middle;
}

main .hc-table tbody tr:last-child td {
    border-bottom: 0;
}

main .hc-table tbody tr:hover {
    background: #fbfaf7;
}

.hc-table-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
}

main .hc-table-compact thead th {
    padding: 0.55rem 0.5rem;
    font-size: 0.56rem;
    letter-spacing: 0.08em;
}

main .hc-table-compact tbody td {
    padding: 0.62rem 0.5rem;
    font-size: 0.7rem;
}

main .hc-table-compact tbody td:first-child,
main .hc-table-compact thead th:first-child {
    padding-left: 1.1rem;
}

main .hc-table-compact tbody td:last-child,
main .hc-table-compact thead th:last-child {
    padding-right: 1.1rem;
}

.hc-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.55rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    line-height: 1.3;
    white-space: nowrap;
}

.hc-badge-success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.hc-badge-warning {
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
}

.hc-badge-danger {
    border-color: #fecdd3;
    background: #fff1f2;
    color: #9f1239;
}

.hc-badge-info {
    border-color: #a7d1c7;
    background: var(--hc-brand-soft);
    color: var(--hc-brand-dark);
}

.hc-badge-neutral {
    border-color: var(--hc-line);
    background: #f8f6f1;
    color: #6f7772;
}

.hc-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 2.75rem 1.25rem;
    border: 1px dashed #d9d3c6;
    border-radius: 1rem;
    background: #fbfaf7;
    color: var(--hc-muted);
    text-align: center;
}

.hc-empty-icon {
    display: flex;
    height: 2.6rem;
    width: 2.6rem;
    align-items: center;
    justify-content: center;
    border-radius: 0.9rem;
    background: var(--hc-brand-soft);
    color: var(--hc-brand);
    font-size: 0.95rem;
}

.hc-empty-title {
    color: var(--hc-ink);
    font-size: 0.86rem;
    font-weight: 800;
}

.hc-empty-text {
    max-width: 28rem;
    font-size: 0.74rem;
    line-height: 1.6;
}

.hc-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 0.75rem;
}

.hc-stat {
    padding: 0.9rem 1rem;
    border: 1px solid var(--hc-line);
    border-radius: 0.9rem;
    background: #fbfaf7;
}

.hc-stat-label {
    display: block;
    color: var(--hc-muted);
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hc-stat-value {
    display: block;
    margin-top: 0.25rem;
    color: var(--hc-ink);
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

/* ------------------------------------------------------------
   Plantillas clínicas fijas
   ------------------------------------------------------------ */

.hc-template-dialog {
    width: min(46rem, calc(100vw - 2rem));
    max-width: none;
    max-height: min(86vh, 50rem);
    margin: auto;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 1.25rem;
    background: transparent;
    color: var(--hc-ink);
}

.hc-template-dialog::backdrop {
    background: rgba(4, 16, 15, 0.58);
    backdrop-filter: blur(4px);
}

.hc-template-dialog-shell {
    display: flex;
    max-height: min(86vh, 50rem);
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--hc-line);
    border-radius: 1.25rem;
    background: var(--hc-surface);
    box-shadow: 0 30px 80px -30px rgba(4, 16, 15, 0.55);
}

.hc-template-dialog-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.2rem 1.35rem 1rem;
    border-bottom: 1px solid var(--hc-line);
    background: linear-gradient(135deg, #fbfaf7, #ffffff);
}

.hc-template-dialog-title {
    margin: 0;
    color: var(--hc-ink);
    font-family: "Fraunces", ui-serif, Georgia, serif;
    font-size: 1.45rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    line-height: 1.15;
}

.hc-template-dialog-subtitle {
    max-width: 36rem;
    margin-top: 0.35rem;
    color: var(--hc-muted);
    font-size: 0.76rem;
    font-weight: 500;
    line-height: 1.55;
}

.hc-template-dialog-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 0.8rem 1.35rem 0;
}

.hc-template-dialog-note {
    display: flex;
    max-width: 28rem;
    align-items: flex-start;
    gap: 0.4rem;
    color: var(--hc-muted);
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.45;
}

.hc-template-dialog-note i {
    margin-top: 0.12rem;
    color: var(--hc-brand);
}

.hc-template-mode {
    display: inline-flex;
    flex-shrink: 0;
    padding: 0.2rem;
    border: 1px solid var(--hc-line);
    border-radius: 0.7rem;
    background: #f4f1ea;
}

.hc-template-mode-btn {
    min-height: 1.8rem;
    padding: 0.3rem 0.65rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--hc-muted);
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 800;
    cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.hc-template-mode-btn:hover {
    color: var(--hc-brand-dark);
}

.hc-template-mode-btn.is-active {
    background: #ffffff;
    color: var(--hc-brand-dark);
    box-shadow: 0 2px 8px -6px rgba(15, 59, 56, 0.45);
}

.hc-template-mode-help {
    margin: 0.55rem 1.35rem 0;
    color: var(--hc-muted);
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.4;
}

.hc-template-list {
    display: grid;
    gap: 0.6rem;
    padding: 0.8rem 1.35rem 1.1rem;
    overflow-y: auto;
}

.hc-template-card {
    display: flex;
    width: 100%;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.78rem 0.85rem;
    border: 1px solid var(--hc-line);
    border-radius: 0.85rem;
    background: #fbfaf7;
    color: var(--hc-ink);
    text-align: left;
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.hc-template-card:hover {
    transform: translateY(-1px);
    border-color: #a7d1c7;
    background: #ffffff;
    box-shadow: 0 12px 24px -22px rgba(15, 59, 56, 0.5);
}

.hc-template-card-icon {
    display: flex;
    width: 2rem;
    height: 2rem;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border-radius: 0.6rem;
    background: var(--hc-brand-soft);
    color: var(--hc-brand);
    font-size: 0.75rem;
}

.hc-template-card-body {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    gap: 0.15rem;
}

.hc-template-card-title {
    color: var(--hc-ink);
    font-size: 0.76rem;
    font-weight: 800;
    line-height: 1.35;
}

.hc-template-card-text {
    color: var(--hc-muted);
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.45;
}

.hc-template-card-action {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.3rem;
    color: var(--hc-brand);
    font-size: 0.63rem;
    font-weight: 800;
    opacity: 0.65;
    transition: opacity 160ms ease;
}

.hc-template-card:hover .hc-template-card-action {
    opacity: 1;
}

.hc-template-dialog-foot {
    display: flex;
    justify-content: flex-end;
    padding: 0.8rem 1.35rem 1rem;
    border-top: 1px solid var(--hc-line);
    background: #fbfaf7;
}

@media (max-width: 640px) {
    .hc-page-header {
        align-items: flex-start;
    }

    .hc-page-actions,
    .hc-form-actions {
        width: 100%;
    }

    .hc-form-actions .hc-btn {
        flex: 1 1 auto;
    }

    .hc-template-dialog {
        width: calc(100vw - 1rem);
        max-height: calc(100vh - 1rem);
    }

    .hc-template-dialog-shell {
        max-height: calc(100vh - 1rem);
    }

    .hc-template-dialog-head {
        padding: 1rem;
    }

    .hc-template-dialog-toolbar {
        align-items: flex-start;
        padding: 0.7rem 1rem 0;
    }

    .hc-template-mode-help {
        margin-right: 1rem;
        margin-left: 1rem;
    }

    .hc-template-list {
        padding: 0.7rem 1rem 1rem;
    }

    .hc-template-card-action {
        display: none;
    }

    .hc-template-dialog-foot {
        padding: 0.7rem 1rem 0.9rem;
    }
}

.hc-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.hc-scrollbar::-webkit-scrollbar {
    width: 7px;
}

.hc-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.hc-scrollbar::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
}

.hc-scrollbar-dark {
    scrollbar-width: thin;
    scrollbar-color: #c9c2b6 transparent;
}

.hc-scrollbar-dark::-webkit-scrollbar {
    width: 8px;
}

.hc-scrollbar-dark::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #d7d0c4;
}

/* Foco visible y consistente para navegación por teclado. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid rgba(20, 107, 96, 0.55);
    outline-offset: 2px;
}

/* Tablas: una base sobria que respeta las clases particulares de cada vista. */
main table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

main table thead th {
    background: #f8f6f1;
    color: #5f6b66;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

main table tbody tr {
    transition: background-color 140ms ease;
}

main table tbody tr:hover {
    background: #fbfaf7;
}

main table td,
main table th {
    border-color: var(--hc-line);
}

/* Inputs nativos que no tengan utilidades explícitas. */
main input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
main select,
main textarea {
    accent-color: var(--hc-brand);
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media print {
    aside,
    header,
    #sidebar-overlay,
    .hc-template-dialog,
    .no-print {
        display: none !important;
    }

    body,
    .hc-canvas,
    main {
        background: #fff !important;
    }

    main {
        padding: 0 !important;
    }
}
