/* WhatsApp Campaign Dashboard - lightweight RTL styling.
   No framework: one file, no build step, no CDN dependency for layout. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a2433;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #ccfbf1;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Cairo", "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { color: #fff; font-weight: 700; display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand:hover { text-decoration: none; opacity: .92; }
.brand-mark { font-size: 20px; }
.logout-form { display: flex; align-items: center; gap: 12px; margin: 0; }
.who { font-size: 13px; opacity: .85; }

/* ---------- layout ---------- */
.layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 20px 56px;
  display: grid;
  grid-template-columns: 208px 1fr;
  gap: 22px;
  align-items: start;
}
.sidenav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 74px;
}
.sidenav a {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14.5px;
}
.sidenav a:hover { background: var(--bg); text-decoration: none; }
.sidenav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.content { min-width: 0; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidenav { position: static; flex-direction: row; flex-wrap: wrap; }
}

/* ---------- page head ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head h1 { font-size: 22px; margin: 0; font-weight: 700; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card h2 { font-size: 16px; margin: 0 0 14px; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 13px; margin: -8px 0 14px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat.ok .value { color: var(--ok); }
.stat.info .value { color: var(--info); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 14px;
}
table.data th, table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}
table.data th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 13px; }
table.data tbody tr:hover { background: #f8fafc; }
table.data td.wrap { white-space: normal; min-width: 220px; }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: embed; text-align: right; }
.muted { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-brand { background: var(--brand-soft); color: var(--brand-dark); }

/* ---------- buttons ---------- */
.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f1f5f9; color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #991b1b; }
.btn-warn { background: var(--warn); }
.btn-warn:hover { background: #92400e; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.btn-ghost:hover { background: rgba(255,255,255,.14); color: #fff; }

/* ---------- forms ---------- */
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.form-row .help { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
input[type=text], input[type=password], input[type=file], input[type=search],
input[type=number], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}
textarea { min-height: 110px; }
.errorlist { color: var(--danger); font-size: 13px; margin: 6px 0 0; padding-right: 18px; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filter-bar .form-row { margin-bottom: 0; }
.filter-bar input, .filter-bar select { min-width: 190px; width: auto; }
.inline-form { display: inline; margin: 0; }

/* ---------- alerts ---------- */
.messages { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.alert {
  padding: 11px 15px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
}
.alert-success, .alert-ok { background: var(--ok-soft); color: #14532d; border-color: #bbf7d0; }
.alert-info, .alert-debug { background: var(--info-soft); color: #1e3a8a; border-color: #bfdbfe; }
.alert-warning { background: var(--warn-soft); color: #78350f; border-color: #fde68a; }
.alert-error, .alert-danger { background: var(--danger-soft); color: #7f1d1d; border-color: #fecaca; }

/* ---------- progress ---------- */
.progress {
  background: #e2e8f0;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.progress > span { display: block; height: 100%; background: var(--brand); }

/* ---------- wizard ---------- */
.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.steps .step {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.steps .step.active { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
.steps .step.done { background: var(--brand-soft); color: var(--brand-dark); border-color: var(--brand-soft); }

/* ---------- message preview ---------- */
.preview-bubble {
  background: #e7ffdb;
  border: 1px solid #c9edb8;
  border-radius: 12px;
  padding: 12px 14px;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.75;
  max-width: 560px;
}
.preview-item { margin-bottom: 14px; }
.preview-item .to { font-size: 13px; color: var(--muted); margin-bottom: 5px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(140deg, #0f766e 0%, #134e4a 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 30px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, .22);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }
.login-card .btn { width: 100%; }

/* ---------- misc ---------- */
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 18px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
code, .mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; }
pre.payload {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 8px;
  overflow: auto;
  direction: ltr;
  text-align: left;
  font-size: 12.5px;
  max-height: 420px;
}

/* ---------- shared inbox ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.check-row label { display: flex; align-items: center; gap: 6px; font-weight: 600; padding-bottom: 9px; }
.conv-card { padding: 0; overflow: hidden; }
.conv-card h2 { padding: 18px 20px 0; }
.conv-card .pagination { padding-bottom: 16px; }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-item { border-top: 1px solid var(--border); }
.conv-item.unread { background: #f0fdfa; }
.conv-item.unread .conv-name { color: var(--brand-dark); }
.conv-link { display: flex; gap: 14px; justify-content: space-between; padding: 12px 20px; color: var(--text); }
.conv-link:hover { background: #f8fafc; text-decoration: none; }
.conv-main { min-width: 0; flex: 1; }
.conv-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.conv-preview { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-item.unread .conv-preview { color: var(--text); font-weight: 600; }
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12.5px; flex-shrink: 0; }
.conv-badges { display: flex; gap: 6px; }
.inbox-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.inbox-side .card { margin-bottom: 14px; }
.thread-card { display: flex; flex-direction: column; }
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 62vh; overflow-y: auto; padding: 4px 2px 12px; }
.msg { max-width: 78%; border-radius: 12px; padding: 9px 12px; border: 1px solid var(--border); font-size: 14px; }
.msg-in { align-self: flex-start; background: #fff; }
.msg-out { align-self: flex-end; background: #e7ffdb; border-color: #c9edb8; }
.msg-campaign { background: #eef6ff; border-color: #cfe0f5; }
.msg-note { align-self: stretch; max-width: none; background: var(--warn-soft); border-color: #fde68a; }
.msg-head { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 3px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.msg-error { color: var(--danger); font-size: 12.5px; margin-top: 4px; }
.msg-foot { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.msg-id { font-size: 10.5px; opacity: .7; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-event { align-self: center; font-size: 12px; color: var(--muted); background: #f1f5f9; border-radius: 999px; padding: 3px 12px; text-align: center; }
.composer { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 6px; }
.composer textarea { min-height: 80px; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.status-form { display: flex; gap: 8px; }
.kv-tight { grid-template-columns: 110px 1fr; font-size: 13.5px; }
.kv-tight dd { overflow-wrap: anywhere; }
tr.selected-row td { background: var(--brand-soft); }
@media (max-width: 960px) {
  .inbox-layout { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .thread { max-height: none; }
}
@media (max-width: 600px) {
  .conv-link { flex-direction: column; gap: 6px; padding: 12px 14px; }
  .conv-meta { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .filter-bar input, .filter-bar select { min-width: 0; width: 100%; }
  .filter-bar .form-row { flex: 1 1 100%; }
}
