:root {
    --bg: #f2f4fb;
    --bg-accent: #eef2ff;
    --panel: #ffffff;
    --panel-soft: rgba(255, 255, 255, 0.72);
    --text: #1b2035;
    --muted: #6b7280;
    --line: #e6e9f5;
    --primary: #6a5cf5;
    --primary-dark: #5343e0;
    --primary-soft: #eeeafe;
    --accent: #17c3b2;
    --accent-soft: #e3faf7;
    --success: #17c3b2;
    --danger: #f24870;
    --danger-soft: #ffe9ee;
    --warn: #f5a524;
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 4px 14px rgba(48, 46, 122, 0.06);
    --shadow: 0 16px 40px rgba(48, 46, 122, 0.10);
    --shadow-lg: 0 30px 70px rgba(30, 24, 90, 0.16);
    font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    max-width: 100%;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    max-width: 100%;
    overflow-x: hidden;
    color: var(--text);
    background:
        radial-gradient(1100px 500px at 100% -10%, rgba(106, 92, 245, 0.10), transparent 60%),
        radial-gradient(900px 500px at -10% 10%, rgba(23, 195, 178, 0.10), transparent 55%),
        var(--bg);
}

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

::selection {
    background: var(--primary);
    color: #fff;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
.primary,
.emergency {
    border: 0;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    padding: 0.8rem 1.15rem;
    box-shadow: 0 10px 24px rgba(106, 92, 245, 0.28);
    max-width: 100%;
    white-space: normal;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

button:hover,
.primary:hover,
.emergency:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(106, 92, 245, 0.34);
}

button:active,
.primary:active,
.emergency:active {
    transform: translateY(0);
}

button:focus-visible,
.primary:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(106, 92, 245, 0.35);
    outline-offset: 2px;
}

.link-button {
    background: transparent;
    color: var(--muted);
    box-shadow: none;
    padding: 0.5rem 0.7rem;
}

.link-button:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
    transform: none;
    box-shadow: none;
}

/* Topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.6rem;
    background: rgba(255, 255, 255, 0.78);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    max-width: 100%;
}

.mobile-menu-button {
    display: none;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary-dark);
    box-shadow: none;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.2rem;
}

.brand.large {
    font-size: 1.5rem;
}

.brand-icon {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-size: 1.5rem;
    font-weight: 900;
    box-shadow: 0 8px 18px rgba(106, 92, 245, 0.32);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--muted);
    font-weight: 700;
}

.professional-action-options { display: grid; gap: 0.7rem; }
.professional-action-option { display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 0.9rem 1rem; }
.professional-action-option span { color: rgba(255, 255, 255, 0.82); font-weight: 600; }
.linked-professional-row { display: flex; align-items: center; gap: 0.75rem; }
.linked-professional-row .checkbox-line { flex: 1; margin: 0; }
.linked-professional-row > button { flex: 0 0 auto; padding: 0.45rem 0.75rem; }

.pwa-notice {
    position: fixed;
    z-index: 1200;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.25rem;
    background: rgba(18, 23, 45, 0.56);
    backdrop-filter: blur(3px);
}
.pwa-notice-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: min(560px, 100%);
    padding: 1.25rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
    box-shadow: var(--shadow-lg);
}

.pwa-notice[hidden] { display: none; }
.pwa-notice-card > div:first-child { display: grid; gap: 0.25rem; flex: 1; }
.pwa-notice span { color: var(--muted); font-size: 0.9rem; line-height: 1.35; }
.pwa-notice-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.pwa-notice-actions button { padding: 0.65rem 0.85rem; }
.notification-status { padding: 0.85rem 1rem; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }
.notification-status.error { background: var(--danger-soft); color: var(--danger); }
.notification-status.success { background: var(--accent-soft); color: #087f73; }

@media (max-width: 640px) {
    .pwa-notice-card { align-items: stretch; flex-direction: column; }
    .pwa-notice-actions button { flex: 1; }
}

.top-actions a {
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
}

.top-actions a:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.report-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.report-icon {
    display: none;
}

.account-menu {
    position: relative;
}

.account-menu summary {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    list-style: none;
    border-radius: 999px;
    padding: 0.3rem 0.85rem 0.3rem 0.3rem;
    color: var(--text);
    transition: background 0.15s ease;
}

.account-menu summary::-webkit-details-marker {
    display: none;
}

.account-menu summary:hover {
    background: var(--primary-soft);
}

.account-avatar {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-weight: 900;
}

.account-options {
    position: absolute;
    right: 0;
    top: calc(100% + 0.6rem);
    z-index: 40;
    display: grid;
    gap: 0.2rem;
    min-width: 210px;
    padding: 0.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
    box-shadow: var(--shadow-lg);
}

.account-options a,
.account-options button {
    width: 100%;
    text-align: left;
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.7rem;
    background: transparent;
    color: var(--text);
    font-weight: 650;
    box-shadow: none;
}

.account-options a:hover,
.account-options button:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
    transform: none;
    box-shadow: none;
}

/* Login */

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background:
        radial-gradient(900px 500px at 15% -10%, rgba(106, 92, 245, 0.16), transparent 55%),
        radial-gradient(900px 600px at 100% 110%, rgba(23, 195, 178, 0.16), transparent 55%),
        var(--bg);
}

