@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #f5f6fb;
    --sidebar-bg: #ffffff;
    --card: #ffffff;
    --border: #e7e8ee;
    --border-soft: #eef0f5;
    --text: #16181d;
    --text-soft: #3f4250;
    --muted: #8a8d9a;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef0ff;
    --primary-100: #e0e2fc;
    --success: #15803d;
    --success-soft: #e7f7ed;
    --danger: #dc2626;
    --danger-soft: #fdecec;
    --warning: #b45309;
    --warning-soft: #fef3d9;
    --info: #1d4ed8;
    --info-soft: #e8eefd;
    --sky: #0284c7;
    --sky-soft: #e3f4fd;
    --violet: #7c3aed;
    --violet-soft: #f1e9fe;
    --rose: #e11d48;
    --rose-soft: #fee6ec;
    --wa-green: #128c4c;
    --wa-green-soft: #dcf7e7;
    --slate: #475569;
    --slate-soft: #eef1f5;
    --teal: #0d9488;
    --teal-soft: #d9f5f1;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(16, 18, 34, 0.04);
    --shadow: 0 1px 3px rgba(16, 18, 34, 0.06), 0 6px 20px -8px rgba(16, 18, 34, 0.08);
    --shadow-lg: 0 12px 32px -12px rgba(16, 18, 34, 0.18);
    --sidebar-grad: linear-gradient(165deg, #201a4d 0%, #34216e 42%, #4c1d95 78%, #5b21b6 100%);
    --brand-grad: linear-gradient(135deg, #818cf8, #4f46e5 55%, #7c3aed);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    background:
        radial-gradient(900px 480px at 105% -8%, #e9e7ff 0%, transparent 55%),
        radial-gradient(700px 420px at -5% 15%, #e3f4fd 0%, transparent 50%),
        radial-gradient(800px 500px at 50% 115%, #fdeef8 0%, transparent 55%),
        var(--bg);
    background-attachment: fixed;
}

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

svg { display: block; }

/* ---------- Mobile topbar (hidden on desktop) ---------- */

.mobile-topbar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}
.nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-soft);
    cursor: pointer;
    flex-shrink: 0;
}
.nav-toggle:hover { background: var(--bg); }
.mobile-topbar-brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 800; font-size: 0.98rem; }
.mobile-topbar-brand .mark {
    width: 26px; height: 26px;
    border-radius: 7px;
    background: linear-gradient(135deg, #818cf8, #4f46e5 55%, #7c3aed);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 26, 0.45);
    z-index: 40;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.sidebar-backdrop.open { display: block; opacity: 1; }

/* ---------- App shell / sidebar ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar-grad);
    position: relative;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    box-shadow: 4px 0 24px -8px rgba(30, 20, 70, 0.35);
    overflow: hidden;
}
.sidebar::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(320px 260px at 15% 0%, rgba(255, 255, 255, 0.14) 0%, transparent 60%),
        radial-gradient(260px 220px at 100% 100%, rgba(129, 140, 248, 0.28) 0%, transparent 60%);
    pointer-events: none;
}

.sidebar-brand {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.5rem 1.25rem 1.2rem;
}

.sidebar-brand .mark {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    background: linear-gradient(135deg, #a5b4fc, #818cf8 55%, #c4b5fd);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2e1065;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25), 0 6px 16px -4px rgba(129, 140, 248, 0.7);
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.sidebar-brand:hover .mark { transform: rotate(-8deg) scale(1.08); }

.sidebar-brand .name {
    font-weight: 800;
    font-size: 1.04rem;
    letter-spacing: -0.01em;
    color: #fff;
    text-shadow: 0 1px 12px rgba(129, 140, 248, 0.4);
}

.sidebar-nav {
    position: relative;
    flex: 1;
    padding: 0.6rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.45rem 0.65rem;
    border-radius: 11px;
    color: rgba(226, 224, 255, 0.75);
    font-size: 0.89rem;
    font-weight: 500;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.nav-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(6px);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, background 0.2s ease;
}
.nav-icon svg { width: 16px; height: 16px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25)); }

.nav-icon.c-indigo { color: #a5b4fc; }
.nav-icon.c-sky { color: #7dd3fc; }
.nav-icon.c-violet { color: #e0b3fe; }
.nav-icon.c-amber { color: #fcd34d; }
.nav-icon.c-rose { color: #fda4af; }
.nav-icon.c-green { color: #6ee7b7; }
.nav-icon.c-slate { color: #cbd5e1; }
.nav-icon.c-teal { color: #5eead4; }

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
    transform: translateX(2px);
}
.nav-item:hover .nav-icon { transform: scale(1.08); background: rgba(255, 255, 255, 0.18); }

.nav-item.active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), 0 4px 14px -6px rgba(0, 0, 0, 0.3);
}
.nav-item.active .nav-icon {
    background: rgba(255, 255, 255, 0.22);
    box-shadow: 0 3px 10px -2px rgba(0, 0, 0, 0.25);
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: -0.85rem;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 22px;
    border-radius: 0 4px 4px 0;
    background: linear-gradient(180deg, #a5b4fc, #fda4af);
    box-shadow: 0 0 10px 1px rgba(165, 180, 252, 0.7);
}

.sidebar-footer {
    position: relative;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding: 0.9rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a5b4fc, #818cf8);
    color: #2e1065;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 800;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
    overflow: hidden;
    text-decoration: none;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.avatar:hover { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55); transform: scale(1.05); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.profile-avatar-preview {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #a5b4fc, #818cf8);
    color: #2e1065;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 800;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.profile-avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

.avatar-remove-btn {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: 2px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    padding: 0;
    transition: background 0.12s ease;
}
.avatar-remove-btn:hover { background: #b91c1c; }

.sidebar-footer .who { flex: 1; min-width: 0; }
.sidebar-footer .who .uname { font-size: 0.85rem; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: rgba(226, 224, 255, 0.75);
    font-size: 0.76rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.logout-btn svg { flex-shrink: 0; }
.logout-btn span { display: none; }
.logout-btn:hover {
    background: rgba(251, 113, 133, 0.16);
    border-color: rgba(251, 113, 133, 0.4);
    color: #fda4af;
}
@media (min-width: 860px) {
    .logout-btn span { display: inline; }
}

.main { flex: 1; min-width: 0; }

.container { max-width: min(1600px, 94vw); margin: 0 auto; padding: 2.25rem 2.5rem 3rem; animation: fade-in-up 0.4s cubic-bezier(0.22, 1, 0.36, 1) both; }

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Page header ---------- */

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; }
.page-header h1 {
    font-size: 1.55rem;
    margin: 0;
    letter-spacing: -0.02em;
    font-weight: 800;
    background: linear-gradient(100deg, var(--text) 35%, var(--primary) 85%, var(--violet) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.page-header p.subtitle { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; }

/* ---------- Cards ---------- */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.4rem 1.6rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
}

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; margin-bottom: 1.25rem; }
.stat-grid .stat-card { animation: fade-in-up 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }
.stat-grid .stat-card:nth-child(1) { animation-delay: 0.03s; }
.stat-grid .stat-card:nth-child(2) { animation-delay: 0.1s; }
.stat-grid .stat-card:nth-child(3) { animation-delay: 0.17s; }

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow);
    border-color: var(--primary-100);
    color: inherit;
}

