:root {
    --app-bg: #f4f7fb;
    --app-sidebar: #111827;
    --app-sidebar-soft: #1f2937;
    --app-line: #dbe3ef;
    --app-ink: #172033;
    --app-muted: #64748b;
    --app-blue: #1769e0;
    --app-green: #12805c;
    --app-red: #c23b3b;
    --app-amber: #9a6415;
    --app-teal: #0f766e;
    --app-cyan: #0369a1;
    --app-violet: #6d28d9;
    --app-slate: #475569;
}

* {
    box-sizing: border-box;
}

body {
    color: var(--app-ink);
    background: var(--app-bg);
}

a {
    text-decoration: none;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(23, 105, 224, 0.12), rgba(18, 128, 92, 0.08)),
        var(--app-bg);
}

.auth-box {
    width: min(440px, 100%);
    border-radius: 16px;
}

.module-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.brand-logo,
.auth-logo {
    display: block;
    object-fit: contain;
    flex: 0 0 auto;
}

.auth-logo {
    width: 76px;
    height: 76px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
    background: var(--app-sidebar);
    color: #e5e7eb;
    padding: 18px 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    color: #ffffff;
    font-size: 18px;
    font-weight: 800;
}

.brand:hover {
    color: #ffffff;
}

.module-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex: 0 0 auto;
}

.brand-logo {
    width: 38px;
    height: 38px;
}

.module-icon {
    background: #eef4ff;
    color: var(--app-blue);
}

.sidebar .nav {
    margin-top: 22px;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    border-radius: 10px;
    color: #cbd5e1;
    padding: 0 10px;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: var(--app-sidebar-soft);
    color: #ffffff;
}

.main {
    min-width: 0;
}

.topbar {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    padding: 0 24px;
    background: #ffffff;
    border-bottom: 1px solid var(--app-line);
}

.user-chip {
    max-width: min(48vw, 380px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--app-muted);
}

.content {
    padding: 24px;
}

.page-title h1 {
    letter-spacing: 0;
}

.module-card {
    display: flex;
    flex-direction: row;
    gap: 14px;
    min-height: 120px;
    color: var(--app-ink);
    border-radius: 14px;
    padding: 18px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.module-card:hover {
    color: var(--app-ink);
    transform: translateY(-1px);
    box-shadow: 0 18px 40px rgba(23, 32, 51, 0.12) !important;
}

.module-card strong,
.cell-main {
    display: block;
    color: var(--app-ink);
    font-weight: 700;
}

.filter-card,
.card {
    border-radius: 14px;
}

.summary-section {
    display: grid;
    gap: 14px;
}

.summary-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.summary-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

.summary-state {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 3px 10px;
    background: #eef2f7;
    color: var(--app-muted);
    font-size: 12px;
    font-weight: 800;
}

.summary-state-ready {
    background: #e9f8f2;
    color: var(--app-green);
}

.summary-state-queued,
.summary-state-calculating {
    background: #fff7e6;
    color: var(--app-amber);
}

.summary-state-failed {
    background: #fff0f0;
    color: var(--app-red);
}

.summary-completed,
.summary-state-message {
    color: var(--app-muted);
    font-size: 13px;
}

.summary-empty {
    display: flex;
    min-height: 150px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px dashed var(--app-line);
    border-radius: 12px;
    background: #ffffff;
    color: var(--app-muted);
    text-align: center;
}

.summary-empty strong {
    color: var(--app-ink);
    font-size: 36px;
    line-height: 1;
}

.summary-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
    gap: 16px;
    align-items: stretch;
}

.summary-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(142px, 1fr));
    gap: 12px;
}

.summary-metric {
    min-height: 112px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid var(--app-line);
    border-radius: 12px;
    padding: 14px;
    background: #ffffff;
    box-shadow: 0 10px 24px rgba(23, 32, 51, 0.06);
}