.login-panel {
    width: min(440px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 2.2rem;
    box-shadow: var(--shadow-lg);
}

.login-panel h1,
.hero h1 {
    margin: 1rem 0 0.35rem;
    font-size: clamp(2rem, 7vw, 2.8rem);
    line-height: 1.08;
    letter-spacing: -0.02em;
}

.login-panel p,
.hero p {
    color: var(--muted);
    font-size: 1.05rem;
    margin: 0;
}

/* App shell */

.app-shell {
    display: grid;
    grid-template-columns: 272px 1fr;
    gap: 1.5rem;
    width: min(1480px, 100%);
    margin: 0 auto;
    padding: 1.5rem;
    min-width: 0;
}

.app-shell.single {
    grid-template-columns: 220px 1fr;
}

.app-shell > *,
.content > *,
.panel,
.medication-admin-list,
.admin-card,
.modal-card {
    min-width: 0;
}

.sidebar {
    position: sticky;
    top: 92px;
    align-self: start;
    display: grid;
    gap: 0.35rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1.1rem;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 112px);
    overflow-y: auto;
}

.patient-switch {
    display: grid;
    gap: 0.45rem;
    padding-bottom: 0.9rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--line);
}

.patient-switch span,
label {
    color: var(--muted);
    font-weight: 700;
    font-size: 0.86rem;
}

.field-help,
.unit-label {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.unit-label {
    color: var(--primary-dark);
}

input,
select,
textarea {
    width: 100%;
    margin-top: 0.35rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fbfbff;
    color: var(--text);
    padding: 0.75rem 0.85rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
    background: #fff;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 0.9rem;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-weight: 700;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.nav-icon {
    display: inline-grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 1rem;
    line-height: 1;
    font-weight: 900;
    flex: 0 0 auto;
}

.nav-item.active,
.nav-item:hover {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    transform: translateX(2px);
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.content {
    display: grid;
    gap: 1.5rem;
    min-width: 0;
}

.hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0 0.5rem;
    min-width: 0;
}

.emergency {
    background: linear-gradient(135deg, var(--danger), #d63a63);
    white-space: nowrap;
    box-shadow: 0 10px 22px rgba(242, 72, 112, 0.32);
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-weight: 700;
    padding: 0.78rem 1rem;
    box-shadow: 0 10px 22px rgba(106, 92, 245, 0.28);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.button-link:hover {
    transform: translateY(-1px);
}

.button-link.subtle {
    background: var(--primary-soft);
    color: var(--primary-dark);
    box-shadow: none;
}

.full-width {
    width: 100%;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: flex-end;
}

.notice,
.toast,
.alert {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 0.95rem 1.1rem;
    background: var(--panel-soft);
    color: var(--muted);
    font-weight: 600;
    overflow-wrap: anywhere;
    backdrop-filter: blur(6px);
}

.toast {
    position: fixed;
    left: 50%;
    top: 84px;
    transform: translateX(-50%);
    z-index: 50;
    background: #1b2035;
    color: #fff;
    border: 0;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.25s ease;
}

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, -8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.attachment-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.screen-feedback {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 45;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 92px;
    min-height: 42px;
    border-radius: 999px;
    background: #1b2035;
    color: #fff;
    font-weight: 800;
    box-shadow: var(--shadow-lg);
}

.back-to-top {
    position: fixed;
    right: 1rem;
    bottom: calc(1rem + 58px);
    z-index: 45;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.2rem;
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.back-to-top.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.alert {
    background: var(--danger-soft);
    color: #b0264d;
    border-color: #ffd0dd;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}

.metric,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    min-width: 0;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.metric:hover,
.panel:hover {
    box-shadow: var(--shadow);
}

.metric {
    display: grid;
    gap: 0.35rem;
    min-height: 146px;
    padding: 1.4rem;
    position: relative;
    overflow: hidden;
}

.metric::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(106, 92, 245, 0.05), rgba(23, 195, 178, 0.05));
    pointer-events: none;
}

.metric span {
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.metric strong {
    font-size: clamp(2rem, 5vw, 2.7rem);
    line-height: 1;
    background: linear-gradient(135deg, var(--text), var(--primary-dark));
    -webkit-background-clip: text;
    background-clip: text;
}

.metric small {
    color: var(--muted);
    font-size: 0.98rem;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    min-width: 0;
}

.panel {
    padding: 1.4rem;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 1rem;
    min-width: 0;
}

h2,
h3 {
    margin: 0;
    line-height: 1.2;
}

h2 {
    font-size: clamp(1.3rem, 4vw, 1.8rem);
    letter-spacing: -0.01em;
}

h3 {
    margin-top: 1rem;
    font-size: 1.02rem;
}

.dose-list {
    display: grid;
    gap: 0.75rem;
}

.dose {
    display: grid;
    grid-template-columns: 46px 1fr auto;
    align-items: center;
    gap: 0.9rem;
    padding: 1rem;
    border: 1px solid;
    border-radius: var(--radius-md);
    min-width: 0;
    transition: transform 0.15s ease;
}

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

.dose-info.is-editable {
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s ease;
}

.dose-info.is-editable:hover {
    background: var(--primary-soft);
}

.dose.done {
    background: var(--accent-soft);
    border-color: #bdeee7;
}

.dose.pending {
    background: var(--danger-soft);
    border-color: #ffd0dd;
}

.dose .check {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    background: #fff;
    border: 3px solid var(--muted);
    color: var(--success);
    box-shadow: none;
}

.dose.done .check {
    border-color: var(--success);
    background: var(--success);
    color: #fff;
}

.dose strong,
.dose small {
    display: block;
    overflow-wrap: anywhere;
}

.dose small,
.dose time {
    color: var(--muted);
}

.grid-two {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem;
    min-width: 0;
}

canvas {
    width: 100%;
    max-width: 100%;
}

.recent-list,
.stack {
    display: grid;
    gap: 0.9rem;
}

.user-table {
    display: grid;
    gap: 0.75rem;
}

.user-row {
    display: grid;
    grid-template-columns: 1.1fr 1.4fr 0.8fr 1.3fr;
    gap: 0.75rem;
    min-width: 720px;
    align-items: center;
    padding: 0.8rem;
    border-radius: var(--radius-sm);
    background: var(--bg-accent);
}

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

.user-actions form {
    display: inline;
}

.user-actions button {
    padding: 0.5rem 0.7rem;
    font-size: 0.82rem;
    box-shadow: none;
}

.user-admin-card summary {
    grid-template-columns: 1fr 1.4fr auto;
}

.separate-actions {
    justify-content: flex-end;
    margin-top: 0.75rem;
}

.danger-button {
    background: linear-gradient(135deg, var(--danger), #d63a63);
    box-shadow: 0 10px 22px rgba(242, 72, 112, 0.28);
}

.user-row.heading {
    background: var(--primary-soft);
    color: var(--muted);
    font-weight: 900;
}

.hint {
    color: var(--muted);
    margin: 0.8rem 0 0;
}

.compact {
    padding: 0.75rem;
}

.patient-access {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 0.85rem;
}

.patient-access legend {
    color: var(--muted);
    font-weight: 800;
    padding: 0 0.4rem;
}

.repeatable-block {
    display: grid;
    gap: 0.7rem;
}

.compact-head {
    margin-bottom: 0;
}

.compact-head h3 {
    margin: 0;
}

.compact-head button,
.emergency-contact-row button {
    box-shadow: none;
    padding: 0.58rem 0.75rem;
}

.emergency-contact-row {
    display: grid;
    grid-template-columns: 1fr 0.8fr 1fr 0.85fr auto;
    gap: 0.7rem;
    align-items: end;
    padding: 0.8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fbfbff;
}

.emergency-contact-row + .emergency-contact-row {
    margin-top: 0.7rem;
}

.emergency-list {
    display: grid;
    gap: 0.5rem;
    margin: 0.75rem 0 1rem;
}

.emergency-list a {
    display: grid;
    gap: 0.15rem;
    padding: 0.8rem;
    border-radius: var(--radius-md);
    background: var(--danger-soft);
    color: var(--text);
    transition: transform 0.15s ease;
}

.emergency-list a:hover {
    transform: translateY(-1px);
}

.emergency-list span {
    color: var(--muted);
}

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--text);
    margin-top: 0.55rem;
}

.checkbox-line input {
    width: auto;
    margin: 0;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.45rem;
}

.suggestion-chips button {
    background: var(--primary-soft);
    color: var(--primary-dark);
    box-shadow: none;
    padding: 0.35rem 0.6rem;
    font-size: 0.78rem;
}

.medication-admin-list {
    display: grid;
    gap: 0.8rem;
}

.admin-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fbfbff;
    padding: 0.95rem;
}

.admin-card summary {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.8rem;
    align-items: center;
}

.admin-card summary em {
    color: var(--muted);
    font-style: normal;
    font-weight: 800;
}

.admin-card form {
    margin-top: 1rem;
}

.inline-admin-action {
    display: flex;
    justify-content: flex-end;
}

.recent-item,
.timeline-item {
    background: var(--bg-accent);
    border-radius: var(--radius-md);
    padding: 0.9rem;
}

.recent-item {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

mark,
.chips span {
    display: inline-block;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--text);
    padding: 0.35rem 0.7rem;
    font-weight: 600;
}

.timeline-item + .timeline-item {
    margin-top: 0.75rem;
}

.timeline-item p {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

.empty {
    display: grid;
    min-height: 180px;
    place-items: center;
    color: var(--muted);
    font-weight: 700;
    border: 1px dashed var(--line);
    border-radius: var(--radius-md);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.8rem;
}

.chips.danger span {
    background: var(--danger-soft);
}

/* Modals */

.modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    z-index: 100;
    display: none;
    place-items: center;
    padding: 1rem;
    background: rgba(20, 20, 40, 0.45);
    backdrop-filter: blur(3px);
}

.modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modal-fade 0.18s ease;
}

@keyframes modal-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    width: 100%;
    max-width: 620px;
    width: min(620px, 100%);
    max-height: 90vh;
    max-height: min(90vh, 900px);
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    animation: modal-pop 0.2s ease;
}

