:root {
    --navy: #19324d;
    --navy-dark: #10253a;
    --blue: #2d7dd2;
    --blue-light: #edf5ff;
    --text: #263746;
    --muted: #75869a;
    --white: #ffffff;
    --background: #f3f7fb;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--background);
    color: var(--text);
}

.app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
}

.sidebar {
    background: var(--navy);
    color: var(--white);
    padding: 28px 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--white);
    color: var(--navy);
    font-size: 24px;
    font-weight: bold;
    text-decoration: none;
}

.brand-name {
    font-size: 20px;
    font-weight: 700;
}

.nav-list {
    display: grid;
    gap: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    border-radius: 8px;
    color: #dfeaf4;
    text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(255, 255, 255, 0.12);
    color: var(--white);
}

.main {
    min-width: 0;
}

.topbar {
    height: 72px;
    padding: 0 36px;
    background: var(--white);
    border-bottom: 1px solid #dde7ef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
}

.user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--blue-light);
    color: var(--blue);
    display: grid;
    place-items: center;
    font-weight: bold;
}

.content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 34px 36px;
}

.welcome {
    margin-bottom: 24px;
}

.welcome h2 {
    margin: 0 0 8px;
    font-size: 28px;
}

.welcome p {
    margin: 0;
    color: var(--muted);
}

.cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.card {
    min-height: 160px;
    padding: 24px;
    border: 1px solid #e1e8ef;
    border-radius: 12px;
    background: var(--white);
    color: inherit;
    text-decoration: none;
    box-shadow: 0 5px 18px rgba(25, 50, 77, 0.04);
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.card:hover {
    transform: translateY(-2px);
    border-color: #bdd8f2;
}

.card-icon {
    width: 44px;
    height: 44px;
    margin-bottom: 18px;
    border-radius: 9px;
    background: var(--blue-light);
    color: var(--blue);
    display: grid;
    place-items: center;
    font-size: 21px;
}

.card h3 {
    margin: 0 0 7px;
    font-size: 18px;
}

.card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.card-form,
.data-panel {
    padding: 24px;
    border: 1px solid #e1e8ef;
    border-radius: 12px;
    background: var(--white);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.form-grid label {
    display: grid;
    gap: 8px;
    color: var(--text);
    font-weight: bold;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid #ccd8e3;
    border-radius: 8px;
    background: var(--white);
    color: var(--text);
}

.form-grid textarea {
    min-height: 160px;
    padding: 12px;
    resize: vertical;
    font: inherit;
    line-height: 1.5;
}

.primary-button {
    height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: var(--blue);
    color: var(--white);
    cursor: pointer;
}

.data-panel p {
    margin: 0;
    color: var(--muted);
}

.data-panel .data-notice,
.card-form .data-notice {
    margin: 0 0 18px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #fff7e6;
    color: #76520b;
    line-height: 1.5;
}

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #e1e8ef;
    white-space: nowrap;
}

.data-table th {
    color: var(--muted);
    font-size: 13px;
}

.patient-form {
    margin: 16px 0 24px;
}

.patient-form h3 {
    margin: 0 0 20px;
}

.patient-form label span {
    color: #b42318;
}

.patient-form .field-feedback {
    margin: -8px 0 18px;
    color: var(--muted);
    font-size: 13px;
}

.form-errors,
.form-success {
    margin: 0 0 18px;
    padding: 12px 14px;
    border-radius: 8px;
    line-height: 1.5;
}

.form-errors {
    background: #fff0ef;
    color: #8f1d14;
}

.form-errors p {
    color: inherit;
    font-weight: bold;
}

.form-errors ul {
    margin: 6px 0 0;
    padding-left: 20px;
}

.form-success {
    background: #eaf7ee;
    color: #216e39;
}

.patient-form-actions,
.dialog-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.secondary-button {
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid #cbd6df;
    border-radius: 8px;
    background: var(--white);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.secondary-button:hover {
    background: #f3f7fb;
}

.patient-table-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.patient-table-heading h3 {
    margin: 0 0 5px;
    font-size: 18px;
}

.patient-table-heading p {
    color: var(--muted);
    font-size: 13px;
}

.patient-filters {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(150px, 210px) auto;
    align-items: end;
    gap: 14px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e8edf1;
}

.patient-filters label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.patient-filters input,
.patient-filters select {
    width: 100%;
    min-width: 0;
    height: 40px;
    padding: 0 11px;
    border: 1px solid #cbd6df;
    border-radius: 7px;
    background: var(--white);
    color: var(--text);
    font: inherit;
}

.patient-filters input:focus-visible,
.patient-filters select:focus-visible,
.clear-filters-button:focus-visible {
    outline: 3px solid rgba(45, 125, 210, 0.35);
    outline-offset: 2px;
}

.clear-filters-button {
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid #cbd6df;
    border-radius: 7px;
    background: #f8fafc;
    color: #40586d;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.clear-filters-button:hover {
    background: #eef4f8;
}

.filter-results {
    grid-column: 1 / -1;
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.appointment-list-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.appointment-list-heading h3 {
    margin: 0 0 5px;
    font-size: 18px;
}

.appointment-list-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.appointment-new-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    text-decoration: none;
}

.appointment-filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
    align-items: end;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e8edf1;
}

.appointment-filters label {
    display: grid;
    gap: 7px;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.appointment-filters input,
.appointment-filters select {
    width: 100%;
    min-width: 0;
    height: 40px;
    padding: 0 10px;
    border: 1px solid #cbd6df;
    border-radius: 7px;
    background: var(--white);
    color: var(--text);
    font: inherit;
}

.appointment-filters input:focus-visible,
.appointment-filters select:focus-visible {
    outline: 3px solid rgba(45, 125, 210, 0.35);
    outline-offset: 2px;
}

.appointment-table {
    min-width: 760px;
}

.appointment-table td {
    vertical-align: top;
}

.appointment-description-cell {
    min-width: 220px;
    max-width: 520px;
    white-space: normal !important;
    line-height: 1.5;
}

.appointment-edit-link {
    color: var(--blue);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.appointment-form .appointment-description-label {
    grid-column: 1 / -1;
}

.appointment-form label[for="appointment-datetime"] {
    position: relative;
}

.appointment-form input[readonly] {
    background: #f3f7fb;
    color: #526579;
    cursor: default;
}

.appointment-form .field-feedback {
    position: absolute;
    top: 76px;
    left: 0;
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.45;
}

.appointment-form-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.appointment-cancel-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.patient-table-wrap {
    max-height: min(620px, 70vh);
    overflow: auto;
    border: 1px solid #e1e8ef;
    border-radius: 8px;
}

.patient-table {
    width: 100%;
    min-width: 0;
    table-layout: auto;
}

.patient-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f5f8fb;
    color: #526579;
    font-weight: 700;
}

.patient-table td {
    white-space: normal;
    vertical-align: top;
}

.patient-table tbody tr:nth-child(even) {
    background: #fafcfe;
}

.patient-table tbody tr:hover {
    background: #f0f7ff;
}

.patient-table td:first-child {
    min-width: 0;
    font-weight: 700;
}

.patient-table td:nth-child(4) {
    min-width: 0;
    overflow-wrap: anywhere;
}

.patient-status {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 9px;
    border-radius: 999px;
    background: #eef2f6;
    color: #536273;
    font-size: 12px;
    font-weight: 700;
}

.patient-status.is-active {
    background: #e8f6ed;
    color: #216e39;
}

.patient-status.is-inactive {
    background: #fff1e8;
    color: #9a4315;
}

.patient-empty-state {
    padding: 28px 16px;
    border: 1px dashed #cbd6df;
    border-radius: 8px;
    background: #fafcfe;
    text-align: center;
}

.patient-info-cell {
    width: 52px;
    text-align: center;
}

.patient-info-button {
    display: inline-grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border: 1px solid #d5dfe7;
    border-radius: 50%;
    background: var(--white);
    color: #40586d;
    cursor: pointer;
}

.patient-info-button:hover {
    border-color: #9eb4c6;
    background: #eef4f8;
    color: var(--navy);
}

.patient-info-button span {
    display: grid;
    width: 16px;
    height: 16px;
    place-items: center;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.add-patient-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid #d5dfe7;
    border-radius: 7px;
    background: #f8fafc;
    color: #40586d;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.add-patient-button:hover {
    border-color: #9eb4c6;
    background: #eef4f8;
}

.add-patient-button span {
    color: var(--blue);
    font-size: 18px;
    line-height: 1;
}

.patient-form-dialog {
    width: min(760px, calc(100vw - 32px));
    max-height: min(880px, calc(100vh - 40px));
    padding: 28px;
    overflow-y: auto;
    border: 1px solid #dfe7ed;
    border-radius: 12px;
    color: var(--text);
    box-shadow: 0 24px 70px rgba(16, 37, 58, 0.24);
}

.patient-form-dialog::backdrop {
    background: rgba(16, 37, 58, 0.58);
    backdrop-filter: blur(2px);
}

.patient-info-dialog {
    width: min(620px, calc(100vw - 32px));
    max-height: min(760px, calc(100vh - 40px));
    padding: 28px;
    overflow-y: auto;
    border: 1px solid #dfe7ed;
    border-radius: 12px;
    color: var(--text);
    box-shadow: 0 24px 70px rgba(16, 37, 58, 0.24);
}

.patient-info-dialog::backdrop {
    background: rgba(16, 37, 58, 0.58);
    backdrop-filter: blur(2px);
}

.patient-details-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 20px;
    margin: 0;
}

.patient-details-list div {
    min-width: 0;
    padding: 13px 0;
    border-bottom: 1px solid #e8edf1;
}

.patient-details-list dt {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.patient-details-list dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 14px;
}

.patient-details-list div:nth-last-child(-n + 2) {
    grid-column: 1 / -1;
}

.patient-dialog-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.patient-dialog-heading h2 {
    margin: 0 0 6px;
    font-size: 22px;
}

.patient-dialog-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.dialog-close-button {
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid #d5dfe7;
    border-radius: 7px;
    background: var(--white);
    color: #526579;
    font: inherit;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.patient-dialog-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dialog-icon-button {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid #d5dfe7;
    border-radius: 7px;
    background: var(--white);
    color: #40586d;
    font: inherit;
    font-size: 19px;
    cursor: pointer;
}

.dialog-icon-button:hover {
    border-color: #9eb4c6;
    background: #eef4f8;
    color: var(--navy);
}

.dialog-delete-button {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid #efc7c3;
    border-radius: 7px;
    background: #fff8f7;
    color: #a52b20;
    font: inherit;
    font-size: 19px;
    cursor: pointer;
}

.dialog-delete-button:hover {
    border-color: #d98a83;
    background: #fff0ee;
}

.dialog-close-button:hover {
    background: #f3f7fb;
}

.patient-form {
    margin: 0;
}

.patient-form input[readonly] {
    background: #f3f7fb;
    color: var(--muted);
    cursor: not-allowed;
}

.patient-success-dialog {
    width: min(480px, calc(100vw - 32px));
    padding: 30px;
    border: 1px solid #dfe7ed;
    border-radius: 12px;
    color: var(--text);
    box-shadow: 0 24px 70px rgba(16, 37, 58, 0.24);
}

.patient-success-dialog::backdrop {
    background: rgba(16, 37, 58, 0.52);
    backdrop-filter: blur(2px);
}

.patient-delete-dialog {
    width: min(460px, calc(100vw - 32px));
    padding: 28px;
    border: 1px solid #ead2d0;
    border-radius: 12px;
    color: var(--text);
    box-shadow: 0 24px 70px rgba(16, 37, 58, 0.24);
}

.patient-delete-dialog::backdrop {
    background: rgba(16, 37, 58, 0.62);
    backdrop-filter: blur(2px);
}

.patient-delete-dialog .patient-dialog-heading {
    margin-bottom: 14px;
}

.patient-delete-message {
    margin: 0 0 24px;
    color: #526579;
    line-height: 1.55;
}

.patient-delete-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.danger-button {
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid #a52b20;
    border-radius: 8px;
    background: #a52b20;
    color: var(--white);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.danger-button:hover {
    border-color: #7f1e16;
    background: #7f1e16;
}

.dialog-mark {
    display: grid;
    width: 44px;
    height: 44px;
    margin-bottom: 18px;
    place-items: center;
    border-radius: 50%;
    background: #e8f6ed;
    color: #216e39;
    font-size: 22px;
    font-weight: 700;
}

.patient-success-dialog h2 {
    margin: 0 0 10px;
    font-size: 22px;
}

.patient-success-dialog p {
    margin: 0 0 24px;
    color: #526579;
    line-height: 1.55;
}

.dialog-actions .primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 700;
}

@media (max-width: 820px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        padding: 18px;
    }

    .brand {
        margin-bottom: 18px;
    }

    .nav-list {
        grid-template-columns: repeat(2, 1fr);
    }

    .topbar {
        padding: 0 20px;
    }

    .content {
        padding: 24px 20px;
    }
}

@media (max-width: 560px) {
    .cards,
    .nav-list {
        grid-template-columns: 1fr;
    }

    .topbar h1 {
        font-size: 18px;
    }

    .user span {
        display: none;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .patient-table-heading {
        align-items: flex-start;
    }

    .patient-filters {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 12px;
    }

    .patient-filters label:first-child,
    .filter-results {
        grid-column: 1 / -1;
    }

    .clear-filters-button {
        width: 100%;
    }

    .appointment-list-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .appointment-filters {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 12px;
    }

    .appointment-filters label:nth-child(3),
    .appointment-filters .filter-results {
        grid-column: 1 / -1;
    }

    .appointment-filters .clear-filters-button {
        width: 100%;
    }

    .appointment-table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
    }

    .appointment-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .appointment-table tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .appointment-table tbody tr[data-appointment-row] {
        display: flex;
        flex-wrap: wrap;
        width: 100%;
        min-width: 0;
        margin-bottom: 12px;
        box-sizing: border-box;
        padding: 8px;
        border: 1px solid #e1e8ef;
        border-radius: 8px;
    }

    .appointment-table tbody tr[data-appointment-row] td {
        display: block;
        flex: 0 0 50%;
        max-width: 50%;
        min-width: 0;
        padding: 7px;
        border: 0;
        overflow-wrap: anywhere;
        white-space: normal;
    }

    .appointment-table tbody tr[data-appointment-row] td:first-child,
    .appointment-table tbody tr[data-appointment-row] td:nth-child(4) {
        flex-basis: 100%;
        max-width: 100%;
    }

    .appointment-table tbody tr[data-appointment-row] td::before {
        display: block;
        margin-bottom: 4px;
        color: var(--muted);
        content: attr(data-label);
        font-size: 11px;
        font-weight: 700;
    }

    .appointment-table tbody tr[data-no-appointment-results] {
        display: block;
    }

    .appointment-table tbody tr[data-no-appointment-results] td {
        display: block;
    }

    .patient-form-dialog {
        max-height: calc(100vh - 24px);
        padding: 20px;
    }

    .patient-form-dialog .form-grid {
        grid-template-columns: 1fr;
    }

    .patient-table {
        table-layout: fixed;
    }

    .patient-table th,
    .patient-table td {
        padding: 8px 4px;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .patient-table th:nth-child(1),
    .patient-table td:nth-child(1) {
        width: 24%;
    }

    .patient-table th:nth-child(2),
    .patient-table td:nth-child(2) {
        width: 23%;
    }

    .patient-table th:nth-child(3),
    .patient-table td:nth-child(3) {
        width: 10%;
    }

    .patient-table th:nth-child(4),
    .patient-table td:nth-child(4) {
        width: 25%;
    }

    .patient-table th:nth-child(5),
    .patient-table td:nth-child(5) {
        width: 18%;
    }

    .patient-table td:first-child {
        min-width: 0;
    }

    .patient-info-cell {
        width: auto;
    }

    .patient-info-button {
        width: 28px;
        height: 28px;
    }

    .patient-info-dialog {
        max-height: calc(100vh - 24px);
        padding: 20px;
    }

    .patient-delete-dialog {
        padding: 20px;
    }

    .patient-delete-actions {
        flex-direction: column-reverse;
    }

    .patient-delete-actions button {
        width: 100%;
    }

    .patient-details-list {
        grid-template-columns: 1fr;
    }

    .patient-details-list div:nth-last-child(-n + 2) {
        grid-column: auto;
    }

    .patient-success-dialog {
        padding: 24px;
    }

    .dialog-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .dialog-actions > * {
        width: 100%;
        text-align: center;
    }
}

.toast-region {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    display: grid;
    gap: 10px;
}

.toast {
    min-width: 280px;
    max-width: 360px;
    padding: 14px 16px;
    border-left: 4px solid var(--blue);
    border-radius: 8px;
    background: var(--white);
    box-shadow: 0 10px 30px rgba(16, 37, 58, 0.16);
    animation: toast-in 0.25s ease-out;
}

.toast strong,
.toast span {
    display: block;
}

.toast strong {
    margin-bottom: 4px;
}

.toast span {
    color: var(--muted);
    font-size: 14px;
}

.toast--closing {
    opacity: 0;
    transform: translateY(8px);
    transition: 0.25s ease;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
