/* ═══════════════════════════════════════════════════════════
   MailFlow SaaS — Stylesheet
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --sidebar-bg: #1a1d23;
    --sidebar-hover: #2a2d35;
    --sidebar-active: #33363f;
    --text: #1a1d23;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;
    --text-light: #c4c9d0;
    --border: #e2e5e9;
    --border-light: #f0f1f3;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff4ff;
    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --info: #0891b2;
    --info-bg: #ecfeff;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.04);
    --transition: 180ms ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ─── LOGIN PAGE ──────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px rgba(0,0,0,.25);
}

.login-brand {
    text-align: center;
    margin-bottom: 36px;
}

.login-brand .logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
}

.login-brand .logo-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
}

.login-brand p {
    color: var(--text-secondary);
    margin-top: 6px;
    font-size: 14px;
}

/* ─── FORM ELEMENTS ───────────────────────────────── */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    min-height: 120px;
    resize: vertical;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235f6368' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ─── BUTTONS ─────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1.5px solid var(--border);
}

.btn-secondary:hover { background: var(--border-light); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-warning { background: var(--warning); color: #fff; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 13px 28px; font-size: 15px; }
.btn-block { width: 100%; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ─── LAYOUT: SIDEBAR + CONTENT ──────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: width var(--transition);
}

.sidebar-brand {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .logo-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-brand span {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-light);
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 2px;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 500;
}

.nav-item .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: .7;
    flex-shrink: 0;
}

.nav-item.active .nav-icon { opacity: 1; }

.nav-divider {
    height: 1px;
    background: rgba(255,255,255,.08);
    margin: 12px 0;
}

.sidebar-footer {
    padding: 16px 16px 20px;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius);
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-info .name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info .email {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.smtp-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: auto;
}

.smtp-status-dot.connected { background: var(--success); }
.smtp-status-dot.disconnected { background: var(--danger); }

/* ─── MAIN CONTENT ────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px;
    max-width: 1400px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
}

.page-header p {
    color: var(--text-secondary);
    margin-top: 4px;
    font-size: 14px;
}

/* ─── CARDS ───────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

/* ─── STAT CARDS ──────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-top: 6px;
    letter-spacing: -0.5px;
}

/* ─── TABLES ──────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
}

th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

td {
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
}

tr:hover td { background: var(--bg); }

/* ─── BADGES ──────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-secondary { background: var(--bg); color: var(--text-secondary); }

/* ─── ALERTS ──────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

.alert.show { display: block; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a7f3d0; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid #a5f3fc; }

/* ─── TABS ────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border-light);
    margin-bottom: 24px;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    transition: color var(--transition);
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
    color: var(--primary);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

/* ─── PROGRESS BAR ────────────────────────────────── */
.progress-bar-wrap {
    width: 100%;
    height: 8px;
    background: var(--border-light);
    border-radius: 100px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 100px;
    transition: width 0.4s ease;
}

.progress-bar.success { background: var(--success); }

/* ─── UPLOAD ZONE ─────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-zone .upload-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 14px;
}

.upload-zone .upload-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ─── COLOR PICKER ────────────────────────────────── */
.color-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-input-wrap input[type="color"] {
    width: 40px;
    height: 36px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    padding: 2px;
    cursor: pointer;
}

.color-input-wrap input[type="text"] {
    width: 100px;
}

/* ─── CAMPAIGN LIVE VIEW ──────────────────────────── */
.campaign-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.campaign-stat {
    text-align: center;
    padding: 14px;
    background: var(--bg);
    border-radius: var(--radius);
}

.campaign-stat .num {
    font-size: 24px;
    font-weight: 700;
}

.campaign-stat .label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

.send-log {
    max-height: 300px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: var(--radius);
    padding: 16px;
}

.send-log .log-entry {
    padding: 3px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.send-log .log-sent { color: #4ade80; }
.send-log .log-failed { color: #f87171; }
.send-log .log-time { color: #64748b; }

/* ─── SMTP PRESETS ────────────────────────────────── */
.presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 20px;
}

.preset-btn {
    padding: 10px 12px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.preset-btn:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

/* ─── VARIABLE BUTTONS ────────────────────────────── */
.var-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.var-btn {
    padding: 4px 10px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(37,99,235,.2);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}

.var-btn:hover {
    background: var(--primary);
    color: #fff;
}

/* ─── CTA PREVIEW ─────────────────────────────────── */
.cta-preview {
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius);
    text-align: center;
    margin-top: 12px;
}

.cta-preview-btn {
    display: inline-block;
    padding: 12px 28px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none;
}

/* ─── SLIDER ──────────────────────────────────────── */
input[type="range"] {
    width: 100%;
    height: 6px;
    appearance: none;
    background: var(--border);
    border-radius: 100px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: var(--shadow);
}

/* ─── MODAL ───────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 25px 50px rgba(0,0,0,.25);
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* ─── PRE-FLIGHT CHECK ────────────────────────────── */
.checklist {
    list-style: none;
    padding: 0;
}

.checklist li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--border-light);
}

.checklist li:last-child { border: none; }

.check-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.check-pass { background: var(--success-bg); color: var(--success); }
.check-fail { background: var(--danger-bg); color: var(--danger); }

/* ─── TEMPLATE PREVIEW IFRAME ─────────────────────── */
.preview-frame {
    width: 100%;
    min-height: 500px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

/* ─── TOGGLE SWITCH ───────────────────────────────── */
.toggle-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 100px;
    position: relative;
    cursor: pointer;
    transition: background var(--transition);
}

.toggle.on { background: var(--primary); }

.toggle::after {
    content: '';
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform var(--transition);
    box-shadow: var(--shadow-sm);
}

.toggle.on::after { transform: translateX(18px); }

/* ─── EMPTY STATE ─────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
}

.empty-state .empty-icon {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 12px;
}

.empty-state h4 {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 6px;
}

/* ─── ROW HELPERS ─────────────────────────────────── */
.row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.row > * { flex: 1; min-width: 200px; }

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.fw-600 { font-weight: 600; }
.hidden { display: none !important; }

/* ─── SCROLLBAR ───────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-brand span,
    .sidebar .nav-item span,
    .sidebar-footer .user-info,
    .sidebar-footer .smtp-status-dot { display: none; }
    .sidebar-brand { justify-content: center; padding: 16px 8px; }
    .sidebar .nav-item { justify-content: center; padding: 10px; }
    .main-content { margin-left: 60px; padding: 20px; }
    .campaign-stats { grid-template-columns: repeat(2, 1fr); }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    #templateGrid { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
    .login-card { padding: 32px 24px; }
    .main-content { padding: 16px; }
}

/* ─── LOADING SPINNER ─────────────────────────────── */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    display: inline-block;
}

.spinner-dark {
    border-color: rgba(0,0,0,.1);
    border-top-color: var(--primary);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── FADEINS ─────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn .3s ease;
}
