:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-muted: #f0f4f8;
    --border: #d8e0ea;
    --border-strong: #b6c3d1;
    --text: #17202a;
    --muted: #607083;
    --primary: #165d59;
    --primary-strong: #104642;
    --accent: #b7791f;
    --danger: #b42318;
    --success: #1f7a4d;
    --info: #285f9f;
    --shadow: 0 12px 34px rgba(23, 32, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

a {
    color: var(--primary);
    font-weight: 700;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

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

.admin-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    grid-template-rows: 72px 1fr;
}

.admin-shell-simple {
    display: block;
    min-height: auto;
}

.admin-topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.admin-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-logo {
    display: block;
    width: auto;
    max-width: 150px;
    height: 34px;
    object-fit: contain;
}

.admin-brand-mark,
.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
    font-size: 13px;
}

.admin-brand strong {
    display: block;
    color: var(--text);
    font-size: 16px;
}

.admin-brand span,
.admin-user small,
.eyebrow {
    color: var(--muted);
    font-size: 12px;
}

.admin-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 0;
}

.admin-user span {
    font-weight: 700;
}

.admin-sidebar {
    padding: 22px 16px;
    border-right: 1px solid var(--border);
    background: #fbfcfe;
}

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

.admin-sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}

.admin-sidebar a:hover,
.admin-sidebar a.is-active {
    background: var(--surface-muted);
}

.admin-sidebar a.is-active {
    box-shadow: inset 3px 0 0 var(--primary);
}

.nav-icon {
    width: 28px;
    height: 28px;
    background: #d9e9e6;
    color: var(--primary-strong);
    font-size: 10px;
}

.admin-content {
    padding: 32px;
    max-width: 1180px;
    width: 100%;
}

.page-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 22px;
}

.page-header h1,
.admin-content h1 {
    margin: 0;
    color: var(--text);
    font-size: 28px;
    line-height: 1.2;
}

.page-header p,
.admin-content > p {
    margin: 8px 0 0;
    color: var(--muted);
}

.metric-grid,
.detail-grid,
.action-grid {
    display: grid;
    gap: 16px;
}

.metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 22px 0;
}

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

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

.metric-card,
.admin-panel,
.empty-state-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric-card {
    padding: 18px;
}

.metric-card span,
.field-label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.metric-card strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
    line-height: 1.1;
}

.admin-panel,
.empty-state-panel {
    padding: 20px;
    margin-top: 18px;
}

.admin-panel h2 {
    margin: 0 0 14px;
    font-size: 18px;
}

.admin-panel p {
    color: var(--muted);
}

.field-list {
    display: grid;
    gap: 12px;
    margin: 0;
}

.field-list dd {
    margin-left: 0;
}

.field-list div {
    min-width: 0;
}

.field-value {
    display: block;
    margin-top: 3px;
    overflow-wrap: anywhere;
    font-weight: 700;
}

.table-wrap {
    overflow-x: auto;
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.admin-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 760px;
}

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

.admin-table th {
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

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

.admin-table small {
    color: var(--muted);
}

.admin-actions,
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 18px 0;
}

.admin-actions a,
.admin-actions button,
.button-link,
.filter-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    cursor: pointer;
    font-weight: 700;
    padding: 8px 12px;
    text-decoration: none;
    white-space: nowrap;
}

.admin-actions button {
    font-family: inherit;
}

.admin-actions a.secondary,
.admin-actions button.secondary,
.filter-chip {
    background: var(--surface);
    color: var(--primary);
}

.filter-chip.is-active {
    background: var(--primary);
    color: #ffffff;
}

.lead-search-panel {
    margin-bottom: 16px;
}

.lead-search-panel .admin-actions {
    margin-bottom: 0;
}

.lead-list-summary {
    color: var(--muted);
    margin: 12px 0 0;
}

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

.pagination a,
.pagination span {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
    padding: 8px 12px;
    text-decoration: none;
}

.pagination a {
    border-color: var(--primary);
    color: var(--primary);
}

