:root {
    --primary: #176c72;
    --primary-light: #2a8990;
    --primary-lighter: #9ed5d8;
    --primary-faint: #eaf6f7;
    --primary-dark: #10555a;
    --success: #087443;
    --success-bg: #e7f7ef;
    --warning: #9a6700;
    --warning-bg: #fff4d6;
    --error: #b42318;
    --error-bg: #fff1f0;
    --text: #172033;
    --text-muted: #617089;
    --text-light: #98a3b3;
    --surface: #ffffff;
    --bg: #f4f7f8;
    --border: rgba(23, 32, 51, 0.11);
    --border-md: rgba(23, 32, 51, 0.18);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --topbar-h: 74px;
    --font: 'DM Sans', Arial, Helvetica, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.45;
    margin: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

button,
input,
select,
textarea {
    font-family: var(--font);
}

button {
    background: none;
    border: 0;
    cursor: pointer;
}

label {
    color: var(--text-muted);
    display: block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.remember-row {
    align-items: center;
    color: var(--text-muted);
    display: flex;
    gap: 9px;
    letter-spacing: 0;
    text-transform: none;
}

.remember-row input {
    flex-shrink: 0;
    margin: 0;
    padding: 0;
    width: auto;
}

input,
select,
textarea {
    background: var(--surface);
    border: 1px solid var(--border-md);
    border-radius: var(--radius-sm);
    color: var(--text);
    display: block;
    font-size: 14px;
    margin-top: 6px;
    outline: none;
    padding: 11px 14px;
    resize: vertical;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(23, 108, 114, 0.12);
}

.topbar {
    align-items: center;
    background: var(--primary);
    box-shadow: 0 2px 8px rgba(23, 108, 114, 0.24);
    display: grid;
    gap: 2px 10px;
    grid-template-columns: 36px 1fr;
    grid-template-rows: 36px 1fr;
    height: var(--topbar-h);
    left: 0;
    padding: 8px 16px 7px;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 100;
}

.topbar-title {
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    text-align: center;
}

.topbar-menu {
    align-items: center;
    background: rgba(255, 255, 255, 0.17);
    border-radius: 50%;
    color: #fff;
    display: flex;
    grid-column: 1;
    grid-row: 1;
    height: 36px;
    justify-content: center;
    width: 36px;
}

.topbar-menu {
    font-size: 20px;
}

.topbar-doctor {
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.12;
    min-width: 0;
    overflow-wrap: anywhere;
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: center;
    white-space: normal;
}

.page {
    min-height: 100vh;
    padding-bottom: 16px;
    padding-top: calc(var(--topbar-h) + 16px);
}

.container {
    padding: 0 16px;
}

.drawer-overlay {
    background: rgba(0, 0, 0, 0.45);
    display: none;
    inset: 0;
    position: fixed;
    z-index: 200;
}

.drawer-overlay.open {
    display: block;
}

.drawer {
    background: var(--primary);
    bottom: 0;
    display: flex;
    flex-direction: column;
    left: -280px;
    position: fixed;
    top: 0;
    transition: left 0.25s ease;
    width: 280px;
    z-index: 300;
}

.drawer.open {
    left: 0;
}

.drawer-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    padding: 20px 16px 16px;
}

.drawer-logo {
    align-items: center;
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.drawer-appname {
    color: #fff;
    font-size: 15px;
    font-weight: 800;
}

.drawer-sub {
    color: rgba(255, 255, 255, 0.66);
    font-size: 11px;
}

.drawer-user {
    align-items: center;
    display: flex;
    gap: 10px;
}

.drawer-user span {
    color: rgba(255, 255, 255, 0.88);
    font-size: 14px;
    font-weight: 800;
    line-height: 1.25;
}

.drawer-nav {
    flex: 1;
    list-style: none;
    margin: 0;
    overflow-y: auto;
    padding: 8px 0;
}

.drawer-nav li a {
    align-items: center;
    border-left: 3px solid transparent;
    color: rgba(255, 255, 255, 0.76);
    display: flex;
    font-size: 14px;
    gap: 12px;
    padding: 13px 20px;
}

.drawer-nav li a.active,
.drawer-nav li a:hover {
    background: rgba(255, 255, 255, 0.12);
    border-left-color: #fff;
    color: #fff;
    font-weight: 700;
}

.nav-icon {
    filter: brightness(0) invert(1);
    height: 20px;
    opacity: 0.9;
    width: 22px;
}

.drawer-footer {
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.55);
    display: flex;
    font-size: 12px;
    justify-content: space-between;
    padding: 14px 20px;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.16);
    border-radius: 20px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    padding: 7px 14px;
}

