:root {
  --brand: #0f766e;
  --brand-600: #0d6b64;
  --brand-700: #115e59;
  --brand-50: #f0fdfa;
  --brand-100: #ccfbf1;
  --accent: #facc15;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --warn: #b45309;
  --warn-50: #fffbeb;
  --ok: #15803d;
  --ok-50: #f0fdf4;
  --info: #1d4ed8;
  --info-50: #eff6ff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --wa-bg: #efeae2;
  --wa-bubble: #d9fdd3;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: #0b2f2c; color: #d1fae5; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; color: #fff; text-decoration: none; }
.logo-mark { width: 38px; height: 38px; border-radius: 11px; background: var(--brand); display: grid; place-items: center; flex: none; }
.logo strong { display: block; font-size: 16px; letter-spacing: -.2px; }
.logo span { display: block; font-size: 11px; color: #99f6e4; text-transform: uppercase; letter-spacing: 1.4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #c7e9e2; text-decoration: none; font-weight: 500; font-size: 14.5px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav svg { width: 19px; height: 19px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot button { margin-top: 8px; background: none; border: 0; color: #99f6e4; padding: 0; cursor: pointer; font: inherit; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 32px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; letter-spacing: -.3px; }
.icon-btn.menu-btn { display: none; }
.content { padding: 28px 32px 60px; max-width: 1280px; }

/* ---------- Components ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font: inherit; font-weight: 600; font-size: 14px;
  padding: 9px 16px; border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, box-shadow .15s, opacity .15s;
}
.btn:hover { background: var(--brand-700); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-50); }
.btn.ai { background: linear-gradient(135deg, #7c3aed, #0f766e); }
.btn.ai:hover { filter: brightness(1.08); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn .spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-title h2 { font-size: 17px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 13px; font-weight: 600; color: #334155; }
.field .hint { font-size: 12.5px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], input[type=datetime-local], select, textarea {
  font: inherit; font-size: 14.5px; color: var(--text); background: #fff; border: 1px solid #cbd5e1; border-radius: 10px;
  padding: 9px 12px; width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
input[type=color] { width: 48px; height: 40px; border: 1px solid #cbd5e1; border-radius: 10px; padding: 3px; background: #fff; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.spacer { flex: 1; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-50); color: var(--ok); border-color: #bbf7d0; }
.badge.warn { background: var(--warn-50); color: var(--warn); border-color: #fde68a; }
.badge.danger { background: var(--danger-50); color: var(--danger); border-color: #fecaca; }
.badge.info { background: var(--info-50); color: var(--info); border-color: #bfdbfe; }
.badge.brand { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-100); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.tabs { display: inline-flex; background: #e9eef3; border-radius: 10px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: transparent; font: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.tabs button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::before { transform: translateX(18px); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: #94a3b8; margin-bottom: 10px; }
.empty h3 { color: var(--text); font-size: 16px; margin-bottom: 6px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { padding: 18px 20px; }
.stat .num { font-size: 30px; font-weight: 800; letter-spacing: -1px; }
.stat .lbl { color: var(--muted); font-size: 13.5px; font-weight: 500; }

/* ---------- Jobs grid ---------- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 340px; }
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.job { display: flex; flex-direction: column; overflow: hidden; }
.job-thumb { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--border); cursor: pointer; }
.job-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.job-thumb .noimg { padding: 18px; font-size: 13px; color: var(--muted); white-space: pre-line; overflow: hidden; max-height: 100%; text-align: left; width: 100%; height: 100%; }
.job-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.job-body h3 { font-size: 15.5px; }
.job-meta { font-size: 13px; color: var(--muted); }
.job-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.job-actions { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.job-actions .btn:first-child { flex: 1; }

/* ---------- Posts list ---------- */
.posts { display: flex; flex-direction: column; gap: 12px; }
.post { display: grid; grid-template-columns: 84px 1fr auto; gap: 16px; padding: 16px; align-items: start; }
.post-thumb { width: 84px; height: 84px; border-radius: 10px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); display: grid; place-items: center; color: #94a3b8; }
.post-thumb img { width: 100%; height: 100%; object-fit: cover; }
.post h3 { font-size: 15px; margin-bottom: 4px; }
.post-when { font-weight: 600; font-size: 13.5px; }
.post-text { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 4px; white-space: pre-line; }
.post-targets { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.post-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.target-error { font-size: 12px; color: var(--danger); margin-top: 4px; }

/* ---------- Groups ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-50); color: var(--brand-700); display: grid; place-items: center; font-weight: 700; flex: none; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-start; justify-content: center; padding: 32px 16px; overflow-y: auto; z-index: 50; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 980px; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: pop .18s; }
.modal.narrow { max-width: 520px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 18px 18px; flex-wrap: wrap; }
.icon-btn { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

.editor { display: grid; grid-template-columns: 340px 1fr; gap: 24px; }
.dropzone {
  border: 2px dashed #cbd5e1; border-radius: 14px; background: var(--surface-2); aspect-ratio: 4 / 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px;
  padding: 20px; cursor: pointer; color: var(--muted); position: relative; overflow: hidden; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-50); }
.dropzone svg { width: 40px; height: 40px; }
.dropzone.has-image { border-style: solid; padding: 0; background: #0f172a; }
.dropzone img { width: 100%; height: 100%; object-fit: contain; }
.dropzone .busy { position: absolute; inset: 0; background: rgba(255,255,255,.85); display: flex; flex-direction: column; gap: 10px; align-items: center; justify-content: center; color: var(--text); font-weight: 600; font-size: 14px; }
.dropzone .busy .spin { width: 28px; height: 28px; border: 3px solid var(--brand); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.image-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.image-actions .btn { flex: 1; }
.ai-box { background: linear-gradient(135deg, #f5f3ff, #f0fdfa); border: 1px solid #ddd6fe; border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.ai-box .row { gap: 8px; }
.ai-box input { background: #fff; }

/* ---------- WhatsApp preview ---------- */
.wa { background: var(--wa-bg); border-radius: 14px; padding: 14px; min-height: 120px; background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 14px 14px; }
.wa-bubble { background: var(--wa-bubble); border-radius: 10px 10px 10px 2px; padding: 6px 6px 8px; max-width: 360px; box-shadow: 0 1px 1px rgba(0,0,0,.12); font-size: 14px; line-height: 1.42; color: #111b21; }
.wa-bubble img { width: 100%; border-radius: 7px; display: block; margin-bottom: 4px; }
.wa-text { padding: 2px 6px; white-space: pre-wrap; word-wrap: break-word; }
.wa-time { text-align: right; font-size: 11px; color: #667781; padding: 0 6px; }

.publish { display: grid; grid-template-columns: 1fr 380px; gap: 24px; }
.group-picker { border: 1px solid var(--border); border-radius: 12px; max-height: 230px; overflow-y: auto; }
.group-picker label { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 14px; }
.group-picker label:last-child { border-bottom: 0; }
.group-picker label:hover { background: var(--surface-2); }
.group-picker input { width: 17px; height: 17px; accent-color: var(--brand); }
.when { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.when label { border: 1.5px solid var(--border); border-radius: 12px; padding: 12px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.when label:has(input:checked) { border-color: var(--brand); background: var(--brand-50); }
.when input { accent-color: var(--brand); margin-top: 3px; }
.when strong { display: block; font-size: 14px; }
.when span { font-size: 12.5px; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; cursor: pointer; }
.check input { accent-color: var(--brand); width: 16px; height: 16px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #134e4a, #0b2f2c 60%); }
.auth .card { width: 100%; max-width: 420px; padding: 32px; }
.auth .logo { color: var(--text); padding: 0 0 22px; }
.auth .logo span { color: var(--brand); }
.auth h2 { font-size: 20px; margin-bottom: 6px; }
.auth p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; max-width: calc(100vw - 40px); }
.toast { background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 14px; max-width: 420px; animation: pop .2s; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }

.status-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); text-decoration: none; }
.status-pill.ok { color: var(--ok); background: var(--ok-50); border-color: #bbf7d0; }
.status-pill.bad { color: var(--danger); background: var(--danger-50); border-color: #fecaca; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.settings-grid .card h2 { font-size: 16px; margin-bottom: 4px; }
.settings-grid .card > p { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; }
.env-note { font-size: 12px; color: var(--warn); }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .editor, .publish { grid-template-columns: 1fr; }
  .dropzone { aspect-ratio: 16 / 10; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .icon-btn.menu-btn { display: grid; }
  .topbar { padding: 12px 16px; }
  .content { padding: 18px 16px 60px; }
  .grid-2, .grid-3, .when { grid-template-columns: 1fr; }
  .post { grid-template-columns: 60px 1fr; }
  .post-thumb { width: 60px; height: 60px; }
  .post-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .modal-backdrop { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
  .modal-foot { border-radius: 0; }
}
