.patient-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.patient-stat-card {
    min-height: 92px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 17px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 15px;
    box-shadow: var(--shadow-sm);
}

.patient-stat-icon {
    width: 43px;
    height: 43px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 13px;
    color: var(--primary);
    background: var(--primary-soft);
}

.patient-stat-icon.blue {
    color: var(--secondary);
    background: var(--secondary-soft);
}

.patient-stat-icon.amber {
    color: var(--warning);
    background: var(--warning-soft);
}

.patient-stat-icon.muted {
    color: #64748b;
    background: #f1f5f9;
}

.patient-stat-card div:last-child {
    display: flex;
    flex-direction: column;
}

.patient-stat-card span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
}

.patient-stat-card strong {
    margin-top: 5px;
    font-size: 24px;
    letter-spacing: -.04em;
}

.patient-list-panel {
    overflow: hidden;
}

.patient-filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.patient-filter-bar select {
    min-width: 145px;
    height: 42px;
    padding: 0 34px 0 11px;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    font-size: 11px;
}

.patient-search-field {
    min-width: 260px;
    height: 42px;
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1;
    padding: 0 12px;
    color: var(--muted);
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.patient-search-field input {
    min-width: 0;
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
    font-size: 11px;
}

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

.patient-table {
    width: 100%;
    min-width: 1050px;
    border-collapse: collapse;
}

.patient-table th {
    padding: 12px 16px;
    color: #7c8998;
    background: #fafbfd;
    border-bottom: 1px solid var(--border);
    font-size: 9px;
    font-weight: 850;
    letter-spacing: .06em;
    text-align: left;
    text-transform: uppercase;
}

.patient-table td {
    padding: 14px 16px;
    border-bottom: 1px solid #eef1f4;
    vertical-align: middle;
}

.patient-table tbody tr {
    transition: background .15s ease;
}

.patient-table tbody tr:hover {
    background: #fbfcfd;
}

.patient-table tbody tr:last-child td {
    border-bottom: 0;
}

.patient-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

.patient-avatar {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 12px;
    color: var(--primary);
    background: var(--primary-soft);
    font-size: 11px;
    font-weight: 900;
}

.patient-identity > span:last-child {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.patient-identity strong {
    font-size: 11px;
}

.patient-identity small {
    max-width: 240px;
    margin-top: 4px;
    overflow: hidden;
    color: var(--muted);
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.risk-inline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 4px 7px;
    border-radius: 999px;
    color: #a13746;
    background: var(--danger-soft);
    font-size: 8px;
    font-weight: 800;
}

.table-main {
    color: var(--ink);
    font-size: 10px;
    font-weight: 700;
}

.table-sub {
    margin-top: 4px;
    color: var(--muted);
    font-size: 9px;
}

.appointment-count-chip {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    color: var(--secondary);
    background: var(--secondary-soft);
    font-size: 10px;
    font-weight: 900;
}

.patient-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 850;
    white-space: nowrap;
}

.patient-status::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.patient-status.active {
    color: #14714d;
    background: var(--success-soft);
}

.patient-status.active::before {
    background: var(--success);
}

.patient-status.inactive {
    color: #65758a;
    background: #f1f5f9;
}

.patient-status.inactive::before {
    background: #94a3b8;
}

.table-actions-cell {
    width: 52px;
    text-align: right;
}

.table-action-button {
    width: 33px;
    height: 33px;
    display: inline-grid;
    place-items: center;
    color: #64748b;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
}

.pagination {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 10px 18px;
    border-top: 1px solid var(--border);
}

.pagination a {
    color: var(--secondary);
    font-size: 10px;
    font-weight: 800;
    text-decoration: none;
}

.pagination span {
    color: var(--muted);
    font-size: 9px;
}

.form-alert {
    padding: 13px 15px;
    margin-bottom: 16px;
    border-radius: 11px;
    font-size: 11px;
    line-height: 1.55;
}

.form-alert strong {
    display: block;
    margin-bottom: 5px;
}

.form-alert ul {
    margin: 0;
    padding-left: 18px;
}

.form-alert-error {
    color: #9f3042;
    background: var(--danger-soft);
    border: 1px solid #ffd8df;
}

.form-alert-success {
    color: #126846;
    background: var(--success-soft);
    border: 1px solid #d4f0e2;
}

.patient-form {
    display: grid;
    gap: 17px;
}

.form-section {
    padding: 22px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.form-section-medical {
    border-top: 3px solid #e65769;
}

.form-section-ortho {
    border-top: 3px solid var(--primary);
}

.form-section-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #edf0f3;
}

.form-section-icon {
    width: 39px;
    height: 39px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 11px;
    color: var(--primary);
    background: var(--primary-soft);
}

.form-section-heading h3 {
    margin: 0;
    font-size: 14px;
}

.form-section-heading p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 10px;
}