@keyframes modal-pop {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
    margin-top: 0.5rem;
}

.modal-actions button[type="button"] {
    background: var(--bg-accent);
    color: var(--text);
    box-shadow: none;
}

details {
    margin-top: 0.75rem;
}

summary {
    cursor: pointer;
    color: var(--primary-dark);
    font-weight: 700;
}

/* Calendar / releases */

.calendar-list,
.release-list {
    display: grid;
    gap: 0.8rem;
}

.calendar-day {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 1rem;
    background: #fff;
}

.calendar-day h3 {
    margin: 0 0 0.75rem;
}

.calendar-event {
    display: grid;
    gap: 0.2rem;
    padding: 0.7rem 0;
    border-top: 1px solid var(--line);
}

.calendar-event.is-editable,
.calendar-chip.is-editable {
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.calendar-event.is-editable:hover {
    background: var(--primary-soft);
}

.calendar-chip.is-editable:hover {
    background: var(--primary-soft);
    transform: translateY(-1px);
}

.calendar-event small,
.version-link {
    color: var(--muted);
}

.version-link {
    margin: 0.85rem 0 0;
    text-align: center;
    font-size: 0.78rem;
}

.version-link a {
    color: inherit;
    text-decoration: none;
}

.version-link a:hover,
.version-link a:focus-visible {
    color: var(--primary);
    text-decoration: underline;
}

.evolution-timeline {
    display: grid;
    gap: 1rem;
}

.evolution-date {
    margin: 1.25rem 0 0;
    color: var(--muted);
    font-size: 1rem;
}

.evolution-card {
    padding: 1.2rem;
}

.evolution-card .section-head > div {
    display: grid;
    gap: 0.2rem;
}

.evolution-content {
    display: grid;
    gap: 0.35rem;
    margin: 1rem 0;
}

.evolution-content h4,
.evolution-content p {
    margin: 0;
}

.evolution-content h4:not(:first-child) {
    margin-top: 0.75rem;
}

.evolution-filters {
    align-items: end;
}

.active-professional-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.55rem 0.75rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    white-space: nowrap;
}

