:root {
    --bg: #f4f7f9;
    --surface: #ffffff;
    --surface-alt: #eef3f6;
    --border: #d6e0e6;
    --text: #1d2b34;
    --muted: #5d727f;
    --primary: #1f6f78;
    --primary-dark: #174f55;
    --accent: #d8ede9;
    --success-bg: #e8f6ee;
    --success-text: #23613d;
    --error-bg: #fdecec;
    --error-text: #8d2d2d;
    --warning-bg: #fff7e6;
    --warning-text: #8a5d14;
    --shadow: 0 10px 30px rgba(24, 51, 68, 0.08);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 0;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(216, 237, 233, 0.65), transparent 32%),
        linear-gradient(180deg, #f8fbfc 0%, #f1f5f7 100%);
    color: var(--text);
    overflow-x: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.site-header,
.page-content,
.site-footer {
    width: min(1180px, calc(100% - clamp(1rem, 4vw, 2rem)));
    margin: 0 auto;
}

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.5rem 0 1rem;
}

.brand {
    display: inline-block;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    min-width: 0;
}

.brand-logo-link {
    flex: 0 0 auto;
    display: inline-flex;
}

.brand-logo {
    width: 58px;
    height: 58px;
    object-fit: contain;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--border);
    padding: 0.25rem;
    box-shadow: 0 6px 18px rgba(24, 51, 68, 0.08);
}

.brand:hover {
    text-decoration: none;
}

.brand-subtitle {
    margin: 0.35rem 0 0;
    color: var(--muted);
    max-width: 680px;
}

.site-nav {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.site-nav a {
    font-weight: 600;
}

.nav-inline-form {
    margin: 0;
}

.nav-link-button {
    background: none;
    color: var(--primary);
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    font-weight: 600;
}

.nav-link-button:hover {
    background: none;
    color: var(--primary-dark);
    text-decoration: underline;
}

.page-content {
    flex: 1;
    padding-bottom: 1rem;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0 0 1rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.site-footer p {
    margin: 0;
}

.staff-login-link {
    color: var(--muted);
    font-size: 0.82rem;
    opacity: 0.72;
}

.staff-login-link:hover {
    color: var(--primary);
    opacity: 1;
}

.card,
.panel,
.login-card,
.table-wrap,
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card,
.panel,
.login-card,
.table-wrap {
    padding: clamp(1rem, 2vw, 1.25rem);
}

.page-grid,
.dashboard-grid,
.stats-grid,
.detail-grid,
.two-column {
    display: grid;
    gap: 1rem;
}

.dashboard-grid {
    grid-template-columns: 2fr 1fr;
}

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

.detail-grid {
    grid-template-columns: 1.25fr 1fr;
    align-items: start;
}

.detail-grid > .stack,
.client-summary-card,
.pets-card {
    align-self: start;
}

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

.stack {
    display: grid;
    gap: 1rem;
    align-content: start;
}

.stat-card {
    padding: 1rem;
}

.stat-label {
    color: var(--muted);
    font-size: 0.92rem;
    margin: 0 0 0.4rem;
}

.stat-value {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
}

.section-heading,
.panel h2,
.card h2,
.card h3 {
    margin-top: 0;
}

.section-heading {
    margin-bottom: 1rem;
}

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

.alert {
    border-radius: 12px;
    padding: 0.9rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-bg);
    border-color: #cfe8d9;
    color: var(--success-text);
}

.alert-error {
    background: var(--error-bg);
    border-color: #f3cfcf;
    color: var(--error-text);
}

.alert-warning {
    background: var(--warning-bg);
    border-color: #f4e2b2;
    color: var(--warning-text);
}

.btn,
button,
input[type="submit"] {
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    font: inherit;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn:hover,
button:hover,
input[type="submit"]:hover {
    background: var(--primary-dark);
    text-decoration: none;
}

button[disabled],
input[type="submit"][disabled] {
    background: #c6d2d7;
    color: #6a7a82;
    cursor: not-allowed;
}

.btn-secondary {
    background: #dfe8ec;
    color: var(--text);
}

.btn-secondary:hover {
    background: #cfdbe0;
}

.btn-warning {
    background: #b17a1c;
}

.btn-warning:hover {
    background: #8c6117;
}

.btn-danger {
    background: #a33a3a;
}

.btn-danger:hover {
    background: #7f2d2d;
}

.button-row,
.actions-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.client-portal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.actions-row form {
    display: inline-flex;
}

form {
    margin: 0;
}

.form-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
}

.form-group {
    display: grid;
    gap: 0.45rem;
    align-content: start;
    min-width: 0;
}

.field-note {
    color: var(--muted);
    font-size: 0.9rem;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group.actions-row {
    display: flex;
    align-items: center;
}

.checkbox-field label {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
}

.checkbox-field input[type="checkbox"] {
    width: auto;
    min-height: 0;
}

label {
    font-weight: 600;
}

input,
select,
textarea {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 0.75rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    font: inherit;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-header,
.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.pagination-pages {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.page-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    min-height: 2.25rem;
    padding: 0.35rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--primary);
    font-weight: 700;
}

.page-number:hover {
    background: var(--surface-alt);
    text-decoration: none;
}

.page-number.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.top-spacing {
    margin-top: 1rem;
}

/* Nested tables inside cards should sit flush with the card content, not look like a second card. */
.card > .table-wrap,
.panel > .table-wrap {
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

th,
td {
    text-align: left;
    padding: 0.8rem 0.7rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.15;
    white-space: nowrap;
}

.badge-active {
    background: #dff4e7;
    color: #22633c;
}

.badge-expired {
    background: #fde5e5;
    color: #8b2b2b;
}

.badge-not-enrolled {
    background: #e8eef2;
    color: #4f6773;
}

.quick-results-table th:nth-child(4),
.quick-results-table td:nth-child(4) {
    text-align: center;
}

.quick-results-table td:nth-child(4) {
    width: 150px;
}

.list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.8rem;
}

.list-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border);
}

