:root {
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-surface-alt: #eef2f7;
    --color-text: #111827;
    --color-text-soft: #4b5563;
    --color-border: #d1d5db;
    --color-primary: #111111;
    --color-primary-hover: #000000;
    --color-primary-contrast: #ffffff;
    --color-info: #2563eb;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --shadow-soft: 0 16px 40px rgba(15, 23, 42, 0.08);
    --radius: 14px;
    --font-family: Inter, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

img {
    max-width: 100%;
}

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

input,
textarea,
select {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 0.45rem;
    color: var(--color-text-soft);
    font-size: 0.92rem;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.checkbox input {
    width: auto;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.7rem 1rem;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 400;
}

.button-primary {
    background: var(--color-primary);
    color: var(--color-primary-contrast);
}

.button-secondary {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border-color: var(--color-border);
}

.button-ghost {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border);
}

.button-danger {
    background: var(--color-danger);
    color: #fff;
}

.public-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.75rem;
}

.brand {
    font-size: 1.1rem;
    font-weight: 700;
}

.shell,
.hero-shell {
    max-width: 1120px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
}

.hero-shell {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: 1.3fr 0.9fr;
    align-items: start;
}

.hero-copy h1 {
    font-size: clamp(2.3rem, 5vw, 4rem);
    line-height: 1.05;
    margin: 0.25rem 0 1rem;
}

.hero-copy p {
    color: var(--color-text-soft);
    font-size: 1.05rem;
    line-height: 1.7;
    max-width: 62ch;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.78rem;
    color: var(--color-info);
    font-weight: 700;
}

.hero-panel,
.stack {
    display: grid;
    gap: 1rem;
}

.hero-actions {
    display: flex;
    gap: 0.9rem;
    margin-top: 1.4rem;
}

.metric-card,
.card {
    background: var(--color-surface);
    border: 1px solid rgba(209, 213, 219, 0.8);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.metric-card {
    padding: 1.25rem;
    display: grid;
    gap: 0.35rem;
}

.metric-card span {
    color: var(--color-text-soft);
}

.card {
    padding: 1.4rem;
}

.auth-card {
    max-width: 460px;
    margin: 3rem auto;
}

.flash {
    margin: 0 auto 1rem;
    max-width: 1120px;
    border-radius: 12px;
    padding: 0.9rem 1.1rem;
    font-weight: 600;
}

.flash-error {
    background: rgba(220, 38, 38, 0.1);
    color: var(--color-danger);
}

.flash-success {
    background: rgba(22, 163, 74, 0.1);
    color: var(--color-success);
}

.admin-shell {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #fff;
    border-right: 1px solid var(--color-border);
    padding: 1.5rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
}

.sidebar-nav {
    display: grid;
    gap: 0.35rem;
}

.sidebar-nav a {
    padding: 0.8rem 0.9rem;
    border-radius: 10px;
    color: var(--color-text);
}

.sidebar-nav a:hover {
    background: var(--color-surface-alt);
}

.admin-main {
    padding: 1.5rem;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.topbar h1,
.card h2,
.card h3 {
    margin-top: 0;
}

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

.metrics-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.metric strong {
    font-size: 2rem;
}

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

.editor-grid {
    grid-template-columns: 1.1fr 0.9fr;
}

.form-grid,
.filter-grid,
.compact-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

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

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    text-align: left;
    padding: 0.9rem 0.7rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

.toolbar {
    display: flex;
    justify-content: flex-end;
}

#open-newsletter-theme-modal {
    margin-right: 20px;
}

.nested-form {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}

.inline-form {
    margin-top: 0.75rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.24rem 0.55rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    background: var(--color-surface-alt);
    color: var(--color-text-soft);
}

.badge-success {
    background: rgba(22, 163, 74, 0.12);
    color: var(--color-success);
}

.badge-info {
    background: rgba(37, 99, 235, 0.12);
    color: var(--color-info);
}

.badge-warning {
    background: rgba(217, 119, 6, 0.12);
    color: var(--color-warning);
}

.badge-danger {
    background: rgba(220, 38, 38, 0.12);
    color: var(--color-danger);
}

.badge-muted {
    background: rgba(75, 85, 99, 0.1);
    color: var(--color-text-soft);
}

.block-editor {
    padding: 1rem;
    border-radius: 12px;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
}

.preview-card {
    position: sticky;
    top: 1rem;
    align-self: start;
}

.email-preview {
    background: #eef2f7;
    padding: 1rem;
    border-radius: 12px;
    overflow: auto;
}

.email-preview table {
    margin: 0 auto;
}

.preview-frame {
    width: 100%;
    min-height: 760px;
    border: 0;
    background: #fff;
    border-radius: 12px;
}

.text-preview {
    white-space: pre-wrap;
    background: var(--color-surface-alt);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--color-border);
}

.thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 10px;
}

details summary {
    list-style: none;
}

details summary::-webkit-details-marker {
    display: none;
}

@media (max-width: 980px) {
    .admin-shell,
    .hero-shell,
    .two-columns,
    .newsletter-grid,
    .editor-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .admin-main {
        padding: 1rem;
    }
}

.hidden {
    display: none !important;
}

.newsletter-editor-page {
    display: grid;
    gap: 1.25rem;
}

.editor-body {
    background: #ececec;
}

.editor-layout-main {
    min-height: 100vh;
    padding: 1rem 1.25rem;
}

.newsletter-editor-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.25rem 0 0.5rem;
}

.newsletter-editor-title {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.newsletter-editor-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: #fff;
    font-size: 1.2rem;
}

.newsletter-editor-title-group {
    display: grid;
    gap: 0.5rem;
}

.subject-display,
.subject-editor {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.subject-display h2 {
    margin: 0;
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.subject-edit-trigger {
    border: 0;
    background: transparent;
    color: var(--color-text-soft);
    cursor: pointer;
}

.subject-editor input {
    min-width: 380px;
    padding: 0.85rem 1rem;
    font-size: 1.2rem;
    font-weight: 600;
}

.newsletter-editor-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.newsletter-save-button {
    width: 148px;
    min-height: 54px;
    padding: 0.55rem 0.8rem;
}

.newsletter-save-button-text {
    display: grid;
    place-items: center;
    min-height: 2.2rem;
    width: 100%;
    text-align: center;
    line-height: 1.15;
}

.newsletter-save-status {
    display: none;
    font-size: 0.72rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.78);
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
}

.newsletter-save-status.is-visible {
    display: block;
}

.newsletter-save-status[data-mode="success"] {
    color: #bbf7d0;
}

.newsletter-save-status[data-mode="error"] {
    color: #fecaca;
}

.newsletter-save-status[data-mode="saving"],
.newsletter-save-status[data-mode="dirty"] {
    color: #bfdbfe;
}

.newsletter-editor-layout {
    display: grid;
    grid-template-columns: 270px minmax(0, 1fr);
    gap: 1.25rem;
    min-height: 72vh;
}

.newsletter-editor-sidebar {
    display: grid;
    gap: 1rem;
    align-content: start;
}

.editor-sidebar-section {
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 1.1rem;
    box-shadow: var(--shadow-soft);
}

.editor-sidebar-section h3 {
    margin: 0 0 1rem;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6b7280;
}

.campaign-settings {
    display: grid;
    gap: 1rem;
}

.campaign-settings-segments {
    margin-top: 0.6rem;
}

.block-palette {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.7rem;
}

.block-tool {
    min-height: 82px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.block-tool:hover {
    border-color: #111827;
    transform: translateY(-1px);
}

.block-tool-missing {
    box-shadow: inset 0 -3px 0 #10b981;
}

.newsletter-editor-canvas-wrap {
    position: relative;
    background: linear-gradient(180deg, #f2f4f7 0%, #eef2f7 100%);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 2rem;
    overflow: visible;
    box-shadow: var(--shadow-soft);
}

.newsletter-editor-canvas {
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 22px 70px rgba(15, 23, 42, 0.14);
}

.editor-block-shell {
    position: relative;
    border: 0;
    transition: box-shadow 0.2s ease;
}

.editor-block-shell:hover,
.editor-block-shell.is-active {
    box-shadow: inset 0 0 0 1px rgba(203, 213, 225, 0.8);
}

.editor-block-shell:hover .editor-block-actions,
.editor-block-shell.is-active .editor-block-actions {
    opacity: 1;
    pointer-events: auto;
}

.editor-block-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.1);
    opacity: 0.16;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 3;
}

.editor-block-actions button {
    border: 0;
    background: #fff;
    min-width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
}

.editor-block-actions button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.editor-block-toolbar {
    position: sticky;
    top: 16px;
    margin: 0 0 1rem auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 0.35rem;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.1);
    z-index: 4;
    width: fit-content;
    max-width: 100%;
}

