/* Medvera Refer application design system */
:root {
    --brand-900: #0b2a4a;
    --brand-800: #123b63;
    --brand-700: #15558b;
    --brand-600: #1d6fb3;
    --brand-100: #e8f2fb;
    --accent-600: #0f766e;
    --accent-100: #e7f6f3;
    --ink-900: #17202a;
    --ink-700: #3d4b5c;
    --ink-500: #697586;
    --border: #dbe2ea;
    --border-strong: #c6d0dc;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --surface-muted: #eef3f8;
    --danger-700: #b42318;
    --danger-100: #fef3f2;
    --success-700: #067647;
    --success-100: #ecfdf3;
    --warning-700: #b54708;
    --warning-100: #fffaeb;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 8px 24px rgba(15, 42, 74, 0.08);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --sidebar-width: 232px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--surface-soft);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink-900);
    background: var(--surface-soft);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
    font: inherit;
}

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

a:hover {
    color: var(--brand-900);
}

img {
    max-width: 100%;
}

h1,
h2,
h3,
h4,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: clamp(1.65rem, 2vw, 2.15rem);
    line-height: 1.15;
    letter-spacing: -0.025em;
}

h2 {
    font-size: 1.25rem;
    line-height: 1.3;
}

h3 {
    font-size: 1.05rem;
}

.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;
}

/* Header and brand */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: 66px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 10px 22px;
    color: #fff;
    background: var(--brand-900);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: #fff;
}

.brand-link:hover {
    color: #fff;
}

.brand-mark {
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 10px;
    color: var(--brand-900);
    background: #fff;
    font-weight: 800;
    font-size: 18px;
    letter-spacing: -0.04em;
}

.brand-copy {
    display: flex;
    align-items: baseline;
    gap: 7px;
    white-space: nowrap;
}

.brand-name {
    font-size: 1.1rem;
    font-weight: 750;
    letter-spacing: -0.02em;
}

.brand-product {
    color: #bcd8ef;
    font-size: 0.92rem;
    font-weight: 600;
}

.topbar-account {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

.topbar-identity {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 0;
    margin-right: 4px;
}

.topbar-username {
    color: #fff;
    font-weight: 650;
    line-height: 1.2;
}

.topbar-practice {
    max-width: 300px;
    overflow: hidden;
    color: #bcd8ef;
    font-size: 0.8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-link,
.topbar-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    color: #fff;
    background: rgba(255, 255, 255, 0.07);
    cursor: pointer;
    font-weight: 650;
}

.topbar-link:hover,
.topbar-button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.14);
}

.topbar-logout-form {
    margin: 0;
}

/* Logged-in application shell */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: calc(100vh - 66px);
}