.active-professional-label {
    color: var(--muted);
    font-weight: 600;
}

.shift-professional-context {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.8rem;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    background: var(--primary-soft);
}

.shift-professional-context span { color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.shift-professional-context strong { color: var(--text); }

.shift-professional-options {
    max-height: 420px;
    max-height: min(420px, 48vh);
    overflow-y: auto;
    align-content: start;
    padding: 0.15rem 0.25rem 0.15rem 0;
}

.shift-professional-group {
    display: grid;
    gap: 0.55rem;
}

.shift-professional-group + .shift-professional-group {
    margin-top: 0.7rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--line);
}

.shift-professional-group h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0;
    color: var(--text);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.shift-professional-group h3 small {
    display: grid;
    place-items: center;
    min-width: 1.65rem;
    height: 1.65rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.75rem;
}

.shift-professional-group-list {
    display: grid;
    gap: 0.55rem;
}

.selectable-professional-option {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: 0.8rem;
    min-height: 72px;
    padding: 0.8rem 1rem;
    border: 2px solid var(--line);
    border-radius: 16px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.selectable-professional-option:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    transform: translateY(-1px);
}

.selectable-professional-option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 3px rgba(106, 92, 245, 0.1);
}

.selectable-professional-option.is-selected {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 3px rgba(106, 92, 245, 0.1);
}

.selectable-professional-option input {
    width: 1.15rem;
    height: 1.15rem;
    margin: 0;
    accent-color: var(--primary);
}

.professional-option-avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #20c7be);
    color: #fff;
    font-weight: 800;
}

.professional-option-copy {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
}

.professional-option-copy strong { color: var(--text); font-size: 1rem; }
.professional-option-copy small { color: var(--muted); font-size: 0.86rem; }
.selectable-professional-option em {
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-style: normal;
    font-weight: 800;
    text-transform: uppercase;
}

@media (max-width: 760px) {
    .active-professional-label { display: none; }
    .active-professional-trigger { max-width: 190px; overflow: hidden; }
    .shift-professional-context { grid-template-columns: 1fr; }
    .shift-professional-context strong + span { margin-top: 0.45rem; }
    .selectable-professional-option { grid-template-columns: auto auto 1fr; }
    .selectable-professional-option em { grid-column: 3; justify-self: start; }
}

.release-panel {
    width: min(720px, 100%);
}

.release-list ul {
    margin: 0.75rem 0 0;
    padding-left: 1.2rem;
    color: var(--muted);
}

.section-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.section-actions .button-link,
.section-actions button {
    min-height: 36px;
    padding: 0.5rem 0.75rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--line);
    gap: 1px;
}

.calendar-weekday {
    min-height: 44px;
    display: grid;
    place-items: center;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 900;
}

.calendar-cell {
    min-height: 142px;
    display: grid;
    align-content: start;
    gap: 0.35rem;
    padding: 0.55rem;
    background: #fff;
    overflow: hidden;
}

.calendar-cell.muted-day {
    background: #f7f8fd;
    color: var(--muted);
}

.calendar-date {
    font-weight: 900;
    color: var(--text);
}

.calendar-empty {
    color: var(--muted);
    font-size: 0.78rem;
}

.calendar-chip {
    display: grid;
    gap: 0.15rem;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--text);
    padding: 0.4rem 0.5rem;
    font-size: 0.78rem;
    line-height: 1.2;
}

.calendar-chip strong {
    color: var(--primary-dark);
    font-size: 0.72rem;
}

.report-period {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.25rem 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
}

.report-period > label,
.report-period > small {
    margin: 0;
}

.report-period > small {
    grid-column: 1 / -1;
    color: var(--muted);
}

