/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1e293b;
    font-size: 14px;
    line-height: 1.5;
}

/* ── Login ──────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px;
    width: 360px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 32px rgba(0,0,0,.07);
}

.login-logo { text-align: center; margin-bottom: 32px; }
.logo-brand { display: block; font-size: 22px; font-weight: 700; color: #1e293b; letter-spacing: -.5px; }
.logo-sub   { display: block; font-size: 13px; color: #94a3b8; margin-top: 3px; }

/* ── Forms ──────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: #374151; margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%; padding: 9px 12px; border: 1px solid #e2e8f0; border-radius: 7px;
    font-size: 14px; color: #1e293b; background: #fff; outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.form-group textarea { resize: vertical; min-height: 72px; }

.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.form-row-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 14px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 5px; padding: 8px 16px;
    border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer;
    border: none; transition: background .12s, opacity .12s; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary { background: #3b82f6; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2563eb; }

.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-danger  { background: #ef4444; color: #fff; }
.btn-danger:hover:not(:disabled)  { background: #dc2626; }

.btn-wa      { background: #25d366; color: #fff; }
.btn-wa:hover:not(:disabled)      { background: #1da851; }

.btn-ghost {
    background: transparent; color: #64748b;
    border: 1px solid #e2e8f0;
}
.btn-ghost:hover:not(:disabled) { background: #f8fafc; border-color: #cbd5e1; }

.btn-sm  { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Alerts ─────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 7px; font-size: 13px; margin-bottom: 16px; }
.alert-error   { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }

/* ── Header ─────────────────────────────────────────────── */
.app-header {
    background: #1e293b; color: #fff; padding: 0 24px;
    display: flex; align-items: center; justify-content: space-between;
    height: 54px; position: sticky; top: 0; z-index: 100; gap: 16px;
}
.header-logo { font-weight: 700; font-size: 15px; letter-spacing: -.3px; white-space: nowrap; flex-shrink: 0; }
.header-nav  { display: flex; gap: 2px; }
.nav-btn {
    padding: 6px 13px; border-radius: 6px; font-size: 13px; font-weight: 500;
    color: #94a3b8; background: transparent; border: none; cursor: pointer;
    transition: all .12s; white-space: nowrap;
}
.nav-btn:hover  { color: #fff; background: rgba(255,255,255,.08); }
.nav-btn.active { color: #fff; background: rgba(255,255,255,.13); }
.header-right { display: flex; align-items: center; gap: 10px; font-size: 13px; }

/* ── Layout ─────────────────────────────────────────────── */
.app-main { padding: 24px; max-width: 1280px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.page-title { font-size: 19px; font-weight: 700; color: #1e293b; letter-spacing: -.3px; margin-bottom: 20px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }

/* ── Cards ──────────────────────────────────────────────── */
.card { background: #fff; border-radius: 10px; border: 1px solid #e2e8f0; padding: 20px; }

/* ── Two-column compose layout ──────────────────────────── */
.compose-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }

/* ── Rich text editor ───────────────────────────────────── */
.editor-toolbar {
    display: flex; gap: 3px; padding: 8px 10px;
    border: 1px solid #e2e8f0; border-bottom: none;
    border-radius: 7px 7px 0 0; background: #f8fafc;
}
.editor-btn {
    width: 30px; height: 28px; border: 1px solid transparent; border-radius: 5px;
    background: transparent; cursor: pointer; font-size: 13px; font-weight: 600;
    color: #374151; display: flex; align-items: center; justify-content: center;
    transition: all .1s;
}
.editor-btn:hover  { background: #e2e8f0; border-color: #cbd5e1; }
.editor-btn.active { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; }
.editor-sep { width: 1px; background: #e2e8f0; margin: 3px 4px; }

.editor-body {
    min-height: 200px; max-height: 400px; overflow-y: auto;
    border: 1px solid #e2e8f0; border-radius: 0 0 7px 7px;
    padding: 14px; font-size: 14px; line-height: 1.7; color: #1e293b;
    outline: none; background: #fff;
}
.editor-body:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.editor-body:empty::before { content: attr(data-placeholder); color: #94a3b8; pointer-events: none; }

/* ── Channel selector ───────────────────────────────────── */
.channel-row { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.channel-pill {
    display: flex; align-items: center; gap: 8px; padding: 8px 14px;
    border: 2px solid #e2e8f0; border-radius: 8px; cursor: pointer;
    background: #fff; transition: all .15s; user-select: none;
}
.channel-pill:hover { border-color: #93c5fd; background: #eff6ff; }
.channel-pill.on-email     { border-color: #3b82f6; background: #eff6ff; }
.channel-pill.on-whatsapp  { border-color: #25d366; background: #f0fdf4; }
.channel-pill input { display: none; }
.channel-icon { font-size: 18px; }
.channel-label { font-size: 13px; font-weight: 600; color: #374151; }

/* ── Contact selector panel ─────────────────────────────── */
.contact-panel { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; }
.panel-head {
    padding: 14px 16px; border-bottom: 1px solid #f1f5f9;
    display: flex; align-items: center; justify-content: space-between;
}
.panel-head-title { font-size: 13px; font-weight: 600; color: #374151; }
.panel-search { padding: 10px 16px; border-bottom: 1px solid #f1f5f9; }
.panel-search input { width: 100%; padding: 7px 10px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; outline: none; }
.panel-search input:focus { border-color: #3b82f6; }
.contact-list { max-height: 360px; overflow-y: auto; }
.contact-row {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    border-bottom: 1px solid #f8fafc; cursor: pointer; transition: background .1s;
}
.contact-row:last-child { border-bottom: none; }
.contact-row:hover { background: #f8fafc; }
.contact-row.selected { background: #eff6ff; }
.contact-row input[type=checkbox] { flex-shrink: 0; width: 16px; height: 16px; cursor: pointer; accent-color: #3b82f6; }
.contact-info { flex: 1; min-width: 0; }
.contact-name  { font-size: 13px; font-weight: 500; color: #1e293b; }
.contact-sub   { font-size: 11px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-icons { display: flex; gap: 4px; }
.c-icon { font-size: 12px; opacity: .5; }
.c-icon.has { opacity: 1; }
.panel-foot { padding: 10px 16px; border-top: 1px solid #f1f5f9; display: flex; justify-content: space-between; align-items: center; }
.sel-count { font-size: 12px; color: #64748b; }

/* ── Send results ───────────────────────────────────────── */
.results-panel {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
    padding: 20px; margin-top: 16px;
}
.results-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.result-row {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 8px 0; border-bottom: 1px solid #f8fafc; font-size: 13px;
}
.result-row:last-child { border-bottom: none; }
.r-ok   { color: #16a34a; flex-shrink: 0; }
.r-fail { color: #dc2626; flex-shrink: 0; }
.r-name { font-weight: 500; }
.r-err  { color: #dc2626; font-size: 12px; }
.r-link a { color: #3b82f6; font-size: 12px; }
.wa-links { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.wa-link-btn { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 6px; text-decoration: none; font-size: 12px; color: #15803d; }
.wa-link-btn:hover { background: #dcfce7; }

/* ── Contacts table ─────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .6px; color: #64748b; padding: 8px 14px; border-bottom: 1px solid #e2e8f0;
}
.table td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }

/* ── Collapsible add form ───────────────────────────────── */
.create-form { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 18px 20px; margin-bottom: 18px; }
.toggle-form-btn { background: none; border: none; color: #3b82f6; font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; display: flex; align-items: center; gap: 6px; }
.collapsible { display: none; padding-top: 16px; }
.collapsible.open { display: block; }

/* ── Badges ─────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 100px; font-size: 11px; font-weight: 600; }
.badge-gray   { background: #f1f5f9; color: #64748b; }
.badge-blue   { background: #eff6ff; color: #2563eb; }
.badge-green  { background: #f0fdf4; color: #16a34a; }
.badge-red    { background: #fef2f2; color: #dc2626; }

/* ── Scraper ─────────────────────────────────────────────── */
.mode-tabs { display: flex; gap: 3px; margin-bottom: 16px; }
.mode-tab {
    padding: 7px 16px; border-radius: 6px; font-size: 13px; font-weight: 500;
    cursor: pointer; border: 1px solid #e2e8f0; background: #fff; color: #64748b; transition: all .12s;
}
.mode-tab.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }

.scrape-results { margin-top: 20px; }
.scrape-result-list { max-height: 360px; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 8px; background: #fff; }
.scrape-row {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    border-bottom: 1px solid #f8fafc; font-size: 13px;
}
.scrape-row:last-child { border-bottom: none; }
.scrape-email { font-weight: 500; flex: 1; }
.scrape-src   { font-size: 11px; color: #94a3b8; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── History ─────────────────────────────────────────────── */
.history-item { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; margin-bottom: 10px; }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.history-subject { font-weight: 600; font-size: 14px; }
.history-date { font-size: 12px; color: #94a3b8; }
.history-preview { font-size: 13px; color: #64748b; margin-bottom: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Settings ────────────────────────────────────────────── */
.settings-section { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 24px; margin-bottom: 20px; }
.settings-title { font-size: 15px; font-weight: 700; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid #f1f5f9; display: flex; align-items: center; gap: 8px; }
.provider-tabs { display: flex; gap: 4px; margin-bottom: 16px; }

/* ── Empty / Loading ─────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: #94a3b8; font-size: 14px; }
.loading     { text-align: center; padding: 32px; color: #94a3b8; font-size: 13px; }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
    position: fixed; bottom: 24px; right: 24px; background: #1e293b;
    color: #fff; padding: 11px 18px; border-radius: 8px; font-size: 13px; font-weight: 500;
    opacity: 0; transform: translateY(6px); transition: all .2s; z-index: 9999; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #dc2626; }
.toast.success { background: #16a34a; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
    .compose-grid { grid-template-columns: 1fr; }
    .form-row, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .app-main { padding: 14px; }
    .app-header { padding: 0 14px; }
    .header-logo { font-size: 13px; }
    .nav-btn { padding: 5px 8px; font-size: 12px; }
}
