:root {
    color-scheme: light;
    --bg: #f3f6f7;
    --panel: #ffffff;
    --text: #182026;
    --muted: #66727c;
    --line: #d9e0e5;
    --accent: #0d6b57;
    --accent-dark: #095343;
    --blue: #9fcfe4;
    --blue-dark: #0078ad;
    --warm: #f2eee8;
    --shadow: 0 16px 40px rgba(25, 42, 54, 0.10);
    --error-bg: #fdecec;
    --error-text: #9a1c1c;
}

* {
    box-sizing: border-box;
}

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

.auth-panel {
    width: min(420px, calc(100% - 32px));
    margin: 10vh auto;
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

h1 {
    margin: 0 0 22px;
    font-size: 26px;
}

label {
    display: block;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--muted);
}

input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 16px;
    color: var(--text);
}

select,
textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    color: var(--text);
    background: #ffffff;
}

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

button,
.button {
    display: inline-block;
    width: 100%;
    padding: 12px 16px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: #ffffff;
    font-size: 16px;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

button.secondary-button,
.secondary-button {
    width: auto;
    align-self: flex-start;
    padding: 10px 12px;
    border: 1px solid rgba(0, 120, 173, 0.36);
    background: #ffffff;
    color: var(--blue-dark);
    font-size: 14px;
}

button.secondary-button:hover,
.secondary-button:hover {
    background: #eef8fb;
}

.danger-button {
    width: auto;
    padding: 10px 12px;
    border: 1px solid #efb4b4;
    background: #fff5f5;
    color: #9a1c1c;
    font-size: 14px;
}

button:hover,
.button:hover {
    background: var(--accent-dark);
}

.error {
    padding: 12px;
    border-radius: 6px;
    background: var(--error-bg);
    color: var(--error-text);
}

.notice {
    padding: 12px;
    border-radius: 6px;
    background: #e9f8ef;
    color: #14532d;
    border: 1px solid #9bd5ad;
}

.muted {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.debug {
    white-space: pre-wrap;
    overflow: auto;
    font-family: Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.45;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.app-shell-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 18px 28px;
    background: linear-gradient(90deg, var(--blue), #c9e3ee);
    color: #123241;
    border-bottom: 1px solid rgba(0, 120, 173, 0.18);
}

.brand-block,
.user-block {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border: 1px solid rgba(0, 120, 173, 0.42);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.52);
    color: var(--blue-dark);
    font-weight: 700;
}

.brand-block strong {
    display: block;
    font-size: 18px;
}

.brand-block span,
.user-block span {
    color: rgba(18, 50, 65, 0.72);
    font-size: 14px;
}

.user-block a {
    padding: 9px 12px;
    border: 1px solid rgba(0, 120, 173, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.52);
    color: #064760;
    text-decoration: none;
    font-size: 14px;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.nav-links a {
    padding: 9px 12px;
    border: 1px solid rgba(0, 120, 173, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.52);
    color: #064760;
    text-decoration: none;
    font-size: 14px;
}

.contacts-page {
    width: min(1440px, calc(100% - 36px));
    margin: 0 auto;
    padding: 28px 0 44px;
}

.contacts-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--blue-dark);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.contacts-hero h1 {
    margin: 0;
    font-size: 34px;
}

.metric-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(96px, 1fr));
    gap: 10px;
}

.metric-strip div {
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 24px rgba(25, 42, 54, 0.06);
}

.metric-strip span {
    display: block;
    font-size: 24px;
    font-weight: 700;
}

.metric-strip small {
    color: var(--muted);
}

.search-panel,
.toolbar-panel {
    display: grid;
    gap: 14px;
    margin-bottom: 22px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 28px rgba(25, 42, 54, 0.07);
}

.toolbar-panel {
    grid-template-columns: 1fr;
}