.report-period-control {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.report-period-control input {
    width: 90px;
    margin: 0;
    padding: 0.55rem 0.65rem;
}

.report-options {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.4rem;
    max-height: 260px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.25rem;
}

.report-option {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    min-height: 42px;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: pointer;
}

.report-option input {
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    flex: 0 0 auto;
}

.report-option span {
    display: block;
    min-width: 0;
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.report-option.is-disabled {
    color: var(--muted);
    background: var(--surface-muted);
    cursor: not-allowed;
    opacity: 0.65;
}

.report-option.is-disabled span {
    color: var(--muted);
}

.report-chart-selector {
    margin: 0;
    padding: 0.8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
}

.report-chart-selector[hidden] {
    display: none;
}

.report-chart-selector legend {
    padding: 0 0.3rem;
    color: var(--text);
    font-weight: 700;
}

.report-chart-selector > p {
    margin: 0 0 0.65rem;
    font-size: 0.84rem;
}

.report-chart-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
}

.report-chart-options .report-option {
    min-height: 38px;
    background: #fff;
}

.report-modal textarea {
    min-height: 320px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
}

.report-pdf-button {
    background: var(--primary);
}

.patient-photo {
    width: 88px;
    height: 88px;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid var(--primary-soft);
}

.whatsapp-button {
    background: #25d366;
    box-shadow: 0 10px 22px rgba(37, 211, 102, 0.32);
}

.whatsapp-button:hover {
    background: #1fb45a;
}

.card-collapse-toggle {
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    box-shadow: none;
}

.panel > .card-collapse-toggle {
    float: right;
    margin-bottom: 0.75rem;
}

.panel.is-collapsed > :not(.section-head):not(.card-collapse-toggle):not(h2):not(h3) {
    display: none !important;
}

/* Mobile drawer backdrop (injected by app_2.js) */

.nav-backdrop {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    z-index: 32;
    background: rgba(15, 15, 30, 0.4);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

body.mobile-nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 980px) {
    .mobile-menu-button {
        display: grid;
        place-items: center;
        flex: 0 0 auto;
    }

    .app-shell,
    .app-shell.single {
        grid-template-columns: 1fr;
        padding: 1rem;
        margin-top: var(--topbar-h, 70px);
    }

    .topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--topbar-h, 70px);
        bottom: 0;
        z-index: 33;
        width: 86%;
        max-width: 340px;
        width: min(86vw, 340px);
        max-width: 100%;
        max-height: none;
        overflow: auto;
        border-radius: 0;
        transform: translateX(-105%);
        transition: transform 0.25s ease;
        grid-template-columns: 1fr;
        padding-top: 1.1rem;
        padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    }

    body.mobile-nav-open .sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .patient-switch {
        grid-column: auto;
    }

    .summary-grid,
    .grid-two {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .topbar {
        padding: 0.85rem 1rem;
        gap: 0.6rem;
    }

    .version-chip {
        display: none;
    }

    .report-label {
        display: none;
    }

    .report-icon {
        display: inline;
        font-size: 1.1rem;
    }

    .report-options {
        grid-template-columns: 1fr;
    }

    .report-chart-options {
        grid-template-columns: 1fr;
    }

    .report-trigger {
        padding: 0.6rem;
    }

    .account-menu summary span:last-child {
        display: none;
    }

    .brand strong {
        font-size: 1rem;
    }

    .brand-icon {
        width: 42px;
        height: 42px;
    }

    .hero {
        align-items: stretch;
        flex-direction: column;
    }

    .hero h1 {
        font-size: 2.1rem;
        overflow-wrap: anywhere;
    }

    .summary-grid,
    .grid-two,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .app-shell,
    .app-shell.single {
        width: 100%;
        padding: 0.75rem;
    }

    .content,
    .panel,
    .medication-admin-list,
    .admin-card,
    .modal-card {
        width: 100%;
        max-width: 100%;
    }

    .emergency-contact-row {
        grid-template-columns: 1fr;
    }

    .sidebar {
        grid-template-columns: 1fr;
        width: min(88vw, 320px);
    }

    .nav-item {
        text-align: left;
        padding: 0.85rem 0.7rem;
        overflow-wrap: anywhere;
    }

    .section-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .section-head button {
        width: 100%;
    }

    .dose {
        grid-template-columns: 42px 1fr;
        width: 100%;
    }

    .dose time {
        grid-column: 2;
    }

    .quick-actions {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .quick-actions button {
        display: block;
        min-height: 48px;
        text-align: center;
        overflow-wrap: anywhere;
    }

    .hero-actions,
    .hero-actions button,
    .quick-actions button,
    .emergency {
        width: 100%;
    }

    .panel,
    .metric,
    .notice {
        width: 100%;
        max-width: 100%;
    }

    .metric {
        min-height: 124px;
    }

    .metric strong {
        font-size: 2.05rem;
    }
}

@media (max-width: 380px) {
    .brand strong {
        display: none;
    }

    .topbar {
        gap: 0.4rem;
    }
}

@media (max-width: 760px) {
    .calendar-grid {
        display: block;
        border: 0;
        background: transparent;
    }

    .calendar-weekday {
        display: none;
    }

    .calendar-cell {
        min-height: 0;
        margin-bottom: 0.75rem;
        border: 1px solid var(--line);
        border-radius: var(--radius-md);
    }
}

@media (max-width: 640px) {
    .admin-card summary {
        grid-template-columns: 1fr;
    }
}

.time-manager {
    display: grid;
    gap: 0.6rem;
}

.field-label {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
}

.time-pill-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 2.55rem;
    padding: 0.65rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(106, 92, 245, 0.045);
}

.time-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 0.5rem 0.42rem 0.78rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 800;
    box-shadow: 0 8px 18px rgba(106, 92, 245, 0.10);
}

.time-pill button {
    display: inline-grid;
    width: 1.25rem;
    height: 1.25rem;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(106, 92, 245, 0.15);
    color: var(--primary-dark);
    box-shadow: none;
    line-height: 1;
}

.time-empty {
    align-self: center;
    color: var(--muted);
    font-weight: 700;
}

.time-add-row {
    display: grid;
    grid-template-columns: minmax(130px, 170px) auto;
    gap: 0.55rem;
    align-items: center;
}

.time-add-row button,
.time-generator button {
    box-shadow: none;
}

.time-generator {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.7rem;
    background: var(--panel-soft);
}

.time-generator summary {
    cursor: pointer;
    font-weight: 800;
    color: var(--primary-dark);
}

.compact-grid {
    margin-top: 0.7rem;
}

.panel.is-collapsed > h1,
.panel.is-collapsed > h2,
.panel.is-collapsed > h3,
.panel.is-collapsed > .section-head {
    display: flex !important;
}