.pagination a.is-disabled {
    border-color: var(--border);
    color: var(--muted);
    pointer-events: none;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 4px 10px;
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.status-new,
.status-documents_uploaded {
    background: #e8f1ff;
    color: var(--info);
}

.status-reviewed,
.status-pdf_generated,
.status-zip_generated {
    background: #fff3da;
    color: var(--accent);
}

.status-email_sent,
.status-resent,
.status-converted {
    background: #e3f6ed;
    color: var(--success);
}

.status-email_failed,
.status-rejected,
.status-invalid,
.status-duplicate {
    background: #fde8e5;
    color: var(--danger);
}

.flash-message {
    border: 1px solid var(--border-strong);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    background: var(--surface);
    margin: 0 0 18px;
    padding: 12px 14px;
}

.admin-alert-modal {
    align-items: center;
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 24px;
    position: fixed;
    z-index: 80;
}

.admin-alert-modal.is-hidden {
    display: none;
}

.admin-alert-backdrop {
    background: rgba(23, 32, 42, 0.38);
    inset: 0;
    position: absolute;
}

.admin-alert-card {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(23, 32, 42, 0.22);
    display: flex;
    flex-direction: column;
    max-width: 420px;
    padding: 28px;
    position: relative;
    text-align: center;
    width: min(100%, 420px);
}

.admin-alert-icon {
    align-items: center;
    background: #e3f6ed;
    border: 1px solid #9fdfbd;
    border-radius: 999px;
    color: var(--success);
    display: inline-flex;
    font-size: 12px;
    font-weight: 900;
    height: 56px;
    justify-content: center;
    margin-bottom: 14px;
    width: 56px;
}

.admin-alert-card h2 {
    margin: 0;
}

.admin-alert-card p {
    color: var(--muted);
    margin: 10px 0 20px;
}

.admin-alert-card button {
    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 8px;
    color: #ffffff;
    cursor: pointer;
    font-weight: 800;
    min-height: 40px;
    min-width: 110px;
    padding: 8px 14px;
}

.sensitive-panel {
    border-color: #e7c985;
    background: #fffdf7;
}

.action-panel {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 190px;
}

.action-panel p {
    margin-bottom: 0;
}

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

.form-row {
    display: grid;
    gap: 8px;
    margin-top: 16px;
}

.form-row label {
    color: var(--text);
    font-weight: 700;
}

.form-row input,
.form-row select,
.form-row textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    padding: 11px 12px;
}

.password-field {
    position: relative;
}

.password-field input {
    padding-right: 48px;
}

.password-toggle {
    align-items: center;
    appearance: none;
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    height: 38px;
    justify-content: center;
    min-height: 0;
    padding: 0;
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
}

.password-toggle:hover,
.password-toggle:focus {
    background: var(--surface-muted);
    outline: 0;
}

.password-toggle-icon {
    border: 2px solid var(--muted);
    border-radius: 999px / 760px;
    display: inline-block;
    height: 14px;
    position: relative;
    width: 22px;
}

.password-toggle-icon::before {
    background: var(--muted);
    border-radius: 999px;
    content: "";
    height: 6px;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
}

.password-toggle[aria-pressed="true"] .password-toggle-icon::after {
    background: var(--danger);
    border-radius: 999px;
    content: "";
    height: 2px;
    left: -4px;
    position: absolute;
    top: 5px;
    transform: rotate(-42deg);
    width: 30px;
}

.form-row textarea {
    min-height: 120px;
    resize: vertical;
}

.checkbox-row {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-muted);
    padding: 12px;
    margin-top: 16px;
}

.checkbox-row input {
    margin-top: 5px;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg);
}

.login-card {
    width: min(100%, 430px);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 28px;
}

.login-card h1 {
    margin: 28px 0 6px;
    font-size: 28px;
}

.login-card .brand-logo {
    height: 42px;
    max-width: 190px;
}

.login-card .admin-actions {
    margin-bottom: 0;
}

@media (max-width: 980px) {
    .admin-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
    }

    .admin-sidebar {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

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

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

@media (max-width: 680px) {
    .admin-topbar,
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .admin-user {
        align-items: flex-start;
    }

    .admin-content {
        padding: 22px 16px;
    }

    .admin-sidebar nav,
    .metric-grid,
    .detail-grid,
    .action-grid {
        grid-template-columns: 1fr;
    }

    .admin-sidebar a {
        min-height: 40px;
    }
}