.app-sidebar {
    position: sticky;
    top: 66px;
    align-self: start;
    height: calc(100vh - 66px);
    display: flex;
    flex-direction: column;
    padding: 20px 14px 16px;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

.sidebar-practice {
    padding: 2px 10px 16px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.sidebar-eyebrow {
    display: block;
    margin-bottom: 3px;
    color: var(--ink-500);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.sidebar-practice-name {
    display: block;
    color: var(--ink-900);
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.35;
}

.sidebar-nav {
    display: grid;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 9px 11px;
    border-radius: 8px;
    color: var(--ink-700);
    font-weight: 600;
}

.nav-link:hover {
    color: var(--brand-900);
    background: var(--surface-muted);
}

.nav-link.is-active {
    color: var(--brand-900);
    background: var(--brand-100);
    font-weight: 750;
}

.sidebar-section-label {
    padding: 18px 10px 6px;
    color: var(--ink-500);
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.sidebar-bottom {
    margin-top: auto;
    padding: 14px 10px 2px;
    border-top: 1px solid var(--border);
}

.sidebar-bottom a {
    color: var(--ink-500);
    font-size: 0.86rem;
    font-weight: 600;
}

.app-workspace {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-main {
    width: 100%;
    flex: 1;
    padding: 30px clamp(20px, 3vw, 48px) 40px;
}

.content-container {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
}

.app-footer {
    padding: 14px clamp(20px, 3vw, 48px) 20px;
    color: var(--ink-500);
    font-size: 0.8rem;
}

/* Page structure */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-heading p,
.page-description {
    max-width: 760px;
    margin-bottom: 0;
    color: var(--ink-500);
}

.page-actions,
.action-row,
.table-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-heading h2,
.section-heading h3 {
    margin-bottom: 0;
}

.card,
.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.card {
    padding: 22px;
}

.card + .card {
    margin-top: 18px;
}

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

.small {
    font-size: 0.86rem;
}

.meta-label {
    display: block;
    margin-bottom: 3px;
    color: var(--ink-500);
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--brand-900);
    background: var(--brand-100);
    font-size: 0.78rem;
    font-weight: 700;
}

.badge-success {
    color: var(--success-700);
    background: var(--success-100);
}

.badge-muted {
    color: var(--ink-700);
    background: var(--surface-muted);
}

/* Buttons */
.btn,
button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.btn:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(29, 111, 179, 0.24);
    outline-offset: 2px;
}

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

.btn-primary:hover {
    color: #fff;
    background: var(--brand-900);
    border-color: var(--brand-900);
}

.btn-secondary {
    color: var(--ink-700);
    background: var(--surface);
    border-color: var(--border-strong);
}

.btn-secondary:hover {
    color: var(--brand-900);
    background: var(--surface-soft);
    border-color: #9fb0c2;
}

.btn-danger {
    color: var(--danger-700);
    background: var(--surface);
    border-color: #f1b4ae;
}

.btn-danger:hover {
    color: #fff;
    background: var(--danger-700);
    border-color: var(--danger-700);
}

.btn-quiet {
    color: var(--brand-700);
    background: transparent;
    border-color: transparent;
}

.btn-quiet:hover {
    color: var(--brand-900);
    background: var(--brand-100);
}

.btn-sm {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 0.84rem;
}

/* Forms */
.form-card {
    max-width: 980px;
}

.form-section + .form-section {
    margin-top: 26px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

form p {
    margin-bottom: 16px;
}

form label {
    display: block;
    margin-bottom: 6px;
    color: var(--ink-700);
    font-weight: 700;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="url"],
select,
textarea {
    width: 100%;
    max-width: 720px;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    color: var(--ink-900);
    background: var(--surface);
    box-shadow: inset 0 1px 2px rgba(16, 24, 40, 0.03);
}

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

input[type="file"] {
    max-width: 100%;
}

input[type="checkbox"] {
    width: 17px;
    height: 17px;
    vertical-align: -3px;
    accent-color: var(--brand-700);
}

.helptext {
    display: block;
    max-width: 720px;
    margin-top: 5px;
    color: var(--ink-500);
    font-size: 0.8rem;
}

ul.errorlist {
    margin: 6px 0 10px;
    padding: 10px 12px 10px 30px;
    border: 1px solid #f1b4ae;
    border-radius: 8px;
    color: var(--danger-700);
    background: var(--danger-100);
}

.form-errors {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid #f1b4ae;
    border-radius: 8px;
    color: var(--danger-700);
    background: var(--danger-100);
}

.location-form-card {
    margin: 0 0 16px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-soft);
}

.location-form-card legend {
    padding: 0 6px;
    color: var(--ink-700);
    font-weight: 750;
}

/* Alerts */
.alert-stack {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
}

.alert {
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.alert-success {
    color: var(--success-700);
    border-color: #a6f4c5;
    background: var(--success-100);
}

.alert-error,
.alert-danger {
    color: var(--danger-700);
    border-color: #f1b4ae;
    background: var(--danger-100);
}

.alert-warning {
    color: var(--warning-700);
    border-color: #fedf89;
    background: var(--warning-100);
}

/* Directory */
.directory-toolbar {
    margin-bottom: 18px;
    padding: 18px;
}

.directory-search {
    display: flex;
    align-items: center;
    gap: 8px;
}

.directory-search input[type="text"] {
    max-width: none;
    flex: 1;
}

.alphabet-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.letter-link {
    min-width: 30px;
    height: 30px;
    display: inline-grid;
    place-items: center;
    padding: 0 7px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--ink-700);
    background: var(--surface);
    font-size: 0.83rem;
    font-weight: 700;
}

.letter-link:hover {
    color: var(--brand-900);
    border-color: #9fb9d3;
    background: var(--brand-100);
}

.letter-link.active {
    color: #fff;
    border-color: var(--brand-700);
    background: var(--brand-700);
}

.directory-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 14px 0 10px;
    color: var(--ink-500);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
}

.data-table th,
.data-table td {
    padding: 14px 15px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    color: var(--ink-500);
    background: #fbfcfe;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

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

.data-table tbody tr:hover {
    background: #fbfdff;
}

.provider-name {
    display: inline-block;
    color: var(--brand-900);
    font-weight: 750;
}

.provider-org,
.table-secondary {
    display: block;
    margin-top: 2px;
    color: var(--ink-500);
    font-size: 0.84rem;
}

.provider-specialty {
    font-weight: 650;
}

.insurance-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.insurance-chip {
    display: inline-flex;
    padding: 2px 7px;
    border-radius: 999px;
    color: var(--ink-700);
    background: var(--surface-muted);
    font-size: 0.75rem;
    font-weight: 650;
}

.empty-state {
    padding: 38px 24px;
    text-align: center;
    color: var(--ink-500);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.pagination-status {
    padding: 0 5px;
    color: var(--ink-500);
    font-size: 0.86rem;
}

/* Detail pages */
.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
    gap: 18px;
    align-items: start;
}

.detail-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 24px;
    margin: 0;
}

.detail-list > div {
    min-width: 0;
}

.detail-list dt {
    margin-bottom: 3px;
    color: var(--ink-500);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.detail-list dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-weight: 600;
}

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

.location-card {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-soft);
}

.location-title {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 6px;
    font-weight: 750;
}

.notes-block {
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Auth and profile */
.auth-main {
    min-height: calc(100vh - 66px);
    display: grid;
    place-items: start center;
    padding: 56px 20px;
}

.auth-card {
    width: min(100%, 460px);
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-md);
}

.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"] {
    max-width: none;
}