.stat-card .icon {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.stat-card:hover .icon { transform: scale(1.12) rotate(-4deg); }
.stat-card .icon svg { width: 20px; height: 20px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.15)); }
.stat-card .icon.indigo { background: linear-gradient(135deg, #818cf8, #4f46e5); color: #fff; box-shadow: 0 6px 16px -6px rgba(79, 70, 229, 0.7); }
.stat-card .icon.green { background: linear-gradient(135deg, #34d399, #059669); color: #fff; box-shadow: 0 6px 16px -6px rgba(5, 150, 105, 0.6); }
.stat-card .icon.amber { background: linear-gradient(135deg, #fbbf24, #d97706); color: #fff; box-shadow: 0 6px 16px -6px rgba(217, 119, 6, 0.6); }
.stat-card .icon.rose { background: linear-gradient(135deg, #fb7185, #e11d48); color: #fff; box-shadow: 0 6px 16px -6px rgba(225, 29, 72, 0.6); }
.stat-card .icon.orange { background: linear-gradient(135deg, #fb923c, #ea580c); color: #fff; box-shadow: 0 6px 16px -6px rgba(234, 88, 12, 0.6); }

/* ---------- Reply feed ---------- */

.reply-feed { display: flex; flex-direction: column; gap: 0.4rem; }
.reply-feed-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 0.6rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: inherit;
    transition: background 0.12s ease;
}
.reply-feed-item:hover { background: var(--primary-soft); text-decoration: none; }
.reply-feed-avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #818cf8, var(--primary) 60%, var(--primary-dark));
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
}
.reply-feed-body { flex: 1; min-width: 0; }
.reply-feed-top {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 0.5rem;
    font-size: 0.88rem;
}
.reply-feed-top strong { color: var(--text); }
.reply-feed-campaign { color: var(--text-soft); font-size: 0.82rem; }
.reply-feed-time {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--text-soft);
    white-space: nowrap;
}
.reply-feed-snippet {
    margin: 0.25rem 0 0;
    font-size: 0.83rem;
    color: var(--text-soft);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.stat-card .label { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.stat-card .value { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }

/* ---------- Tables ---------- */

table { width: 100%; min-width: 540px; border-collapse: collapse; font-size: 0.89rem; }
th, td { text-align: left; padding: 0.7rem 0.6rem; border-bottom: 1px solid var(--border-soft); }
th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--primary-soft); }
tbody tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--primary); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: linear-gradient(135deg, #818cf8, var(--primary) 60%, var(--primary-dark));
    background-size: 160% 160%;
    background-position: 0% 50%;
    color: #fff;
    border: none;
    padding: 0.6rem 1.15rem;
    border-radius: var(--radius-sm);
    font-size: 0.87rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 2px 6px -1px rgba(79, 70, 229, 0.4);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background-position 0.35s ease;
}
.btn:hover {
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px -4px rgba(79, 70, 229, 0.55);
    background-position: 100% 50%;
}
.btn:active { color: #fff; transform: translateY(0); box-shadow: 0 2px 6px -1px rgba(79, 70, 229, 0.4); }
.btn.danger:hover, .btn.danger:active { color: #fff; }
.btn.secondary { background: #fff; color: var(--text-soft); border: 1px solid var(--border); box-shadow: none; }
.btn.secondary:hover { background: var(--bg); color: var(--text); border-color: var(--primary-100); box-shadow: 0 2px 8px -3px rgba(16, 18, 34, 0.15); }
.btn.danger { background: linear-gradient(135deg, #fb7185, var(--danger) 60%, #b91c1c); background-size: 160% 160%; box-shadow: 0 2px 6px -1px rgba(220, 38, 38, 0.4); }
.btn.danger:hover { box-shadow: 0 6px 16px -4px rgba(220, 38, 38, 0.5); }
.btn.small { padding: 0.38rem 0.8rem; font-size: 0.8rem; }

/* ---------- Forms ---------- */

label { display: block; margin-bottom: 0.35rem; font-size: 0.82rem; font-weight: 600; color: var(--text-soft); }
input[type=text], input[type=password], input[type=email], input[type=datetime-local], input[type=file], select, textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { min-height: 130px; resize: vertical; line-height: 1.5; }

/* ---------- Rich text toolbar ---------- */

.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem;
    border: 1.5px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--bg);
}
.rte-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 0.5rem;
    border: 1.5px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-soft);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.rte-toolbar button svg { width: 16px; height: 16px; }
.rte-toolbar button:hover { background: var(--primary-soft); color: var(--primary-dark); }
.rte-toolbar button.active,
.rte-toolbar button:active { background: var(--primary-100); border-color: var(--primary-100); color: var(--primary-dark); }
.rte-toolbar select#rte-block {
    width: auto;
    margin: 0;
    padding: 0.35rem 0.5rem;
    font-size: 0.82rem;
    height: 32px;
}
.rte-toolbar input[type=color] {
    width: 32px;
    height: 32px;
    padding: 2px;
    margin: 0;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}
.rte-sep { width: 1px; height: 22px; background: var(--border); margin: 0 0.15rem; flex-shrink: 0; }

.rte-editor {
    width: 100%;
    min-height: 200px;
    max-height: 480px;
    overflow-y: auto;
    padding: 0.75rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text);
    background: #fff;
    margin-bottom: 1rem;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.rte-editor:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.rte-editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.rte-editor p { margin: 0 0 0.75em; }
.rte-editor ul, .rte-editor ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.rte-editor blockquote { margin: 0 0 0.75em; padding-left: 0.9em; border-left: 3px solid var(--primary-100); color: var(--text-soft); }
.rte-editor a { color: var(--primary); text-decoration: underline; }

#rte-toolbar-wa + textarea { border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }

.form-row { display: flex; gap: 1.1rem; }
.form-row > div { flex: 1; }

/* ---------- Filter bar ---------- */

.filter-bar { margin-bottom: 1.25rem; }

.filter-bar-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.filter-date-input {
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 0.55rem 0.85rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.filter-date-input:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.filter-date-input input[type=date] {
    width: auto;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-dark);
}
.filter-date-input input[type=date]:focus { box-shadow: none; }

.filter-to-label {
    font-size: 0.85rem;
    color: var(--text-soft);
    font-weight: 500;
}

.filter-presets { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.filter-pill {
    background: var(--primary-soft);
    color: var(--primary-dark);
    border: none;
    border-radius: 999px;
    padding: 0.5rem 1rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.filter-pill:hover { background: var(--primary-100); }
.filter-pill.active { background: var(--primary); color: #fff; }

.filter-clear {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-soft);
    text-decoration: none;
    padding: 0.5rem 0.4rem;
}
.filter-clear:hover { color: var(--danger); text-decoration: underline; }

@media (max-width: 560px) {
    .filter-bar-form { gap: 0.5rem; }
    .filter-presets { width: 100%; }
}

/* ---------- Bulk actions bar ---------- */

.bulk-actions-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--primary-soft);
    border: 1px solid var(--primary-100);
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
    margin-bottom: 0.85rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-dark);
}
.bulk-actions-bar.visible { display: flex; }

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.25rem 1.5rem;
}
.info-grid > div { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.info-grid .muted { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.info-grid strong { font-size: 0.92rem; font-weight: 600; color: var(--text); overflow-wrap: break-word; }
.info-grid .badge { align-self: flex-start; }

/* ---------- Badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.24rem 0.7rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    box-shadow: inset 0 0 0 1px rgba(16, 18, 34, 0.04);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.55rem; margin: 0 0 1rem; }
.badge.draft { background: #eef0f3; color: #4b4f5a; }
.badge.scheduled { background: var(--info-soft); color: var(--info); }
.badge.sending { background: var(--warning-soft); color: var(--warning); }
.badge.sending::before { animation: pulse-dot 1.3s ease-in-out infinite; }
.badge.completed { background: var(--success-soft); color: var(--success); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.pending { background: #eef0f3; color: #4b4f5a; }
.badge.sent { background: var(--success-soft); color: var(--success); }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.3); }
}

/* ---------- Alerts ---------- */

.alert { display: flex; align-items: center; gap: 0.6rem; padding: 0.8rem 1.05rem; border-radius: var(--radius-sm); margin-bottom: 1.1rem; font-size: 0.87rem; font-weight: 500; }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--info-soft); color: var(--info); }

/* ---------- Misc ---------- */

.muted { color: var(--muted); font-size: 0.85rem; }

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--muted);
}
.empty-state .icon-wrap {
    width: 60px; height: 60px;
    border-radius: 18px;
    background: linear-gradient(135deg, #818cf8, #4f46e5 55%, #7c3aed);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.1rem;
    box-shadow: 0 0 0 6px rgba(129, 140, 248, 0.12), 0 10px 24px -10px rgba(79, 70, 229, 0.5);
}
.empty-state .icon-wrap svg { width: 27px; height: 27px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2)); }
.empty-state p { margin: 0; font-size: 0.9rem; }

code {
    background: var(--bg);
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    padding: 0.1rem 0.35rem;
    font-size: 0.85em;
}

.attachment-current {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.8rem;
    margin-bottom: 0.75rem;
    color: var(--text-soft);
    font-size: 0.87rem;
}
.attachment-current svg { flex-shrink: 0; color: var(--muted); }
.attachment-current a, .attachment-current span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Login page ---------- */

.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
    background: var(--bg);
}
.login-wrap::before, .login-wrap::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.55;
    animation: blob-float 14s ease-in-out infinite;
    z-index: 0;
}
.login-wrap::before {
    width: 480px; height: 480px;
    background: radial-gradient(circle, #c7d2fe, transparent 70%);
    top: -160px; left: -120px;
}
.login-wrap::after {
    width: 420px; height: 420px;
    background: radial-gradient(circle, #ddd6fe, transparent 70%);
    bottom: -140px; right: -100px;
    animation-delay: -7s;
}
@keyframes blob-float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -20px) scale(1.08); }
}
.login-card {
    position: relative;
    z-index: 1;
    width: 380px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 2.3rem 2.1rem 2.1rem;
    box-shadow: var(--shadow-lg);
    animation: fade-in-up 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.login-card .mark {
    width: 46px; height: 46px;
    border-radius: 13px;
    background: linear-gradient(135deg, #818cf8, #4f46e5 55%, #7c3aed);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    box-shadow: 0 0 0 6px rgba(99, 102, 241, 0.12), 0 8px 20px -6px rgba(79, 70, 229, 0.55);
    margin-bottom: 1.2rem;
}
.login-card h1 {
    font-size: 1.35rem;
    margin: 0 0 0.15rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(100deg, var(--text) 35%, var(--primary) 85%, var(--violet) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.login-card .sub { color: var(--muted); font-size: 0.86rem; margin: 0 0 1.4rem; }

/* ---------- WhatsApp connect ---------- */

.wa-qr {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.75rem 1.25rem;
    gap: 0.6rem;
}
.wa-qr img { max-width: 260px; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem; background: #fff; box-shadow: var(--shadow-sm); }

.wa-or { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; margin: 0.3rem 0; }

.wa-phone-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    max-width: 320px;
}
.wa-phone-form input[type=text] { margin-bottom: 0; text-align: center; }

.wa-pairing-code {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    color: var(--primary-dark);
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1.4rem;
    word-break: break-word;
}

.wa-back-btn { margin-top: 0.4rem; }

.wa-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--primary-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: wa-spin 0.8s linear infinite;
}
@keyframes wa-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
    .mobile-topbar { display: flex; }

    .app-shell { display: block; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        height: 100dvh;
        width: 270px;
        max-width: 82vw;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }

    .main { width: 100%; }

    .container { padding: 1.5rem 1.25rem 2.5rem; }

    .stat-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; gap: 0; }
    .page-header { flex-wrap: wrap; }
    .info-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
    .container { padding: 1.1rem 0.9rem 2rem; }
    .page-header h1 { font-size: 1.25rem; }
    .card, .stat-card { padding: 1.1rem 1.15rem; }
    .info-grid { grid-template-columns: 1fr; }
    table { font-size: 0.82rem; }
    th, td { padding: 0.55rem 0.4rem; }

    .login-card { width: 100%; max-width: 340px; padding: 1.9rem 1.6rem 1.8rem; }
    .login-wrap { padding: 1.25rem; }
}

/* ---------- Template preview modal ---------- */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(16, 18, 34, 0.5);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.modal-overlay.open { display: flex; }

.modal-box {
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modal-pop 0.18s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes modal-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.1rem 1.3rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}
.modal-close:hover { background: var(--danger-soft); color: var(--danger); }

.modal-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.3rem;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.85rem;
    color: var(--text-soft);
    flex-shrink: 0;
}