@media (max-width: 640px) {
    .time-add-row {
        grid-template-columns: 1fr;
    }
}
@supports (bottom: env(safe-area-inset-bottom)) {
    .screen-feedback {
        bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    .back-to-top {
        bottom: calc(1rem + env(safe-area-inset-bottom) + 58px);
    }
}
.sidebar-nav {
    display: grid;
    gap: 0.45rem;
}

.nav-group {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
}

.nav-group[open] {
    border-color: rgba(106, 92, 245, 0.10);
    background: rgba(106, 92, 245, 0.035);
}

.nav-group summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    cursor: pointer;
    padding: 0.55rem 0.7rem;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    list-style: none;
}

.nav-group summary::-webkit-details-marker {
    display: none;
}

.nav-group summary::after {
    content: "+";
    display: grid;
    width: 1.35rem;
    height: 1.35rem;
    place-items: center;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 0.9rem;
    line-height: 1;
}

.nav-group[open] summary::after {
    content: "-";
}

.nav-group-items {
    display: grid;
    gap: 0.25rem;
    padding: 0 0.35rem 0.45rem;
}

.nav-group .nav-item {
    padding: 0.72rem 0.65rem;
}
.dose-check-form,
.dose-remove-form {
    margin: 0;
}

.dose-remove-form {
    display: flex;
    justify-content: flex-end;
}

.dose-remove {
    min-width: 34px;
    height: 34px;
    padding: 0 0.7rem;
    border-radius: 999px;
    background: #fff;
    color: var(--danger);
    border: 1px solid #ffd0dd;
    box-shadow: none;
    font-size: 1.15rem;
    line-height: 1;
}

.dose-remove.all {
    min-width: 0;
    font-size: 0.82rem;
    color: #fff;
    background: linear-gradient(135deg, var(--danger), #d63a63);
    border-color: transparent;
}

.dose-remove:hover {
    transform: translateY(-1px);
}

.improvement-filter {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.improvement-filter label {
    min-width: 220px;
    flex: 1;
}

.improvement-user-group {
    display: grid;
    gap: 0.75rem;
    margin-top: 1rem;
}

.improvement-user-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-top: 0.5rem;
}

.status-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--success);
    color: #fff;
    font-weight: 800;
}

.admin-card.is-completed {
    background: #f0fffc;
    border-color: #bdeee7;
}

@media (max-width: 720px) {
    .dose {
        grid-template-columns: 42px 1fr 58px;
    }

    .dose time {
        grid-column: 2;
    }

    .dose-remove-form {
        grid-column: 3;
        grid-row: 1 / span 2;
        align-self: center;
    }

    .dose-remove.all {
        padding: 0 0.45rem;
        font-size: 0.72rem;
    }
}
.timeline-shell .content {
    gap: 1.25rem;
}

.timeline-hero {
    align-items: center;
}

.patient-heading {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.timeline-patient-photo {
    width: 74px;
    height: 74px;
    border-radius: 18px;
    object-fit: cover;
    border: 1px solid var(--line);
    box-shadow: 0 14px 28px rgba(75, 65, 180, 0.14);
    flex: 0 0 auto;
}

.timeline-patient-photo.placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-size: 1.6rem;
    font-weight: 800;
}

.timeline-date-actions,
.timeline-date-form,
.timeline-summary-chips,
.timeline-quick-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.timeline-date-form label {
    flex: 1;
    min-width: 220px;
}

.timeline-summary-chips span,
.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 800;
    padding: 0.35rem 0.65rem;
    font-size: 0.86rem;
}

.timeline-panel {
    overflow: hidden;
}

.day-timeline {
    position: relative;
    display: grid;
    gap: 0.95rem;
    padding: 0.75rem 0 0.25rem;
}

.day-timeline::before {
    content: "";
    position: absolute;
    left: 92px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, transparent, var(--primary-soft), transparent);
}

.timeline-event {
    display: grid;
    grid-template-columns: 72px 40px minmax(0, 1fr);
    gap: 0.7rem;
    align-items: start;
    position: relative;
}

.timeline-event > time {
    color: var(--muted);
    font-weight: 800;
    padding-top: 0.8rem;
    text-align: right;
}

.timeline-marker {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: 0 8px 18px rgba(76, 67, 180, 0.1);
    z-index: 1;
}

.timeline-event-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 0.85rem 1rem;
    background: #fff;
    min-width: 0;
}

.timeline-event-head,
.timeline-event-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.timeline-event-head strong {
    color: var(--text);
    overflow-wrap: anywhere;
}

.timeline-event-head span,
.timeline-event-foot small {
    color: var(--muted);
    font-weight: 700;
}

.timeline-event-card p {
    margin: 0.45rem 0;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.timeline-event.type-medication .timeline-event-card {
    background: #fff7fa;
    border-color: #ffd0dd;
}

.timeline-event.type-medication:not(.is-pending) .timeline-event-card,
.timeline-event.type-vitals .timeline-event-card {
    background: #effdfa;
    border-color: #bdeee7;
}

.timeline-event.type-appointment .timeline-event-card {
    background: #f6f3ff;
    border-color: #ded6ff;
}

.timeline-event.type-diary .timeline-event-card {
    background: #fffaf0;
    border-color: #ffe3ae;
}

.timeline-event.type-document .timeline-event-card {
    background: #f6fbff;
    border-color: #d5ebff;
}

.timeline-event.is-pending .status-pill {
    background: var(--danger-soft);
    color: var(--danger);
}

@media (max-width: 720px) {
    .timeline-hero,
    .timeline-date-actions,
    .timeline-date-form,
    .timeline-quick-actions {
        align-items: stretch;
    }

    .timeline-date-actions > *,
    .timeline-quick-actions > *,
    .timeline-date-form button {
        width: 100%;
        justify-content: center;
    }

    .day-timeline::before {
        left: 52px;
    }

    .timeline-event {
        grid-template-columns: 48px 34px minmax(0, 1fr);
        gap: 0.55rem;
    }

    .timeline-event > time {
        font-size: 0.82rem;
    }

    .timeline-marker {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }
}
.health-tabs {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    align-items: center;
}

.health-tabs a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0.55rem 0.85rem;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--primary);
    font-weight: 800;
    text-decoration: none;
}

