:root {
    --bg: #eef0f8;
    --bg-2: #f7f8fc;
    --card: #ffffff;
    --primary: #6366f1;
    --primary-2: #8b5cf6;
    --primary-dark: #4f46e5;
    --gold: #d4af37;
    --danger: #e11d48;
    --text: #1f2433;
    --muted: #8b90a4;
    --border: #e7e9f2;
    --ring: rgba(99, 102, 241, 0.18);
    --shadow: 0 10px 30px rgba(31, 36, 51, 0.07);
    --shadow-lg: 0 20px 50px rgba(31, 36, 51, 0.12);
    --radius: 18px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Prompt", "Segoe UI", system-ui, sans-serif;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 100% -10%, rgba(139, 92, 246, 0.10), transparent 60%),
        radial-gradient(900px 500px at -10% 0%, rgba(99, 102, 241, 0.10), transparent 55%),
        var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.container { max-width: 980px; margin: 0 auto; padding: 0 20px; }

/* ---------------- Header ---------------- */
/* ---------------- Sidebar ---------------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 248px;
    height: 100vh;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(31, 36, 51, 0.04);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    z-index: 50;
}
.content-area { margin-left: 248px; padding: 32px 0; }
body:not(.has-sidebar) .content-area { margin-left: 0; }

.brand {
    font-size: 1.18rem;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: 0.2px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 4px 8px 18px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.brand-text {
    background: linear-gradient(120deg, var(--primary-dark), var(--primary-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.brand-mark { filter: drop-shadow(0 2px 4px rgba(99,102,241,0.3)); }
.brand-logo { height: 34px; width: auto; max-width: 150px; border-radius: 7px; object-fit: contain; }

.side-create { margin: 16px 0 18px; width: 100%; }

.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    text-decoration: none;
    color: #4b5168;
    font-weight: 500;
    font-size: 0.94rem;
    padding: 11px 13px;
    border-radius: 11px;
    transition: background 0.15s, color 0.15s;
}
.side-nav a .ic { font-size: 1.05rem; width: 22px; text-align: center; }
.side-nav a:hover { background: #f1f2fb; color: var(--primary-dark); }
.side-nav a.active {
    background: linear-gradient(120deg, rgba(99,102,241,0.14), rgba(139,92,246,0.14));
    color: var(--primary-dark);
    font-weight: 600;
}

.side-foot {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.side-foot .user-chip { text-align: center; }
.side-foot .btn { width: 100%; }

@media (max-width: 860px) {
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
        padding: 12px 16px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .brand { border-bottom: none; padding: 0 8px 0 0; margin: 0; }
    .side-create { width: auto; margin: 0; order: 3; }
    .side-nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; gap: 4px; order: 4; }
    .side-nav a { padding: 8px 11px; }
    .side-foot { margin: 0; padding: 0; border-top: none; flex-direction: row; align-items: center; order: 2; }
    .side-foot .btn { width: auto; }
    .content-area { margin-left: 0; padding: 22px 0; }
}

/* ---------------- Cards ---------------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px;
    margin-bottom: 22px;
    box-shadow: var(--shadow);
}
h2 {
    margin-top: 0;
    margin-bottom: 18px;
    font-size: 1.18rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s, border-color 0.15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(31, 36, 51, 0.10); }
.btn:active { transform: translateY(0); }
.btn-primary {
    background: linear-gradient(120deg, var(--primary), var(--primary-2));
    color: #fff;
    border: none;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.30);
}
.btn-primary:hover { box-shadow: 0 12px 26px rgba(99, 102, 241, 0.42); }
.btn-ghost { background: transparent; border-color: var(--border); color: #4b5168; }
.btn-danger { color: var(--danger); border-color: #fbcfe0; background: #fff; }
.btn-danger:hover { background: #fff1f5; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 10px; }
.btn-block { width: 100%; padding: 12px; font-size: 0.95rem; }

/* ---------------- Forms ---------------- */
label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 0.92rem; }
input[type=text], input[type=url], input[type=password],
input[type=datetime-local], textarea, select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: 11px;
    font: inherit;
    margin-top: 6px;
    background: #fcfcff;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--ring);
    background: #fff;
}
textarea { resize: vertical; }
.stack > label, .stack > fieldset { margin-bottom: 18px; }
fieldset {
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 16px 18px;
    background: #fafbff;
}
legend { font-weight: 600; padding: 0 8px; color: #4b5168; }
.radio { font-weight: 400; display: inline-flex; align-items: center; gap: 7px; margin-right: 18px; }
.radio input { width: auto; margin: 0; }
.btn-row { display: flex; gap: 10px; margin-bottom: 10px; }
.hidden { display: none; }
.form-actions { display: flex; gap: 12px; margin-top: 4px; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.inline-form input { width: auto; flex: 1; min-width: 170px; margin-top: 0; }

/* ---------------- Table ---------------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 14px 10px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 0.9rem; }
th {
    color: var(--muted);
    font-weight: 600;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: #f8f9ff; }
tbody tr:last-child td { border-bottom: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }

.target-list { list-style: none; padding: 0; margin: 8px 0 0; }
.target-list li { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; background: #fafbff; }

code { background: #eef0fb; color: #4f46e5; padding: 2px 7px; border-radius: 6px; font-size: 0.82em; }
.muted { color: var(--muted); font-size: 0.85rem; }
.preview { margin-top: 3px; }
.err { color: var(--danger); }

/* ---------------- Media thumbs / previews ---------------- */
.thumb {
    display: block;
    width: 96px;
    height: 66px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 6px;
    background: #f3f4f6;
    box-shadow: 0 3px 8px rgba(31, 36, 51, 0.10);
}
.media-preview { margin-top: 10px; }
.media-preview img, .media-preview video,
.media-current {
    max-width: 320px;
    max-height: 240px;
    border-radius: 14px;
    border: 1px solid var(--border);
    display: block;
    box-shadow: var(--shadow);
}
.current-media { margin: 6px 0 10px; }
.media-current { margin: 6px 0; }

/* ---------------- User chip ---------------- */
.user-chip {
    background: linear-gradient(120deg, rgba(99,102,241,0.12), rgba(139,92,246,0.12));
    color: var(--primary-dark);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid rgba(99,102,241,0.18);
}

/* ---------------- Status badges ---------------- */
.status { padding: 4px 12px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; display: inline-block; }
.status-scheduled { background: #e0e7ff; color: #3730a3; }
.status-sent { background: #d1fae5; color: #065f46; }
.status-failed { background: #ffe4e6; color: #9f1239; }
.status-draft { background: #eef0f5; color: #4b5563; }

/* ---------------- Login page ---------------- */
.login-page {
    background:
        radial-gradient(900px 500px at 80% 10%, rgba(168, 85, 247, 0.45), transparent 55%),
        radial-gradient(800px 600px at 10% 90%, rgba(56, 189, 248, 0.35), transparent 55%),
        linear-gradient(135deg, #4338ca 0%, #6d28d9 50%, #7c3aed 100%);
}
.login-page .content-area { padding: 0; }
.login-page main { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 22px;
    padding: 38px 34px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.login-card h2 { margin-bottom: 4px; font-size: 1.5rem; }
.login-card .stack { text-align: left; margin-top: 22px; }
.login-logo {
    width: 64px; height: 64px;
    margin: 0 auto 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.8rem;
    border-radius: 18px;
    background: linear-gradient(120deg, var(--primary), var(--primary-2));
    box-shadow: 0 10px 24px rgba(99, 102, 241, 0.4);
}
.login-sub { color: var(--muted); margin: 0; font-size: 0.92rem; }
.login-error {
    background: #ffe4e6;
    color: #9f1239;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    margin-top: 18px;
}
.ok-msg {
    background: #d1fae5;
    color: #065f46;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
}
.edit-admin input[type=text] { min-width: 130px; }

/* ---------------- Toggle rows (group settings) ---------------- */
.switch {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafbff;
    margin-bottom: 10px;
    font-weight: 400;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.switch:hover { border-color: rgba(99, 102, 241, 0.35); background: #f6f7ff; }
.switch input[type=checkbox] {
    width: 20px;
    height: 20px;
    margin: 1px 0 0;
    accent-color: var(--primary);
    flex: 0 0 auto;
    cursor: pointer;
}
.switch span { line-height: 1.45; }

/* ---------------- Detected groups ---------------- */
.detected { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--border); }
.detected h3 { font-size: 0.98rem; font-weight: 600; margin: 0 0 12px; }
.detected-hint {
    margin-top: 18px;
    padding: 12px 14px;
    background: #f6f7ff;
    border: 1px dashed rgba(99, 102, 241, 0.3);
    border-radius: 12px;
}
.target-list li form { margin: 0; }

/* ---------------- Target checkboxes ---------------- */
.target-checks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 6px;
    margin-top: 8px;
}
.check {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fafbff;
    font-weight: 400;
    cursor: pointer;
    font-size: 0.9rem;
    transition: border-color 0.15s, background 0.15s;
}
.check:hover { border-color: rgba(99,102,241,0.35); background: #f6f7ff; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: 0 0 auto; }
.check-all { display: inline-flex; margin-bottom: 6px; background: #eef0fb; border-color: rgba(99,102,241,0.2); }
.tgt { font-size: 0.88rem; white-space: nowrap; }
.tgt .dot { color: var(--primary); font-size: 0.6rem; vertical-align: middle; }
.send-summary {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 14px 16px;
    background: #fafbff;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 18px;
}
.sched-box {
    margin-top: 14px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
}
.rec-freq { margin: 12px 0 4px; }
.day-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.day-picker .check { padding: 8px 12px; }
.day-picker.all-on .check { opacity: 0.75; cursor: default; border-style: dashed; }

/* ---------------- Button sets ---------------- */
.set-picker {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px dashed var(--border);
}
.set-picker select { width: auto; flex: 1; min-width: 200px; margin-top: 0; }
.btn-chip {
    display: inline-block;
    background: linear-gradient(120deg, rgba(99,102,241,0.12), rgba(139,92,246,0.12));
    color: var(--primary-dark);
    border: 1px solid rgba(99,102,241,0.18);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    margin: 2px 3px 2px 0;
}

@media (max-width: 640px) {
    nav { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
    .card { padding: 18px; }
    th, td { padding: 10px 6px; }
}
