:root,
[data-theme="red"] {
    --red: #e11d48;
    --red-mid: #c41e3a;
    --red-dark: #9f1239;
    --red-deep: #881337;
    --red-light: #fff1f2;
    --red-glow: rgba(225, 29, 72, 0.35);
    --accent-tint-start: #fff1f2;
    --accent-tint-end: #ffe4e6;
    --accent-tint-border: #f9a8b4;
    --accent-tint-border-soft: #fecdd3;
    --white: #ffffff;
    --bg: #f8fafc;
    --bg-mesh: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(225, 29, 72, 0.08), transparent),
               radial-gradient(ellipse 60% 40% at 100% 0%, rgba(251, 113, 133, 0.06), transparent);
    --panel: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --sidebar: #be123c;
    --sidebar-hover: rgba(255, 255, 255, 0.12);
    --gradient-sidebar: linear-gradient(175deg, #e11d48 0%, #be123c 40%, #9f1239 100%);
    --gradient-topbar: linear-gradient(90deg, #f43f5e 0%, #e11d48 40%, #be123c 100%);
    --gradient-hero: linear-gradient(135deg, #be123c 0%, #e11d48 50%, #fb7185 100%);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 32px rgba(190, 18, 60, 0.12), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-sidebar: 4px 0 24px rgba(190, 18, 60, 0.15);
    --shadow-topbar: 0 2px 12px rgba(190, 18, 60, 0.2);
    --radius: 12px;
    --radius-lg: 16px;
    --ok: #16a34a;
    --danger: #dc2626;
}

[data-theme="black"] {
    --red: #171717;
    --red-mid: #262626;
    --red-dark: #0a0a0a;
    --red-deep: #000000;
    --red-light: #f5f5f5;
    --red-glow: rgba(23, 23, 23, 0.35);
    --accent-tint-start: #f5f5f5;
    --accent-tint-end: #e5e5e5;
    --accent-tint-border: #d4d4d4;
    --accent-tint-border-soft: #e5e5e5;
    --bg-mesh: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(23, 23, 23, 0.06), transparent),
               radial-gradient(ellipse 60% 40% at 100% 0%, rgba(82, 82, 82, 0.05), transparent);
    --sidebar: #171717;
    --gradient-sidebar: linear-gradient(175deg, #404040 0%, #171717 40%, #0a0a0a 100%);
    --gradient-topbar: linear-gradient(90deg, #525252 0%, #262626 40%, #171717 100%);
    --gradient-hero: linear-gradient(135deg, #171717 0%, #404040 50%, #737373 100%);
    --shadow-lg: 0 12px 32px rgba(23, 23, 23, 0.12), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-sidebar: 4px 0 24px rgba(23, 23, 23, 0.18);
    --shadow-topbar: 0 2px 12px rgba(23, 23, 23, 0.22);
}

[data-theme="blue"] {
    --red: #2563eb;
    --red-mid: #1d4ed8;
    --red-dark: #1e3a8a;
    --red-deep: #172554;
    --red-light: #eff6ff;
    --red-glow: rgba(37, 99, 235, 0.35);
    --accent-tint-start: #eff6ff;
    --accent-tint-end: #dbeafe;
    --accent-tint-border: #93c5fd;
    --accent-tint-border-soft: #bfdbfe;
    --bg-mesh: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(37, 99, 235, 0.08), transparent),
               radial-gradient(ellipse 60% 40% at 100% 0%, rgba(96, 165, 250, 0.06), transparent);
    --sidebar: #1d4ed8;
    --gradient-sidebar: linear-gradient(175deg, #3b82f6 0%, #1d4ed8 40%, #1e3a8a 100%);
    --gradient-topbar: linear-gradient(90deg, #60a5fa 0%, #2563eb 40%, #1d4ed8 100%);
    --gradient-hero: linear-gradient(135deg, #1d4ed8 0%, #2563eb 50%, #60a5fa 100%);
    --shadow-lg: 0 12px 32px rgba(37, 99, 235, 0.12), 0 4px 12px rgba(15, 23, 42, 0.06);
    --shadow-sidebar: 4px 0 24px rgba(37, 99, 235, 0.15);
    --shadow-topbar: 0 2px 12px rgba(37, 99, 235, 0.2);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.icon { width: 1.125rem; height: 1.125rem; flex-shrink: 0; }
.icon-spin { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

a { color: var(--red); text-decoration: none; }
a:hover { color: var(--red-dark); text-decoration: underline; }

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 252px;
    background: var(--gradient-sidebar);
    color: var(--white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: var(--shadow-sidebar);
}

.sidebar-brand {
    padding: 1.35rem 1.25rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.sidebar-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 10px;
    background: rgba(255,255,255,0.2);
    font-weight: 800;
    font-size: 0.72rem;
    letter-spacing: 0.02em;
    backdrop-filter: blur(4px);
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    align-items: baseline;
    gap: 0.2rem;
    line-height: 1.15;
}

.sidebar-brand-name {
    font-weight: 700;
}

.sidebar-brand-ai {
    font-weight: 800;
    font-size: 0.82rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.92;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    padding: 1rem 0.75rem;
    gap: 0.2rem;
    flex: 1;
}

.sidebar nav a {
    color: rgba(255,255,255,0.92);
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background 0.15s, color 0.15s;
}

.nav-icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    flex-shrink: 0;
    transition: background 0.15s, box-shadow 0.15s;
}

.nav-icon {
    width: 1.15rem;
    height: 1.15rem;
    display: block;
    flex-shrink: 0;
}

.nav-label {
    line-height: 1.3;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: var(--sidebar-hover);
    color: var(--white);
    text-decoration: none;
}

.sidebar nav a:hover .nav-icon-wrap,
.sidebar nav a.active .nav-icon-wrap {
    background: rgba(255, 255, 255, 0.22);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.sidebar nav a.active {
    background: rgba(255,255,255,0.18);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
}

.sidebar nav a.active .nav-icon-wrap {
    background: rgba(255, 255, 255, 0.28);
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
    background-image: var(--bg-mesh);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.75rem;
    height: 58px;
    background: var(--gradient-topbar);
    border-bottom: none;
    box-shadow: var(--shadow-topbar);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--white);
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    min-width: 0;
}

.topbar-brand {
    font-weight: 700;
    letter-spacing: -0.02em;
}

.topbar-page-sep {
    opacity: 0.55;
    font-weight: 400;
}

.topbar-page {
    font-weight: 500;
    opacity: 0.92;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}

.topbar-user {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.theme-picker {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.theme-picker-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.75);
    padding-right: 0.15rem;
}

.theme-swatch {
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.9);
    padding: 0;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    flex-shrink: 0;
}

.theme-swatch:hover {
    transform: scale(1.06);
}

.theme-swatch[aria-pressed="true"] {
    box-shadow: 0 0 0 2px var(--white), 0 0 0 4px rgba(255, 255, 255, 0.35);
    transform: scale(1.08);
}

.theme-swatch-red {
    background: linear-gradient(135deg, #ffffff 0%, #ffffff 48%, #e11d48 52%, #e11d48 100%);
}

.theme-swatch-black {
    background: linear-gradient(135deg, #ffffff 0%, #ffffff 48%, #171717 52%, #171717 100%);
}

.theme-swatch-blue {
    background: linear-gradient(135deg, #ffffff 0%, #ffffff 48%, #2563eb 52%, #2563eb 100%);
}

.content {
    flex: 1;
    padding: 1.75rem 2rem 2.5rem;
    max-width: 1200px;
    width: 100%;
    min-width: 0;
}

.panel {
    padding: 1.25rem 1.5rem;
    margin-top: 1.5rem;
    max-width: 100%;
    min-width: 0;
}

.page-dashboard .content {
    max-width: 1280px;
}

.main-centered {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: var(--white);
}

.card, .panel, .stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.auth-card {
    width: min(420px, 100%);
    padding: 2rem;
    border-top: 4px solid var(--red);
}

body.login-page .auth-card h1 {
    color: var(--red);
}

h1 { margin: 0 0 0.35rem; font-size: 1.6rem; color: var(--text); }
h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }

.page-header {
    margin-bottom: 0.5rem;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: center;
    white-space: nowrap;
}

.inline-form { display: inline; margin: 0; }

.btn-link {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-weight: 600;
    color: var(--red);
    cursor: pointer;
    text-decoration: none;
}

.btn-link:hover { text-decoration: underline; }

.danger-link { color: var(--danger); }

.pill-role-viewer { background: #f4f4f5; color: #52525b; }
.pill-role-operator { background: #dbeafe; color: #1d4ed8; }
.pill-role-admin { background: #fce7f3; color: #be185d; }
.pill-role-super_admin { background: #1e293b; color: #f8fafc; }

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-top: 1.25rem;
}

.stat-card { padding: 1rem 1.25rem; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; margin-top: 0.25rem; color: var(--red); }
.stat-sub { font-size: 1rem; color: var(--muted); font-weight: 400; }

.action-card {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.action-card h3 {
    margin: 0;
    font-size: 1.05rem;
}

.form { display: grid; gap: 1rem; margin-top: 1rem; }
.form label { display: grid; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.form input,
.form select,
.form textarea {
    padding: 0.65rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text);
    font-size: 0.95rem;
}

.form input:focus,
.form select:focus,
.form textarea:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: 0 0 0 3px var(--red-light);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    font-size: 0.92rem;
}

.checkbox-row input { width: auto; }

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.75rem 1.25rem;
    margin: 0.75rem 0 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.15rem;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    font-size: 0.92rem;
    transition: background 0.15s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--red) 0%, var(--red-mid) 100%);
    color: white;
    box-shadow: 0 2px 8px var(--red-glow);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--red-mid) 0%, var(--red-dark) 100%);
    color: white;
    text-decoration: none;
    box-shadow: 0 4px 12px var(--red-glow);
}
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.btn-glow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    border-radius: 10px;
    background: var(--white);
    color: var(--red-dark);
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
    transition: transform 0.15s, box-shadow 0.15s;
}
.btn-glow:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    color: var(--red-deep);
    text-decoration: none;
}

.btn-hero-ghost {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    border-radius: 10px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.35);
    color: var(--white);
    font-weight: 600;
    text-decoration: none;
    backdrop-filter: blur(4px);
    transition: background 0.15s;
}
.btn-hero-ghost:hover {
    background: rgba(255,255,255,0.25);
    color: var(--white);
    text-decoration: none;
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.btn-ghost:hover { background: var(--bg); text-decoration: none; }

.topbar .btn-ghost.topbar-logout {
    border-color: rgba(255, 255, 255, 0.65);
    color: var(--white);
}

.topbar .btn-ghost.topbar-logout:hover {
    background: var(--red-dark);
    border-color: var(--white);
    color: var(--white);
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
}

.btn-white {
    background: var(--white);
    color: var(--red);
    border-color: var(--white);
}
.btn-white:hover { background: var(--red-light); text-decoration: none; }

.alert { padding: 0.75rem 1rem; border-radius: 8px; margin: 1rem 0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: var(--red-light); color: var(--red-dark); border: 1px solid var(--accent-tint-border); }

.banner-running {
    background: linear-gradient(135deg, var(--accent-tint-start) 0%, var(--accent-tint-end) 100%);
    border: 1px solid var(--accent-tint-border-soft);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-top: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.banner-running-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 12px;
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--red);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.data-table th, .data-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.data-table th { color: var(--muted); font-weight: 600; background: #fafafa; }
.nowrap { white-space: nowrap; }
.row-current { background: var(--red-light); }

.pill {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
}
.pill-completed { background: #dcfce7; color: #166534; }
.pill-running { background: var(--red-light); color: var(--red-dark); }
.pill-failed { background: #fef2f2; color: #991b1b; }
.pill-pending { background: #f4f4f5; color: #52525b; }

.code-block {
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    overflow: auto;
    font-size: 0.82rem;
}
.hidden { display: none; }

.flash-list { margin-bottom: 1rem; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    background: var(--red-light);
    color: var(--red-dark);
    border: 1px solid var(--accent-tint-border);
    margin-bottom: 0.5rem;
}

code {
    background: #f4f4f5;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.88em;
}

.mode-tabs {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.mode-tab {
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--white);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
}

.mode-tab.active {
    background: var(--red);
    color: var(--white);
    border-color: var(--red);
}

.mode-panel { display: none; margin-top: 1rem; }
.mode-panel.active { display: block; }

.scrape-step-title {
    font-size: 0.95rem;
    margin: 1.25rem 0 0.5rem;
    color: var(--muted);
}

.checkbox-row-end {
    align-self: end;
    padding-bottom: 0.5rem;
}

.filter-bar { margin-top: 1rem; }
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
}
.filter-bar label { display: grid; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.filter-bar input,
.filter-bar select {
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.92rem;
}
.filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    align-items: center;
}
.results-meta { margin: 1rem 0 0.5rem; }
.table-wrap {
    margin-top: 0.5rem;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap.panel {
    padding: 0;
    margin-top: 1.5rem;
}
.data-table-hover tbody tr.row-link { cursor: pointer; }
.data-table-hover tbody tr.row-link:hover { background: var(--red-light); }
.row-title { color: var(--text); font-weight: 600; text-decoration: none; }
.row-title:hover { color: var(--red); text-decoration: underline; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--red); }
.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.25rem;
}
.back-link { font-size: 0.9rem; display: inline-block; margin-bottom: 0.5rem; }
.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
}
.profile-tabs { margin-top: 1rem; }
.profile-tabs .mode-tab { text-decoration: none; }
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
}
.detail-section h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.75rem; }
.detail-list { margin: 0; }
.detail-list dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-top: 0.65rem; }
.detail-list dt:first-child { margin-top: 0; }
.detail-list dd { margin: 0.15rem 0 0; }
.thread-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: 1rem;
    overflow: hidden;
}
.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    background: #fafafa;
    border-bottom: 1px solid var(--border);
}
.thread-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}
.thread-empty { padding: 1rem; margin: 0; }
.message {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}
.message:last-child { border-bottom: none; }
.message-inbound { background: var(--white); }
.message-outbound {
    margin: 0.75rem 0 0 1rem;
    padding: 0.85rem;
    border-radius: 8px;
    background: var(--red-light);
    border: 1px solid var(--accent-tint-border);
}
.message-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.35rem;
    font-size: 0.88rem;
}
.message-subject { font-weight: 600; margin-bottom: 0.35rem; }
.message-body {
    white-space: pre-wrap;
    font-size: 0.92rem;
    color: var(--text);
    max-height: 240px;
    overflow: auto;
}
.pill-status-new { background: #f4f4f5; color: #52525b; }
.pill-status-enriched { background: #dbeafe; color: #1e40af; }
.pill-status-queued { background: #fef9c3; color: #854d0e; }
.pill-status-contacted { background: var(--red-light); color: var(--red-dark); }
.pill-status-opened { background: #e0e7ff; color: #3730a3; }
.pill-status-clicked { background: #ede9fe; color: #5b21b6; }
.pill-status-replied { background: #dcfce7; color: #166534; }
.pill-status-unsubscribed { background: #f4f4f5; color: #71717a; }
.pill-status-bounced { background: #fef2f2; color: #991b1b; }
.pill-status-do_not_contact { background: #1f2937; color: #f9fafb; }
.pill-draft { background: #f4f4f5; color: #52525b; }
.pill-sent, .pill-delivered { background: #dbeafe; color: #1e40af; }
.pill-opened { background: #e0e7ff; color: #3730a3; }
.pill-clicked { background: #ede9fe; color: #5b21b6; }
.pill-replied { background: #dcfce7; color: #166534; }
.pill-bounced, .pill-failed { background: #fef2f2; color: #991b1b; }
.pill-open { background: var(--red-light); color: var(--red-dark); }
.pill-closed { background: #f4f4f5; color: #52525b; }
.pill-waiting_customer, .pill-waiting_agent { background: #fef9c3; color: #854d0e; }
.pill-approved { background: #dcfce7; color: #166534; }
.pill-discarded { background: #f4f4f5; color: #71717a; }

/* ——— Dashboard ——— */
.dashboard { display: flex; flex-direction: column; gap: 1.75rem; }

.dash-hero {
    position: relative;
    border-radius: 20px;
    background: var(--gradient-hero);
    padding: 2rem 2.25rem;
    overflow: hidden;
    color: var(--white);
    box-shadow: var(--shadow-lg);
}

.dash-hero-content { position: relative; z-index: 1; max-width: 560px; }

.dash-eyebrow {
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.9;
}

.dash-hero-title {
    margin: 0 0 0.5rem;
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--white);
}

.dash-hero-sub {
    margin: 0 0 1.5rem;
    opacity: 0.92;
    font-size: 1rem;
    line-height: 1.55;
}

.dash-hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

.dash-hero-visual {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.dash-orb {
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(2px);
}
.dash-orb-1 { width: 280px; height: 280px; top: -80px; right: -40px; }
.dash-orb-2 { width: 160px; height: 160px; bottom: -40px; right: 25%; background: rgba(255,255,255,0.08); }
.dash-orb-3 { width: 100px; height: 100px; top: 30%; right: 15%; background: rgba(255,255,255,0.06); }

.dash-job-banner { margin-top: 0; }

.dash-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.dash-kpi-card {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 1.15rem 1.2rem;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s, transform 0.2s;
}

.dash-kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.dash-kpi-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dash-kpi-icon svg { width: 1.35rem; height: 1.35rem; }

.dash-kpi-leads { background: linear-gradient(135deg, var(--accent-tint-start), var(--accent-tint-end)); color: var(--red); }
.dash-kpi-email { background: linear-gradient(135deg, #eff6ff, #dbeafe); color: #2563eb; }
.dash-kpi-sent { background: linear-gradient(135deg, #f0fdf4, #dcfce7); color: #16a34a; }
.dash-kpi-replies { background: linear-gradient(135deg, #fdf4ff, #fae8ff); color: #9333ea; }
.dash-kpi-scrape { background: linear-gradient(135deg, #fff7ed, #ffedd5); color: #ea580c; }

.dash-kpi-body { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }

.dash-kpi-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.dash-kpi-value {
    font-size: 1.65rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--text);
}

.dash-kpi-value-sm { font-size: 1rem; font-weight: 700; }

.dash-kpi-hint {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.15rem;
}

.dash-chart-panel { margin-top: 0; }

.dash-chart-wrap {
    position: relative;
    height: 320px;
    width: 100%;
}

.dash-section-title {
    margin: 0 0 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}

.dash-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.dash-action-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.35rem;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    position: relative;
    overflow: hidden;
}

.dash-action-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: var(--gradient-hero);
    opacity: 0;
    transition: opacity 0.2s;
}

.dash-action-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-tint-border-soft);
    text-decoration: none;
    color: inherit;
}

.dash-action-card:hover::before { opacity: 1; }

.dash-action-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dash-action-icon svg { width: 1.5rem; height: 1.5rem; }

.dash-action-maps .dash-action-icon {
    background: linear-gradient(135deg, var(--accent-tint-start), var(--accent-tint-end));
    color: var(--red);
}

.dash-action-email .dash-action-icon {
    background: linear-gradient(135deg, #fdf4ff, #fae8ff);
    color: #a21caf;
}

.dash-action-card h3 {
    margin: 0 0 0.35rem;
    font-size: 1.05rem;
    font-weight: 700;
}

.dash-action-card p {
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.45;
}

.dash-action-arrow {
    margin-left: auto;
    align-self: center;
    font-size: 1.25rem;
    color: var(--muted);
    transition: transform 0.2s, color 0.2s;
}

.dash-action-card:hover .dash-action-arrow {
    transform: translateX(4px);
    color: var(--red);
}

.dash-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.dash-stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}

.dash-stat-card:hover { box-shadow: var(--shadow-md); }

.dash-stat-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dash-stat-icon svg { width: 1.35rem; height: 1.35rem; }

.dash-stat-icon-rotation {
    background: linear-gradient(135deg, #fff7ed, #ffedd5);
    color: #ea580c;
}

.dash-stat-icon-business {
    background: linear-gradient(135deg, var(--accent-tint-start), var(--accent-tint-end));
    color: var(--red);
}

.dash-stat-icon-runs {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    color: #2563eb;
}

.dash-stat-body { display: flex; flex-direction: column; gap: 0.15rem; }

.dash-stat-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.dash-stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text);
    line-height: 1.1;
}

.dash-stat-sub {
    font-size: 1rem;
    font-weight: 500;
    color: var(--muted);
}

.dash-panels {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
    align-items: start;
}

.dash-panel {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.5rem;
    box-shadow: var(--shadow-sm);
}

.dash-panel-wide { min-width: 0; }

.dash-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.dash-panel-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.dash-panel-title h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.dash-panel-title .icon { color: var(--red); }

.dash-panel-link {
    font-size: 0.88rem;
    font-weight: 600;
    text-decoration: none;
}

.dash-db-status {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding: 1rem;
    border-radius: 12px;
}

.dash-db-ok { background: linear-gradient(135deg, #f0fdf4, #dcfce7); }
.dash-db-error { background: linear-gradient(135deg, #fef2f2, #fee2e2); }

.dash-db-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 0.35rem;
    flex-shrink: 0;
}

.dash-db-ok .dash-db-dot {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}

.dash-db-error .dash-db-dot {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}

.dash-db-status strong { display: block; margin-bottom: 0.15rem; }
.dash-db-status p { margin: 0; font-size: 0.88rem; }

.dash-service-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.dash-service-item {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface-elevated, #fff);
}

.dash-service-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 0.35rem;
    flex-shrink: 0;
}

.dash-service-running .dash-service-dot {
    background: #16a34a;
    box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.15);
}

.dash-service-stopped .dash-service-dot {
    background: #dc2626;
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.12);
}

.dash-service-disabled .dash-service-dot {
    background: #94a3b8;
    box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.15);
}

.dash-service-body {
    flex: 1;
    min-width: 0;
}

.dash-service-body strong {
    margin-right: 0.5rem;
}

.dash-service-pill {
    font-size: 0.72rem;
    vertical-align: middle;
}

.dash-service-body p {
    margin: 0.35rem 0 0;
    font-size: 0.88rem;
    line-height: 1.45;
}

.dash-db-compact {
    margin: 1rem 0 0;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    font-size: 0.84rem;
}

.dash-db-compact strong {
    font-weight: 600;
}

.reply-history-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.data-table-modern thead th {
    background: #f8fafc;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.data-table-modern tbody tr:hover { background: #fafafa; }

.dash-empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
}

.dash-empty svg {
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.dash-empty p { margin: 0; font-size: 0.92rem; }

/* Rotation queries page */
.queries-panel {
    overflow: hidden;
}

.queries-section-title {
    font-size: 1rem;
    margin: 0 0 1rem;
    color: var(--muted);
}

.queries-settings-form,
.queries-filter-form {
    margin-top: 0;
}

.queries-notes {
    margin-top: 0.75rem;
}

.queries-table-wrap {
    margin-top: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.queries-table {
    font-size: 0.76rem;
    line-height: 1.35;
    min-width: 480px;
    table-layout: fixed;
    width: 100%;
}

.queries-table th,
.queries-table td {
    padding: 0.35rem 0.4rem;
    vertical-align: middle;
}

.queries-table.data-table-modern thead th {
    font-size: 0.68rem;
    letter-spacing: 0.03em;
    padding: 0.4rem 0.4rem;
}

.queries-table strong {
    font-weight: 600;
    font-size: inherit;
}

.queries-col-day {
    width: 3.25rem;
}

.queries-col-label {
    width: 18%;
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queries-col-term {
    width: 14%;
    max-width: 7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queries-col-state {
    width: 2.75rem;
    text-align: center;
}

.queries-col-num {
    width: 2.75rem;
    text-align: center;
}

.queries-col-file {
    width: 22%;
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queries-file {
    word-break: break-all;
    font-size: 0.72rem;
}

.queries-table .pill {
    font-size: 0.62rem;
    padding: 0.1rem 0.35rem;
}

.queries-today-pill {
    margin-left: 0.15rem;
}

.queries-col-actions {
    width: 4.5rem;
    white-space: nowrap;
}

.queries-col-actions.table-actions {
    flex-wrap: nowrap;
    gap: 0.35rem;
    font-size: 0.74rem;
}

.queries-col-actions .btn-link {
    font-size: inherit;
}

@media (max-width: 900px) {
    .dash-panels { grid-template-columns: 1fr; }
    .dash-hero-title { font-size: 1.5rem; }
    .queries-col-hide-md {
        display: none;
    }
}

/* === Global responsive === */
.panel-narrow {
    max-width: 720px;
    width: 100%;
}

.panel-narrow-sm {
    max-width: 520px;
    width: 100%;
}

.text-preview {
    margin-top: 0.35rem;
    max-width: 100%;
    word-break: break-word;
}

.alert-actions {
    margin-top: 0.5rem;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.topbar-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-page {
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: var(--white);
    cursor: pointer;
    flex-shrink: 0;
}

.nav-toggle:hover {
    background: rgba(255, 255, 255, 0.22);
}

.nav-toggle-icon {
    width: 1.15rem;
    height: 1.15rem;
    display: block;
}

.sidebar-backdrop {
    display: none;
}

.form input,
.form select,
.form textarea,
.filter-bar input,
.filter-bar select {
    width: 100%;
    max-width: 100%;
}

.data-table td a,
.data-table td code,
.detail-list dd a {
    word-break: break-word;
}

body.nav-open {
    overflow: hidden;
}

@media (max-width: 1024px) {
    .nav-toggle {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(272px, 88vw);
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        overflow-y: auto;
    }

    .sidebar nav {
        flex-direction: column;
        flex-wrap: nowrap;
        padding: 0.75rem;
    }

    .sidebar nav a {
        flex-direction: row;
        text-align: left;
        min-width: 0;
        font-size: 0.9rem;
        padding: 0.55rem 0.75rem;
    }

    .nav-label {
        max-width: none;
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 150;
        background: rgba(15, 23, 42, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.22s ease;
    }

    .layout.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .layout.sidebar-open .sidebar-backdrop {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .layout {
        flex-direction: row;
    }

    .main-wrapper {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 768px) {
    h1 { font-size: 1.35rem; }

    .content {
        padding: 1rem;
    }

    .panel {
        padding: 1rem;
        margin-top: 1rem;
    }

    .topbar {
        padding: 0 0.85rem;
        height: 52px;
    }

    .topbar-user {
        display: none;
    }

    .theme-picker-label {
        display: none;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .filter-grid {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        width: 100%;
    }

    .filter-actions .btn {
        flex: 1 1 auto;
        min-width: 0;
    }

    .page-header-row,
    .profile-header {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header-row > .btn,
    .page-header-row > a.btn {
        width: 100%;
        justify-content: center;
    }

    .banner-running {
        flex-direction: column;
        align-items: flex-start;
    }

    .dash-hero {
        padding: 1.35rem 1.25rem;
        border-radius: 16px;
    }

    .dash-hero-title {
        font-size: 1.35rem;
    }

    .dash-hero-actions {
        flex-direction: column;
    }

    .dash-hero-actions .btn-glow,
    .dash-hero-actions .btn-hero-ghost {
        width: 100%;
        justify-content: center;
    }

    .dash-kpi-grid {
        grid-template-columns: 1fr 1fr;
    }

    .dash-chart-wrap {
        height: 240px;
    }

    .dash-panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .pagination {
        flex-wrap: wrap;
    }

    .thread-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .message-outbound {
        margin-left: 0;
    }

    .table-actions {
        white-space: normal;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.35rem;
    }

    .data-table {
        font-size: 0.82rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.55rem;
    }

    .queries-col-hide-sm {
        display: none;
    }

    .queries-col-actions.table-actions {
        display: grid;
        gap: 0.35rem;
        white-space: normal;
    }

    .queries-today-pill {
        display: inline-block;
        margin-left: 0;
        margin-top: 0.25rem;
    }
}

@media (max-width: 480px) {
    .dash-kpi-grid {
        grid-template-columns: 1fr;
    }

    .dash-kpi-value {
        font-size: 1.4rem;
    }

    .auth-card {
        padding: 1.5rem;
    }

    .mode-tabs {
        gap: 0.35rem;
    }

    .mode-tab {
        font-size: 0.8rem;
        padding: 0.4rem 0.7rem;
    }
}

/* --- Email template studio --- */
.page-email-studio .content {
    max-width: none;
    padding: 1.25rem 1.5rem 2rem;
}

.email-studio-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.email-studio-header h1 {
    margin: 0.35rem 0 0.25rem;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.email-studio-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.email-studio-meta {
    margin-bottom: 1rem;
    padding: 1rem 1.25rem;
}

.email-studio-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
    gap: 0.85rem 1rem;
    align-items: end;
}

.email-studio-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin: 0;
}

.email-studio-field-check {
    justify-content: flex-end;
    padding-bottom: 0.35rem;
}

.email-studio-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.email-studio-workspace {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr) minmax(320px, 420px);
    gap: 1rem;
    align-items: start;
}

.email-studio-panel-title {
    margin: 0 0 0.35rem;
    font-size: 0.92rem;
    font-weight: 700;
}

.email-studio-panel-hint {
    margin: 0 0 0.85rem;
    font-size: 0.8rem;
}

.email-studio-sidebar {
    padding: 1rem;
    position: sticky;
    top: 74px;
    max-height: calc(100vh - 90px);
    overflow: auto;
}

.email-starter-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.email-starter-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    width: 100%;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.email-starter-card:hover {
    border-color: var(--red);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.email-starter-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
}

.email-starter-desc {
    font-size: 0.75rem;
    color: var(--muted);
}

.email-merge-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.email-merge-tag {
    border: 1px dashed var(--accent-tint-border);
    background: var(--red-light);
    color: var(--red-dark);
    border-radius: 999px;
    padding: 0.25rem 0.55rem;
    font-size: 0.72rem;
    font-family: ui-monospace, Consolas, monospace;
    cursor: pointer;
}

.email-merge-tag:hover {
    border-color: var(--red);
    background: var(--accent-tint-end);
}

.email-studio-editor,
.email-studio-preview {
    padding: 1rem 1.1rem;
    min-width: 0;
}

.email-studio-editor-head,
.email-studio-preview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.email-editor-tabs,
.email-preview-modes {
    display: inline-flex;
    padding: 0.2rem;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
}

.email-editor-tab,
.email-preview-mode {
    border: none;
    background: transparent;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}

.email-editor-tab.active,
.email-preview-mode.active {
    background: var(--white);
    color: var(--red);
    box-shadow: var(--shadow-sm);
}

.email-studio-subject-field {
    margin-bottom: 0.75rem;
}

.email-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.65rem;
}

.email-tool-btn {
    min-width: 2.25rem;
    height: 2rem;
    padding: 0 0.55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--white);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
}

.email-tool-btn:hover {
    border-color: var(--red);
    color: var(--red);
}

.email-editor-pane {
    display: none;
}

.email-editor-pane.active {
    display: block;
}

.email-code-editor {
    width: 100%;
    min-height: 420px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.55;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    background: #0f172a;
    color: #e2e8f0;
    tab-size: 2;
}

.email-text-editor {
    background: var(--white);
    color: var(--text);
    min-height: 320px;
}

.email-studio-preview {
    position: sticky;
    top: 74px;
}

.email-inbox-mock {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(180deg, var(--bg) 0%, var(--white) 100%);
    padding: 0.85rem 1rem;
    margin-bottom: 0.75rem;
}

.email-inbox-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.email-inbox-from {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.82rem;
    margin-bottom: 0.35rem;
}

.email-inbox-from strong {
    display: block;
    font-size: 0.88rem;
}

.email-inbox-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--gradient-topbar);
    color: var(--white);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 800;
}

.email-inbox-to {
    font-size: 0.82rem;
    margin-bottom: 0.35rem;
}

.email-inbox-subject {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.35;
}

.email-preview-frame-wrap {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #cbd5e1;
    box-shadow: inset 0 2px 8px rgba(15, 23, 42, 0.06);
}

.email-preview-frame-wrap.desktop .email-preview-frame {
    width: 100%;
    height: 520px;
    border: none;
    display: block;
    background: #f1f5f9;
}

.email-preview-frame-wrap.mobile {
    max-width: 375px;
    margin: 0 auto;
}

.email-preview-frame-wrap.mobile .email-preview-frame {
    width: 100%;
    height: 620px;
    border: none;
    display: block;
    background: #f1f5f9;
}

.email-preview-note {
    margin: 0.65rem 0 0;
    font-size: 0.75rem;
}

.email-test-send {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.email-test-send-title {
    margin: 0 0 0.35rem;
    font-size: 0.92rem;
    font-weight: 700;
}

.email-test-send-hint {
    margin: 0 0 0.75rem;
    font-size: 0.78rem;
    line-height: 1.45;
}

.email-test-send-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.email-test-input {
    flex: 1 1 180px;
    min-width: 0;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.88rem;
}

.email-test-input:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: 0 0 0 3px var(--red-light);
}

.email-test-status {
    margin: 0.55rem 0 0;
    font-size: 0.8rem;
    min-height: 1.2em;
}

.email-test-status-ok {
    color: var(--ok);
}

.email-test-status-error {
    color: var(--danger);
}

@media (max-width: 1200px) {
    .email-studio-workspace {
        grid-template-columns: 220px minmax(0, 1fr);
    }

    .email-studio-preview {
        grid-column: 1 / -1;
        position: static;
    }
}

@media (max-width: 900px) {
    .email-studio-meta-grid {
        grid-template-columns: 1fr 1fr;
    }

    .email-studio-workspace {
        grid-template-columns: 1fr;
    }

    .email-studio-sidebar {
        position: static;
        max-height: none;
    }

    .email-code-editor {
        min-height: 280px;
    }
}

@media (max-width: 600px) {
    .email-studio-meta-grid {
        grid-template-columns: 1fr;
    }

    .email-studio-header-actions {
        width: 100%;
    }

    .email-studio-header-actions .btn {
        flex: 1;
    }
}

/* Pipeline run progress (runs page + modal) */
.run-status-cell {
    min-width: 11rem;
}

.run-progress-line {
    font-size: 0.82rem;
    margin-top: 0.25rem;
    line-height: 1.35;
}

.run-status-cell .run-details-btn {
    margin-top: 0.35rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.78rem;
}

.run-progress-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.run-progress-modal[hidden] {
    display: none !important;
}

body.modal-open {
    overflow: hidden;
}

.run-progress-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.run-progress-modal-panel {
    position: relative;
    width: min(520px, 100%);
    max-height: min(80vh, 640px);
    overflow: auto;
    margin: 0;
    z-index: 1;
}

.run-progress-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.run-progress-modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.run-progress-steps {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.run-progress-step {
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    background: var(--surface-2, #f8fafc);
}

.run-progress-step-running {
    border-color: var(--red, #e11d48);
    box-shadow: 0 0 0 1px rgba(225, 29, 72, 0.08);
}

.run-progress-step-completed {
    opacity: 0.92;
}

.run-progress-step-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
}

.run-progress-step-num {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted, #64748b);
}

.run-progress-step-detail {
    margin-top: 0.35rem;
    font-size: 0.85rem;
}

.run-actions-cell {
    min-width: 8.5rem;
}

.run-actions-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
}

.resend-template-field {
    display: block;
    margin-bottom: 0.75rem;
}

.resend-template-field select {
    width: 100%;
    margin-top: 0.35rem;
}

.resend-modal-intro {
    margin: 0 0 1rem;
    font-size: 0.88rem;
    line-height: 1.5;
}

.resend-preview-line {
    margin: 0 0 1rem;
    font-size: 0.85rem;
}

.resend-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.run-retry-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
}

.run-retry-hint {
    font-size: 0.75rem;
}

/* Runs page — compact table */
.page-runs #runs-table {
    font-size: 0.8rem;
}

.page-runs #runs-table th,
.page-runs #runs-table td {
    padding: 0.45rem 0.55rem;
    line-height: 1.35;
}

.page-runs #runs-table .pill {
    font-size: 0.68rem;
    padding: 0.1rem 0.45rem;
}

.page-runs #runs-table .run-progress-line {
    font-size: 0.72rem;
}

.page-runs #runs-table .run-details-btn,
.page-runs #runs-table .run-retry-form .btn {
    font-size: 0.72rem;
    padding: 0.12rem 0.45rem;
}

.page-runs #runs-table .run-retry-hint {
    font-size: 0.68rem;
}

.page-runs #runs-table .run-info-cell {
    min-width: 9rem;
    max-width: 14rem;
}

.page-runs #runs-table .run-info-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-bottom: 0.2rem;
}

.page-runs #runs-table .run-info-type {
    font-weight: 600;
    color: var(--text);
    font-size: 0.78rem;
}

.page-runs #runs-table .run-info-day {
    font-size: 0.72rem;
}

.page-runs #runs-table .run-info-label {
    font-size: 0.74rem;
    color: var(--muted);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 13rem;
}

.page-runs #runs-table .run-info-cell .run-progress-line {
    margin-top: 0.25rem;
}

.page-runs #runs-table .run-info-cell .run-details-btn {
    margin-top: 0.2rem;
}

/* Reply service toggle (Reply Settings) */
.reply-service-panel {
    margin-bottom: 1.25rem;
}

.reply-service-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.reply-service-title {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
}

.reply-service-desc {
    margin: 0;
    max-width: 42rem;
}

.reply-service-controls {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-shrink: 0;
}

.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 52px;
    height: 30px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 999px;
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 24px;
    width: 24px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--ok);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.toggle-switch input:focus-visible + .toggle-slider {
    box-shadow: 0 0 0 3px var(--red-glow);
}

.toggle-switch input:disabled + .toggle-slider {
    opacity: 0.55;
    cursor: not-allowed;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