.health-tabs a:hover {
    background: var(--primary-soft);
}

.problem-list-panel {
    scroll-margin-top: calc(var(--topbar-h, 80px) + 18px);
}

.problem-list {
    display: grid;
    gap: 0.65rem;
    padding-left: 1.35rem;
    margin: 0;
}

.problem-list li {
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #f8fbff;
}

.problem-list strong,
.problem-list span {
    display: block;
}

.problem-list span {
    color: var(--muted);
    margin-top: 0.2rem;
    font-weight: 700;
}

@media (max-width: 720px) {
    .health-tabs a {
        width: 100%;
        justify-content: center;
    }
}
.body-map-layout {
    display: grid;
    grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}

.body-figure {
    position: relative;
    min-height: 420px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: linear-gradient(180deg, #fbfdff, #f4f6ff);
    overflow: hidden;
}

.body-figure::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 34px;
    width: 86px;
    height: 86px;
    transform: translateX(-50%);
    border-radius: 50%;
    background: #dfe7ff;
}

.body-figure::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 128px;
    width: 118px;
    height: 170px;
    transform: translateX(-50%);
    border-radius: 42px 42px 34px 34px;
    background: #dfe7ff;
    box-shadow: -78px 24px 0 -34px #dfe7ff, 78px 24px 0 -34px #dfe7ff, -34px 214px 0 -18px #dfe7ff, 34px 214px 0 -18px #dfe7ff;
}

.body-region {
    position: absolute;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 2px solid #fff;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 900;
    text-decoration: none;
    box-shadow: 0 8px 18px rgba(76, 67, 180, 0.12);
}

.body-region.has-data {
    background: linear-gradient(135deg, var(--danger), #d63a63);
    color: #fff;
}

.body-region.head { left: calc(50% - 17px); top: 58px; }
.body-region.heart { left: calc(50% + 10px); top: 152px; }
.body-region.lungs { left: calc(50% - 48px); top: 162px; }
.body-region.abdomen { left: calc(50% - 17px); top: 230px; }
.body-region.kidneys { left: calc(50% + 34px); top: 238px; }
.body-region.joints { left: calc(50% - 17px); top: 346px; }
.body-region.skin { left: calc(50% - 108px); top: 210px; }
.body-region.metabolic { left: calc(50% + 78px); top: 210px; }

.body-region-list {
    display: grid;
    gap: 0.75rem;
}

.body-region-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
    padding: 0.85rem 1rem;
}

.body-region-card div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.body-region-card span,
.body-region-card small {
    color: var(--muted);
    font-weight: 700;
}

.body-region-card ul {
    margin: 0.65rem 0 0;
    padding-left: 1.1rem;
    color: var(--muted);
}

@media (max-width: 820px) {
    .body-map-layout {
        grid-template-columns: 1fr;
    }

    .body-figure {
        min-height: 380px;
    }
}
.quick-health-form {
    display: grid;
    grid-template-columns: minmax(180px, 0.9fr) minmax(240px, 1.5fr) auto;
    gap: 0.8rem;
    align-items: end;
    padding: 0.9rem;
    margin: 0.85rem 0 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(248, 250, 252, 0.85);
}

.quick-health-form label {
    margin: 0;
}

.health-record-list {
    margin-top: 0.75rem;
}

.health-entry-panel {
    scroll-margin-top: calc(var(--topbar-h, 80px) + 18px);
}

.permission-panel .field-help {
    display: block;
    margin-bottom: 0.75rem;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.55rem;
}

.permission-grid .checkbox-line,
.audit-permission {
    min-height: 44px;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.72);
}

.audit-permission {
    margin-top: 0.75rem;
}

@media (max-width: 720px) {
    .quick-health-form {
        grid-template-columns: 1fr;
    }

    .quick-health-form button {
        width: 100%;
    }
}
.compact-summary {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.compact-summary .metric {
    min-height: 112px;
    padding: 1rem 1.05rem;
}

.compact-summary .metric strong {
    font-size: clamp(1.7rem, 3.5vw, 2.25rem);
}

.metric-link {
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.metric-link:hover {
    transform: translateY(-1px);
}

.card-collapse-toggle {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
    box-shadow: 0 10px 22px rgba(106, 92, 245, 0.22);
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin: 0.8rem 0 0.4rem;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 38px;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--primary-dark);
    font-weight: 800;
    text-decoration: none;
}

@media (max-width: 720px) {
    .compact-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
.permission-groups {
    display: grid;
    gap: 0.75rem;
}

.permission-group-card {
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.62);
}

.permission-group-card > strong {
    display: block;
    margin-bottom: 0.55rem;
    color: var(--ink);
}

.action-permissions {
    margin-top: 0.75rem;
}

@media (max-width: 980px) {
    body.mobile-nav-open {
        overflow: hidden;
    }

    .sidebar {
        top: var(--topbar-h, 70px);
        bottom: auto;
        height: calc(100dvh - var(--topbar-h, 70px));
        max-height: calc(100dvh - var(--topbar-h, 70px));
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(7.5rem + env(safe-area-inset-bottom, 0px));
        scrollbar-gutter: stable;
    }

    .sidebar-nav {
        min-height: 0;
        padding-bottom: 1.5rem;
    }
}

@media (max-width: 640px) {
    .sidebar {
        width: min(92vw, 340px);
        height: calc(100dvh - var(--topbar-h, 70px));
        max-height: calc(100dvh - var(--topbar-h, 70px));
    }
}
.chart-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.7rem 0 0.85rem;
}