.bounce-meta { flex-wrap: wrap; row-gap: 0.7rem; column-gap: 1.5rem; align-items: flex-start; }
.bounce-meta .meta-item { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; max-width: 100%; }
.bounce-meta .meta-label { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.bounce-meta strong { font-weight: 700; color: var(--text); font-size: 0.85rem; word-break: break-word; }

.modal-attachment {
    display: none;
    align-items: center;
    gap: 0.45rem;
    padding: 0.7rem 1.3rem;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.85rem;
    color: var(--muted);
    flex-shrink: 0;
}
.modal-attachment a { color: var(--primary); text-decoration: none; }
.modal-attachment a:hover { text-decoration: underline; }

.action-buttons { display: flex; flex-wrap: nowrap; gap: 0.4rem; }
.replies-table { min-width: 760px; }

.select-all-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-soft);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-soft);
    cursor: pointer;
    flex-shrink: 0;
}
/* Inside a modal-box there's no surrounding .card padding, so this needs its own
   horizontal padding to line up with the modal's header/footer/meta rows. */
.modal-box .select-all-row { padding: 0.75rem 1.3rem; margin-bottom: 0; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding: 0.9rem 1.3rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-box > form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 auto;
}

.tpl-preview-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1.3rem;
    overflow-y: auto;
    font-size: 0.92rem;
    line-height: 1.6;
    color: var(--text);
}
.tpl-preview-body.plain { white-space: pre-wrap; word-break: break-word; }