.form-grid {
    display: grid;
    gap: 15px;
}

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

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

.field {
    min-width: 0;
}

.field-span-2 {
    grid-column: span 2;
}

.field-span-3 {
    grid-column: span 3;
}

.field label {
    display: block;
    margin-bottom: 7px;
    color: #3c4b5e;
    font-size: 10px;
    font-weight: 800;
}

.field label > span {
    color: var(--danger);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    color: var(--ink);
    background: #fbfcfd;
    border: 1px solid #dfe5eb;
    border-radius: 10px;
    outline: 0;
    font-size: 11px;
    transition: border-color .17s ease, box-shadow .17s ease, background .17s ease;
}

.field input,
.field select {
    height: 43px;
    padding: 0 12px;
}

.field textarea {
    min-height: 78px;
    padding: 11px 12px;
    resize: vertical;
    line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    background: #fff;
    border-color: #60aaa4;
    box-shadow: 0 0 0 4px rgba(11,111,104,.08);
}

.uppercase-input {
    text-transform: uppercase;
}

.medical-warning-input {
    color: #8e2d3c !important;
    background: #fff8f9 !important;
    border-color: #f4cbd1 !important;
}

.checkbox-field {
    display: flex;
    align-items: flex-end;
}

.consent-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.check-card {
    position: relative;
    min-height: 67px;
    display: flex !important;
    align-items: center;
    gap: 11px;
    margin: 0 !important;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fbfcfd;
    cursor: pointer;
}

.check-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.check-card-box {
    width: 27px;
    height: 27px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border: 1px solid #cfd7df;
    border-radius: 8px;
    color: transparent;
    background: #fff;
}

.check-card input:checked + .check-card-box {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.check-card > span:last-child {
    display: flex;
    flex-direction: column;
}

.check-card strong {
    color: var(--ink);
    font-size: 10px;
}

.check-card small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 8px;
    font-weight: 500;
    line-height: 1.4;
}

.sticky-form-actions {
    position: sticky;
    bottom: 12px;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 13px;
    background: rgba(255,255,255,.93);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 15px 40px rgba(27,47,69,.12);
    backdrop-filter: blur(15px);
}

.patient-profile-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 22px;
    padding: 23px;
    margin-bottom: 16px;
    background:
        radial-gradient(circle at 92% 10%, rgba(11,111,104,.08), transparent 16rem),
        #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.patient-profile-main {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 16px;
}

.patient-profile-avatar {
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 20px;
    color: #fff;
    background: linear-gradient(145deg, #1c968c, #0b6f68);
    box-shadow: 0 12px 30px rgba(11,111,104,.19);
    font-size: 20px;
    font-weight: 900;
}

.patient-profile-copy {
    min-width: 0;
}

.patient-profile-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.patient-profile-title-row h2 {
    margin: 0;
    font-size: 23px;
    letter-spacing: -.035em;
}

.patient-code-line,
.patient-contact-line {
    display: flex;
    align-items: center;
    gap: 9px 15px;
    flex-wrap: wrap;
}

.patient-code-line {
    margin-top: 7px;
}

.patient-code-line span {
    color: #526276;
    font-size: 9px;
    font-weight: 800;
}

.patient-contact-line {
    margin-top: 13px;
}

.patient-contact-line span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
    font-size: 9px;
}

.patient-profile-actions {
    display: flex;
    gap: 9px;
    flex: 0 0 auto;
}

.clinical-warning-banner {
    display: flex;
    gap: 13px;
    padding: 16px 18px;
    margin-bottom: 16px;
    color: #8f2d3c;
    background: #fff5f6;
    border: 1px solid #ffd8df;
    border-left: 4px solid #e14e62;
    border-radius: 13px;
}

.clinical-warning-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 11px;
    background: #ffe4e8;
}

.clinical-warning-banner strong {
    font-size: 11px;
}

.clinical-warning-banner p {
    margin: 5px 0 0;
    font-size: 9px;
    line-height: 1.5;
}

.patient-profile-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.patient-profile-stats article {
    padding: 15px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 13px;
}

.patient-profile-stats span {
    display: block;
    color: var(--muted);
    font-size: 9px;
}

.patient-profile-stats strong {
    display: block;
    margin-top: 6px;
    font-size: 19px;
}

.patient-profile-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(300px, .72fr);
    gap: 18px;
    align-items: start;
}

.patient-profile-primary,
.patient-profile-sidebar {
    min-width: 0;
}

.profile-timeline {
    padding: 6px 18px;
}

.profile-timeline-item {
    position: relative;
    display: grid;
    grid-template-columns: 12px 78px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    min-height: 66px;
    border-bottom: 1px solid #eef1f4;
}

.profile-timeline-item:last-child {
    border-bottom: 0;
}