.chart-toolbar label {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    min-height: 36px;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.76);
    color: var(--ink);
    font-weight: 800;
    cursor: pointer;
}

.chart-toolbar input {
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
}

.chart-toolbar label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.chart-toolbar label:focus-within {
    outline: 2px solid rgba(106, 92, 245, 0.35);
    outline-offset: 2px;
}

.chart-period-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.8rem;
    color: var(--muted);
    font-weight: 800;
}

.chart-period-control input {
    width: 90px;
    min-height: 38px;
    padding: 0.4rem 0.55rem;
}

.record-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.icon-edit-button {
    display: inline-grid;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    place-items: center;
    padding: 0;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-dark);
    box-shadow: none;
    font-size: 1rem;
}

.upload-progress {
    display: grid;
    gap: 0.45rem;
    padding: 0.8rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
}

.upload-progress-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.upload-progress-track {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--line);
}

.upload-progress-track span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), #17c3b2);
    transition: width 160ms ease;
}

.upload-progress small {
    color: var(--muted);
}

.upload-progress.error {
    border-color: #ef4444;
    background: #fff1f2;
}

.edit-history-summary {
    display: block;
    margin-top: 0.35rem;
    color: var(--primary-dark);
    font-weight: 800;
}

.edit-history-panel {
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
}

.edit-history-panel summary {
    cursor: pointer;
    color: var(--primary-dark);
    font-weight: 800;
}

.edit-history-panel article {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
}

.edit-history-panel ul {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
}


.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.75rem;
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.38rem 0.65rem;
    border-radius: 999px;
    background: rgba(248, 250, 252, 0.9);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

.chart-legend-item::before {
    content: "";
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 999px;
    background: var(--series-color, var(--primary));
}

.chart-note {
    margin: 0.55rem 0 0;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

@media (max-width: 640px) {
    .chart-toolbar label {
        flex: 1 1 calc(50% - 0.5rem);
        justify-content: center;
        text-align: center;
    }
}
#bpChart {
    display: block;
    width: 100%;
    height: 280px;
    min-height: 280px;
}
.large-textarea,
.quick-health-form textarea.large-textarea {
    min-height: 96px;
    resize: both;
    overflow: auto;
}

.quick-health-form textarea.large-textarea {
    min-width: min(100%, 320px);
}

.appointment-card .attachment-list {
    margin-bottom: 0.85rem;
}

@media (max-width: 720px) {
    .large-textarea,
    .quick-health-form textarea.large-textarea {
        width: 100%;
        resize: vertical;
    }
}
.time-repeat-note {
    display: block;
    width: 100%;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
}
.dose.saving {
    opacity: 0.72;
    pointer-events: none;
}
.quick-health-form {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    align-items: end;
}

.quick-health-form .health-field-wide {
    grid-column: span 2;
}

.quick-health-form small,
.type-config-form small {
    display: block;
    margin-top: 0.35rem;
    color: var(--muted);
}

.type-config-list {
    display: grid;
    gap: 0.75rem;
    margin-top: 1rem;
}

.type-field-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    padding: 0.85rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.type-field-options legend {
    padding: 0 0.35rem;
    color: var(--muted);
    font-weight: 800;
}

.type-field-options .check-option,
.type-config-form > .check-option {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 40px;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.72);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
}

@media (max-width: 720px) {
    .quick-health-form .health-field-wide {
        grid-column: auto;
    }

    .type-field-options {
        display: grid;
        grid-template-columns: 1fr;
    }
}

.vital-settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 0.85rem;
}

.vital-setting-card {
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.72);
}

.vital-setting-head,
.vital-value-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.vital-setting-head {
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.vital-setting-card input[type="color"] {
    min-height: 44px;
    padding: 0.25rem;
}

.vital-value-list mark {
    margin: 0;
}

@media (max-width: 640px) {
    .vital-settings-grid {
        grid-template-columns: 1fr;
    }
}

.medication-recurrence {
    display: grid;
    grid-column: 1 / -1;
    gap: 0.75rem;
    min-width: 0;
    margin: 0;
    padding: 0.9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel-soft);
}

.medication-recurrence legend {
    padding: 0 0.35rem;
    color: var(--text);
    font-weight: 800;
}

.schedule-interval-control,
.specific-date-add {
    display: grid;
    grid-template-columns: minmax(100px, 160px) 1fr;
    gap: 0.55rem;
    align-items: center;
}

.schedule-interval-control > span {
    color: var(--muted);
    font-weight: 800;
}

.specific-date-manager {
    display: grid;
    gap: 0.55rem;
}

.specific-date-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 2.55rem;
    padding: 0.65rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
}

.specific-date-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.42rem 0.5rem 0.42rem 0.78rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 800;
}

.specific-date-pill button {
    display: inline-grid;
    width: 1.25rem;
    height: 1.25rem;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(106, 92, 245, 0.15);
    color: var(--primary-dark);
    box-shadow: none;
    line-height: 1;
}

.schedule-preview {
    padding: 0.7rem;
    border-left: 3px solid var(--primary);
    background: rgba(106, 92, 245, 0.06);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

@media (max-width: 640px) {
    .schedule-interval-control,
    .specific-date-add {
        grid-template-columns: 1fr;
    }
}
