:root {
    color-scheme: light;
    font-family: "Segoe UI", "Nirmala UI", system-ui, sans-serif;
    color: #142e29;
    background: #f3f7f5;
    --ink: #142e29;
    --muted: #506762;
    --paper: #fff;
    --surface: #f7faf8;
    --border: #dce6e1;
    --control-border: #a5b9b0;
    --brand: #146653;
    --brand-hover: #0d5142;
    --brand-light: #e8f5ee;
    --nav: #102f29;
    --focus: #237b66;
    --danger: #a42b38;
    --danger-light: #fceef0;
    --radius: 14px;
    --shadow: 0 1px 2px #102f290a, 0 8px 24px #102f2907;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
a { color: var(--brand); text-underline-offset: .2em; }
button, summary, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .62; }
form[data-submitting] button:disabled { cursor: wait; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(2rem, 4vw, 2.85rem); font-weight: 730; letter-spacing: -.045em; line-height: 1.12; }
h2 { font-size: 1.15rem; line-height: 1.3; letter-spacing: -.015em; }
h3 { font-size: 1.15rem; line-height: 1.3; }
.muted, .page-heading p, .section-heading p { color: var(--muted); }

.skip-link { position: fixed; z-index: 9; top: 8px; left: 8px; transform: translateY(-150%); padding: 8px 12px; background: var(--paper); }
.skip-link:focus { transform: none; }
.topbar { background: var(--nav); color: #fff; }
.topbar-inner { display: flex; align-items: center; gap: 38px; width: min(100% - 64px, 1320px); margin: auto; min-height: 66px; }
.topbar a, .topbar button { text-decoration: none; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-size: 1.2rem; font-weight: 750; letter-spacing: -.03em; }
.brand-mark { display: inline-block; position: relative; width: 27px; aspect-ratio: 1; border-radius: 8px; background: #a9eabe; flex: none; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: var(--nav); border-radius: 2px; }
.brand-mark::before { inset: 26% 24% 60% 25%; box-shadow: 0 6px var(--nav), 0 12px var(--nav); width: 38%; }
.brand-mark::after { width: 13%; height: 14%; top: 26%; right: 17%; }
.brand-mark-large { width: 38px; border-radius: 11px; }
.brand-mark-large::before { box-shadow: 0 8px var(--nav), 0 16px var(--nav); }
.topbar nav { display: flex; align-items: center; gap: 5px; }
.topbar nav a, .sign-out button {
    display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px; border: 0;
    border-radius: 8px; color: #d7e8e0; background: transparent; font-size: .9rem; font-weight: 620;
}
.topbar nav a:hover, .topbar nav a[aria-current], .sign-out button:hover { background: #25463d; color: #fff; }
.topbar :focus-visible { outline-color: #a9eabe; }
.sign-out { margin-left: auto; }
.sign-out button { border: 1px solid #53756a; white-space: nowrap; }
.shell { width: min(100% - 64px, 1320px); margin: auto; padding: 37px 0 64px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 0 0 24px; }
.page-heading > div { min-width: 0; }
.page-heading p { margin-top: 8px; overflow-wrap: anywhere; }
.panel { background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }

.button {
    display: inline-flex; gap: 8px; align-items: center; justify-content: center; min-height: 42px;
    padding: 8px 15px; border: 1px solid transparent; border-radius: 9px; text-decoration: none;
    font-size: .9rem; font-weight: 660; line-height: 1.25; white-space: nowrap;
}
.button-primary { color: #fff; background: var(--brand); }
.button-primary:hover:not(:disabled) { background: var(--brand-hover); }
.button-secondary { color: var(--ink); border-color: var(--control-border); background: var(--paper); }
.button-secondary:hover { background: var(--brand-light); border-color: var(--brand); }
.button-quiet { color: var(--brand); background: transparent; }
.button-quiet:hover { background: var(--brand-light); }
.button-danger { color: #fff; background: var(--danger); }
.button-danger:hover { background: #86202b; }
.upload-mark { font-size: 1.2rem; line-height: 1; }
.notice { padding: 11px 14px; border-radius: 8px; margin-bottom: 15px; font-size: .92rem; }
.notice ul { margin: 0; padding-left: 18px; }
.notice-success { color: #145744; background: var(--brand-light); border: 1px solid #b8decb; }
.notice-error { color: var(--danger); background: var(--danger-light); border: 1px solid #ecc2cb; }
.validation-summary-valid, .field-validation-valid { display: none; }

.status-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 22px; }
.status-card {
    display: grid; gap: 6px; padding: 12px 16px; border: 1px solid var(--border); border-radius: 12px;
    background: var(--paper); color: var(--ink); text-decoration: none;
}
.status-card:hover { border-color: var(--focus); }
.status-card.is-active { background: var(--brand-light); border-color: #72ac94; box-shadow: inset 0 -2px #65a78c; }
.status-card strong { font-size: 1.52rem; line-height: 1.16; font-weight: 730; font-variant-numeric: tabular-nums; }
.status-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .83rem; font-weight: 650; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tone, #6c817b); flex: none; }
.tone-all { --tone: #156653; }
.tone-none { --tone: #64766f; --tint: #f3f6f4; }
.tone-knocked { --tone: #345c98; --tint: #eef4ff; }
.tone-running { --tone: #805400; --tint: #fff5db; }
.tone-win { --tone: #146653; --tint: #e6f5eb; }
.tone-cancelled { --tone: #9e2a39; --tint: #fceef0; }

.filter-bar { display: grid; grid-template-columns: minmax(104px, .7fr) minmax(120px, 1fr) minmax(154px, 1.25fr) auto; gap: 12px; align-items: end; padding: 16px 20px; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; border-bottom: 1px solid var(--border); }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; min-width: 0; }
.field label { color: var(--ink); font-size: .86rem; font-weight: 670; }
.field :is(input:not([type=file]), select, textarea), .mapping-row select, .status-select {
    width: 100%; min-width: 0; min-height: 42px; border: 1px solid var(--control-border);
    border-radius: 8px; padding: 8px 10px; color: var(--ink); background: var(--paper);
}
.field input::placeholder { color: #5c716b; opacity: 1; }
.field textarea { resize: vertical; }
.field-error { color: var(--danger); font-size: .86rem; }
.input-validation-error { border-color: var(--danger) !important; }
.filter-actions, .form-actions, .message-actions, .row-actions, .contact-line { display: flex; align-items: center; gap: 8px; }
.filter-actions, .form-actions, .row-actions, .contact-line { flex-wrap: wrap; }
.list-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; }
.list-heading > span { color: var(--muted); font-size: .86rem; white-space: nowrap; }
.lead-table, .preview-table { width: 100%; border-collapse: collapse; }
.lead-table th, .preview-table thead th {
    padding: 10px 12px; color: var(--muted); background: var(--surface); border-block: 1px solid var(--border);
    font-size: .78rem; font-weight: 700; text-align: left; white-space: nowrap;
}
.lead-table :is(th, td):first-child { padding-left: 20px; }
.lead-table :is(th, td):last-child { padding-right: 20px; }
.lead-table td { padding: 12px; border-top: 1px solid var(--border); vertical-align: middle; font-size: .9rem; }
.lead-table tbody tr:hover, .lead-table tbody tr:target { background: #f8fbf9; }
.lead-table tbody tr { scroll-margin-top: 12px; }
.number-cell, .phone-value, .pagination { font-variant-numeric: tabular-nums; }
.lead-table .number-cell { color: var(--muted); overflow-wrap: anywhere; min-width: 55px; max-width: 100px; }
.business-cell { width: 31%; }
.business-cell strong { overflow-wrap: anywhere; font-size: .95rem; }
.business-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 7px; margin-top: 3px; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.category-label { color: #245746; background: #edf5ef; border-radius: 5px; padding: 1px 6px; }
.phone-cell { width: 25%; }
.phone-value { font-weight: 600; overflow-wrap: anywhere; }
.mini-button, .message-preview summary {
    display: inline-flex; justify-content: center; align-items: center; min-height: 34px; padding: 4px 9px;
    border: 1px solid var(--border); border-radius: 7px; font-size: .78rem; line-height: 1.3;
    font-weight: 680; color: var(--brand); background: var(--paper); text-decoration: none; white-space: nowrap;
}
.mini-button:hover, .message-preview summary:hover { border-color: #8fbaa9; background: var(--brand-light); }
.delete-link { color: var(--danger); }
.delete-link:hover { border-color: #e9b1ba; background: var(--danger-light); }
.message-preview { position: relative; }
.message-preview summary { list-style: none; }
.message-preview summary::-webkit-details-marker { display: none; }
.message-preview[open] summary { background: var(--brand-light); border-color: var(--brand); }
.message-body {
    position: absolute; z-index: 3; top: calc(100% + 8px); right: 0; width: min(420px, 82vw);
    max-height: 280px; overflow: auto; padding: 14px; border: 1px solid var(--control-border);
    border-radius: 10px; box-shadow: 0 9px 28px #102f2924; background: var(--paper);
    white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6;
}
.status-select { width: 112px; min-height: 36px; padding: 5px 8px; color: var(--tone); background: var(--tint); font-size: .84rem; font-weight: 680; }
.status-select option { color: var(--ink); background: var(--paper); }
.mobile-label { display: none; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: .87rem; }
.pagination > div { display: flex; gap: 8px; }
.empty-state { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 46px 16px 54px; border-top: 1px solid var(--border); }
.empty-state p { color: var(--muted); }
.empty-state .button { margin-top: 5px; }
.empty-mark { width: 54px; height: 54px; display: grid; align-content: center; justify-items: center; gap: 4px; background: var(--brand-light); border: 1px solid #cee8d9; border-radius: 13px; }
.empty-mark i { width: 22px; height: 2px; background: var(--brand); border-radius: 2px; }
.empty-mark i:last-child { width: 14px; justify-self: start; margin-left: 15px; }

.back-link { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 16px; font-size: .9rem; font-weight: 650; }
.editor-panel, .upload-panel, .error-page { max-width: 820px; padding: clamp(16px, 3vw, 26px); }
.editor-panel > h2 { margin-bottom: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.field-full { grid-column: 1 / -1; }
.edit-extras { margin-top: 18px; padding: 12px 0; border-block: 1px solid var(--border); }
.edit-extras summary { font-weight: 660; }
.edit-extras .form-grid { margin-top: 12px; }
.form-actions { margin-top: 18px; }
.delete-panel { max-width: 570px; }
.delete-panel h1, .error-page h1 { font-size: clamp(1.75rem, 4vw, 2.2rem); }
.delete-panel > p, .error-page p { margin: 8px 0 16px; color: var(--muted); }
.delete-record { display: grid; gap: 3px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow-wrap: anywhere; }
.delete-record span { color: var(--muted); }

.upload-panel { max-width: 690px; }
.upload-field { display: grid; justify-items: center; gap: 7px; padding: 26px 14px; text-align: center; border: 1px dashed #79a895; border-radius: 10px; background: var(--surface); }
.upload-field > span:not(.file-mark) { color: var(--muted); font-size: .88rem; }
.upload-field input { max-width: 100%; margin-top: 8px; font-size: .88rem; }
.upload-field input::file-selector-button { min-height: 36px; margin-right: 8px; border: 1px solid var(--control-border); border-radius: 7px; padding: 5px 10px; color: var(--ink); background: var(--paper); cursor: pointer; }
.file-mark { width: 38px; height: 38px; display: inline-grid; place-items: center; flex: none; border-radius: 10px; color: var(--brand); background: var(--brand-light); font-size: 1.25rem; font-weight: 680; }
.workbook-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 18px; padding: 16px 20px; margin-bottom: 16px; }
.workbook-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.workbook-title h2 { font-size: 1rem; overflow-wrap: anywhere; }
.workbook-title p { margin-top: 3px; color: var(--muted); font-size: .87rem; }
.layout-form { display: grid; grid-template-columns: minmax(115px, 1fr) 90px auto; align-items: end; gap: 10px; }
.mapping-panel, .preview-panel { margin-bottom: 16px; }
.section-heading { padding: 16px 20px; }
.section-heading p { margin-top: 5px; font-size: .89rem; }
.mapping-headers, .mapping-row { display: grid; grid-template-columns: minmax(160px, .8fr) minmax(220px, 1fr) minmax(0, 1.3fr); align-items: center; gap: 16px; padding: 8px 20px; border-top: 1px solid var(--border); }
.mapping-headers { color: var(--muted); background: var(--surface); font-size: .8rem; font-weight: 680; }
.mapping-row label { font-weight: 650; font-size: .89rem; }
.mapping-row select { text-overflow: ellipsis; }
.mapping-example { font-size: .88rem; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.preview-table-wrap { overflow: auto; }
.preview-table th, .preview-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.preview-table tbody th { color: var(--muted); font-size: .82rem; }
.preview-table td { min-width: 112px; max-width: 250px; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-import { padding: 0 20px 16px; }

.shell-guest { display: grid; align-items: start; justify-items: center; padding-top: clamp(36px, 10vh, 96px); }
.login-panel { width: min(100%, 460px); background: var(--paper); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.login-intro { padding: 26px 26px 23px; background: var(--nav); color: #fff; }
.login-intro h1 { font-size: clamp(1.65rem, 5vw, 2.1rem); margin-top: 12px; }
.login-intro p { margin-top: 7px; font-size: .96rem; color: #d7e8e0; }
.login-form { display: grid; gap: 15px; padding: 24px 26px 26px; }
.login-form .notice { margin: 0; }
.login-form .button { justify-content: space-between; margin-top: 3px; }
.toast { position: fixed; z-index: 5; bottom: 22px; right: 22px; max-width: calc(100vw - 44px); padding: 9px 14px; border-radius: 9px; background: var(--nav); color: #fff; box-shadow: var(--shadow); opacity: 0; pointer-events: none; }
.toast.is-visible { opacity: 1; }
.copy-buffer { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

@media (max-width: 930px) {
    .topbar-inner, .shell { width: calc(100% - 40px); }
    .lead-table .mini-button, .message-preview summary { padding-inline: 7px; }
    .lead-table :is(th, td) { padding-inline: 8px; }
    .lead-table :is(th, td):first-child { padding-left: 14px; }
    .lead-table :is(th, td):last-child { padding-right: 14px; }
    .workbook-panel { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
    .topbar-inner, .shell { width: calc(100% - 32px); }
    .shell { padding-top: 26px; }
    .topbar-inner { gap: 12px; min-height: 58px; }
    .topbar nav { gap: 1px; }
    .topbar nav a, .sign-out button { padding-inline: 8px; font-size: .83rem; }
    .status-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
    .status-card { padding: 8px 10px; }
    .status-card strong { font-size: 1.3rem; }
    .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 10px; }
    .list-heading { padding: 13px 12px; }
    .lead-table, .lead-table tbody { display: block; }
    .lead-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .lead-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 12px; border-top: 1px solid var(--border); padding: 12px; }
    .lead-table :is(td, td:first-child, td:last-child) { border: 0; padding: 0; width: auto; }
    .lead-table .number-cell { grid-column: 2; grid-row: 1; justify-self: end; min-width: 0; max-width: 100%; text-align: right; }
    .business-cell { grid-column: 1; grid-row: 1; }
    .mobile-label { display: block; color: var(--muted); font-size: .76rem; margin-bottom: 3px; }
    .message-actions { flex-wrap: wrap; }
    .message-cell:has(.message-preview[open]) { grid-column: 1 / -1; grid-row: 3; }
    .message-cell:has(.message-preview[open]) .message-actions { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; }
    .actions-cell { align-self: end; }
    .lead-table .mini-button, .message-preview summary, .status-select { min-height: 44px; }
    .message-body { position: static; width: 100%; max-height: 220px; margin-top: 8px; box-shadow: none; }
    .mapping-headers, .mapping-row { grid-template-columns: minmax(128px, .8fr) minmax(0, 1.25fr); gap: 6px 10px; padding-inline: 13px; }
    .mapping-headers span:last-child { display: none; }
    .mapping-example { grid-column: 2; }
}

@media (max-width: 420px) {
    .page-heading { align-items: start; flex-wrap: wrap; }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .filter-actions { gap: 4px; }
    .filter-actions .button { padding-inline: 9px; }
    .layout-form { grid-template-columns: minmax(0, 1fr) 84px; }
    .layout-form .button { grid-column: 1 / -1; justify-self: start; }
    .status-label { font-size: .78rem; gap: 5px; }
    .login-intro, .login-form { padding-inline: 19px; }
}

@media (max-width: 350px) {
    .topbar-inner { width: calc(100% - 24px); gap: 8px; }
    .topbar nav a, .sign-out button { padding-inline: 6px; }
}