.timeline-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #94a3b8;
}

.timeline-dot.status-completed,
.timeline-dot.status-closed {
    background: var(--success);
}

.timeline-dot.status-in_progress,
.timeline-dot.status-called {
    background: var(--primary);
}

.timeline-dot.status-waiting,
.timeline-dot.status-arrived {
    background: var(--warning);
}

.timeline-date,
.timeline-content {
    display: flex;
    flex-direction: column;
}

.timeline-date strong,
.timeline-content strong {
    font-size: 10px;
}

.timeline-date span,
.timeline-content span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 8px;
}

.profile-info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 11px;
    padding: 17px;
}

.profile-info-block {
    min-height: 80px;
    padding: 13px;
    border: 1px solid #edf0f3;
    border-radius: 11px;
    background: #fbfcfd;
}

.profile-info-block.span-2 {
    grid-column: span 2;
}

.profile-info-block span {
    display: block;
    color: var(--muted);
    font-size: 8px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.profile-info-block strong {
    display: block;
    margin-top: 7px;
    color: #2f3d4f;
    font-size: 10px;
    font-weight: 650;
    line-height: 1.55;
}

.profile-side-list {
    padding: 7px 17px 16px;
}

.profile-side-list > div {
    padding: 12px 0;
    border-bottom: 1px solid #eef1f4;
}

.profile-side-list > div:last-child {
    border-bottom: 0;
}

.profile-side-list span {
    display: block;
    color: var(--muted);
    font-size: 8px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.profile-side-list strong {
    display: block;
    margin-top: 6px;
    color: #324154;
    font-size: 10px;
    line-height: 1.5;
}

.profile-side-list small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 8px;
}

.consent-status-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 16px;
}

.consent-status-list span {
    padding: 7px 9px;
    border-radius: 999px;
    font-size: 8px;
    font-weight: 850;
}

.consent-status-list span.yes {
    color: #13704c;
    background: var(--success-soft);
}

.consent-status-list span.no {
    color: #69788a;
    background: #f1f5f9;
}

.profile-module-placeholder {
    padding: 32px 20px;
    color: var(--muted);
    text-align: center;
}

.profile-module-placeholder > div {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    margin: 0 auto 12px;
    border-radius: 17px;
    color: var(--primary);
    background: var(--primary-soft);
}

.profile-module-placeholder strong {
    display: block;
    color: var(--ink);
    font-size: 11px;
}

.profile-module-placeholder span {
    display: block;
    max-width: 430px;
    margin: 7px auto 0;
    font-size: 9px;
    line-height: 1.55;
}

.patient-danger-panel form {
    padding: 15px 17px 17px;
}

.danger-button {
    width: 100%;
    min-height: 40px;
    border: 1px solid #f0c7ce;
    border-radius: 10px;
    color: #a33647;
    background: var(--danger-soft);
    font-size: 10px;
    font-weight: 850;
    cursor: pointer;
}

.full-width-button {
    width: 100%;
}

@media (max-width: 1120px) {
    .patient-stats-grid,
    .patient-profile-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .patient-profile-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .form-grid-3,
    .consent-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .field-span-3 {
        grid-column: span 2;
    }

    .patient-filter-bar {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .patient-search-field {
        flex-basis: 100%;
    }
}

@media (max-width: 650px) {
    .patient-stats-grid,
    .patient-profile-stats,
    .form-grid-2,
    .form-grid-3,
    .consent-grid,
    .profile-info-grid {
        grid-template-columns: 1fr;
    }

    .field-span-2,
    .field-span-3,
    .profile-info-block.span-2 {
        grid-column: span 1;
    }

    .patient-profile-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .patient-profile-actions {
        width: 100%;
    }

    .patient-profile-actions a {
        flex: 1;
    }

    .patient-profile-main {
        align-items: flex-start;
    }

    .profile-timeline-item {
        grid-template-columns: 10px 65px minmax(0, 1fr);
    }

    .profile-timeline-item .status-badge {
        grid-column: 2 / 4;
        margin-bottom: 9px;
    }

    .sticky-form-actions {
        flex-direction: column-reverse;
    }

    .sticky-form-actions a,
    .sticky-form-actions button {
        width: 100%;
    }
}

/* Minimum readable type sizes for patient forms, lists and profiles. */
.patient-stat-card span,
.patient-filter-bar select,
.patient-search-field input,
.patient-avatar,
.patient-identity strong,
.table-main,
.appointment-count-chip,
.patient-status,
.form-section-heading p,
.field label {
    font-size: 13px;
}

.patient-table th,
.patient-identity small,
.risk-inline,
.table-sub {
    font-size: 12px;
}

.fin-validation-message {
    display: block;
    min-height: 1.25em;
    margin-top: 6px;
    color: var(--danger);
    font-size: 13px;
    font-weight: 700;
}