.modal-section-title {
    margin: 0 0 0.4rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-soft);
}
.bounce-preview-sections {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 1.3rem;
}
.bounce-preview-sections .tpl-preview-body {
    flex: none;
    min-height: auto;
    padding: 0;
    overflow: visible;
}
.tpl-preview-body p { margin: 0 0 0.75em; }
.tpl-preview-body ul, .tpl-preview-body ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.tpl-preview-body blockquote { margin: 0 0 0.75em; padding-left: 0.9em; border-left: 3px solid var(--primary-100); color: var(--text-soft); }
.tpl-preview-body a { color: var(--primary); text-decoration: underline; }

/* Any table living inside a .card scrolls horizontally instead of breaking the layout
   (only matters above the stacked-table breakpoint below, where tables stay real tables). */
.card { overflow-x: auto; }

/* ---------- Stacked "card" tables on narrow screens (no horizontal scrolling) ---------- */

@media (max-width: 700px) {
    table, .replies-table { min-width: 0; width: 100%; }
    .card { overflow-x: visible; }

    table, thead, tbody, tr, th, td { display: block; }
    thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

    tbody tr {
        border: 1px solid var(--border-soft);
        border-radius: var(--radius-sm);
        padding: 0.7rem 0.85rem;
        margin-bottom: 0.6rem;
        background: #fff;
    }
    tbody tr:last-child { margin-bottom: 0; }
    tbody tr:hover { background: #fff; box-shadow: inset 0 0 0 1px var(--primary-100); }
    tbody tr:hover td:first-child { box-shadow: none; }

    td {
        display: block;
        padding: 0.4rem 0;
        border-bottom: 1px solid var(--border-soft);
        text-align: left;
    }
    td:last-child { border-bottom: none; padding-bottom: 0; }
    td:first-child { padding-top: 0; }

    td[data-label]:not([data-label=""]) {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        gap: 0.3rem 0.75rem;
        text-align: right;
    }
    td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--muted);
        text-align: left;
        flex-shrink: 0;
    }
}