.profile-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 0.7fr);
    gap: 18px;
}

/* Destructive confirmation */
.danger-card {
    max-width: 720px;
    border-color: #f1b4ae;
}

.danger-card h1,
.danger-card h2 {
    color: var(--danger-700);
}

/* Mobile/tablet */
@media (max-width: 1050px) {
    .detail-grid,
    .profile-grid {
        grid-template-columns: 1fr;
    }

    .provider-table th:nth-child(5),
    .provider-table td:nth-child(5) {
        display: none;
    }
}

@media (max-width: 860px) {
    .app-topbar {
        position: static;
        padding: 10px 14px;
    }

    .topbar-identity {
        display: none;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        position: static;
        width: 100%;
        height: auto;
        padding: 8px 12px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-practice,
    .sidebar-section-label,
    .sidebar-bottom {
        display: none;
    }

    .sidebar-nav {
        display: flex;
        gap: 5px;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .nav-link {
        min-height: 36px;
        flex: 0 0 auto;
        padding: 7px 10px;
        font-size: 0.85rem;
    }

    .app-main {
        padding: 22px 16px 32px;
    }

    .page-header {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
    }

    .directory-search {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .directory-search input[type="text"] {
        flex-basis: 100%;
    }

    .provider-table thead {
        display: none;
    }

    .provider-table,
    .provider-table tbody,
    .provider-table tr,
    .provider-table td {
        display: block;
        width: 100%;
    }

    .provider-table tr {
        padding: 14px 15px;
        border-bottom: 1px solid var(--border);
    }

    .provider-table tr:last-child {
        border-bottom: 0;
    }

    .provider-table td {
        display: grid;
        grid-template-columns: 105px minmax(0, 1fr);
        gap: 10px;
        padding: 5px 0;
        border: 0;
    }

    .provider-table td::before {
        content: attr(data-label);
        color: var(--ink-500);
        font-size: 0.72rem;
        font-weight: 800;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    .provider-table td:first-child {
        display: block;
        padding-bottom: 10px;
    }

    .provider-table td:first-child::before,
    .provider-table td[data-label="Actions"]::before {
        display: none;
    }

    .provider-table td[data-label="Actions"] {
        display: block;
        padding-top: 10px;
    }

    .provider-table th:nth-child(5),
    .provider-table td:nth-child(5) {
        display: grid;
    }

    .detail-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .brand-product {
        display: none;
    }

    .topbar-link {
        display: none;
    }

    .topbar-button {
        min-height: 34px;
        padding: 6px 9px;
    }

    .card,
    .auth-card {
        padding: 18px;
    }

    .page-actions .btn,
    .action-row .btn {
        flex: 1 1 auto;
    }

    .pagination {
        justify-content: space-between;
    }
}
