:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #64748b;
    --border: #dbe3ef;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

label {
    display: grid;
    gap: 6px;
    color: #334155;
    font-size: 14px;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--border);
    padding: 12px;
    text-align: left;
    vertical-align: top;
}

th {
    color: #475569;
    font-size: 13px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
}

.login-shell {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(392px, 100%);
    position: relative;
    z-index: 1;
    margin: 0 auto;
    align-items: stretch;
}

.login-eyebrow {
    color: #64748b;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
    text-align: center;
    padding: 2px 0;
}

.login-eyebrow::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 8px;
    border-radius: 999px;
    background: #2563eb;
    vertical-align: middle;
}

.login-card,
.panel,
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow:
        0 12px 36px rgba(15, 23, 42, .08),
        0 1px 0 rgba(255, 255, 255, .7) inset;
}

.login-card {
    padding: 30px;
    backdrop-filter: blur(12px);
    width: 100%;
    flex: 1 1 auto;
}

.login-card form {
    display: grid;
    gap: 18px;
    margin-top: 20px;
}

.login-card h2 {
    margin: 0;
    font-size: 1.25rem;
    letter-spacing: -0.03em;
}

.login-card .button.primary {
    width: 100%;
    min-height: 48px;
    box-shadow: none;
}

.login-card input {
    min-height: 48px;
    border-radius: 14px;
    background: #fff;
}

.login-card input::placeholder {
    color: #94a3b8;
}

.login-card input:focus {
    background: #fff;
}

.login-card label {
    color: #334155;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
    align-items: start;
}

.sidebar {
    background: #0f172a;
    color: #e2e8f0;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    transition: width .2s ease;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar.collapsed {
    width: 72px;
}

.sidebar-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.sidebar.collapsed .brand,
.sidebar.collapsed .menu-label,
.sidebar.collapsed nav a span:last-child,
.sidebar.collapsed .sidebar-user-text {
    display: none;
}

.brand {
    display: inline-flex;
    align-items: center;
    min-width: 0;
}

.brand-logo {
    display: block;
    width: 100%;
    max-width: 180px;
    height: auto;
}

.menu-label {
    color: #94a3b8;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.sidebar nav {
    display: grid;
    gap: 6px;
}

.sidebar nav a,
.sidebar .ghost {
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 8px;
    color: #cbd5e1;
    padding: 10px 12px;
}

.sidebar nav a:hover,
.sidebar nav a.active,
.sidebar .ghost:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid rgba(255, 255, 255, .14);
    margin-top: auto;
    padding-top: 16px;
}

.sidebar-user-text {
    min-width: 0;
    flex: 1;
}

.sidebar-user-text strong,
.sidebar-user-text small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-text small {
    color: #94a3b8;
}

.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    flex: 0 0 auto;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, .08);
    color: inherit;
    cursor: pointer;
    font: inherit;
    font-weight: 800;
}

.icon-button.light {
    background: #f8fafc;
    color: #334155;
    border: 1px solid var(--border);
}