.filter-grid {
    display: grid;
    grid-template-columns: minmax(260px, 2fr) repeat(3, minmax(170px, 1fr));
    gap: 14px;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.search-form {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 140px;
    gap: 14px;
    align-items: end;
    width: 100%;
}

.search-form label {
    margin: 0;
}

.form-panel {
    margin-bottom: 24px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 28px rgba(25, 42, 54, 0.07);
}

.form-panel h2 {
    margin-top: 0;
}

.form-panel h3 {
    margin: 18px 0 10px;
    font-size: 17px;
}

.form-panel h4 {
    grid-column: 1 / -1;
    margin: 16px 0 0;
    font-size: 15px;
    color: var(--blue-dark);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 14px;
}

.form-actions {
    margin-top: 16px;
}

.form-grid.compact {
    align-items: end;
}

.signup-link-form label {
    margin-bottom: 0;
}

.signup-link-form button {
    align-self: end;
    min-height: 45px;
}

.secondary-link {
    width: auto;
    margin-top: 12px;
    background: #ffffff;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.text-button {
    width: auto;
    padding: 0;
    background: transparent;
    color: var(--accent);
    font-size: 14px;
    text-decoration: underline;
}

.text-button:hover {
    background: transparent;
    color: var(--accent-dark);
}

.action-cell {
    display: flex;
    gap: 12px;
    align-items: center;
}

.admin-grid,
.role-grid,
.admin-check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin: 18px 0 26px;
}

.admin-tile,
.role-card {
    display: block;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    text-decoration: none;
    box-shadow: 0 12px 28px rgba(25, 42, 54, 0.07);
}

.admin-tile strong,
.admin-tile span {
    display: block;
}

.admin-tile span {
    margin-top: 8px;
    color: var(--muted);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    color: var(--text);
}

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

.search-panel label {
    margin: 0;
    color: #3d4b55;
    font-weight: 700;
}

.search-panel input {
    background: #fbfcfd;
}

.contact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 16px;
}

.contact-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 220px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 14px 32px rgba(25, 42, 54, 0.08);
    animation: cardIn 220ms ease-out both;
    animation-delay: var(--delay);
}

.contact-card[hidden] {
    display: none;
}

.card-select-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.select-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.select-check input {
    width: auto;
    margin: 0;
}

.card-id {
    color: var(--muted);
    font-size: 12px;
}

.contact-card:hover {
    border-color: rgba(0, 120, 173, 0.45);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.contact-card-main {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 12px;
    align-items: center;
}

.avatar {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background: #e4f2f7;
    color: var(--blue-dark);
    font-weight: 700;
}

.contact-card h3 {
    margin: 0 0 4px;
    font-size: 18px;
    line-height: 1.25;
}

.contact-card p {
    margin: 0;
    color: var(--muted);
    line-height: 1.35;
}

.contact-meta {
    display: grid;
    gap: 7px;
    color: #33434d;
    font-size: 14px;
}

.contact-meta span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
}

.chip {
    max-width: 100%;
    padding: 6px 9px;
    border-radius: 999px;
    background: var(--warm);
    color: #51463c;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.chip.strong {
    background: #e1f2ec;
    color: var(--accent-dark);
}

.chip.alert {
    background: #fff4d6;
    color: #8a5a00;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.inline-edit {
    margin-top: 4px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.contact-edit-form h4 {
    margin: 14px 0 8px;
    color: var(--blue-dark);
    font-size: 15px;
}

.empty-state {
    padding: 22px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.7);
    color: var(--muted);
    text-align: center;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(13, 27, 34, 0.48);
}

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

.contact-modal {
    width: min(980px, 100%);
    max-height: min(760px, calc(100vh - 44px));
    overflow: auto;
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 26px 80px rgba(0, 0, 0, 0.24);
}

.export-modal {
    width: min(860px, 100%);
}

.export-form {
    padding: 22px;
}

.export-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.export-format-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin: 0 0 16px;
}

.export-field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 6px 14px;
    margin-bottom: 18px;
}

.edit-modal {
    width: min(1040px, 100%);
}

.modal-edit-body {
    background: #ffffff;
}

.permission-override-panel {
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.permission-override-panel h3 {
    margin: 0 0 6px;
}

.permission-override-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.form-tabs {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    gap: 8px;
    padding: 14px 22px 0;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff, #f7fafb);
    overflow-x: auto;
}

.form-tab-button {
    width: auto;
    min-width: 110px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
    background: #f6f8f9;
    color: #42535e;
    font-size: 14px;
    white-space: nowrap;
}

.form-tab-button.active,
.form-tab-button:hover {
    background: #ffffff;
    color: var(--blue-dark);
}

.form-tab-panel {
    display: none;
    padding: 18px 22px 8px;
}

.form-tab-panel.active {
    display: block;
}

.tabbed-form .form-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: flex;
    justify-content: flex-end;
    padding: 14px 22px;
    border-top: 1px solid var(--line);
    background: #ffffff;
    box-shadow: 0 -12px 24px rgba(25, 42, 54, 0.08);
}