.list-item:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.pill-note {
    display: inline-block;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 0.85rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-available {
    background: #e2f2e8;
    color: #266240;
}

.status-used {
    background: #e7eef3;
    color: #4c6472;
}

.status-unavailable {
    background: #f2e7e7;
    color: #8b3a3a;
}

.empty-state {
    padding: 1rem;
    border: 1px dashed var(--border);
    border-radius: 12px;
    color: var(--muted);
    background: #fbfdfe;
}

.pets-empty-state {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 0;
    flex-wrap: wrap;
}

.pets-empty-state .btn {
    width: auto;
    flex: 0 0 auto;
}

.login-page {
    min-height: calc(100vh - 11rem);
    display: grid;
    place-items: center;
    padding: 0 1rem 1rem;
}

.login-card {
    width: min(460px, 100%);
}

.login-card-header {
    display: grid;
    justify-items: center;
    gap: 0.75rem;
    text-align: center;
}

.login-logo {
    width: min(190px, 64vw);
    height: auto;
    object-fit: contain;
}

.summary-list {
    display: grid;
    gap: 0.75rem;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.summary-item:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.benefit-status-actions,
.benefit-table-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.benefit-status-actions {
    justify-content: flex-end;
}

.benefit-table-actions form,
.benefit-status-actions form {
    display: inline-flex;
}

.inline-count-form {
    align-items: center;
    gap: 0.45rem;
}

.inline-count-form select {
    width: 4.5rem;
    min-width: 4.5rem;
    padding: 0.55rem 0.65rem;
}

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

.pets-table {
    table-layout: fixed;
    min-width: 0;
}

.pets-table .actions-column {
    width: 180px;
}

.pets-table th,
.pets-table td {
    overflow-wrap: anywhere;
}

.benefit-table-actions {
    align-items: center;
    justify-content: flex-end;
}

.benefit-table-actions .btn,
.benefit-table-actions button {
    width: auto;
    min-width: 0;
    padding: 0.55rem 0.75rem;
    text-align: center;
    white-space: nowrap;
}

.benefit-table-actions form {
    width: auto;
}

.location-card {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fbfdfe;
    flex-wrap: wrap;
}

.location-form {
    display: grid;
    gap: 0.75rem;
    flex: 1 1 320px;
}

.location-meta {
    font-size: 0.92rem;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(21, 40, 53, 0.48);
    display: grid;
    place-items: center;
    padding: 1rem;
    z-index: 999;
}

.modal-backdrop[hidden] {
    display: none !important;
}

.modal-panel {
    width: min(640px, 100%);
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 22px 50px rgba(15, 36, 49, 0.28);
    padding: 1.25rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.modal-close {
    color: var(--muted);
    font-weight: 600;
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
}

.checkbox-row input {
    width: auto;
    min-height: 0;
}

@media (max-width: 1100px) {
    .dashboard-grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 900px) {
    .two-column,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .site-header {
        flex-direction: column;
        align-items: stretch;
    }

    .site-nav {
        gap: 0.5rem;
    }

    .list-item,
    .summary-item,
    .table-header,
    .pagination-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .benefit-status-actions {
        justify-content: flex-start;
    }

    .modal-header,
    .location-card,
    .client-portal-header {
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    body {
        background: linear-gradient(180deg, #f8fbfc 0%, #f1f5f7 100%);
    }

    .site-header {
        padding-top: 1rem;
    }

    .brand-logo {
        width: 48px;
        height: 48px;
    }

    .brand {
        font-size: 1.2rem;
    }

    .brand-subtitle,
    .site-footer {
        font-size: 0.9rem;
    }

    .site-nav {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: stretch;
    }

    .site-nav a,
    .nav-link-button {
        display: flex;
        min-height: 42px;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        background: var(--surface-alt);
        padding: 0.65rem 0.75rem;
        text-align: center;
    }

    .nav-inline-form,
    .nav-inline-form button {
        width: 100%;
    }

    .card,
    .panel,
    .login-card,
    .table-wrap,
    .stat-card {
        border-radius: 10px;
    }

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

    .stat-value {
        font-size: 1.35rem;
    }

    .section-heading {
        font-size: 1.45rem;
    }

    .actions-row,
    .button-row,
    .form-group.actions-row {
        display: grid;
        grid-template-columns: 1fr;
    }

    .actions-row > *,
    .button-row > *,
    .actions-row form,
    .benefit-status-actions form,
    .benefit-table-actions form {
        width: 100%;
    }

    .btn,
    button,
    input[type="submit"] {
        width: 100%;
        text-align: center;
    }

    .summary-item {
        gap: 0.35rem;
    }

    .login-page {
        min-height: calc(100vh - 9rem);
        padding-inline: 0;
    }

    table {
        min-width: 620px;
    }
}

@media (max-width: 420px) {
    .site-nav {
        grid-template-columns: 1fr;
    }

    .site-header,
    .page-content,
    .site-footer {
        width: calc(100% - 0.75rem);
    }
}