.content {
    min-width: 0;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.page-header {
    margin: 0 0 20px;
}

.page-header h1 {
    margin: 0 0 6px;
    font-size: 30px;
}

.page-header p {
    margin: 0;
    color: var(--muted);
}

.with-actions {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}

.panel {
    padding: 20px;
    margin-bottom: 20px;
}

.panel h2,
.card h2 {
    margin-top: 0;
}

.section-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h2 {
    margin: 0;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    padding: 10px 14px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

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

.button.primary:hover {
    background: var(--primary-dark);
}

.button.danger {
    border-color: #fecaca;
    color: var(--danger);
}

.button.light {
    background: #f8fafc;
}

.button.ghost {
    background: transparent;
    border: 0;
}

.flash {
    border-radius: 8px;
    margin-bottom: 18px;
    padding: 12px 14px;
}

.flash.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.flash.error {
    background: var(--error-bg);
    color: var(--error-text);
}

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

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

.stat-link {
    color: inherit;
    display: block;
    text-decoration: none;
}

.stat-link article {
    height: 100%;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.stat-link:hover article {
    border-color: var(--primary);
    box-shadow: 0 10px 24px rgba(37, 99, 235, .12);
    transform: translateY(-1px);
}

.stats article,
.stat-button {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 18px;
}

.stat-button {
    color: inherit;
    cursor: pointer;
    font: inherit;
    text-align: left;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.stat-button:hover,
.stat-button.active {
    border-color: var(--primary);
    box-shadow: 0 10px 24px rgba(37, 99, 235, .12);
    transform: translateY(-1px);
}

.stats strong {
    display: block;
    font-size: 32px;
}

.stats span:not(.stat-icon),
.muted {
    color: var(--muted);
}

.stats small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

.stat-icon {
    float: right;
    color: #94a3b8;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.patient-results {
    max-height: min(72vh, 980px);
    overflow: auto;
    padding-right: 4px;
}

.patient-table-panel {
    padding: 0;
    overflow: hidden;
}

.patient-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
}

.patient-table td {
    background: #fff;
}

.patient-table tr:hover td {
    background: #f8fafc;
}

.block {
    display: block;
}

.block-action {
    margin-top: 8px;
    width: max-content;
}

.card {
    padding: 18px;
}

.patient-card {
    display: flex;
    flex-direction: column;
    min-height: 270px;
    padding: 0;
}

.patient-card > :not(.card-footer) {
    padding-left: 18px;
    padding-right: 18px;
}

.patient-card .card-title {
    padding-top: 18px;
}

.card-title {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
}

.card-title h2 {
    font-size: 19px;
    margin-bottom: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: #e0f2fe;
    color: #075985;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.status-active,
.status-paid {
    background: #dcfce7;
    color: #166534;
}

.status-inactive,
.status-unpaid,
.status-cancelada {
    background: #fee2e2;
    color: #991b1b;
}

.status-admin {
    background: #fee2e2;
    color: #991b1b;
}

.status-programada {
    background: #dbeafe;
    color: #1d4ed8;
}

.status-proxima-a-comenzar {
    background: #fed7aa;
    color: #9a3412;
}

.status-confirmada {
    background: #dcfce7;
    color: #166534;
}

.status-en-curso {
    background: #dcfce7;
    color: #166534;
}

.status-completada {
    background: #e2e8f0;
    color: #334155;
}

.status-finalizada {
    background: #f1f5f9;
    color: #475569;
}

.status-reprogramada {
    background: #fef3c7;
    color: #92400e;
}

.payment-badge {
    display: inline-flex;
    width: fit-content;
    border: 1px solid #bbf7d0;
    border-radius: 999px;
    background: #f0fdf4;
    color: #15803d;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 800;
}

.payment-badge.unpaid {
    border-color: #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.card-actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mini-menu {
    position: absolute;
    top: 38px;
    right: 0;
    z-index: 20;
    display: none;
    min-width: 180px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 30px rgba(15, 23, 42, .16);
}

.mini-menu.open {
    display: grid;
}

.mini-menu a,
.mini-menu button {
    border: 0;
    background: #fff;
    color: var(--text);
    padding: 10px 12px;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.mini-menu a:hover,
.mini-menu button:hover {
    background: #f8fafc;
}

.patient-contact,
.patient-meta {
    color: var(--muted);
    font-size: 14px;
}

.patient-meta {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.patient-meta p,
.patient-contact p {
    margin: 0;
}

.patient-meta span {
    color: var(--muted);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    margin-top: auto;
    padding: 12px 18px;
}

.card-footer a {
    color: var(--primary);
    font-weight: 700;
    font-size: 14px;
}

[data-patient-empty] {
    grid-column: 1 / -1;
}

.category-card {
    display: grid;
    gap: 18px;
}

.category-card h2 {
    display: flex;
    gap: 10px;
    align-items: center;
}

.color-dot {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    flex: 0 0 auto;
}

.filters {
    display: grid;
    grid-template-columns: 1fr 180px auto;
    gap: 12px;
    align-items: end;
}

.reports-filters {
    grid-template-columns: 1fr 120px 140px auto;
}

[data-auto-submit] .auto-submit-button,
[data-patient-filter] .auto-submit-button,
[data-report-filter] .auto-submit-button {
    display: none;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid.one {
    grid-template-columns: 1fr;
}

.form-grid.one textarea,
.form-grid.one .checkbox {
    grid-column: auto;
}

.form-grid textarea,
.form-grid .checkbox {
    grid-column: span 2;
}

.checkbox {
    display: flex;
    gap: 8px;
    align-items: center;
}

.checkbox input {
    width: auto;
}

.checkbox.small {
    font-weight: 500;
}

.grid.two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.patient-detail-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.patient-records-panel {
    min-width: 0;
}

.inline-actions,
.panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.panel-actions .button,
.panel-actions a {
    flex: 1 1 160px;
}

.soft-divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 22px 0;
}

.table-wrap {
    overflow-x: auto;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.inline-form select,
.inline-form input {
    width: auto;
}

.select-search {
    margin-bottom: 8px;
}

.autocomplete {
    position: relative;
    display: block;
}

.autocomplete-list,
.autocomplete-empty {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 30;
    overflow: auto;
    max-height: 260px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 16px 36px rgba(15, 23, 42, .16);
}

.autocomplete-list button {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid #eef2f7;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 12px;
    text-align: left;
}

.autocomplete-list button:hover,
.autocomplete-list button:focus {
    background: #f8fafc;
    outline: none;
}

.autocomplete-list button:last-child {
    border-bottom: 0;
}

.autocomplete-empty {
    color: var(--muted);
    font-size: 14px;
    padding: 12px;
}

.tag-picker {
    border: 1px solid var(--border);
    border-radius: 8px;
    grid-column: 1 / -1;
    padding: 12px;
}

.tag-picker legend {
    font-weight: 800;
    padding: 0 6px;
}

.tag-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 12px;
}

.tag-option {
    align-items: center;
    background: color-mix(in srgb, var(--tag-color, #6366f1) 10%, #fff);
    border: 1px solid var(--tag-color, var(--border));
    border-radius: 8px;
    display: inline-flex;
    flex-direction: row;
    gap: 6px;
    padding: 6px 9px;
}

.tag-option input {
    width: auto;
}

.quick-status-actions,
.color-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.color-preset {
    border: 2px solid #fff;
    border-radius: 999px;
    box-shadow: 0 0 0 1px var(--border);
    cursor: pointer;
    height: 28px;
    width: 28px;
}

.toolbar,
.table-actions,
.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.calendar-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-end;
}

.calendar-jump label {
    gap: 4px;
}

.calendar-jump input {
    min-width: 150px;
}

.calendar-controls {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-end;
    padding: 14px;
}

.calendar-nav {
    display: flex;
    gap: 8px;
    align-items: center;
}

.pagination-bar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
}

.button.small {
    padding: 7px 10px;
    font-size: 13px;
}

.button.full {
    width: 100%;
}

.button.icon-only {
    width: 40px;
    padding-left: 0;
    padding-right: 0;
    font-size: 20px;
}

.button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.list-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
}

.list-row p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.calendar-shell {
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
    margin-bottom: 20px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: 74px repeat(7, minmax(130px, 1fr));
    min-width: 984px;
}

.calendar-head {
    border-bottom: 1px solid var(--border);
}

.calendar-hour-head,
.calendar-day-head,
.calendar-hour {
    background: #f8fafc;
    border-right: 1px solid var(--border);
    padding: 10px;
    text-align: center;
}

.calendar-hour {
    display: grid;
    align-content: center;
    gap: 2px;
}

.calendar-hour small {
    color: var(--muted);
    font-size: 12px;
}

.calendar-day-head {
    display: grid;
    gap: 4px;
}

.calendar-day-head.today span {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    justify-self: center;
}

.calendar-scroll {
    max-height: calc(100vh - 260px);
    overflow: auto;
}

.calendar-row {
    border-bottom: 1px solid var(--border);
}

.calendar-cell {
    position: relative;
    min-height: 82px;
    border-right: 1px solid var(--border);
    padding: 5px;
}

.today-soft {
    background: #eff6ff;
}

.slot-add {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    width: 100%;
    border: 1px dashed transparent;
    background: transparent;
    color: transparent;
    cursor: pointer;
    font-size: 22px;
}

.calendar-cell:hover .slot-add {
    border-color: #93c5fd;
    color: #60a5fa;
}

.appointment-chip {
    position: relative;
    display: grid;
    gap: 2px;
    width: 100%;
    border: 0;
    border-left: 6px solid #3b82f6;
    border-radius: 8px;
    padding: 8px 8px 7px;
    text-align: left;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    color: var(--appointment-fg, #0f172a);
    background: var(--appointment-bg, #fff);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}

.appointment-chip strong,
.appointment-chip span,
.appointment-chip small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.appointment-meta {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    align-items: center;
    font-size: 11px;
    font-weight: 800;
}

.appointment-status-text,
.appointment-payment-text {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
}

.appointment-status-text {
    background: var(--appointment-status-bg, rgba(255, 255, 255, .45));
    color: var(--appointment-status-fg, #0f172a);
}

.appointment-payment-text.paid {
    background: #bbf7d0;
    color: #14532d;
}

.appointment-payment-text.unpaid {
    background: #fecaca;
    color: #7f1d1d;
}

.appointment-programada {
    --appointment-bg: #dbeafe;
    --appointment-fg: #1e3a8a;
    --appointment-status-bg: #bfdbfe;
    --appointment-status-fg: #1d4ed8;
    border-left-color: #3b82f6;
}

.appointment-proxima-a-comenzar {
    --appointment-bg: #fb923c;
    --appointment-fg: #fff7ed;
    --appointment-status-bg: #fed7aa;
    --appointment-status-fg: #9a3412;
    border-left-color: #c2410c;
}

.appointment-confirmada {
    --appointment-bg: #bbf7d0;
    --appointment-fg: #14532d;
    --appointment-status-bg: #dcfce7;
    --appointment-status-fg: #166534;
    border-left-color: #22c55e;
}

.appointment-en-curso {
    --appointment-bg: #22c55e;
    --appointment-fg: #f0fdf4;
    --appointment-status-bg: #dcfce7;
    --appointment-status-fg: #166534;
    border-left-color: #16a34a;
}

.appointment-completada {
    --appointment-bg: #cbd5e1;
    --appointment-fg: #334155;
    --appointment-status-bg: #e2e8f0;
    --appointment-status-fg: #475569;
    border-left-color: #64748b;
}

.appointment-finalizada {
    --appointment-bg: #475569;
    --appointment-fg: #f8fafc;
    --appointment-status-bg: #cbd5e1;
    --appointment-status-fg: #334155;
    border-left-color: #475569;
}

.appointment-completada.paid {
    --appointment-bg: #cbd5e1;
    --appointment-fg: #334155;
    border-left-color: #64748b;
}

.appointment-finalizada.paid {
    --appointment-bg: #cbd5e1;
    --appointment-fg: #334155;
    --appointment-status-bg: #e2e8f0;
    --appointment-status-fg: #475569;
    border-left-color: #64748b;
}

.appointment-en-curso.paid {
    --appointment-bg: #86efac;
    --appointment-fg: #14532d;
    border-left-color: #10b981;
}

.appointment-cancelada {
    --appointment-bg: #fee2e2;
    --appointment-fg: #991b1b;
    --appointment-status-bg: #fecaca;
    --appointment-status-fg: #7f1d1d;
    border-left-color: #ef4444;
}

.appointment-cancelada.paid {
    --appointment-bg: #fee2e2;
    --appointment-fg: #991b1b;
    --appointment-status-bg: #fecaca;
    --appointment-status-fg: #7f1d1d;
    border-left-color: #ef4444;
}

.appointment-reprogramada {
    --appointment-bg: #fcd34d;
    --appointment-fg: #422006;
    --appointment-status-bg: #fde68a;
    --appointment-status-fg: #92400e;
    border-left-color: #f59e0b;
}

.appointment-chip em {
    position: absolute;
    top: 5px;
    right: 6px;
    color: #16a34a;
    font-style: normal;
    font-weight: 900;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
}

.modal.open {
    display: grid;
    place-items: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .55);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(900px, calc(100vw - 32px));
    max-height: calc(100vh - 40px);
    overflow: auto;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
}

.modal-card.compact {
    width: min(520px, calc(100vw - 32px));
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    border-bottom: 1px solid var(--border);
    padding: 18px;
}

.modal-header h2,
.modal-header p {
    margin: 0;
}

.modal-header p {
    margin-top: 4px;
    color: var(--muted);
}

.modal-body {
    padding: 18px;
}

.detail-stack {
    display: grid;
    gap: 12px;
}

.detail-stack p {
    margin: 0;
}

.compact-details {
    gap: 6px 12px;
}

.compact-details dt {
    margin: 0;
}

.compact-details dd {
    margin: 0 0 4px;
}

.compact-details dd:last-child {
    margin-bottom: 0;
}

.below-calendar {
    display: none;
}

.record {
    border-top: 1px solid var(--border);
    padding: 16px 0;
}

.record h3 {
    margin: 0 0 4px;
}

.record-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 14px;
}

.record-actions form {
    margin: 0;
}

.sharing-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    border-top: 1px solid var(--border);
    padding: 12px 0;
}

.details {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr);
    gap: 8px 12px;
}

.details dt {
    color: var(--muted);
    font-weight: 700;
}

.details dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.empty {
    color: var(--muted);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.settings-actions {
    justify-content: flex-end;
    margin-top: 4px;
}

.switch-row {
    display: flex;
    grid-template-columns: none;
    flex-direction: row;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.switch-row span {
    display: grid;
    gap: 3px;
}

.switch-row small {
    color: var(--muted);
    font-weight: 500;
}

.switch-row input {
    width: auto;
}

.notice {
    border: 1px solid #fbbf24;
    border-radius: 8px;
    background: #fffbeb;
    color: #92400e;
    margin: 0;
    padding: 12px;
}

.disabled-panel {
    opacity: .72;
}

pre {
    overflow: auto;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 8px;
    padding: 14px;
}

@media (max-width: 860px) {
    .app-shell,
    .login-shell,
    .grid.two,
    .patient-detail-grid,
    .stats {
        grid-template-columns: 1fr;
    }

    .login-page {
        padding: 16px;
    }

    .login-shell {
        width: min(100%, 392px);
    }

    .login-card {
        padding: 24px;
        border-radius: 20px;
    }

    .sidebar {
        width: 100%;
        overflow: hidden;
        max-height: 1000px;
        transition: max-height .2s ease;
        position: static;
        height: auto;
        overscroll-behavior: auto;
    }

    .sidebar.collapsed {
        width: 100%;
        max-height: 72px;
    }

    .sidebar-toggle {
        transform: rotate(90deg);
        transition: transform .2s ease;
    }

    .sidebar.collapsed .sidebar-toggle {
        transform: rotate(-90deg);
    }

    .filters,
    .form-grid,
    .settings-grid,
    .patient-detail-grid {
        grid-template-columns: 1fr;
    }

    .form-grid textarea,
    .form-grid .checkbox {
        grid-column: auto;
    }

    .with-actions,
    .topbar,
    .section-header,
    .calendar-controls {
        align-items: flex-start;
        flex-direction: column;
    }

    .inline-actions,
    .panel-actions {
        width: 100%;
    }

    .panel-actions .button,
    .panel-actions a {
        flex: 1 1 100%;
    }

    .calendar-nav {
        width: 100%;
    }
}