.tabbed-form .form-actions button {
    width: auto;
}

.relationships-panel {
    padding: 18px 22px 24px;
    border-top: 1px solid var(--line);
    background: #fbfcfd;
}

.relationships-panel h3 {
    margin: 0 0 12px;
}

.relationship-list {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.relationship-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.relationship-item strong,
.relationship-item span {
    display: block;
}

.relationship-item span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.relationship-form {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.contact-modal header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 22px;
    border-bottom: 1px solid rgba(0, 120, 173, 0.18);
    background: linear-gradient(90deg, #f9fbfc, #eaf5f9);
}

.contact-modal h2 {
    margin: 0;
    font-size: 24px;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font-size: 20px;
}

.modal-content {
    display: block;
    min-height: 280px;
    background: #ffffff;
}

.modal-tabs {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 14px 22px 0;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff, #f7fafb);
    overflow-x: auto;
}

.tab-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 104px;
    height: 42px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px 8px 0 0;
    background: #f6f8f9;
    color: #42535e;
    font-size: 14px;
    white-space: nowrap;
    box-shadow: none;
}

.tab-button:hover,
.tab-button.active {
    background: #ffffff;
    color: var(--blue-dark);
}

.tab-button.active {
    border-bottom-color: #ffffff;
    box-shadow: 0 -4px 16px rgba(0, 120, 173, 0.08);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.modal-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
    padding: 22px;
    background:
        linear-gradient(90deg, rgba(159, 207, 228, 0.18), transparent 36%),
        #ffffff;
}

.modal-field {
    min-width: 0;
    padding: 12px;
    border: 1px solid rgba(0, 120, 173, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: 0 8px 20px rgba(25, 42, 54, 0.05);
}

.modal-field span {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 12px;
}

.modal-field strong {
    display: block;
    color: var(--text);
    font-size: 14px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 880px) {
    .app-shell-header,
    .contacts-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .user-block {
        width: 100%;
        justify-content: space-between;
    }

    .search-panel {
        grid-template-columns: 1fr;
    }

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

@media (max-width: 560px) {
    .contacts-page {
        width: min(100% - 24px, 1440px);
        padding-top: 18px;
    }

    .contacts-hero h1 {
        font-size: 28px;
    }

    .metric-strip {
        width: 100%;
    }

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

.topbar span {
    margin-left: 12px;
    color: var(--muted);
}

.topbar a {
    color: var(--accent);
    text-decoration: none;
}

.list-page {
    padding: 24px;
}

.help-page {
    width: min(1180px, calc(100% - 36px));
    margin: 0 auto;
    padding: 30px 0 50px;
}

.help-hero {
    padding: 24px 0 18px;
}

.help-hero h1 {
    margin-bottom: 10px;
    font-size: 34px;
}

.help-hero p {
    max-width: 760px;
    color: var(--muted);
    line-height: 1.55;
}

.help-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin: 20px 0 34px;
}

.help-section,
.faq-item {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 28px rgba(25, 42, 54, 0.06);
}

.help-section h2 {
    margin: 0 0 10px;
    font-size: 18px;
}

.help-section p,
.faq-item p {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.section-heading h2 {
    margin-top: 0;
}

.faq-section {
    display: grid;
    gap: 12px;
}

.faq-item summary {
    cursor: pointer;
    font-weight: 700;
}

.faq-item p {
    margin-top: 12px;
}

.faq-admin-list {
    display: grid;
    gap: 14px;
}

.table-wrap {
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.mapping-table table {
    min-width: 760px;
}

.mapping-table select {
    min-width: 240px;
}

.audit-details {
    max-width: 520px;
    max-height: 180px;
    margin: 0;
    overflow: auto;
    white-space: pre-wrap;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
}

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

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}

th {
    position: sticky;
    top: 0;
    background: #eef3f2;
    color: #243039;
    font-weight: 700;
}
