:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --surface-soft: #eef3f5;
    --border: #d9e1e5;
    --text: #1f2933;
    --muted: #667986;
    --green: #108463;
    --green-dark: #0b6f52;
    --green-soft: #e7f6ef;
    --amber: #a35c00;
    --amber-soft: #fff4df;
    --red: #b42318;
    --red-soft: #fff0ef;
    --shadow: 0 12px 30px rgba(31, 41, 51, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    width: min(1440px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 40px;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(28px, 3vw, 42px);
    line-height: 1.05;
}

.source-path {
    max-width: 46%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    max-width: 60%;
}

.notice {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.notice.error {
    border-color: #f3b7b2;
    background: var(--red-soft);
    color: var(--red);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric {
    min-height: 92px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

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

.metric strong {
    display: block;
    font-size: 32px;
    line-height: 1;
}

.filters {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 220px auto auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.filters label {
    display: grid;
    gap: 6px;
}

.filters span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.filters input,
.filters select {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}

.filters button,
.button-link,
.secondary-link,
.pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 16px;
    border-radius: 6px;
    border: 1px solid var(--green);
    background: var(--green);
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.button-link {
    white-space: nowrap;
}

.warning-link {
    border-color: var(--amber);
    background: var(--amber);
}

.secondary-link {
    border-color: var(--border);
    background: var(--surface-soft);
    color: var(--text);
}

.table-panel {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-summary {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
}

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

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

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

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

td strong,
td small {
    display: block;
}

td small,
.muted {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

tr.is-sent {
    background: #fbfffd;
}

tr.is-removing {
    opacity: 0;
    transform: translateX(12px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.status-pill.sent {
    background: var(--green-soft);
    color: var(--green-dark);
}

.status-pill.pending {
    background: var(--amber-soft);
    color: var(--amber);
}

.status-pill.waiting {
    margin-top: 6px;
    background: var(--surface-soft);
    color: var(--muted);
}

.status-pill.responded {
    margin-top: 6px;
    background: var(--green-soft);
    color: var(--green-dark);
}

.status-pill.not-responded {
    margin-top: 6px;
    background: var(--red-soft);
    color: var(--red);
}

details {
    max-width: 320px;
}

summary {
    color: var(--green-dark);
    cursor: pointer;
    font-weight: 700;
}

details p {
    margin: 10px 0 0;
    padding: 10px;
    border-radius: 6px;
    background: var(--surface-soft);
    color: var(--text);
    line-height: 1.45;
}

.row-actions {
    display: grid;
    gap: 6px;
    min-width: 188px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fbfdfe;
}

.response-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding-top: 2px;
}

.whatsapp-button,
.mark-button,
.response-button {
    width: 100%;
    min-width: 0;
    height: 36px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--green);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.whatsapp-button:hover,
.mark-button:hover,
.response-button:hover,
.filters button:hover,
.button-link:hover,
.pagination a:hover {
    background: var(--green-dark);
}

.whatsapp-button {
    height: 40px;
    box-shadow: 0 8px 18px rgba(16, 132, 99, 0.18);
}

.whatsapp-button:hover {
    transform: translateY(-1px);
}

.warning-link:hover,
.response-button.not-responded:hover {
    background: var(--red);
}

.mark-button {
    background: #fff;
    border-color: var(--border);
    color: var(--green-dark);
}

.mark-button:hover {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
}

.mark-button.is-marked,
.mark-button.is-marked:disabled {
    border-color: #b7e4d1;
    background: var(--green-soft);
    color: var(--green-dark);
    cursor: default;
}

.mark-button.is-marked::before {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: currentColor;
    content: "";
    vertical-align: 1px;
}

.response-button {
    height: 34px;
    background: #fff;
    border-color: var(--border);
    color: var(--muted);
    font-size: 12px;
}

.response-button:hover {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
}

.response-button.responded {
    background: #fff;
    color: var(--green-dark);
}

.response-button.responded:hover,
.response-button.responded.is-active {
    border-color: #9bd6bf;
    background: var(--green-soft);
    color: var(--green-dark);
}

.response-button.not-responded {
    background: #fff;
    color: var(--red);
}

.response-button.not-responded:hover,
.response-button.not-responded.is-active {
    border-color: #f0aaa3;
    background: var(--red-soft);
    color: var(--red);
}

.response-button.is-active {
    box-shadow: inset 0 0 0 1px currentColor;
}

.response-button.is-active::before {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: currentColor;
    content: "";
    vertical-align: 1px;
}

.warning-link:hover {
    border-color: var(--red);
    color: #fff;
}

.response-button.not-responded:hover {
    border-color: #f0aaa3;
    background: var(--red-soft);
    color: var(--red);
}

.mark-button:hover,
.response-button:hover {
    transform: translateY(-1px);
}

.mark-button:disabled:hover,
.response-button:disabled:hover {
    transform: none;
}

.button-link:hover,
.pagination a:hover {
    color: #fff;
}

.whatsapp-button:disabled,
.mark-button:disabled,
.response-button:disabled {
    background: #edf2f4;
    border-color: #d4dde2;
    color: #8a9aa3;
    cursor: not-allowed;
    box-shadow: none;
}

.empty-state {
    padding: 40px 16px;
    color: var(--muted);
    text-align: center;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 14px 16px;
}

.pagination span {
    color: var(--muted);
    font-size: 13px;
}

.pagination a.disabled {
    pointer-events: none;
    border-color: var(--border);
    background: var(--surface-soft);
    color: #9aabb4;
}

@media (max-width: 900px) {
    .app-shell {
        width: min(100% - 20px, 720px);
        padding-top: 16px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .source-path {
        max-width: 100%;
    }

    .topbar-actions {
        align-items: stretch;
        flex-direction: column;
        max-width: 100%;
        width: 100%;
    }

    .metrics,
    .filters {
        grid-template-columns: 1fr;
    }

    .metric {
        min-height: 78px;
    }

    .table-summary,
    .pagination {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100% - 16px, 520px);
        padding-bottom: 24px;
    }

    h1 {
        font-size: 30px;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .metric {
        min-height: 74px;
        padding: 12px;
    }

    .metric span {
        margin-bottom: 8px;
        font-size: 12px;
    }

    .metric strong {
        font-size: 25px;
    }

    .filters {
        padding: 12px;
    }

    .filters button,
    .secondary-link {
        width: 100%;
    }

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

    .table-summary {
        margin-bottom: 10px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
    }

    .table-scroll {
        overflow: visible;
    }

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

    table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    tbody {
        display: grid;
        gap: 10px;
    }

    tr {
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
        box-shadow: var(--shadow);
        overflow: hidden;
    }

    tr.is-sent {
        background: #fbfffd;
    }

    td {
        display: grid;
        grid-template-columns: 112px minmax(0, 1fr);
        gap: 10px;
        padding: 11px 12px;
        border-bottom: 1px solid var(--border);
        font-size: 14px;
        overflow-wrap: anywhere;
    }

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

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

    td.empty-state {
        display: block;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
    }

    td.empty-state::before {
        content: none;
    }

    details {
        max-width: 100%;
        min-width: 0;
    }

    details p {
        width: 100%;
        margin-top: 8px;
    }

    .row-actions,
    .response-actions,
    .response-actions form,
    .send-form,
    .manual-sent-form,
    .topbar-actions .button-link,
    .topbar-actions .secondary-link,
    .whatsapp-button,
    .mark-button,
    .response-button {
        width: 100%;
    }

    .whatsapp-button,
    .mark-button,
    .response-button {
        min-width: 0;
        height: 42px;
    }

    .pagination {
        margin-top: 10px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
    }

    .pagination a {
        width: 100%;
    }
}

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

    td {
        grid-template-columns: 1fr;
        gap: 6px;
    }
}
