:root {
  --bg: #f6f6f8; --card: #fff; --text: #16161a; --muted: #6b6b76; --line: #e7e7ec;
  --accent: #d6246e; --accent-2: #f77737; --ok: #12805c; --bad: #c62828; --warn: #b26a00;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 16px; margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }
code { background: #f0f0f3; padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; justify-content: flex-end; }
.error { color: var(--bad); min-height: 1em; margin: 6px 0 0; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand.big { font-size: 24px; justify-content: center; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(45deg, #feda75, var(--accent-2), var(--accent), #962fbf, #4f5bd5); }

/* Layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--card); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: var(--text); padding: 9px 12px; border-radius: 8px; }
.sidebar nav a.active, .sidebar nav a:hover { background: #fbeef4; color: var(--accent); }
.account { margin-top: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.account img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
main { padding: 28px 32px; max-width: 1100px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 700; } .stat .l { color: var(--muted); font-size: 12px; }
.banner { background: #fff7e8; border: 1px solid #f3dcb0; color: #6b4600; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }

/* Forms */
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f6c3d8; border-color: var(--accent); }
textarea { resize: vertical; }
label { display: block; font-weight: 600; margin: 14px 0 6px; }
.row { display: flex; gap: 8px; align-items: center; } .row > select { width: auto; min-width: 190px; }
.gap-top { margin-top: 12px; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 9px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f4f4f6; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .6; cursor: wait; }
.checks { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.check { font-weight: 400; display: flex; gap: 8px; align-items: center; margin: 0; }
.check input { width: auto; }

/* Segmented control */
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; font: inherit; border: 0; background: #fff; padding: 9px 8px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: #fbeef4; color: var(--accent); font-weight: 600; }

/* Media picker */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 300px; overflow: auto; margin-bottom: 8px; padding: 2px; }
.media { position: relative; aspect-ratio: 9/16; border-radius: 8px; overflow: hidden; cursor: pointer; background: #eee; border: 2px solid transparent; }
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media.sel { border-color: var(--accent); box-shadow: 0 0 0 2px #f6c3d8; }
.media .tag { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 4px; }
.selected-media { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.selected-media img { width: 44px; height: 60px; object-fit: cover; border-radius: 6px; }

/* Rules */
.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; margin-bottom: 16px; }
.rule { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.rule.off { opacity: .6; }
.rule-top { display: flex; gap: 12px; }
.rule-thumb { width: 52px; height: 72px; border-radius: 8px; object-fit: cover; background: linear-gradient(135deg, #fbeef4, #fff0e6); flex: none; display: grid; place-items: center; font-size: 22px; }
.rule h3 { margin: 0 0 4px; font-size: 15px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { background: #f2f2f5; border-radius: 20px; padding: 1px 9px; font-size: 12px; }
.rule .msg { background: #f7f7f9; border-radius: 8px; padding: 8px 10px; font-size: 13px; white-space: pre-wrap; max-height: 80px; overflow: hidden; }
.rule-foot { display: flex; justify-content: space-between; align-items: center; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); grid-column: 1 / -1; }

/* Toggle */
.switch { position: relative; width: 38px; height: 22px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #ccc; border-radius: 22px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }

/* Table */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.text { max-width: 280px; word-break: break-word; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.sent { background: #e3f5ee; color: var(--ok); } .badge.failed { background: #fde8e8; color: var(--bad); }
.badge.skipped { background: #fff3dc; color: var(--warn); } .badge.no_match, .badge.pending { background: #eee; color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(20,20,30,.45); display: flex; justify-content: center; align-items: flex-start; padding: 30px 16px; overflow: auto; z-index: 10; }
.modal-card { width: 100%; max-width: 640px; }
.preview { margin-top: 14px; background: #fafafa; border-radius: 10px; padding: 12px; }
.bubble { margin-top: 6px; display: inline-block; max-width: 80%; background: linear-gradient(135deg, #7b3fe4, #d6246e); color: #fff; padding: 9px 13px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; word-break: break-word; }
.bubble:empty::before { content: "Your message will appear here"; opacity: .7; }
.test-result { margin-top: 10px; } .test-result .bubble { display: block; width: fit-content; margin-top: 8px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 10px; padding: 28px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: #16161a; color: #fff; padding: 10px 18px; border-radius: 10px; transition: .25s; z-index: 20; }
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .account { margin: 0; }
  main { padding: 18px 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row { flex-wrap: wrap; }
  .seg { flex-direction: column; } .seg button { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* Setup checklist & status text */
.ok { color: var(--ok); } .bad { color: var(--bad); }
.steps { margin: 8px 0 0; padding-left: 0; list-style: none; display: grid; gap: 4px; }
.steps li a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.steps li.done { opacity: .55; } .steps li.done a { text-decoration: none; }
.problem { background: #fdecec; border: 1px solid #f3c2c2; color: #7a1c1c; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; word-break: break-word; }
.row .check { white-space: nowrap; }