.bottom-nav {
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    bottom: 0;
    display: flex;
    height: 60px;
    justify-content: space-around;
    left: 0;
    position: fixed;
    right: 0;
    z-index: 100;
}

.bn-item {
    align-items: center;
    color: var(--text-muted);
    display: flex;
    flex: 1;
    flex-direction: column;
    font-size: 10px;
    gap: 2px;
    padding: 8px 0;
}

.bn-item.active {
    color: var(--primary);
}

.bn-icon {
    filter: brightness(0) saturate(100%) invert(44%) sepia(11%) saturate(752%) hue-rotate(179deg) brightness(92%) contrast(88%);
    height: 21px;
    width: 21px;
}

.bn-item.active .bn-icon {
    filter: brightness(0) saturate(100%) invert(31%) sepia(23%) saturate(1511%) hue-rotate(136deg) brightness(92%) contrast(87%);
}

.bn-label {
    font-size: 10px;
    font-weight: 700;
}

.bn-fab {
    align-items: center;
    background: var(--primary);
    border-radius: 50%;
    box-shadow: 0 4px 14px rgba(23, 108, 114, 0.42);
    color: #fff;
    display: flex;
    font-size: 28px;
    font-weight: 500;
    height: 52px;
    justify-content: center;
    margin-top: -16px;
    width: 52px;
}

.bn-fab-icon {
    filter: brightness(0) invert(1);
    height: 25px;
    width: 25px;
}

.bn-fab.active {
    outline: 3px solid var(--primary-faint);
}

.bottom-spacer {
    height: 68px;
}

.card,
.workspace,
.history {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 14px;
    overflow: hidden;
}

.workspace,
.history {
    padding: 16px;
}

.page-title {
    align-items: flex-start;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 16px;
}

.page-title h1,
.login-panel h1,
.validation-panel h1 {
    color: var(--text);
    font-size: 20px;
    line-height: 1.18;
    margin: 0;
}

.page-title .btn {
    flex-shrink: 0;
    width: auto;
}

.page-title > div:first-child {
    min-width: 0;
}

.prescription-id-title {
    overflow-wrap: anywhere;
}

.prescription-detail-workspace {
    padding-top: 0;
}

.prescription-detail-heading {
    border-bottom: 1px solid var(--border);
    padding: 14px 16px 12px;
    text-align: center;
}

.prescription-detail-heading .eyebrow {
    margin-bottom: 4px;
}

.prescription-detail-heading h1 {
    font-size: 19px;
}

.prescription-detail-navigation {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 12px 16px 4px;
}

.prescription-detail-navigation .btn {
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 8px;
    text-align: center;
    white-space: nowrap;
}

.history h2 {
    font-size: 16px;
    margin: 0 0 12px;
}

.clickable-row {
    cursor: pointer;
}

.clickable-row:hover td,
.clickable-row:focus-visible td {
    background: var(--primary-faint);
}

.eyebrow {
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    margin: 0 0 5px;
    text-transform: uppercase;
}

.muted,
.patient-hint {
    color: var(--text-muted);
    font-size: 13px;
    margin: 0;
    overflow-wrap: anywhere;
}

.form-stack,
.grid-form,
.prescription-form {
    display: grid;
    gap: 14px;
}