.editor-block-toolbar.is-disabled {
    opacity: 0.7;
}

.editor-toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.editor-toolbar-label {
    font-size: 0.76rem;
    color: var(--color-text-soft);
}

.editor-toolbar-select {
    width: auto;
    min-width: 88px;
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
}

.editor-block-toolbar button {
    border: 0;
    background: #fff;
    min-width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
}

.editor-block-toolbar button:hover {
    background: var(--color-surface-alt);
}

.editor-block-toolbar button:disabled,
.editor-block-toolbar select:disabled,
.editor-block-toolbar input:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.editor-block-toolbar input[type="color"] {
    width: 34px;
    min-width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    cursor: pointer;
}

.newsletter-block {
    position: relative;
    margin: 0;
}

.newsletter-block [contenteditable="true"] {
    outline: none;
}

.newsletter-block [contenteditable="true"]:focus {
    box-shadow: inset 0 0 0 1px rgba(17, 24, 39, 0.18);
    background: rgba(243, 244, 246, 0.55);
}

.newsletter-block-header {
    padding: 2.5rem 2rem;
    text-align: center;
}

.newsletter-brand {
    font-size: 3rem;
    line-height: 1;
    font-weight: 300;
    letter-spacing: -0.06em;
    color: var(--block-text-color, currentColor);
}

.newsletter-header-logo,
.newsletter-footer-logo {
    display: block;
    max-width: 100%;
    object-fit: contain;
    margin: 0 auto 12px;
}

.newsletter-block-hero {
    display: grid;
    gap: 1rem;
    padding: 0 0 2rem;
}

.newsletter-block-hero h3,
.newsletter-block-text h4 {
    margin: 0;
    padding: 0 2rem;
    color: var(--block-text-color, currentColor);
}

.newsletter-block-hero h3 {
    font-size: 2rem;
    line-height: 1.1;
}

.newsletter-block-text h4 {
    padding-top: 2rem;
    font-size: 1.5rem;
}

.newsletter-richtext {
    padding: 0 2rem 2rem;
    line-height: 1.7;
    color: var(--block-text-color, #334155);
}

.newsletter-richtext a,
.newsletter-brand a,
.newsletter-block h3 a,
.newsletter-block h4 a {
    color: var(--block-text-color, currentColor);
    text-decoration: underline;
}

.newsletter-richtext p:first-child {
    margin-top: 0;
}

.newsletter-richtext p:last-child {
    margin-bottom: 0;
}

.newsletter-image-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
    background: #f8fafc;
    color: var(--block-text-color, #64748b);
    border: 1px dashed #cbd5e1;
    cursor: pointer;
    overflow: hidden;
}

.newsletter-image-slot span {
    padding: 1rem 1.25rem;
    text-align: center;
    line-height: 1.6;
}

.newsletter-image-slot.is-dragover {
    border-color: #111827;
    background: #eef4ff;
}

.newsletter-image-slot.has-image {
    border: 0;
    background: #fff;
}

.newsletter-image-slot img {
    width: 100%;
    display: block;
}

.newsletter-block-image .newsletter-image-slot {
    min-height: 420px;
}

.newsletter-block-double-image .double-image-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.newsletter-block-double-image .newsletter-image-slot {
    min-height: 280px;
}

.newsletter-block-cta {
    padding: 2rem;
    display: grid;
    gap: 1rem;
    justify-items: center;
}

.cta-fields {
    width: 100%;
    display: grid;
    gap: 0.75rem;
}

.newsletter-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0.85rem 1.6rem;
    border-radius: 999px;
    background: #111111;
    color: #fff;
    font-weight: 400;
}

.newsletter-block-spacer {
    padding: 2rem;
}

