:root {
  --primary: #0b5c56;
  --primary-dark: #084741;
  --primary-light: #e0f2f0;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1c2b2a;
  --muted: #6b7a78;
  --border: #e2e8e7;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --success: #1e824c;
  --success-bg: #e8f7ef;
  --warn: #b7791f;
  --warn-bg: #fdf3e0;
  --radius: 14px;
  --nav-h: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Heebo', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}
.topbar-title {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.brand-logo {
  height: 22px;
  width: auto;
  max-width: 140px;
  display: block;
  flex-shrink: 0;
}
.topbar-context {
  font-size: 0.92rem;
  font-weight: 600;
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.auth-brand-icon {
  width: 72px;
  height: 72px;
  display: block;
}
.app-update-backdrop { z-index: 300; }
.app-update-backdrop .agent-modal { pointer-events: auto; }
.icon-btn {
  position: relative;
  background: none; border: none; color: inherit;
  padding: 8px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.icon-btn.danger { color: var(--danger); font-size: 0.9rem; }
.badge-count {
  position: absolute; top: 2px; inset-inline-end: 0;
  background: #e74c3c; color: #fff; border-radius: 10px;
  font-size: 0.65rem; padding: 1px 5px; font-weight: 700;
}

/* ---------- Page ---------- */
.page {
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 24px);
  max-width: 720px;
  margin: 0 auto;
}
.page-title { font-size: 1.35rem; margin: 8px 0 12px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-title { font-size: 1rem; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }
.section-title.compact { margin: 0 0 8px; font-size: 0.92rem; }
.draft-card { margin-bottom: 14px; }
.draft-text { white-space: pre-wrap; word-break: break-word; font-size: 0.95rem; line-height: 1.45; }
.btn.is-disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.plain-list { margin: 0; padding-inline-start: 1.2rem; }
.plain-list li { margin-bottom: 6px; }
.system-topbar { background: #1a2332; color: #fff; }
.system-topbar .topbar-title { color: #fff; }
.system-topbar .btn-secondary { background: rgba(255,255,255,0.12); color: #fff; border: none; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.error-text { color: var(--danger); }
.error-code { font-size: 3rem; margin: 0; color: var(--primary); }
.chev { color: var(--muted); font-size: 1.3rem; }
.clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Cards & lists ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 12px;
}
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  text-decoration: none;
  color: inherit;
  min-height: 52px;
}
.list-item.unread { border-inline-start: 4px solid var(--primary); }
.dot-unread { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }
.empty-state { text-align: center; padding: 28px 16px; }
.kv > div { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; gap: 12px; }
.kv > div + div { border-top: 1px solid var(--border); }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 2px;
}
.stat-num { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.stat-num.warn { color: var(--danger); }
.stat-label { color: var(--muted); font-size: 0.82rem; }

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 13px; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.gap-sm { gap: 6px; flex-wrap: wrap; }
.row.space-between { justify-content: space-between; }
.row.align-center { align-items: center; }
.checkbox-row { flex-direction: row !important; align-items: center; gap: 10px; font-weight: 500; }
.checkbox-row input[type="checkbox"] { width: auto; }
.field-mappings { display: flex; flex-direction: column; gap: 8px; }
.mapping-row select, .mapping-row input[type="text"] { flex: 1; min-width: 120px; }
.mapping-row .wp-remove-mapping { flex-shrink: 0; min-width: 36px; padding: 8px; }
.grow { flex: 1; min-width: 0; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 0.9rem; font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="date"], input[type="datetime-local"], select, textarea {
  font: inherit;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  width: 100%;
  color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--muted); }
textarea { resize: vertical; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
legend { font-size: 0.85rem; color: var(--muted); padding: 0 4px; }
.check-row { flex-direction: row; align-items: center; gap: 9px; font-weight: 400; padding: 5px 0; }
.check-row input { width: auto; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
input[type="file"] { font-size: 0.9rem; }
details summary { cursor: pointer; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600;
  border: none; border-radius: 11px;
  padding: 12px 18px;
  cursor: pointer;
  text-decoration: none;
  min-height: 46px;
  transition: filter 0.15s;
}
.btn:active { filter: brightness(0.92); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; min-height: 36px; font-size: 0.85rem; }
.btn-card { width: 100%; background: var(--card); border: 1px solid var(--border); color: inherit; text-align: start; }
.as-link { background: none; border: none; cursor: pointer; font: inherit; padding: 0; }
.link-muted { color: var(--muted); font-size: 0.88rem; display: inline-block; margin-top: 14px; text-decoration: none; }

/* ---------- Badges & chips ---------- */
.status-badge {
  font-size: 0.72rem; font-weight: 700;
  border-radius: 999px; padding: 4px 10px;
  white-space: nowrap; flex-shrink: 0;
  background: var(--bg); color: var(--muted);
}
.status-connected, .status-published, .status-completed { background: var(--success-bg); color: var(--success); }
.status-connecting, .status-scheduled, .status-publishing, .status-pending, .status-running { background: var(--warn-bg); color: var(--warn); }
.status-disconnected, .status-error, .status-failed, .status-partially_failed, .status-reconnect_required { background: var(--danger-bg); color: var(--danger); }
.status-draft, .status-ready_for_preview, .status-approved, .status-not_connected, .status-not_configured, .status-cancelled, .status-archived, .status-suspended { background: var(--bg); color: var(--muted); }
.role-badge { background: var(--primary-light); color: var(--primary-dark); }
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.chip {
  font-size: 0.72rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 9px; color: var(--muted);
}
.chip-primary { background: var(--primary-light); color: var(--primary-dark); border-color: transparent; }

/* ---------- Flash ---------- */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.flash { border-radius: 10px; padding: 12px 14px; font-size: 0.9rem; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--surface-2, #eef4ff); color: var(--text, inherit); }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--card);
  border-top: 1px solid var(--border);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
}
.bottomnav a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.68rem; font-weight: 600;
}
.bottomnav a.active { color: var(--primary); }
.create-circle {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  margin-top: -18px;
  box-shadow: 0 4px 10px rgba(11, 92, 86, 0.35);
}
.create-btn span:last-child { margin-top: 1px; }

/* ---------- Auth ---------- */
.auth-page {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 60%, #052e2a 100%);
}
.auth-card {
  background: var(--card);
  border-radius: 18px;
  padding: 28px 22px;
  width: 100%; max-width: 400px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.auth-card h1 { margin: 8px 0 4px; font-size: 1.3rem; }
.auth-card form { text-align: start; margin-top: 16px; }
.auth-logo { display: flex; justify-content: center; }
.auth-page .flash-stack { width: 100%; max-width: 400px; }
.lang-switch { display: flex; justify-content: center; gap: 14px; margin-top: 18px; }
.lang-switch a { color: var(--muted); text-decoration: none; font-size: 0.88rem; padding: 4px 10px; border-radius: 8px; }
.lang-switch a.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 700; }

/* ---------- WhatsApp connection ---------- */
.qr-wrap { text-align: center; padding: 10px 0; }
.qr-wrap img { border: 1px solid var(--border); border-radius: 12px; max-width: 100%; height: auto; }

/* ---------- Chat ---------- */
.chat-box { padding: 0; overflow: hidden; }
.chat-messages {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px;
  max-height: 42vh; overflow-y: auto;
  background: #ece5dd;
}
.chat-messages.static { max-height: none; background: transparent; padding: 0; }
.chat-bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.from-user { align-self: flex-end; background: #d9fdd3; border-end-end-radius: 3px; }
.from-agent { align-self: flex-start; background: #fff; border-end-start-radius: 3px; }
.chat-bubble.thinking { color: var(--muted); font-style: italic; }
.chat-bubble.error { background: #fde8e8; color: #9b1c1c; }
.chat-input-row {
  display: flex; gap: 8px; padding: 10px;
  border-top: 1px solid var(--border); background: var(--card);
}
.chat-input-row textarea { flex: 1; }

/* ---------- Media ---------- */
.media-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.media-thumb {
  position: relative; width: 92px; height: 92px;
  border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
}
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb-selectable { cursor: pointer; }
.media-thumb-selectable input[type="radio"] {
  position: absolute; top: 6px; inset-inline-start: 6px; z-index: 1;
  width: 18px; height: 18px; accent-color: var(--primary, #128c7e);
}
.media-thumb-selectable:has(input:checked) { outline: 3px solid var(--primary, #128c7e); }
.media-remove {
  position: absolute; top: 3px; inset-inline-end: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  border: none; background: rgba(0,0,0,0.6); color: #fff;
  cursor: pointer; font-size: 0.75rem;
}
.media-badge {
  position: absolute; bottom: 3px; inset-inline-start: 3px;
  min-width: 22px; height: 22px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 0.7rem;
  padding: 0 4px; pointer-events: none;
}
.media-edit-wm {
  position: absolute; bottom: 3px; inset-inline-end: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  border: none; background: rgba(0,0,0,0.6); color: #fff;
  cursor: pointer; font-size: 0.75rem;
}
.media-processing-note {
  display: flex; align-items: center; gap: 8px;
  padding: 14px; border-radius: 7px; margin-bottom: 6px;
  background: var(--bg); color: var(--muted); font-size: 0.85rem;
}
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: wm-spin 0.9s linear infinite;
  vertical-align: middle;
}
.spinner-sm { width: 12px; height: 12px; border-width: 2px; }
@keyframes wm-spin { to { transform: rotate(360deg); } }

/* ---------- Media uploader (dropzone) ---------- */
.uploader-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}
.uploader-zone:hover, .uploader-zone:focus-visible { border-color: var(--primary); }
.uploader-zone.is-dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.uploader-zone .uploader-native-input {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.uploader-prompt { pointer-events: none; }
.uploader-icon { font-size: 1.4rem; color: var(--muted); line-height: 1; }
.uploader-hint { margin-top: 6px; font-size: 0.85rem; color: var(--muted); }
.uploader-status { display: flex; flex-direction: column; gap: 4px; }
.uploader-status:not(:empty) { margin-top: 8px; }
.uploader-file {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 10px; border-radius: 8px; font-size: 0.82rem;
  background: var(--bg); border: 1px solid var(--border);
}
.uploader-file-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  direction: ltr; text-align: start;
}
.uploader-file-state { flex-shrink: 0; color: var(--muted); }
.uploader-file.is-uploading .uploader-file-state { color: var(--primary); }
.uploader-file.is-done { border-color: #b7e4c7; background: #ecfdf3; }
.uploader-file.is-done .uploader-file-state { color: #1a7f37; }
.uploader-file.is-error { border-color: #f5c2c7; background: #fde8e8; }
.uploader-file.is-error .uploader-file-state { color: #9b1c1c; }
.uploader-file.is-cancelled { opacity: 0.65; }

/* ---------- Watermark editor modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none !important; }
.changelog-backdrop { z-index: 250; }
.changelog-modal {
  width: 100%;
  max-width: 560px;
  max-height: min(720px, 90vh);
  margin: 0;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0,0,0,0.28);
}
.changelog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.changelog-title { margin: 0 0 4px; font-size: 1.25rem; }
.changelog-header p { margin: 0; }
.changelog-close { flex-shrink: 0; color: var(--muted); margin: -6px -6px 0 0; }
[dir="rtl"] .changelog-close { margin: -6px 0 0 -6px; }
.changelog-list { max-height: calc(min(720px, 90vh) - 82px); overflow-y: auto; padding: 4px 18px 18px; }
.changelog-release { padding-top: 14px; }
.changelog-release + .changelog-release { margin-top: 14px; border-top: 1px solid var(--border); }
.changelog-release-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.changelog-release-heading h3 { margin: 0; color: var(--primary); font-size: 1rem; }
.changelog-release-heading time { color: var(--muted); font-size: 0.78rem; direction: ltr; }
.changelog-release ul { margin: 9px 0 0; padding-inline-start: 1.2rem; line-height: 1.5; }
.changelog-release li + li { margin-top: 5px; }
.wm-modal {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: var(--radius); padding: 16px;
}
.wm-title { margin: 0 0 8px; font-size: 1.05rem; }
.wm-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.wm-actions .btn { flex: 1; min-width: 110px; }
.wm-video-hint { color: var(--primary-dark); background: var(--primary-light); padding: 6px 10px; border-radius: 8px; }
.wm-stage {
  position: relative; margin-top: 10px;
  border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
  background: #000;
  touch-action: none;
  direction: ltr; /* placement math uses left/top; keep coords LTR even in RTL UI */
}
.wm-media { display: block; width: 100%; height: auto; max-height: 60vh; object-fit: contain; vertical-align: top; }
.wm-logo {
  position: absolute; cursor: move; z-index: 2;
  outline: 1px dashed rgba(255,255,255,0.85);
  touch-action: none;
  user-select: none; -webkit-user-drag: none;
}
.wm-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  aspect-ratio: 4 / 3;
  background: #1a1a1a;
  color: rgba(255,255,255,0.65);
  font-size: 0.88rem;
  text-align: center;
  padding: 16px;
}
.wm-handle {
  position: absolute; width: 14px; height: 14px; z-index: 3;
  background: var(--primary); border: 2px solid #fff; border-radius: 50%;
  cursor: nwse-resize; touch-action: none;
}
.wm-opacity-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 0.9rem; }
.wm-opacity-row input[type="range"] { flex: 1; }
.wm-applyall-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 12px; font-size: 0.88rem; cursor: pointer;
}

.logo-thumb { width: 42px; height: 42px; object-fit: contain; border-radius: 8px; background: var(--bg); }
.logo-preview { max-width: 140px; max-height: 140px; object-fit: contain; border-radius: 10px; background: var(--bg); padding: 8px; }

/* ---------- WhatsApp-style preview ---------- */
.wa-preview {
  background: #ece5dd url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" opacity="0.05"><circle cx="30" cy="30" r="2" fill="%23000"/></svg>');
  border-radius: var(--radius);
  padding: 18px 14px;
  border: 1px solid var(--border);
}
.wa-preview-bubble {
  background: #fff;
  border-radius: 10px;
  border-start-start-radius: 2px;
  padding: 8px;
  max-width: 480px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}
.wa-preview-media { width: 100%; border-radius: 7px; margin-bottom: 6px; display: block; }

/* WhatsApp-style multi-media album grid inside the bubble */
.wa-album {
  display: grid;
  gap: 2px;
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 6px;
}
.wa-album-item {
  position: relative;
  overflow: hidden;
  background: #000;
  min-height: 72px;
}
.wa-album-media {
  width: 100%;
  height: 100%;
  min-height: 72px;
  max-height: 220px;
  object-fit: cover;
  display: block;
}
.wa-album-processing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  background: var(--bg);
}
.wa-album-more {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 600;
  pointer-events: none;
}
.wa-album--1 { grid-template-columns: 1fr; }
.wa-album--1 .wa-album-media { max-height: 280px; }
.wa-album--2 { grid-template-columns: 1fr 1fr; }
.wa-album--2 .wa-album-item { aspect-ratio: 1; }
.wa-album--3 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.wa-album--3 .wa-album-item:first-child { grid-row: span 2; }
.wa-album--3 .wa-album-item { aspect-ratio: 1; }
.wa-album--3 .wa-album-item:first-child { aspect-ratio: auto; }
.wa-album--4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.wa-album--4 .wa-album-item { aspect-ratio: 1; }
.wa-album--5 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: 1fr 1fr;
}
.wa-album--5 .wa-album-item:nth-child(1) { grid-column: 1 / span 3; }
.wa-album--5 .wa-album-item:nth-child(2) { grid-column: 4 / span 3; }
.wa-album--5 .wa-album-item:nth-child(3) { grid-column: 1 / span 2; }
.wa-album--5 .wa-album-item:nth-child(4) { grid-column: 3 / span 2; }
.wa-album--5 .wa-album-item:nth-child(5) { grid-column: 5 / span 2; }
.wa-album--5 .wa-album-item { aspect-ratio: 1; }
.wa-album--6 {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}
.wa-album--6 .wa-album-item { aspect-ratio: 1; }
.wa-album--many {
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(72px, 1fr);
}
.wa-album--many .wa-album-item { aspect-ratio: 1; }

.wa-preview-text { white-space: pre-wrap; word-break: break-word; font-size: 0.95rem; padding: 2px 4px; color: var(--text); }
.wa-preview-content {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}
.wa-preview-part + .wa-preview-part { margin-top: 0.35rem; }
.wa-preview-text strong { font-weight: 700; }
.wa-preview-text em { font-style: italic; }
.wa-preview-text s { text-decoration: line-through; }
.wa-preview-time { text-align: end; font-size: 0.68rem; color: var(--muted); padding: 2px 4px 0; }

.preview-selection-menu {
  position: fixed;
  z-index: 150;
  transform: translate(-50%, calc(-100% - 8px));
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0,0,0,0.14);
}
.preview-selection-menu[hidden] { display: none !important; }
.preview-menu-btn {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
}
.preview-menu-btn:hover,
.preview-menu-btn:focus-visible {
  background: var(--bg);
}
.preview-menu-format {
  min-width: 30px;
  padding: 6px 8px;
  font-size: 0.9rem;
}
.preview-edit-modal {
  width: 100%;
  max-width: 480px;
  padding: 16px;
}
.preview-edit-title { margin: 0 0 10px; font-size: 1.05rem; }
#preview-edit-textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
}
.preview-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.agent-modal {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 16px;
}
.agent-modal-title { margin: 0 0 8px; font-size: 1.05rem; }
.agent-create-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.agent-create-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: auto;
  padding: 14px 16px;
}
.agent-create-option strong {
  font-size: 0.95rem;
}
.agent-create-option:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- Misc ---------- */
.optin-card { border-color: var(--primary); background: var(--primary-light); }
.filter-form input[type="search"] { font-size: 1rem; }
.pagination { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.page-link {
  min-width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; text-decoration: none; color: var(--muted);
  background: var(--card); border: 1px solid var(--border); font-size: 0.85rem;
}
.page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.template-body-note {
  border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px;
  color: var(--muted); font-size: 0.85rem; background: var(--bg);
}

@media (min-width: 720px) {
  .page-title { font-size: 1.55rem; }
}

/* ---------- Country select ---------- */
.country-select { position: relative; }
.country-select-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); text-align: start; cursor: pointer;
}
.country-select-value { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.country-select-panel[hidden] {
  display: none !important;
}
.country-select-panel:not([hidden]) {
  display: flex;
  flex-direction: column;
}
.country-select-panel {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px;
}
.country-select-search {
  margin: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
}
.country-select-list {
  list-style: none; margin: 0; padding: 0 0 8px; overflow-y: auto; flex: 1;
}
.country-select-option {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer;
}
.country-select-option:hover { background: var(--primary-light); }
.country-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 18px;
  flex-shrink: 0;
}
.country-flag-img {
  display: block;
  width: 24px;
  height: 18px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.country-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.country-select-placeholder { color: var(--muted); }

/* ---------- Integration cards ---------- */
.integration-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.integration-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 14px; cursor: pointer; text-align: start; border: 1px solid var(--border);
}
.integration-card-icon { font-size: 1.6rem; }
.integration-card-title { font-weight: 600; font-size: 0.95rem; }
.integration-card-status { font-size: 0.75rem; }
.integration-card-status.ok { color: var(--primary); }
.integration-card-status.warn { color: var(--muted); }
.integration-card-badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); }
.integration-card-badge.on { color: var(--primary); }
.integration-modal-backdrop { z-index: 120; }
body.modal-open { overflow: hidden; }
.chart-container { position: relative; height: 260px; width: 100%; }
.chart-wrap .chart-container { min-height: 240px; }
.plan-option { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.plan-option input { margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: repeat(2, 1fr); } }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: start; }
.integration-modal-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px;
}
.code-block, .api-key-display {
  display: block; padding: 10px 12px; background: var(--bg); border-radius: 8px;
  overflow-x: auto; font-size: 0.85rem; border: 1px solid var(--border);
}

