:root {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-2: #fafafb;
  --border: #e3e3e8;
  --text: #1c1c1e;
  --muted: #6b6b73;
  --accent: #b33048;
  --accent-hover: #942539;
  --accent-soft: #f9eaed;
  --dark: #111114;
  --green: #1a7f37;
  --green-soft: #e7f5ec;
  --amber: #9a6700;
  --amber-soft: #fff4d6;
  --blue: #0b63c5;
  --blue-soft: #e6f0fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  /* Fonts: Fira Code for headings, the Mac system font for reading text. */
  --font-heading: "Fira Code", ui-monospace, Menlo, monospace;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --font-mono: "Fira Code", ui-monospace, Menlo, monospace;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); }
h1, h2, h3, th, .brand small { font-family: var(--font-heading); }
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { line-height: 1.5; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* Sign-in */
.signin { position: fixed; inset: 0; background: var(--dark); display: grid; place-items: center; padding: 16px; z-index: 60; }
.signin-card { background: #fff; border-radius: 16px; padding: 36px 32px; width: 100%; max-width: 380px; text-align: center; }
.signin-logo { width: 200px; height: auto; }
.signin-card h1 { margin: 6px 0 4px; font-size: 16px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.google-btn { justify-content: center; width: 100%; padding: 11px 14px; margin-top: 8px; font-weight: 600; }
.user-box { font-size: 12px; color: #c8c8cf; padding: 10px 12px 0; line-height: 1.4; overflow-wrap: anywhere; }
.user-box button { background: none; border: 0; color: #f0a5b1; padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }

/* Layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--dark); color: #fff; padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { color: #fff; text-decoration: none; padding: 0 4px 20px; display: block; }
.brand-plate { display: block; padding: 4px 8px 0; }
.brand-plate img { display: block; width: 100%; height: auto; }
.brand small { display: block; font-weight: 600; font-size: 11px; color: #9a9aa3; letter-spacing: .12em; text-transform: uppercase; margin-top: 6px; padding-left: 8px; }
.nav-link { display: flex; align-items: center; gap: 10px; color: #c8c8cf; text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500; }
.nav-link svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-link:hover { background: #1f1f24; color: #fff; }
.nav-link.active { background: #26262c; color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.mode-badge { margin-top: auto; font-size: 12px; padding: 10px 12px; border-radius: 8px; line-height: 1.4; }
.mode-badge.simulate { background: #2b2412; color: #f5cf6b; }
.mode-badge.live { background: #12281a; color: #6fdc8c; }
.main { padding: 28px 32px 64px; max-width: 1280px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards & panels */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.sticky { position: sticky; top: 20px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); border-color: #cfcfd6; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--accent); }
.btn.danger.solid { background: var(--accent); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; }

/* Forms */
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field { margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
input[type=text], input[type=email], input[type=tel], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
textarea { resize: vertical; min-height: 220px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(179,48,72,.25); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 180px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #efeff3; vertical-align: middle; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.check-cell, th.check-cell { width: 36px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* Chips & status pills */
.chip { display: inline-block; background: #eef0f4; color: #3a3a40; border-radius: 999px; padding: 2px 9px; font-size: 12px; margin: 1px 3px 1px 0; white-space: nowrap; }
.chip-select { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-select label { margin: 0; font-weight: 500; font-size: 13px; border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; cursor: pointer; background: #fff; user-select: none; }
.chip-select input { display: none; }
.chip-select label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.pill { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 6px; padding: 2px 8px; white-space: nowrap; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--accent-soft); color: var(--accent); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.grey { background: #eef0f4; color: var(--muted); }

/* Toolbar */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }
.bulk-bar { display: flex; gap: 8px; align-items: center; background: var(--dark); color: #fff; border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; flex-wrap: wrap; }
.bulk-bar .btn { background: #26262c; color: #fff; border-color: #3a3a42; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); }

/* Notices */
.notice { border-radius: 8px; padding: 12px 14px; line-height: 1.5; margin-bottom: 16px; }
.notice.info { background: var(--blue-soft); color: #0a4a91; }
.notice.warn { background: var(--amber-soft); color: #6b4800; }
.notice.error { background: var(--accent-soft); color: #9b0014; }
.notice.ok { background: var(--green-soft); color: #145c2a; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }

/* Campaign list cards */
.campaign-row { display: flex; align-items: center; gap: 14px; }
.channel-icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex: none; font-size: 16px; }
.channel-icon.email { background: var(--blue-soft); }
.channel-icon.whatsapp { background: var(--green-soft); }

/* Previews */
.preview-frame { width: 100%; height: 560px; border: 1px solid var(--border); border-radius: 8px; background: #f2f2f4; }
.wa-preview { background: #e5ddd5; background-image: radial-gradient(#d9d0c7 1px, transparent 1px); background-size: 14px 14px; border-radius: 10px; padding: 24px 16px; min-height: 260px; }
.wa-bubble { background: #fff; border-radius: 0 10px 10px 10px; padding: 8px 10px 18px; max-width: 85%; box-shadow: 0 1px 1px rgba(0,0,0,.1); white-space: pre-wrap; line-height: 1.45; position: relative; font-size: 14px; }
.wa-bubble .time { position: absolute; right: 8px; bottom: 3px; font-size: 11px; color: #8a8a8a; }
.wa-image { display: block; width: calc(100% + 12px); margin: -4px -6px 8px; border-radius: 8px; max-height: 260px; object-fit: cover; }
.wa-image-empty { background: #d9d0c7; color: #7a6f66; border-radius: 10px 10px 0 0; max-width: 85%; height: 120px; display: grid; place-items: center; font-size: 13px; }
.wa-thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.wa-button { background: #fff; border-radius: 10px; margin-top: 4px; max-width: 85%; text-align: center; padding: 9px; color: #027eb5; font-weight: 500; box-shadow: 0 1px 1px rgba(0,0,0,.1); }
.wa-to { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17,17,20,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { padding: 18px 20px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid #f0f0f3; }
.close-x { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--dark); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: 380px; line-height: 1.4; animation: in .2s ease-out; }
.toast.error { background: #9b0014; }
.toast.ok { background: #145c2a; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.placeholder-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.placeholder-btns button { font-family: var(--font-mono); font-size: 12px; }
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
code { font-family: var(--font-mono); font-size: 12.5px; background: #f0f0f3; padding: 1px 5px; border-radius: 4px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
  .brand { padding: 4px 12px 4px 4px; width: 150px; }
  .brand-plate { padding: 2px 0; }
  .brand small { display: none; }
  .mode-badge { margin: 0; width: 100%; }
  .main { padding: 20px 16px 48px; }
  .editor-grid, .grid-2 { grid-template-columns: 1fr; }
  .sticky { position: static; }
  dl.kv { grid-template-columns: 1fr; }
}