.spacer-control {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.newsletter-block-footer {
    padding: 1.5rem 0;
    border-top: 0;
}

.theme-config-block {
    display: grid;
    gap: 0.9rem;
}

.theme-config-block h4 {
    margin: 0;
}

.newsletter-theme-tabs {
    display: flex;
    gap: 0.75rem;
}

.newsletter-theme-tab {
    min-width: 120px;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    background: #fff;
    color: var(--color-text);
    cursor: pointer;
    font-weight: 600;
}

.newsletter-theme-tab.is-active {
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    border-color: var(--color-primary);
}

.theme-rich-editor {
    display: grid;
    gap: 0.7rem;
}

.theme-rich-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.theme-rich-editor-toolbar button {
    min-width: 38px;
    height: 38px;
    padding: 0 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}

.theme-rich-editor-input {
    min-height: 180px;
    padding: 0.9rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 14px;
    background: var(--color-surface);
    line-height: 1.7;
}

.theme-rich-editor-input:focus {
    outline: none;
    border-color: #94a3b8;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.18);
}

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

.theme-upload-dropzone {
    display: grid;
    gap: 0.3rem;
    justify-items: center;
    padding: 1.1rem 1rem;
    border: 1px dashed var(--color-border);
    border-radius: 14px;
    background: #f8fafc;
    color: var(--color-text-soft);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.theme-upload-dropzone strong {
    color: var(--color-text);
}

.theme-upload-dropzone small {
    color: #64748b;
}

.theme-upload-dropzone.is-dragover,
.theme-upload-dropzone.has-file {
    border-color: #111827;
    background: #eef4ff;
}

.newsletter-list-actions {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 34px;
}

.newsletter-list-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: #fff;
    font-size: 1rem;
    color: var(--color-text);
    cursor: pointer;
}

.newsletter-list-icon-danger {
    color: var(--color-danger);
    border-color: rgba(220, 38, 38, 0.24);
}

.newsletter-list-icon-danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

.newsletter-list-table th,
.newsletter-list-table td {
    vertical-align: middle;
}

.newsletter-subject-link {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    font-weight: 400;
}

.newsletter-list-test-status {
    min-height: 1.4rem;
    font-size: 0.92rem;
    color: var(--color-text-soft);
}

.newsletter-list-test-status[data-mode="success"] {
    color: var(--color-success);
}

.newsletter-list-test-status[data-mode="error"] {
    color: var(--color-danger);
}

.newsletter-list-test-status[data-mode="saving"] {
    color: var(--color-info);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
}

.pagination-status {
    color: var(--color-text-soft);
    font-weight: 600;
}

.theme-preview-image {
    max-width: 180px;
    max-height: 90px;
    object-fit: contain;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 0.5rem;
    background: #fff;
}

.newsletter-theme-modal-card {
    width: min(100%, 760px);
}

.editor-modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    overflow-y: auto;
    padding: 1.5rem;
}

.editor-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.editor-modal-card {
    position: relative;
    width: min(100%, 460px);
    max-height: calc(100vh - 3rem);
    margin: 0 auto;
    background: #fff;
    border-radius: 18px;
    padding: 1.5rem;
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.3);
    z-index: 1;
    overflow-y: auto;
}

.editor-modal-card h3 {
    margin-top: 0;
}

.editor-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
}

.confirm-modal-card {
    width: min(100%, 520px);
}

.confirm-modal-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    background: rgba(220, 38, 38, 0.1);
    color: var(--color-danger);
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.85rem;
}

.confirm-modal-copy {
    color: var(--color-text-soft);
    line-height: 1.65;
}

.confirm-modal-subject {
    margin-top: 1rem;
    padding: 0.95rem 1rem;
    border-radius: 14px;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border);
    font-weight: 700;
    overflow-wrap: anywhere;
}

.editor-link-status {
    min-height: 1.5rem;
    margin-top: 0.75rem;
    font-size: 0.92rem;
    color: var(--color-text-soft);
}

.editor-link-status[data-mode="success"] {
    color: var(--color-success);
}

.editor-link-status[data-mode="error"] {
    color: var(--color-danger);
}

@media (max-width: 980px) {
    .newsletter-editor-layout {
        grid-template-columns: 1fr;
    }

    .newsletter-editor-topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .newsletter-editor-title,
    .newsletter-editor-actions,
    .subject-display,
    .subject-editor {
        flex-wrap: wrap;
    }

    .subject-editor input {
        min-width: 0;
        width: 100%;
    }
}
