:root {
    --bg: #f5f8fb;
    --panel: #ffffff;
    --text: #182231;
    --muted: #718094;
    --line: #dce4eb;
    --primary: #13a6d8;
    --primary-dark: #0b82ad;
    --success: #36b9a8;
    --danger: #ef6f7d;
    --warn: #f2b94b;
    --shadow: 0 10px 30px rgba(19, 40, 60, 0.08);
    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;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    max-width: 100%;
    overflow-x: hidden;
}

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

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

button,
.primary,
.emergency {
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    padding: 0.78rem 1rem;
    box-shadow: 0 8px 20px rgba(19, 166, 216, 0.22);
    max-width: 100%;
    white-space: normal;
}

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

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

.link-button:hover {
    background: #eaf4f8;
    color: var(--text);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
    max-width: 100%;
}

.mobile-menu-button {
    display: none;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 8px;
    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: 48px;
    height: 48px;
    place-items: center;
    border-radius: 14px;
    background: var(--primary);
    color: #fff;
    font-size: 1.6rem;
    font-weight: 900;
}

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

.top-actions a {
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
}

.top-actions a:hover {
    background: #eaf4f8;
    color: var(--text);
}

.account-menu {
    position: relative;
}

.account-menu summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    list-style: none;
    border-radius: 8px;
    padding: 0.35rem 0.55rem;
    color: var(--text);
}

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

.account-menu summary:hover {
    background: #eaf4f8;
}

.account-avatar {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 900;
}

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

.account-options a,
.account-options button {
    width: 100%;
    text-align: left;
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: linear-gradient(135deg, #e6f8fc 0%, #f7fbfc 44%, #f7f1eb 100%);
}

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

.login-panel h1,
.hero h1 {
    margin: 1rem 0 0.35rem;
    font-size: clamp(2rem, 7vw, 3rem);
    line-height: 1.05;
}

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

.app-shell {
    display: grid;
    grid-template-columns: 280px 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;
}

.sidebar {
    position: sticky;
    top: 88px;
    align-self: start;
    display: grid;
    gap: 0.55rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: var(--shadow);
}

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

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

.field-help,
.unit-label {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 650;
    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: 8px;
    background: #fff;
    color: var(--text);
    padding: 0.75rem 0.85rem;
}

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

.nav-item {
    padding: 0.9rem 1rem;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 800;
}

.nav-item.active,
.nav-item:hover {
    background: var(--primary);
    color: #fff;
}

.content {
    display: grid;
    gap: 1.4rem;
    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: var(--danger);
    white-space: nowrap;
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    padding: 0.78rem 1rem;
    box-shadow: 0 8px 20px rgba(19, 166, 216, 0.22);
}

.button-link.subtle {
    background: #eaf4f8;
    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: 8px;
    padding: 0.95rem 1rem;
    background: #eef3f7;
    color: var(--muted);
    font-weight: 650;
    overflow-wrap: anywhere;
}

.toast {
    position: fixed;
    left: 50%;
    top: 76px;
    transform: translateX(-50%);
    z-index: 50;
    background: #102030;
    color: #fff;
    border: 0;
    box-shadow: var(--shadow);
}

.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: #102030;
    color: #fff;
    font-weight: 900;
    box-shadow: 0 12px 30px rgba(15, 25, 35, 0.24);
}

.alert {
    background: #fff0f1;
    color: #ac3340;
    border-color: #ffd3d8;
}

.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: 8px;
    box-shadow: var(--shadow);
    min-width: 0;
}

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

.metric span {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 900;
    letter-spacing: 0;
    text-transform: uppercase;
}

.metric strong {
    font-size: clamp(2rem, 5vw, 2.8rem);
    line-height: 1;
}

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

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

.panel {
    padding: 1.35rem;
}

.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.35rem, 4vw, 2rem);
}

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

.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: 8px;
    min-width: 0;
}

.dose.done {
    background: #eaf8f5;
    border-color: #bce9e2;
}

.dose.pending {
    background: #fff4f5;
    border-color: #f7d1d6;
}

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

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

.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: 8px;
    background: #f6f8fa;
}

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

.user-actions form {
    display: inline;
}

.user-actions button {
    padding: 0.45rem 0.6rem;
    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: var(--danger);
}

.user-row.heading {
    background: #eaf4f8;
    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: 8px;
    padding: 0.8rem;
}

.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.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbfc;
}

.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.75rem;
    border-radius: 8px;
    background: #fff0f1;
    color: var(--text);
}

.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: #eaf4f8;
    color: var(--primary-dark);
    box-shadow: none;
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
}

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

.admin-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbfc;
    padding: 0.9rem;
}

.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;
}

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

.recent-item,
.timeline-item {
    background: #f6f8fa;
    border-radius: 8px;
    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: #e6f8fc;
    color: var(--text);
    padding: 0.35rem 0.65rem;
}

.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: 800;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

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

.chips.danger span {
    background: #fff0f1;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    place-items: center;
    padding: 1rem;
    background: rgba(15, 25, 35, 0.42);
}

.modal.open {
    display: grid;
}

.modal-card {
    width: min(620px, 100%);
    max-height: min(90vh, 900px);
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1.4rem;
    box-shadow: 0 24px 70px rgba(20, 35, 50, 0.26);
}

.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;
}

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

details {
    margin-top: 0.75rem;
}

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

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

    .app-shell {
        grid-template-columns: 1fr;
        padding: 1rem;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 74px;
        bottom: 0;
        z-index: 35;
        width: min(86vw, 360px);
        max-width: 100%;
        overflow: auto;
        transform: translateX(-110%);
        transition: transform 0.2s ease;
        grid-template-columns: 1fr;
    }

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

    .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;
    }

    .top-actions a:first-child {
        display: none;
    }

    .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.25rem;
        overflow-wrap: anywhere;
    }

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

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

    .sidebar {
        grid-template-columns: 1fr;
        width: 100%;
        max-width: 100%;
    }

    .nav-item {
        text-align: center;
        padding: 0.8rem 0.5rem;
        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.15rem;
    }
}