/* ---------- Send / success overlays ---------- */

.send-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(16, 18, 34, 0.55);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.send-overlay.open { opacity: 1; }

.send-overlay-box, .success-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.2rem 2.6rem;
    text-align: center;
    max-width: 300px;
    animation: modal-pop 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.send-plane-wrap {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.send-plane-wrap::before, .send-plane-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--primary-soft);
    animation: send-ring 1.5s ease-out infinite;
}
.send-plane-wrap::after { animation-delay: 0.5s; }
.send-plane-wrap svg {
    position: relative;
    width: 28px;
    height: 28px;
    color: var(--primary);
    animation: send-plane-fly 1.1s ease-in-out infinite;
}
@keyframes send-ring {
    0% { transform: scale(0.55); opacity: 0.8; }
    100% { transform: scale(1.4); opacity: 0; }
}
@keyframes send-plane-fly {
    0%, 100% { transform: translate(-3px, 3px) rotate(0deg); }
    50% { transform: translate(3px, -3px) rotate(8deg); }
}

.send-overlay-box .title, .success-box .title { font-size: 1rem; font-weight: 700; color: var(--text); }
.send-overlay-box .sub, .success-box .sub { font-size: 0.83rem; color: var(--muted); display: flex; align-items: center; gap: 0.3rem; }

