:root {
    color-scheme: light;
    --page-width: 1024px;
    --bg: #f6f8fb;
    --panel: #ffffff;
    --text: #162033;
    --muted: #657187;
    --line: #dce3ed;
    --brand: #1478a8;
    --brand-dark: #0d5d83;
    --success: #16794a;
    --warning: #a86400;
    --danger: #b42318;
    --soft-blue: #e8f4fa;
    --soft-green: #e8f7ef;
    --soft-red: #fdebea;
    --soft-yellow: #fff5db;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    padding: 10px 0 36px;
}

.page-tabs {
    display: grid;
    gap: 8px;
    left: 12px;
    position: fixed;
    top: 18px;
    z-index: 20;
}

.page-tabs a {
    background: #ffffff;
    border: 1px solid var(--line);
    border-left: 4px solid transparent;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 8px 22px rgba(22, 32, 51, .08);
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    padding: 9px 11px;
    text-decoration: none;
}

.page-tabs a:hover,
.page-tabs a.active {
    border-left-color: var(--brand);
    color: var(--brand-dark);
}

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

button {
    border: 0;
    border-radius: 7px;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    padding: 10px 14px;
}

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

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

button.ghost {
    background: #eef3f7;
    color: var(--text);
}

button.ghost:hover {
    background: #dfe9f1;
}

.link-button {
    background: transparent;
    color: var(--brand);
    padding: 0;
}

.link-button:hover {
    background: transparent;
    color: var(--brand-dark);
    text-decoration: underline;
}

