body {
    font-family: Arial, sans-serif;
    background: #f5f5f5;
    margin: 0;
    color: #1f2937;
}

.container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 16px;
}

h1, h2, h3 {
    margin: 0 0 12px 0;
}

.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 16px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

label {
    font-size: 12px;
    font-weight: 700;
    display: block;
    margin-bottom: 4px;
}

input, select, textarea, button {
    width: 100%;
    box-sizing: border-box;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    padding: 8px;
    font-size: 13px;
}

textarea {
    min-height: 66px;
}

button {
    background: #111827;
    color: #fff;
    cursor: pointer;
    border: 0;
}

button.secondary {
    background: #4b5563;
}

button.danger {
    background: #b91c1c;
}

a.btn-link {
    display: inline-block;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    text-decoration: none;
    color: #111827;
    font-size: 12px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th, td {
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    padding: 8px;
    vertical-align: top;
}

.sort-link {
    color: #111827;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.sort-arrow {
    font-size: 11px;
    color: #4b5563;
}

.item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 4px;
}

.inline-form {
    display: inline;
}

.icon-btn {
    width: 24px;
    min-width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 999px;
    background: #b91c1c;
    color: #fff;
    font-size: 12px;
    line-height: 24px;
    text-align: center;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e5e7eb;
    font-size: 11px;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.patient-form-page {
    max-width: 1120px;
    margin: 0 auto 16px;
    padding: 18px;
}

.patient-form-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 12px;
    margin-bottom: 14px;
}

