:root {
    --bg: #f7f8fb;
    --panel: #ffffff;
    --panel-strong: #eef3f8;
    --text: #172033;
    --muted: #667085;
    --line: #dde4ee;
    --accent: #1d8f71;
    --accent-strong: #12664f;
    --danger: #b42318;
    --shadow: 0 18px 45px rgba(22, 34, 51, 0.10);
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(247, 248, 251, 0.96)),
        radial-gradient(circle at top right, rgba(29, 143, 113, 0.18), transparent 32rem);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

button,
input {
    font: inherit;
}

.app-shell {
    width: min(100%, 720px);
    min-height: 100vh;
    margin: 0 auto;
    padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.topbar {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
    min-height: 54px;
}

.brand {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
    font-size: 22px;
    font-weight: 800;
}

#back-button {
    grid-column: 1;
}

#refresh-button {
    grid-column: 3;
}

.brand span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-mark,
.company-avatar {
    flex: 0 0 auto;
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #1d8f71;
    color: #fff;
    font-size: 15px;
    font-weight: 800;
}

.icon-button {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.78);
    color: var(--text);
    box-shadow: 0 6px 18px rgba(22, 34, 51, 0.08);
    font-size: 28px;
    line-height: 1;
}

.icon-button:active,
.company-row:active,
.promo-card:active,
.card-action:active {
    transform: translateY(1px);
}

.hero-panel {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin: 12px 0 16px;
    padding: 22px 20px;
    border: 1px solid rgba(221, 228, 238, 0.9);
    border-radius: 8px;
    background: linear-gradient(135deg, #ffffff, #eef6f3);
    box-shadow: var(--shadow);
}

.eyebrow,
.promo-label,
.dialog-kicker {
    margin: 0 0 8px;
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: 30px;
    line-height: 1.08;
}

.hero-panel p:last-child {
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.45;
}

.status-pill {
    align-self: flex-start;
    flex: 0 0 auto;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(29, 143, 113, 0.12);
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 800;
}

.status-pill.is-loading {
    background: rgba(102, 112, 133, 0.14);
    color: var(--muted);
}

.toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 6px 0 12px;
    background: linear-gradient(180deg, var(--bg) 70%, rgba(247, 248, 251, 0));
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 48px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
}

.search-box span {
    color: var(--muted);
    font-size: 24px;
}

.search-box input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
}

.upload-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 122px;
    height: 48px;
    padding: 0 12px;
    border: 1px solid rgba(29, 143, 113, 0.28);
    border-radius: 8px;
    background: #fff;
    color: var(--accent-strong);
    font-weight: 800;
    box-shadow: 0 8px 22px rgba(22, 34, 51, 0.06);
}

.upload-button input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.content-panel {
    padding: 4px 0 20px;
}

.upload-status {
    margin: 0 0 12px;
    padding: 12px 14px;
    border: 1px solid rgba(29, 143, 113, 0.24);
    border-radius: 8px;
    background: rgba(29, 143, 113, 0.08);
    color: var(--accent-strong);
    font-size: 14px;
    font-weight: 800;
}

.upload-status.is-error {
    border-color: rgba(180, 35, 24, 0.28);
    background: rgba(180, 35, 24, 0.08);
    color: var(--danger);
}

.list-meta {
    min-height: 22px;
    margin: 6px 2px 10px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.company-list,
.promo-list {
    display: grid;
    gap: 10px;
}

.company-row {
    display: grid;
    grid-template-columns: 42px 1fr 24px;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 72px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: inherit;
    text-align: left;
    box-shadow: 0 8px 22px rgba(22, 34, 51, 0.06);
}

.company-main {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.company-name {
    overflow: hidden;
    font-size: 18px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.company-note,
.promo-footer,
.promo-conditions {
    color: var(--muted);
}

.chevron {
    color: #98a2b3;
    font-size: 32px;
    line-height: 1;
    text-align: right;
}

.promo-card {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 8px 22px rgba(22, 34, 51, 0.06);
}

.promo-card-head,
.promo-footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.promo-card h2 {
    margin-bottom: 0;
    overflow-wrap: anywhere;
    font-size: 24px;
}

.valid-badge {
    flex: 0 0 auto;
    padding: 7px 9px;
    border-radius: 999px;
    background: rgba(29, 143, 113, 0.12);
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 800;
}

.promo-conditions {
    margin: 14px 0;
    line-height: 1.45;
}

.promo-footer {
    align-items: center;
    flex-wrap: wrap;
    font-size: 14px;
}

.promo-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.card-action {
    min-height: 34px;
    padding: 0 11px;
    border: 1px solid rgba(29, 143, 113, 0.26);
    border-radius: 999px;
    background: #fff;
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 800;
}

.empty-state {
    margin-top: 18px;
    padding: 24px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    text-align: center;
}

.promo-dialog {
    width: min(calc(100% - 24px), 640px);
    max-height: min(82vh, 760px);
    padding: 24px 18px 18px;
    border: 0;
    border-radius: 8px;
    color: var(--text);
    box-shadow: var(--shadow);
}

.promo-dialog::backdrop {
    background: rgba(23, 32, 51, 0.42);
}

.dialog-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: var(--panel-strong);
    color: var(--text);
    font-size: 26px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 112px 1fr;
    gap: 10px 12px;
    margin: 18px 0;
}

.detail-grid dt {
    color: var(--muted);
    font-weight: 800;
}

.detail-grid dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.raw-mail {
    max-height: 220px;
    overflow: auto;
    padding: 12px;
    border-radius: 8px;
    background: #f2f5f9;
    color: #344054;
    white-space: pre-wrap;
}

@media (max-width: 520px) {
    .app-shell {
        padding-right: 12px;
        padding-left: 12px;
    }

    .hero-panel {
        display: block;
        padding: 20px 16px;
    }

    .status-pill {
        display: inline-flex;
        margin-top: 14px;
    }

    h1 {
        font-size: 28px;
    }

    .brand {
        font-size: 20px;
    }

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

    .upload-button {
        width: 100%;
    }

    .promo-card-head,
    .promo-footer {
        display: grid;
    }

    .promo-actions {
        width: 100%;
    }

    .card-action {
        flex: 1 1 auto;
    }

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