.grid-form,
.compact-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: 1fr;
}

.wide {
    grid-column: 1 / -1;
}

.login-shell {
    align-items: center;
    background: linear-gradient(160deg, var(--primary-dark) 0%, var(--primary) 62%, var(--primary-lighter) 100%);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.login-panel,
.validation-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(16, 85, 90, 0.28);
    display: grid;
    gap: 24px;
    max-width: 380px;
    padding: 30px 24px;
    width: 100%;
}

.validation-panel {
    max-width: 480px;
}

.prescription-workspace {
    padding: 0;
}

.prescription-title {
    border-bottom: 1px solid var(--border);
    margin: 0;
    padding: 16px;
}

.prescription-layout {
    display: grid;
    grid-template-columns: 1fr;
}

.patient-panel,
.prescription-panel {
    align-content: start;
    display: grid;
    gap: 16px;
    padding: 16px;
}

.patient-panel {
    background: #f8fbfc;
    border-bottom: 1px solid var(--border);
}

.panel-heading {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.panel-heading > div {
    align-items: center;
    display: flex;
    gap: 10px;
    min-width: 0;
}

.panel-heading > div > div {
    align-items: start;
    display: grid;
    gap: 1px;
}

.panel-heading strong {
    font-size: 15px;
}

.panel-subtitle {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
}

.step-badge {
    align-items: center;
    background: var(--primary);
    border-radius: 50%;
    color: #fff;
    display: inline-flex;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 800;
    height: 28px;
    justify-content: center;
    width: 28px;
}

.patient-add-button {
    align-items: center;
    background: var(--primary-faint);
    border: 1px solid var(--primary-lighter);
    border-radius: var(--radius-sm);
    color: var(--primary-dark);
    display: inline-flex;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 800;
    gap: 7px;
    min-height: 38px;
    padding: 8px 12px;
}

.patient-add-button span {
    align-items: center;
    background: var(--primary);
    border-radius: 50%;
    color: #fff;
    display: inline-flex;
    font-size: 16px;
    height: 20px;
    justify-content: center;
    line-height: 1;
    width: 20px;
}

.patient-search-box {
    display: grid;
    gap: 10px;
}

.patient-results {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-height: 260px;
    overflow-y: auto;
}

.patient-result,
.patient-result-empty {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    display: grid;
    gap: 2px;
    padding: 12px 14px;
    text-align: left;
    width: 100%;
}

.patient-result:last-child,
.patient-result-empty:last-child {
    border-bottom: 0;
}

.patient-result:active,
.patient-result:hover {
    background: var(--primary-faint);
}

.patient-result strong {
    font-size: 14px;
}

.patient-result span,
.patient-card span {
    color: var(--text-muted);
    font-size: 12px;
}

.patient-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--success);
    border-radius: var(--radius-md);
    display: grid;
    gap: 8px;
    padding: 14px;
}

.patient-card div {
    display: grid;
    gap: 4px;
}

.status-pill {
    background: var(--success-bg);
    border-radius: 20px;
    color: var(--success);
    display: inline-flex;
    font-size: 11px;
    font-weight: 800;
    justify-self: start;
    padding: 3px 9px;
}

.patient-create-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 14px;
    padding: 16px;
}

.form-section-title {
    color: var(--text);
    font-size: 14px;
    font-weight: 800;
}

.selected-patient-field input {
    background: #f8fbfc;
    color: var(--primary-dark);
    font-weight: 800;
}

.btn {
    align-items: center;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    display: inline-flex;
    font-size: 14px;
    font-weight: 700;
    gap: 6px;
    justify-content: center;
    min-height: 44px;
    padding: 11px 18px;
    transition: opacity 0.15s, background 0.15s;
    width: 100%;
}