.patient-form-kicker {
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.patient-form-subtitle {
    margin-top: -4px;
}

.patient-form-back {
    white-space: nowrap;
}

.patient-form {
    display: grid;
    gap: 12px;
}

.patient-form-block {
    margin: 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f8fafc;
    padding: 10px;
}

.patient-form-block legend {
    font-size: 12px;
    font-weight: 700;
    color: #111827;
    padding: 0 6px;
}

.patient-form-note {
    margin-top: 8px;
}

.patient-form-actions {
    margin-top: 2px;
}

.patient-form-actions button,
.patient-form-actions .btn-link {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 170px;
}

.patient-grid-main .patient-grid-span {
    grid-column: span 2;
}

.flash {
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 13px;
}

.flash-success {
    background: #dcfce7;
    border: 1px solid #22c55e;
}

.flash-error {
    background: #fee2e2;
    border: 1px solid #ef4444;
}

.small {
    font-size: 11px;
    color: #6b7280;
}

.patients-grid tbody tr:nth-child(odd) {
    background: #eef2f7;
}

.patients-grid tbody tr:nth-child(even) {
    background: #f8fafc;
}

.patients-grid-discharged tbody tr {
    background: #fef2f2;
}

.patients-grid-discharged tbody tr.patient-row-discharged {
    border-left: 3px solid #dc2626;
}

.desktop-patient-table {
    display: block;
}

.mobile-patient-list {
    display: none;
}

.patient-mobile-card {
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px;
}

.patient-mobile-card-discharged {
    background: #fef2f2;
    border-color: #fca5a5;
}

.patient-mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.patient-mobile-name {
    font-size: 14px;
    font-weight: 700;
}

.patient-mobile-meta {
    font-size: 12px;
    color: #4b5563;
}

.patient-mobile-section {
    margin-top: 8px;
}

.patient-mobile-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.patient-mobile-actions .btn-link,
.patient-mobile-actions button {
    flex: 1;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto !important;
}

.patient-filter-actions {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
}

.btn-action {
    width: auto !important;
    min-width: 170px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 0;
    color: #fff;
    font-size: 13px;
    text-decoration: none;
    padding: 0 12px;
    box-sizing: border-box;
}

.btn-filter {
    background: #1f2937;
}

.btn-clear {
    background: #6b7280;
}

.btn-export {
    background: #1d4ed8;
}

.audit-form-actions {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.audit-form-actions button,
.audit-form-actions .btn-link {
    flex: 1;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-audit-back {
    background: #1d4ed8;
    color: #fff !important;
    border: 0;
}

.locations-page button {
    width: auto;
}

.locations-header-card {
    display: grid;
    gap: 10px;
}

.locations-summary {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.locations-add-sector-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
}

.sector-card {
    display: grid;
    gap: 12px;
}

.sector-card-header {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 10px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
}

.sector-title {
    margin-bottom: 4px;
}

.sector-order-actions,
.bed-order-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.sector-card-forms {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.sector-inline-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
}

.sector-beds-table .col-order {
    width: 60px;
}

.sector-beds-table .col-actions {
    width: 130px;
}

.bed-order-number {
    font-weight: 700;
    color: #4b5563;
}

.bed-edit-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}

.login-animated-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background:
        radial-gradient(circle at 12% 20%, #e5e7eb 0%, transparent 40%),
        radial-gradient(circle at 85% 80%, #d1d5db 0%, transparent 45%),
        linear-gradient(120deg, #f8fafc, #eef2f7, #f5f5f5);
    background-size: 150% 150%, 160% 160%, 200% 200%;
    animation: loginBgShift 14s ease-in-out infinite alternate;
}

.login-shell {
    max-width: 920px;
    margin: 22px auto 10px;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 14px;
    align-items: stretch;
    position: relative;
}

.login-brand {
    background: #111827;
    color: #fff;
    border-radius: 8px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid #1f2937;
}

.login-brand .small {
    color: #d1d5db;
    font-size: 12px;
}

.login-kicker {
    margin: 0 0 6px;
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #d1d5db;
}

.login-card {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(17, 24, 39, 0.08);
}

.login-form {
    display: grid;
    gap: 10px;
}

.login-footer {
    text-align: center;
    margin: 10px 0 16px;
    font-weight: 700;
}

.login-foster {
    grid-column: 1 / -1;
    margin: 0;
    background: #f8fafc;
    border: 1px solid #d1d5db;
}

.login-foster h3 {
    margin-bottom: 8px;
}

.login-foster-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

@keyframes loginBgShift {
    0% {
        background-position: 0% 0%, 100% 100%, 0% 50%;
    }
    50% {
        background-position: 20% 15%, 80% 85%, 50% 50%;
    }
    100% {
        background-position: 35% 20%, 65% 75%, 100% 50%;
    }
}

@media (max-width: 1000px) {
    .grid, .grid-3 {
        grid-template-columns: 1fr;
    }

    .patient-form-page {
        padding: 12px;
    }

    .patient-form {
        gap: 10px;
    }

    .patient-form-block {
        padding: 8px;
    }

    .patient-form-block legend {
        font-size: 11px;
    }

    .patient-form label {
        margin-bottom: 3px;
    }

    .patient-form input,
    .patient-form select,
    .patient-form textarea {
        padding: 7px;
        font-size: 12px;
    }

    .patient-form textarea {
        min-height: 58px;
    }

    .patient-form-header {
        flex-direction: column;
        align-items: stretch;
    }

    .patient-form-back {
        width: 100%;
        text-align: center;
    }

    .patient-grid-main .patient-grid-span {
        grid-column: auto;
    }

    .patient-form-actions button,
    .patient-form-actions .btn-link {
        width: 100%;
        min-width: 0;
    }

    .patient-form-actions {
        position: sticky;
        bottom: 8px;
        z-index: 8;
        padding: 8px;
        border: 1px solid #d1d5db;
        border-radius: 8px;
        background: #ffffff;
        box-shadow: 0 8px 20px rgba(17, 24, 39, 0.12);
    }

    .locations-add-sector-form,
    .sector-card-forms,
    .sector-inline-form {
        grid-template-columns: 1fr;
    }

    .sector-card-header {
        align-items: stretch;
        flex-direction: column;
    }

    .desktop-patient-table {
        display: none;
    }

    .mobile-patient-list {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .btn-action {
        width: 100%;
        min-width: 0;
    }

    .login-shell {
        grid-template-columns: 1fr;
    }
}
