:root {
    --bg: #f6f7fb;
    --panel: #ffffff;
    --ink: #101828;
    --muted: #667085;
    --line: #d9e0ea;
    --accent: #1868db;
    --accent-dark: #124da3;
    --accent-soft: #eaf2ff;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --shadow: 0 18px 45px rgba(16, 24, 40, 0.10);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

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

button,
input,
select,
textarea {
    font: inherit;
}

.auth-page {
    background:
        radial-gradient(circle at top left, rgba(24, 104, 219, 0.14), transparent 32rem),
        linear-gradient(135deg, #f8fbff 0%, #eef4fb 46%, #f9fafb 100%);
}

.auth-shell {
    display: grid;
    min-height: 100vh;
    padding: 1rem;
    place-items: center;
}

.auth-panel {
    width: min(100%, 29rem);
    padding: 1.5rem;
    border: 1px solid rgba(217, 224, 234, 0.9);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.brand-lockup,
.app-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-mark {
    display: inline-grid;
    width: 2.75rem;
    height: 2.75rem;
    flex: 0 0 auto;
    border-radius: 8px;
    place-items: center;
    background: var(--accent);
    color: #ffffff;
    font-weight: 800;
}

.eyebrow {
    margin: 0 0 0.2rem;
    color: var(--accent-dark);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

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

.auth-panel h1 {
    margin-bottom: 0;
    font-size: clamp(1.75rem, 7vw, 2.35rem);
    line-height: 1.08;
}

.auth-intro {
    margin: 1.15rem 0 1.35rem;
    color: var(--muted);
}

.auth-form {
    display: grid;
    gap: 1rem;
}

.field-group {
    display: grid;
    gap: 0.45rem;
}

.field-group label {
    color: #344054;
    font-size: 0.9rem;
    font-weight: 700;
}

.field-group input,
.field-group textarea {
    width: 100%;
    min-height: 3rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    padding: 0.75rem 0.9rem;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field-group textarea {
    min-height: 10rem;
    resize: vertical;
}

.field-group select {
    width: 100%;
    min-height: 3rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
    padding: 0.75rem 0.9rem;
    outline: none;
}

.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus,
.body-editor:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(24, 104, 219, 0.14);
}

.primary-button,
.nav-button,
.secondary-button,
.danger-button {
    border: 0;
    cursor: pointer;
    font-weight: 800;
}

.primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 3rem;
    border-radius: 8px;
    background: var(--accent);
    color: #ffffff;
    padding: 0.75rem 1rem;
    transition: background 160ms ease, transform 160ms ease;
}

.primary-button:hover,
.primary-button:focus-visible {
    background: var(--accent-dark);
}

.primary-button:active {
    transform: translateY(1px);
}

.send-email-button {
    box-shadow: 0 10px 22px rgba(24, 104, 219, 0.22);
}

.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.85rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: #344054;
    padding: 0.65rem 1rem;
}

.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.85rem;
    border: 1px solid #f3b7b2;
    border-radius: 8px;
    background: var(--danger-bg);
    color: var(--danger);
    padding: 0.65rem 1rem;
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
    cursor: wait;
    opacity: 0.68;
}

.form-alert,
.field-error {
    color: var(--danger);
}

.form-alert {
    margin-bottom: 1rem;
    border: 1px solid #f3b7b2;
    border-radius: 8px;
    background: var(--danger-bg);
    padding: 0.75rem 0.9rem;
    font-size: 0.92rem;
}

.form-alert p,
.field-error {
    margin: 0;
}

.field-error {
    font-size: 0.85rem;
}

.message-stack {
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    left: 0.75rem;
    z-index: 5;
    display: grid;
    gap: 0.5rem;
    pointer-events: none;
}

.message {
    justify-self: center;
    width: min(100%, 34rem);
    border: 1px solid #abefc6;
    border-radius: 8px;
    background: #ecfdf3;
    color: #067647;
    padding: 0.75rem 1rem;
    box-shadow: 0 12px 28px rgba(16, 24, 40, 0.12);
    font-weight: 700;
    transition: opacity 200ms ease, transform 200ms ease;
}

.message-dismissed {
    opacity: 0;
    transform: translateY(-0.4rem);
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    padding: 0.85rem 1rem;
    backdrop-filter: blur(14px);
}

.app-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.app-brand {
    width: fit-content;
    font-weight: 900;
}

.app-brand .brand-mark {
    width: 2.25rem;
    height: 2.25rem;
}

.app-nav {
    display: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    width: 100%;
}

.app-nav.is-open {
    display: grid;
}

.menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    min-height: 2.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: #344054;
    padding: 0.55rem 0.8rem;
    cursor: pointer;
    font-weight: 800;
}