.btn:active {
    opacity: 0.82;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

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

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

.btn-secondary,
.btn-ghost {
    background: var(--primary-faint);
    border-color: var(--primary-lighter);
    color: var(--primary-dark);
}

.action-row {
    display: grid;
    gap: 10px;
}

.action-row form {
    margin: 0;
}

.consult-search {
    align-items: end;
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
}

.consult-list {
    display: grid;
    gap: 10px;
}

.consult-item {
    background: #f8fbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 10px;
    padding: 14px;
}

.consult-item-link {
    cursor: pointer;
    display: block;
}

.consult-item-link:hover,
.consult-item-link:focus-visible {
    background: var(--primary-faint);
    border-color: var(--primary-lighter);
}

.consult-main {
    align-items: start;
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.consult-main strong {
    color: var(--text);
    font-size: 15px;
    line-height: 1.25;
}

.consult-main span,
.consult-meta span {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
}

.consult-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.consult-meta span {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 8px;
}

.consult-item p {
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
    margin: 0;
    overflow-wrap: anywhere;
}

.cid-results {
    border: 1px solid var(--border);
    display: grid;
    overflow: hidden;
}

.cid-result {
    align-items: start;
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 3px;
    grid-template-columns: 68px minmax(0, 1fr);
    padding: 12px 14px;
}

.cid-result:last-child {
    border-bottom: 0;
}

.cid-result strong {
    color: var(--primary-dark);
    font-size: 14px;
}

.cid-result span {
    color: var(--text);
    font-size: 14px;
    line-height: 1.35;
}

.cid-result small {
    color: var(--text-muted);
    font-size: 12px;
    grid-column: 2;
}

.empty-state {
    background: #f8fbfc;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 6px;
    padding: 16px;
}

.patient-list {
    display: grid;
    gap: 10px;
}

.patient-list-item {
    background: #f8fbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    display: grid;
    gap: 4px;
    padding: 14px;
}

.patient-list-item:active,
.patient-list-item:hover {
    background: var(--primary-faint);
    border-color: var(--primary-lighter);
}

.patient-list-item strong {
    font-size: 15px;
    line-height: 1.25;
}

.patient-list-item span {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
}

.patient-page-form {
    margin-top: 4px;
}

.alert {
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 14px;
    padding: 12px 16px;
}

.alert-error {
    background: var(--error-bg);
    border: 1px solid #f0a3a0;
    color: var(--error);
}

.alert-success {
    background: var(--success-bg);
    border: 1px solid #82d2aa;
    color: var(--success);
}

.prescription-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    overflow: hidden;
    padding: 0;
}

dl {
    display: grid;
    margin: 0;
}

dt,
dd {
    border-bottom: 1px solid var(--border);
    margin: 0;
    padding: 11px 14px;
}

dt {
    background: #f8fbfc;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

dd {
    color: var(--text);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.break-text {
    overflow-wrap: anywhere;
}

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

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

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

th {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

td {
    font-size: 14px;
}

td a {
    color: var(--primary);
    font-weight: 800;
}

@media (min-width: 480px) {
    body {
        background: #e8eef0;
    }

    .consult-search {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .consult-search .btn {
        width: auto;
    }

    .topbar,
    .bottom-nav {
        left: 50%;
        max-width: 480px;
        right: auto;
        transform: translateX(-50%);
        width: 480px;
    }

    .page {
        background: var(--bg);
        margin: 0 auto;
        max-width: 480px;
        min-height: 100vh;
    }

    .drawer {
        max-width: 280px;
    }
}

@media (min-width: 920px) {
    .topbar,
    .bottom-nav,
    .page {
        max-width: 760px;
        width: 760px;
    }

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

    .prescription-layout {
        grid-template-columns: minmax(300px, 340px) 1fr;
    }

    .patient-panel {
        border-bottom: 0;
        border-right: 1px solid var(--border);
    }

    .action-row {
        align-items: center;
        display: flex;
        flex-wrap: wrap;
    }

    .action-row .btn {
        width: auto;
    }

    dl {
        grid-template-columns: 150px 1fr;
    }
}