.app-header {
    align-items: center;
    background: linear-gradient(135deg, #ffffff 0%, #edf7fb 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 24px;
    justify-content: space-between;
    margin: 0 auto;
    padding: 18px 22px;
    width: min(var(--page-width), calc(100% - 28px));
}

.eyebrow {
    color: var(--brand);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    margin: 0 0 6px;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
}

h1 {
    font-size: 30px;
}

h2 {
    font-size: 19px;
}

.subtle,
.muted {
    color: var(--muted);
}

.subtle {
    margin: 8px 0 0;
}

.muted {
    display: block;
    font-size: 13px;
    margin-top: 3px;
}

.health-card {
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 12px;
    min-width: 244px;
    padding: 10px 12px;
}

.health-card span:last-child {
    color: var(--muted);
    display: block;
    font-size: 13px;
    margin-top: 2px;
}

.health-heart {
    align-items: center;
    color: #98a2b3;
    display: inline-flex;
    font-size: 28px;
    height: 32px;
    justify-content: center;
    line-height: 1;
    width: 34px;
}

.health-heart::before {
    content: "\2665";
}

.health-card[data-state="online"] .health-heart {
    animation: heartBeat 1.05s ease-in-out infinite;
    color: #d92d20;
}

.health-card[data-state="offline"] .health-heart,
.health-card[data-state="unknown"] .health-heart {
    animation: none;
    color: #98a2b3;
}

@keyframes heartBeat {
    0%,
    100% {
        transform: scale(1);
    }
    18% {
        transform: scale(1.24);
    }
    34% {
        transform: scale(.96);
    }
    52% {
        transform: scale(1.16);
    }
}

.page-shell {
    display: grid;
    gap: 12px;
    margin: 0 auto;
    padding: 12px 0 0;
    width: min(var(--page-width), calc(100% - 28px));
}

.panel,
.notice {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.panel {
    padding: 12px;
}

.notice {
    padding: 12px 14px;
}

.notice.success {
    background: var(--soft-green);
    border-color: #bfe8d2;
}

.notice.error {
    background: var(--soft-red);
    border-color: #fac5c0;
}

.notice.warning {
    background: var(--soft-yellow);
    border-color: #f3dda8;
}

.upload-panel form,
.composer-footer,
.table-toolbar,
.toolbar-actions,
.dialog-head {
    align-items: center;
    display: flex;
    gap: 12px;
}

.upload-panel form {
    justify-content: space-between;
}

.file-picker {
    align-items: center;
    display: flex;
    gap: 12px;
    width: 100%;
}

.file-picker span,
label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

input[type="file"],
input[type="text"],
select,
textarea {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    padding: 8px 10px;
    width: 100%;
}

textarea {
    line-height: 1.45;
    resize: vertical;
}

.composer-panel {
    display: block;
}

.composer-main {
    display: grid;
    gap: 7px;
}

.composer-footer {
    justify-content: space-between;
}

.template-row {
    align-items: center;
    display: grid;
    gap: 8px;
    grid-template-columns: auto minmax(220px, 1fr) 180px auto;
}

.token-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.token-row span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.table-panel {
    padding: 0;
}

.table-toolbar {
    justify-content: space-between;
    padding: 12px;
}

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

table {
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 100%;
    width: 100%;
}

th,
td {
    padding: 8px 8px;
    text-align: left;
    white-space: nowrap;
    vertical-align: middle;
}

th {
    background: #f9fbfd;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
}

tbody tr:hover {
    background: #fbfdff;
}

tr.duplicate-row {
    color: #98a2b3;
    opacity: .54;
}

tr.duplicate-row .link-button,
tr.duplicate-row .status-pill {
    filter: grayscale(1);
}

.provider-tab-cell {
    background: linear-gradient(180deg, #eef7fc 0%, #dfeff8 100%);
    border-right: 1px solid var(--line);
    padding: 0;
    text-align: center;
    vertical-align: top;
}

.provider-tab {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px 0 0 8px;
    color: var(--text);
    display: inline-flex;
    font-size: 12px;
    font-weight: 900;
    justify-content: center;
    letter-spacing: .04em;
    margin: 8px auto;
    min-height: 118px;
    padding: 10px 6px;
    text-transform: uppercase;
    transform: rotate(180deg);
    writing-mode: vertical-rl;
}

.confirm-table th:nth-child(1),
.confirm-table td:nth-child(1) {
    width: 44px;
}

.confirm-table th:nth-child(2),
.confirm-table td:nth-child(2) {
    width: 34px;
}

.confirm-table th:nth-child(3),
.confirm-table td:nth-child(3) {
    width: 118px;
}

.confirm-table th:nth-child(4),
.confirm-table td:nth-child(4) {
    width: 132px;
}

.confirm-table th:nth-child(5),
.confirm-table td:nth-child(5) {
    width: 224px;
}

.confirm-table th:nth-child(6),
.confirm-table td:nth-child(6) {
    width: 116px;
}

.confirm-table th:nth-child(7),
.confirm-table td:nth-child(7) {
    width: 112px;
}

.confirm-table th:nth-child(8),
.confirm-table td:nth-child(8) {
    width: auto;
}

.reminder-table th:nth-child(1),
.reminder-table td:nth-child(1) {
    width: 154px;
}

.reminder-table th:nth-child(2),
.reminder-table td:nth-child(2) {
    width: 250px;
}

.reminder-table th:nth-child(3),
.reminder-table td:nth-child(3) {
    width: 138px;
}

.reminder-table th:nth-child(4),
.reminder-table td:nth-child(4) {
    width: auto;
}

.reminder-status {
    white-space: nowrap;
}

.reminder-status .row-check {
    margin-right: 12px;
    vertical-align: middle;
}

.address-cell {
    white-space: normal;
    word-break: break-word;
}

.empty {
    color: var(--muted);
    padding: 30px;
    text-align: center;
}

.status-pill {
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    justify-content: center;
    line-height: 1.2;
    min-width: 96px;
    padding: 5px 9px;
    text-align: center;
    white-space: nowrap;
}

.status-none {
    background: #eef3f7;
    color: #39485f;
}

.status-queued,
.status-sent {
    background: var(--soft-yellow);
    color: var(--warning);
}

.status-yes {
    background: var(--soft-green);
    color: var(--success);
}

.status-no,
.status-reply,
.status-error,
.status-duplicate {
    background: var(--soft-red);
    color: var(--danger);
}

.reply-cell {
    max-width: none;
    white-space: normal;
    word-break: break-word;
}

dialog {
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 60px rgba(22, 32, 51, .22);
    max-width: 820px;
    padding: 0;
    width: min(820px, calc(100vw - 28px));
}

dialog::backdrop {
    background: rgba(22, 32, 51, .34);
}

.dialog-head {
    border-bottom: 1px solid var(--line);
    justify-content: space-between;
    padding: 12px 14px;
}

.history-mobile-label {
    display: block;
    margin-top: 6px;
}

#historyMobileInput {
    margin-top: 4px;
    max-width: 180px;
    padding: 5px 8px;
}

.history-mobile-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.history-patient-name {
    color: var(--ink);
    font-size: 15px;
    font-weight: 900;
    min-height: 20px;
}

.history-reply {
    background: #f9fbfd;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 8px;
    padding: 12px 14px;
}

.history-reply textarea {
    min-height: 78px;
}

.history-reply-actions {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.history-content {
    background: #ffffff;
    max-height: 62vh;
    overflow: auto;
    padding: 18px 14px;
}

.message-row {
    display: flex;
    margin: 10px 0;
}

.message-row.received {
    justify-content: flex-start;
}

.message-row.sent {
    justify-content: flex-end;
}

.message-bubble {
    border-radius: 34px;
    font-size: 20px;
    line-height: 1.35;
    width: min(560px, calc(100% - 54px));
    padding: 20px;
    position: relative;
    white-space: normal;
    word-break: break-word;
}

.message-bubble::after {
    display: none;
}

.message-row.unread .message-bubble::before {
    background: #ff1919;
    border-radius: 999px;
    content: "";
    height: 28px;
    left: 12px;
    position: absolute;
    top: 16px;
    width: 10px;
}

.message-row.unread .message-text,
.message-row.unread .message-meta {
    padding-left: 18px;
}

.message-row.received .message-bubble {
    background: linear-gradient(135deg, #ffd7ea 0%, #f59bcc 100%);
    border-bottom-left-radius: 0;
    color: #111827;
}

.message-row.sent .message-bubble {
    background: linear-gradient(135deg, #8ed4f1 0%, #3f9cca 100%);
    border-bottom-right-radius: 0;
    color: #ffffff;
}

.message-text {
    font-size: inherit;
    margin: 0;
    white-space: pre-wrap;
}

.message-meta {
    font-size: inherit;
    font-weight: 700;
    margin-top: 10px;
    opacity: .82;
}

.sms-centre-shell {
    height: calc(100vh - 164px);
    min-height: 520px;
}

.sms-centre-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 0;
}

.sms-centre-toolbar {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 12px;
}

.sms-centre-content {
    background: #ffffff;
    overflow: auto;
    padding: 18px 14px 24px;
}

.centre-message-row {
    display: flex;
    margin: 10px 0;
}

.centre-message-row.received {
    justify-content: flex-start;
}

.centre-message-row.sent {
    justify-content: flex-end;
}

.centre-message-bubble {
    border-radius: 34px;
    font-size: 20px;
    line-height: 1.35;
    padding: 20px;
    position: relative;
    white-space: normal;
    width: min(560px, calc(100% - 54px));
    word-break: break-word;
}

.centre-message-bubble::after {
    display: none;
}

.centre-message-row.received .centre-message-bubble {
    background: linear-gradient(135deg, #ffd7ea 0%, #f59bcc 100%);
    border-bottom-left-radius: 0;
    color: #111827;
}

.centre-message-row.sent .centre-message-bubble {
    background: linear-gradient(135deg, #8ed4f1 0%, #3f9cca 100%);
    border-bottom-right-radius: 0;
    color: #ffffff;
}

.centre-message-heading {
    font-size: inherit;
    font-weight: 800;
    margin-bottom: 10px;
    opacity: .82;
}

.centre-message-bubble .link-button {
    color: inherit;
    font-weight: 800;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

#toast {
    background: var(--text);
    border-radius: 7px;
    bottom: 20px;
    color: #fff;
    left: 50%;
    opacity: 0;
    padding: 10px 14px;
    pointer-events: none;
    position: fixed;
    transform: translate(-50%, 12px);
    transition: opacity .18s ease, transform .18s ease;
    z-index: 10;
}

#toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.sr-only {
    clip: rect(0, 0, 0, 0);
    border: 0;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
}

@media (max-width: 900px) {
    .app-header,
    .table-toolbar,
    .upload-panel form {
        align-items: stretch;
        flex-direction: column;
    }

    .health-card,
    .template-row {
        min-width: 0;
        width: 100%;
    }

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

    .toolbar-actions {
        flex-wrap: wrap;
    }
}