.send-dots span {
    display: inline-block;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--primary);
    animation: pulse-dot 1.1s ease-in-out infinite;
}
.send-dots span:nth-child(2) { animation-delay: 0.15s; }
.send-dots span:nth-child(3) { animation-delay: 0.3s; }

.success-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(16, 18, 34, 0.45);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.35s ease;
}
.success-overlay.fade-out { opacity: 0; }

.success-check {
    position: relative;
    width: 58px; height: 58px;
    border-radius: 50%;
    background: var(--success-soft);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    animation: success-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.success-check::before, .success-check::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--success);
    opacity: 0;
    animation: success-ripple 0.9s 0.15s ease-out;
}
.success-check::after { animation-delay: 0.35s; }
.success-check svg { position: relative; width: 30px; height: 30px; color: var(--success); }
.success-check svg path {
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    animation: success-draw 0.35s 0.2s ease-out forwards;
}
@keyframes success-pop {
    0% { transform: scale(0); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}
@keyframes success-ripple {
    0% { transform: scale(0.8); opacity: 0.6; }
    100% { transform: scale(1.9); opacity: 0; }
}
@keyframes success-draw {
    to { stroke-dashoffset: 0; }
}

/* Large / wide monitors: scale content up so it doesn't look lost in the extra space. */
@media (min-width: 1400px) {
    .page-header h1 { font-size: 1.85rem; }
    .page-header p.subtitle { font-size: 0.98rem; }
    .stat-card .value { font-size: 1.85rem; }
    .stat-card .label { font-size: 0.88rem; }
    .stat-card { padding: 1.5rem 1.7rem; }
    .card { padding: 1.7rem 1.9rem; }
    table { font-size: 0.96rem; }
    th { font-size: 0.76rem; }
    th, td { padding: 0.85rem 0.75rem; }
    .btn { padding: 0.68rem 1.3rem; font-size: 0.92rem; }
    .stat-grid { gap: 1.4rem; }
}