/* ---------- System administration ---------- */
.system-page { max-width: 960px; }
.system-nav {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.system-nav-link {
  padding: 8px 14px; border-radius: 999px; text-decoration: none;
  font-size: 0.9rem; color: var(--muted); border: 1px solid transparent;
}
.system-nav-link:hover { color: var(--text); background: var(--bg); }
.system-nav-link.active {
  color: var(--primary); background: var(--primary-light);
  border-color: color-mix(in srgb, var(--primary) 25%, var(--border));
  font-weight: 600;
}
.system-hub-grid {
  display: grid; gap: 14px; margin-top: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .system-hub-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .system-hub-grid { grid-template-columns: repeat(4, 1fr); }
}
.system-hub-card {
  display: flex; flex-direction: column; gap: 8px; padding: 18px;
  text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s;
}
.system-hub-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
}
.system-hub-icon { font-size: 1.75rem; line-height: 1; }
.system-hub-title { margin: 0; font-size: 1.05rem; }

.plan-admin-list { display: grid; gap: 14px; }
.plan-admin-card { gap: 12px; }
.plan-admin-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.plan-admin-name { margin: 0; font-size: 1.15rem; }
.plan-price-dl {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
  margin: 0; padding: 12px; background: var(--bg); border-radius: 10px;
}
.plan-price-dl div { display: flex; flex-direction: column; gap: 2px; }
.plan-price-dl dt { margin: 0; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.plan-price-dl dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.plan-admin-actions { margin-top: 4px; }

.form-section { gap: 12px; }
.form-section .section-title { margin: 0 0 4px; font-size: 1rem; }
.grid-2 .span-2 { grid-column: 1 / -1; }
.field-hint { display: block; margin-top: 4px; }
.plan-check { align-self: end; padding: 10px 0; }
.plan-features-grid { align-items: start; }
.form-actions {
  display: flex; flex-wrap: wrap; gap: 10px; padding-top: 4px;
  position: sticky; bottom: 12px; z-index: 5;
}
.warn-box { border-color: color-mix(in srgb, var(--warn, #c90) 35%, var(--border)); background: color-mix(in srgb, var(--warn, #c90) 8%, var(--card)); }
.plan-readonly-preview { opacity: 0.92; }
.plan-readonly-preview input:disabled,
.plan-readonly-preview textarea:disabled,
.plan-readonly-preview select:disabled { opacity: 0.75; cursor: not-allowed; }

.password-meter { margin-top: 6px; display: grid; gap: 4px; }
.password-meter-head {
  display: flex; align-items: center; gap: 8px;
}
.password-meter-bar {
  flex: 1; height: 4px; border-radius: 999px; background: var(--border); overflow: hidden;
}
.password-meter-fill {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: var(--danger); transition: width .15s ease, background-color .15s ease;
}
.password-meter-fill[data-level="1"] { background: #e57373; }
.password-meter-fill[data-level="2"] { background: #ffb74d; }
.password-meter-fill[data-level="3"] { background: #81c784; }
.password-meter-fill[data-level="4"] { background: var(--primary); }
.password-meter-label {
  flex-shrink: 0; font-size: 0.75rem; line-height: 1; white-space: nowrap;
}
.password-meter-label.warn { color: var(--danger, #c62828); }
.password-meter-label.ok { color: var(--primary); }
.small.ok { color: var(--primary); }
.small.err { color: var(--danger); }
.password-meter-rules {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 4px 10px;
  font-size: 0.72rem; line-height: 1.2; color: var(--muted);
}
.password-meter-rules li::before { content: '• '; }
.password-meter-rules[hidden] { display: none !important; }
