:root {
    --red: #e53935;
    --red-dark: #b71c1c;
    --orange: #ff8a00;
    --ink: #251817;
    --muted: #756463;
    --line: #f0d8d4;
    --paper: #fffaf7;
    --white: #ffffff;
    --green: #138a4a;
    --yellow: #a86700;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
    color: var(--ink);
    background: linear-gradient(180deg, #fff4ed 0%, #fffaf7 280px, #ffffff 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

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

.login-card {
    width: min(440px, 100%);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 24px 70px rgba(183, 28, 28, 0.12);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: 22px;
    min-width: 0;
}

.brand span:last-child {
    overflow-wrap: anywhere;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--white);
    background: linear-gradient(135deg, var(--red), var(--orange));
    font-weight: 900;
}

.shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 28px;
    background: rgba(255, 250, 247, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.nav a,
.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    min-height: 42px;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
}

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

.nav a.active,
.button.primary,
button.primary {
    color: var(--white);
    background: linear-gradient(135deg, var(--red), var(--orange));
}

.button.ghost {
    background: #fff0eb;
    color: var(--red-dark);
}

.container {
    max-width: 1220px;
    margin: 0 auto;
    padding: 28px;
    width: 100%;
}

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

h1 {
    margin: 0 0 8px;
    font-size: 32px;
    line-height: 1.1;
}

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

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.stat,
.panel,
.table-wrap {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 35px rgba(183, 28, 28, 0.07);
}

.stat {
    padding: 18px;
}

.stat strong {
    display: block;
    font-size: 30px;
    margin-bottom: 4px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.panel {
    padding: 18px;
}

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

.section-title h2 {
    margin: 0;
}

.form-row {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

label {
    font-weight: 800;
    font-size: 13px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    font: inherit;
    background: var(--white);
}

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

.inline {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.check-row {
    display: flex;
    gap: 16px;
    align-items: center;
}

.check-row label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.check-row input {
    width: auto;
}

.table-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
}

.table-tools form {
    display: flex;
    gap: 8px;
    flex: 1;
    max-width: 520px;
}

.call-filters form {
    max-width: 760px;
}

.export-actions {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
    table-layout: fixed;
}

.lead-table th:nth-child(1),
.lead-table td:nth-child(1) {
    width: 34%;
}

.lead-table th:nth-child(2),
.lead-table td:nth-child(2) {
    width: 22%;
}

.lead-table th:nth-child(3),
.lead-table td:nth-child(3) {
    width: 12%;
}

.lead-table th:nth-child(4),
.lead-table td:nth-child(4) {
    width: 16%;
}

.lead-table th:nth-child(5),
.lead-table td:nth-child(5) {
    width: 16%;
}

.call-table {
    min-width: 980px;
}

th,
td {
    text-align: left;
    padding: 13px 14px;
    border-bottom: 1px solid #f5e5e0;
    vertical-align: top;
    overflow-wrap: anywhere;
}

th {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #fff7f2;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    background: #fff0eb;
    color: var(--red-dark);
}

.badge.green {
    background: #e9f8ef;
    color: var(--green);
}

.badge.yellow {
    background: #fff5d8;
    color: var(--yellow);
}

.notice {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #e9f8ef;
    color: var(--green);
    font-weight: 700;
}

.error {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    background: #fff0eb;
    color: var(--red-dark);
    font-weight: 700;
}

.contact-results {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.contact-result {
    width: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    text-align: left;
    background: #fff8f4;
    border: 1px solid var(--line);
    color: var(--ink);
    white-space: normal;
}

.contact-result.selected {
    border-color: var(--red);
    background: #fff1e9;
    box-shadow: 0 0 0 2px rgba(229, 57, 53, 0.12);
}

.contact-check {
    min-width: 74px;
    padding: 6px 9px;
    border-radius: 999px;
    background: #fff0eb;
    color: var(--red-dark);
    font-size: 12px;
    font-weight: 900;
    text-align: center;
}

.contact-result.selected .contact-check {
    color: var(--white);
    background: linear-gradient(135deg, var(--red), var(--orange));
}

.selected-contact {
    display: none;
    margin-top: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff7f2;
    font-weight: 800;
}

.previous-call {
    display: none;
    margin-top: 8px;
    margin-bottom: 14px;
    padding: 12px;
    border: 1px solid #f6e2d8;
    border-radius: 8px;
    background: #fffaf2;
    color: var(--muted);
}

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

.callback-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px;
    border: 1px solid #f5e5e0;
    border-radius: 8px;
    background: #fffaf7;
}

.callback-meta {
    display: grid;
    gap: 6px;
    justify-items: end;
}

.empty-state {
    padding: 18px;
    border-radius: 8px;
    background: #fff8f4;
    color: var(--muted);
}

.lead-cell {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
}

.lead-cell > div {
    min-width: 0;
}

.lead-cell a.call-chip,
a.call-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 34px;
    min-height: 34px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid rgba(229, 57, 53, 0.24);
    background: linear-gradient(135deg, var(--red), var(--orange));
    color: var(--white);
    font-weight: 900;
    font-size: 13px;
    white-space: nowrap;
    box-shadow: 0 8px 18px rgba(229, 57, 53, 0.18);
}

.lead-cell a.call-chip:hover,
a.call-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(229, 57, 53, 0.24);
}

@media (max-width: 900px) {
    .topbar,
    .hero {
        align-items: flex-start;
        flex-direction: column;
    }

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

    .container {
        padding: 18px;
    }

    .nav {
        justify-content: flex-start;
        width: 100%;
    }

    .nav a {
        flex: 1 1 150px;
    }

    table {
        min-width: 760px;
    }

    .inline,
    .table-tools,
    .table-tools form {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .table-tools form,
    .call-filters form,
    .export-actions {
        max-width: none;
        width: 100%;
    }

    .export-actions {
        flex-direction: column;
    }

    .section-title,
    .callback-item {
        align-items: stretch;
        flex-direction: column;
    }

    .callback-meta {
        justify-items: start;
    }
}

@media (max-width: 760px) {
    body {
        background: #fffaf7;
    }

    .topbar {
        position: static;
        padding: 14px;
    }

    .brand {
        font-size: 18px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
        flex: 0 0 auto;
    }

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

    .nav a,
    .button,
    button {
        width: 100%;
        white-space: normal;
        min-width: 0;
    }

    .container {
        padding: 14px;
    }

    h1 {
        font-size: 28px;
    }

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

    .panel {
        padding: 14px;
    }

    .table-wrap {
        overflow: visible;
        border: 0;
        box-shadow: none;
        background: transparent;
    }

    table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0 12px;
        table-layout: auto;
    }

    thead {
        display: none;
    }

    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--white);
        box-shadow: 0 10px 28px rgba(183, 28, 28, 0.06);
        overflow: hidden;
    }

    td {
        display: grid;
        grid-template-columns: minmax(96px, 34%) minmax(0, 1fr);
        gap: 10px;
        padding: 11px 12px;
        border-bottom: 1px solid #f5e5e0;
        overflow-wrap: anywhere;
    }

    .lead-cell {
        flex-direction: column;
        gap: 10px;
    }

    .call-chip {
        width: 100%;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 800;
        font-size: 12px;
        text-transform: uppercase;
    }

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

    td[colspan] {
        display: block;
    }

    td[colspan]::before {
        content: '';
        display: none;
    }
}

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

    td {
        grid-template-columns: 1fr;
    }
}