.summary-metric > span:not(.status) {
    color: var(--app-muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.summary-metric strong {
    display: block;
    color: var(--app-ink);
    font-size: 32px;
    line-height: 1;
    letter-spacing: 0;
}

.summary-metric-total {
    border-color: rgba(23, 105, 224, 0.24);
    background: #172033;
}

.summary-metric-total > span,
.summary-metric-total strong {
    color: #ffffff;
}

.summary-chart .card-body {
    min-height: 292px;
}

.summary-chart-box {
    position: relative;
    width: 100%;
    height: 260px;
}

.summary-chart canvas {
    width: 100% !important;
    height: 100% !important;
}

.form-label {
    color: var(--app-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.table {
    --bs-table-color: var(--app-ink);
}

.table th {
    color: var(--app-muted);
    font-size: 12px;
    text-transform: uppercase;
    white-space: nowrap;
}

.sort-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: inherit;
}

.sort-link:hover,
.sort-link.active {
    color: var(--app-blue);
}

.sort-indicator {
    min-width: 10px;
    font-size: 11px;
}

.table td {
    overflow-wrap: anywhere;
}

.cell-sub {
    display: block;
    margin-top: 4px;
    color: var(--app-muted);
    font-size: 12px;
    line-height: 1.35;
}

.status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 0 9px;
    background: #eef2f7;
    color: var(--app-muted);
    font-size: 12px;
    font-weight: 800;
}

.status.processed {
    background: #eaf2ff;
    color: var(--app-blue);
}

.status.delivered {
    background: #e9f8f2;
    color: var(--app-green);
}

.status.sent,
.status.inbound {
    background: #eaf2ff;
    color: var(--app-blue);
}

.status.dropped {
    background: #fff0f0;
    color: var(--app-red);
}

.status.failed,
.status.rejected,
.status.unsubscribed {
    background: #fff0f0;
    color: var(--app-red);
}

.status.bounce {
    background: #ffe8e8;
    color: #991b1b;
}

.status.deferred {
    background: #fff7e6;
    color: var(--app-amber);
}

.status.expired,
.status.no_funds {
    background: #fff7e6;
    color: var(--app-amber);
}

.status.optout {
    background: #f3e8ff;
    color: var(--app-violet);
}

.status.open {
    background: #e6fbff;
    color: var(--app-cyan);
}

.status.nodata {
    background: #f3e8ff;
    color: var(--app-violet);
}

.status.notfound {
    background: #f1f5f9;
    color: var(--app-slate);
}

.status.unknown {
    background: #eef2f7;
    color: var(--app-muted);
}

.details-button {
    min-height: 34px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 0;
    margin: 0;
}

.detail-grid dt,
.detail-grid dd {
    border-bottom: 1px solid var(--app-line);
    margin: 0;
    padding: 10px 0;
}

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

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

.payload-preview {
    max-height: 260px;
    overflow: auto;
    border-radius: 8px;
    padding: 10px;
    background: #f8fafc;
    color: var(--app-slate);
    font-size: 12px;
    white-space: pre-wrap;
}

.event-list {
    padding-top: 16px;
}

.event-list h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

.event-list ol {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.event-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--app-line);
    border-radius: 10px;
    padding: 9px 10px;
}

.event-list li span {
    font-weight: 700;
}

.event-list time {
    color: var(--app-muted);
}

.empty {
    color: var(--app-muted);
    text-align: center;
}

@media (max-width: 991.98px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 1020;
        padding: 12px 14px;
    }

    .sidebar .nav {
        flex-direction: row !important;
        gap: 8px;
        margin-top: 12px;
        overflow-x: auto;
    }

    .sidebar .nav-link {
        flex: 0 0 auto;
    }

    .topbar {
        justify-content: space-between;
        min-height: 58px;
        padding: 0 16px;
    }

    .content {
        padding: 16px;
    }

    .summary-layout {
        grid-template-columns: 1fr;
    }

    .summary-heading,
    .summary-actions {
        align-items: flex-start;
    }

    .summary-heading {
        flex-direction: column;
    }

    .summary-actions {
        justify-content: flex-start;
    }

    .summary-chart .card-body {
        min-height: 260px;
    }

    .summary-chart-box {
        height: 232px;
    }

    .summary-metric strong {
        font-size: 28px;
    }
}

@media (max-width: 760px) {
    .table-responsive {
        overflow: visible;
    }

    .table {
        min-width: 0;
    }

    .table thead {
        display: none;
    }

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

    .table tr {
        border: 1px solid var(--app-line);
        border-radius: 12px;
        margin: 12px;
        background: #ffffff;
        overflow: hidden;
    }

    .table td {
        display: grid;
        grid-template-columns: 116px minmax(0, 1fr);
        gap: 10px;
        border-bottom: 1px solid var(--app-line);
        padding: 10px 12px;
    }

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

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

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

    .detail-grid dt {
        border-bottom: 0;
        padding-bottom: 2px;
    }

    .detail-grid dd {
        padding-top: 0;
    }

    .event-list li {
        display: block;
    }

    .event-list time {
        display: block;
        margin-top: 4px;
    }
}