.menu-toggle span,
.menu-toggle span::before,
.menu-toggle span::after {
    display: block;
    width: 1.15rem;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    content: "";
}

.menu-toggle span {
    position: relative;
}

.menu-toggle span::before,
.menu-toggle span::after {
    position: absolute;
    left: 0;
}

.menu-toggle span::before {
    top: -0.4rem;
}

.menu-toggle span::after {
    top: 0.4rem;
}

.app-nav a,
.nav-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.5rem;
    border-radius: 8px;
    background: #f2f5f9;
    color: #344054;
    padding: 0.55rem 0.7rem;
    font-size: 0.92rem;
    text-align: center;
}

.app-nav a[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 800;
}

.nav-button {
    width: 100%;
}

.dashboard-shell {
    width: min(100%, 72rem);
    margin: 0 auto;
    padding: 1.25rem 1rem 2.5rem;
}

.dashboard-hero {
    display: grid;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.dashboard-hero h1 {
    margin-bottom: 0;
    font-size: clamp(1.8rem, 8vw, 3.25rem);
    line-height: 1.08;
}

.dashboard-summary {
    max-width: 38rem;
    margin-bottom: 0;
    color: var(--muted);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: 0 10px 28px rgba(16, 24, 40, 0.06);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.stat-card strong {
    display: block;
    margin-top: 0.35rem;
    font-size: clamp(1.6rem, 10vw, 2.25rem);
    line-height: 1;
}

.dashboard-card {
    display: block;
    min-height: 11.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: 0 10px 28px rgba(16, 24, 40, 0.06);
    transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

a.dashboard-card:hover,
a.dashboard-card:focus-visible {
    border-color: rgba(24, 104, 219, 0.45);
    box-shadow: 0 14px 34px rgba(16, 24, 40, 0.10);
    transform: translateY(-2px);
}

.card-icon {
    display: inline-grid;
    width: 2.4rem;
    height: 2.4rem;
    margin-bottom: 1rem;
    border-radius: 8px;
    place-items: center;
    background: #eef8f3;
    color: #087443;
    font-weight: 900;
}

.dashboard-card h2 {
    margin-bottom: 0.45rem;
    font-size: 1.05rem;
}

.dashboard-card p {
    margin-bottom: 0;
    color: var(--muted);
}

.page-heading {
    display: grid;
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.page-heading h1 {
    margin-bottom: 0;
    font-size: clamp(1.85rem, 8vw, 3rem);
    line-height: 1.08;
}

.page-heading p {
    max-width: 42rem;
    margin-bottom: 0;
    color: var(--muted);
}

.composer-form {
    display: grid;
    gap: 1rem;
}

.form-panel,
.detail-panel,
.empty-state {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: 0 10px 28px rgba(16, 24, 40, 0.06);
}

.form-grid {
    display: grid;
    gap: 1rem;
}

.optional-label,
.composer-topline span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.composer-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.composer-topline label {
    color: #344054;
    font-weight: 800;
}

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.75rem;
}

.editor-toolbar button {
    min-width: 2.75rem;
    min-height: 2.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    color: #344054;
    cursor: pointer;
    font-weight: 800;
}

.editor-toolbar button:hover,
.editor-toolbar button:focus-visible,
.editor-toolbar button.is-active {
    border-color: rgba(24, 104, 219, 0.45);
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.image-dialog {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(16, 24, 40, 0.42);
}

.image-dialog[hidden] {
    display: none;
}

.image-dialog__panel {
    width: min(100%, 34rem);
    max-height: calc(100vh - 2rem);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: var(--shadow);
}

.image-dialog__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.image-dialog__header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.image-dialog__form,
.image-dialog__options {
    display: grid;
    gap: 0.9rem;
}

.image-dialog__options {
    grid-template-columns: 1fr;
}

.image-dialog__options label {
    display: flex;
    min-height: 2.75rem;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    font-weight: 800;
}

.body-editor {
    min-height: 18rem;
    max-height: 48rem;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 0.9rem;
    outline: none;
}

.body-editor:empty::before {
    color: #98a2b3;
    content: attr(data-placeholder);
}

.body-editor h2 {
    margin-bottom: 0.6rem;
    font-size: 1.4rem;
}

.body-editor h1 {
    margin-bottom: 0.7rem;
    font-size: 1.65rem;
}

.body-editor h3 {
    margin-bottom: 0.55rem;
    font-size: 1.2rem;
}

.body-editor p,
.body-editor ul,
.body-editor ol,
.body-editor blockquote {
    margin-bottom: 0.85rem;
}

.body-editor blockquote {
    border-left: 3px solid var(--line);
    margin-left: 0;
    padding-left: 1rem;
    color: #475467;
}

.compact-editor {
    min-height: 8rem;
    max-height: 20rem;
}

.form-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.history-list,
.detail-layout {
    display: grid;
    gap: 0.85rem;
}

.history-card {
    display: grid;
    gap: 0.85rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: 0 10px 28px rgba(16, 24, 40, 0.06);
    transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.history-card:hover,
.history-card:focus-visible {
    border-color: rgba(24, 104, 219, 0.45);
    box-shadow: 0 14px 34px rgba(16, 24, 40, 0.10);
    transform: translateY(-1px);
}

.history-main h2 {
    margin-bottom: 0.25rem;
    font-size: 1rem;
}

.history-main p,
.history-meta {
    color: var(--muted);
}

.history-main p {
    margin-bottom: 0;
    overflow-wrap: anywhere;
}

.history-meta {
    display: grid;
    gap: 0.4rem;
    font-size: 0.9rem;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card-actions form,
.heading-actions form,
.form-actions form {
    display: contents;
}

.filter-form {
    display: grid;
    gap: 0.85rem;
    margin-bottom: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 1rem;
    box-shadow: 0 10px 28px rgba(16, 24, 40, 0.06);
}

.filter-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.65rem;
    align-items: end;
}

.section-block {
    margin-top: 1.5rem;
}

.section-heading {
    display: grid;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.section-heading h2 {
    margin-bottom: 0;
}

.muted-note {
    margin: 0;
    color: var(--muted);
    font-weight: 700;
}

.confirm-panel {
    max-width: 42rem;
}

.status-badge {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 900;
}

.status-draft {
    background: #eef4ff;
    color: #3538cd;
}

.status-queued {
    background: #fff7e6;
    color: #b54708;
}

.status-sending {
    background: #eaf2ff;
    color: #124da3;
}

.status-sent {
    background: #ecfdf3;
    color: #067647;
}

.status-failed {
    background: #fff1f0;
    color: #b42318;
}

.status-completed,
.status-sent {
    background: #ecfdf3;
    color: #067647;
}

.status-partially_failed,
.status-cancelled,
.status-skipped {
    background: #f2f4f7;
    color: #475467;
}

.status-pending {
    background: #f8fafc;
    color: #344054;
}

.empty-state {
    display: grid;
    justify-items: start;
    gap: 0.6rem;
}

.empty-state h2,
.detail-panel h2 {
    margin-bottom: 0;
    font-size: 1.1rem;
}

.empty-state p {
    margin-bottom: 0.4rem;
    color: var(--muted);
}

.detail-row {
    display: grid;
    gap: 0.2rem;
    border-bottom: 1px solid var(--line);
    padding: 0.85rem 0;
}

.detail-row:first-child {
    padding-top: 0;
}

.detail-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.detail-row span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

.detail-row strong {
    overflow-wrap: anywhere;
}

.email-body-raw {
    overflow: auto;
    max-height: 36rem;
    margin: 1rem 0 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    color: #344054;
    padding: 1rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.heading-actions {
    display: grid;
    gap: 0.65rem;
}

.preview-shell {
    width: min(100%, 82rem);
    margin: 0 auto;
    padding: 1.25rem 1rem 2.5rem;
}

.preview-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: min(100%, 22rem);
    margin-bottom: 1rem;
}

.preview-recipient-form {
    width: min(100%, 42rem);
    grid-template-columns: 1fr;
    align-items: end;
}

.preview-recipient-form label {
    color: #344054;
    font-size: 0.9rem;
    font-weight: 800;
}

.preview-recipient-form select {
    min-height: 2.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 0.65rem 0.8rem;
}

.preview-toggle {
    min-height: 2.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: #344054;
    cursor: pointer;
    font-weight: 800;
}

.preview-toggle.is-active {
    border-color: rgba(24, 104, 219, 0.45);
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.email-preview-stage {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #e8edf4;
    padding: 1rem;
}

.email-preview-frame {
    display: block;
    width: min(100%, 760px);
    min-height: 760px;
    margin: 0 auto;
    border: 1px solid #cfd7e3;
    border-radius: 8px;
    background: #ffffff;
    transition: width 160ms ease;
}

.email-preview-frame.is-mobile-preview {
    width: min(100%, 390px);
}

.settings-panel {
    max-width: 34rem;
}

.action-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.compact-heading {
    margin-top: 1.25rem;
}

.compact-heading h2 {
    margin-bottom: 0;
}

.compact-button {
    min-height: 2.35rem;
    padding: 0.45rem 0.7rem;
    font-size: 0.85rem;
}

.import-summary {
    display: grid;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.import-summary ul {
    margin: 0.35rem 0 0;
    padding-left: 1.2rem;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
}

.review-preview-frame {
    width: 100%;
    min-height: 32rem;
    margin-top: 1rem;
}

.progress-label {
    margin: 1rem 0 0.55rem;
    color: var(--muted);
}

.progress-track {
    overflow: hidden;
    height: 0.8rem;
    border-radius: 999px;
    background: #e4e7ec;
}

.progress-fill {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.metrics-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    padding: 0.75rem;
}

.metrics-grid strong,
.metrics-grid span {
    display: block;
}

.metrics-grid strong {
    font-size: 1.25rem;
}

.metrics-grid span {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

@media (min-width: 42rem) {
    .auth-panel {
        padding: 2rem;
    }

    .app-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding-inline: 1.5rem;
    }

    .app-header-top {
        display: contents;
    }

    .app-nav {
        display: grid;
        width: auto;
        grid-template-columns: repeat(4, auto);
    }

    .menu-toggle {
        display: none;
    }

    .app-nav a,
    .nav-button {
        min-width: 5.3rem;
    }

    .dashboard-shell {
        padding: 2rem 1.5rem 3rem;
    }

    .dashboard-hero {
        grid-template-columns: minmax(0, 1fr) minmax(18rem, 0.55fr);
        align-items: end;
        margin-bottom: 1.75rem;
    }

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

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

    .page-heading {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: end;
        margin-bottom: 1.75rem;
    }

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

    .field-full {
        grid-column: 1 / -1;
    }

    .form-actions {
        grid-template-columns: repeat(4, auto);
        justify-content: end;
    }

    .heading-actions {
        grid-auto-flow: column;
        justify-content: end;
    }

    .filter-form {
        grid-template-columns: minmax(0, 1fr) minmax(12rem, 0.4fr) auto;
        align-items: end;
    }

    .filter-actions {
        grid-auto-flow: column;
        grid-template-columns: none;
        justify-content: end;
    }

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

    .history-card {
        grid-template-columns: minmax(0, 1fr) minmax(18rem, auto);
        align-items: center;
    }

    .history-card .card-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .history-meta {
        grid-template-columns: repeat(5, auto);
        align-items: center;
        justify-content: end;
        text-align: right;
    }

    .preview-recipient-form {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .metrics-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .section-heading {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: end;
    }
}

@media (min-width: 64rem) {
    .app-nav {
        grid-template-columns: repeat(8, auto);
    }

    .dashboard-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .stats-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .detail-layout {
        grid-template-columns: minmax(18rem, 0.42fr) minmax(0, 1fr);
        align-items: start;
    }
}
