:root {
  --canvas: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --ink: #0f1a26;
  --ink-2: #2f3b4a;
  --muted: #717c8c;
  --line: #e7ecf3;
  --line-strong: #d4dbe5;
  --accent: #12a48a;          /* أخضر واتساب منقّح */
  --accent-2: #0c8f78;
  --accent-press: #0a7a66;
  --accent-soft: #e8f7f3;
  --live: #25d366;
  --warn: #b45309;
  --danger: #dc2626;
  --success: #14935a;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: "Cairo", system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow-sm: 0 1px 2px rgba(15, 26, 38, .06);
  --shadow: 0 1px 3px rgba(15, 26, 38, .05), 0 12px 30px rgba(15, 26, 38, .07);
  --shadow-lg: 0 16px 46px rgba(15, 26, 38, .14);
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background:
    radial-gradient(820px 480px at 88% -8%, rgba(37, 211, 102, .10) 0%, transparent 55%),
    radial-gradient(720px 520px at 4% 2%, rgba(18, 164, 138, .07) 0%, transparent 52%),
    var(--canvas);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------------- topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, .72);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid rgba(231, 236, 243, .9);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand h1 { font-size: 17px; font-weight: 800; margin: 0; }
.brand p { font-size: 12.5px; margin: 1px 0 0; color: var(--muted); font-weight: 500; }
.mark {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: linear-gradient(155deg, #15c39a, #0c8f78 70%);
  position: relative;
  box-shadow: 0 6px 16px rgba(18, 164, 138, .35), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.mark::before {
  content: ""; position: absolute; inset: 27% 20% auto 20%; height: 13%;
  background: rgba(255, 255, 255, .55); border-radius: 3px;
}
.mark::after {
  content: ""; position: absolute; inset: auto 20% 27% 20%; height: 13%;
  background: rgba(255, 255, 255, .9); border-radius: 3px;
}

.status-cluster { display: flex; align-items: center; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700;
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: #fff; white-space: nowrap; box-shadow: var(--shadow-sm);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transition: background .2s; }
.pill--idle .dot { background: #9aa3ad; }
.pill--qr { color: var(--warn); border-color: #f3dcae; background: #fff8ec; }
.pill--qr .dot { background: var(--warn); }
.pill--ready { color: var(--success); border-color: #b6e6c8; background: #eefaf2; }
.pill--ready .dot { background: var(--live); box-shadow: 0 0 0 4px rgba(37, 211, 102, .18); animation: pulse 2s ease-in-out infinite; }
.pill--down { color: var(--danger); border-color: #f3cbc6; background: #fdf2f1; }
.pill--down .dot { background: var(--danger); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, .35); }
  50% { box-shadow: 0 0 0 5px rgba(37, 211, 102, .10); }
}

/* ---------------- layout ---------------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 20px;
  max-width: 1200px;
  margin: 26px auto;
  padding: 0 20px;
}
.col-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* ---------------- cards ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow .2s, transform .2s;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfcfe, #fff);
}
.card__head h2 { font-size: 16px; font-weight: 700; margin: 0; }
.card__body { padding: 20px; }
.step {
  width: 28px; height: 28px; flex: none;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 800; font-family: var(--sans);
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  color: #fff; border-radius: 9px;
  box-shadow: 0 4px 10px rgba(18, 164, 138, .3);
}
.ico { font-size: 20px; color: var(--accent); width: 28px; text-align: center; }

.lead { margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); font-size: 13.5px; margin: 0; }
.hint { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
b { font-weight: 700; }

/* ---------------- connect ---------------- */
.connect { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.qr {
  width: 208px; height: 208px; flex: none;
  border: 1px solid var(--line-strong); border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(180deg, #fff, #f7f9fc);
  padding: 12px; box-shadow: inset 0 0 0 6px #fff, var(--shadow-sm);
}
.qr img { width: 100%; height: 100%; image-rendering: pixelated; border-radius: 4px; }
.qr__placeholder { font-size: 14px; color: var(--muted); text-align: center; font-weight: 600; }
.connect__copy { flex: 1; min-width: 230px; }
.ok-note, .save-hint { font-size: 13.5px; font-weight: 700; color: var(--success); }
.ok-note {
  margin-top: 12px; display: inline-block;
  background: var(--accent-soft); color: var(--accent-2);
  padding: 8px 14px; border-radius: 10px; border: 1px solid #cdeee6;
}

/* ---------------- groups ---------------- */
.groups { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.group-row {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 15px; border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer; transition: border-color .14s, background .14s, box-shadow .14s;
  background: #fff;
}
.group-row:hover { border-color: var(--line-strong); background: var(--surface-2); }
.group-row.is-on {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.group-row input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; cursor: pointer; }
.group-row .g-name { font-size: 14.5px; font-weight: 700; }
.group-row .g-meta { font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 1px; }

/* ---------------- region tools ---------------- */
.region-tools {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.file-btn { cursor: pointer; }
.file-btn > span {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 16px; border-radius: 11px;
  background: linear-gradient(155deg, #1b2330, #0f1a26);
  color: #fff; font-size: 13.5px; font-weight: 700;
  box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s;
}
.file-btn > span::before { content: "⬆"; font-size: 13px; opacity: .85; }
.file-btn:hover > span { transform: translateY(-1px); box-shadow: var(--shadow); }

.pager { display: flex; align-items: center; gap: 8px; }
.pager .mono { font-family: var(--mono); font-size: 13px; min-width: 66px; text-align: center; color: var(--ink-2); }

.fill-toggle {
  display: flex; align-items: center; gap: 8px; margin-inline-start: auto;
  background: var(--surface-2); padding: 4px; border-radius: 11px; border: 1px solid var(--line);
}
.fill-toggle__label { font-size: 12.5px; color: var(--muted); font-weight: 600; padding-inline-start: 6px; }
.seg {
  border: none; background: transparent; color: var(--ink-2);
  font-family: var(--sans); font-size: 12.5px; font-weight: 700;
  padding: 7px 13px; cursor: pointer; border-radius: 8px;
  transition: background .14s, color .14s, box-shadow .14s;
}
.seg:hover { color: var(--ink); }
.seg--active {
  background: #fff; color: var(--accent-2);
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
}

/* ---------------- stage / canvas ---------------- */
.stage {
  border: 1.5px dashed var(--line-strong); border-radius: 14px;
  padding: 16px; background: var(--surface-2); overflow: auto;
  display: flex; justify-content: center;
}
.canvas-wrap { position: relative; line-height: 0; box-shadow: var(--shadow-lg); border-radius: 6px; }
#pdfCanvas { display: block; border-radius: 6px; }
.overlay { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
/* شريط الـ redaction — العلامة المميزة */
.rbox {
  position: absolute;
  background: rgba(15, 26, 38, .88);
  border: 1px solid #000;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
  border-radius: 2px;
}
.rbox--preview { background: rgba(18, 164, 138, .26); border: 1.5px solid var(--accent); }
.rbox__del {
  position: absolute; top: -11px; inset-inline-start: -11px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--danger); color: #fff; border: 2px solid #fff;
  font-size: 14px; line-height: 1; cursor: pointer; display: grid; place-items: center;
  padding: 0; box-shadow: var(--shadow-sm); transition: transform .12s;
}
.rbox__del:hover { transform: scale(1.12); }

.rects-info { display: flex; flex-direction: column; gap: 9px; }
#rectsCount { font-family: var(--sans); font-size: 13px; font-weight: 700; color: var(--ink-2); }
.rects-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rects-list li {
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; display: flex; justify-content: space-between; align-items: center;
}
.rects-list button {
  font-family: var(--sans);
  background: none; border: none; color: var(--danger); cursor: pointer;
  font-size: 12.5px; font-weight: 700;
}
.rects-list button:hover { text-decoration: underline; }

/* ---------------- save bar ---------------- */
.save-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 15px 18px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  position: sticky; bottom: 14px;
}

/* ---------------- buttons ---------------- */
.btn {
  font-family: var(--sans); font-size: 14px; font-weight: 700;
  border-radius: 11px; border: 1px solid transparent; cursor: pointer;
  padding: 10px 18px; transition: background .14s, border-color .14s, transform .12s, box-shadow .14s;
}
.btn--primary {
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  color: #fff; box-shadow: 0 8px 20px rgba(18, 164, 138, .3);
}
.btn--primary:hover { background: linear-gradient(155deg, #14b298, var(--accent-press)); transform: translateY(-1px); box-shadow: 0 10px 26px rgba(18, 164, 138, .38); }
.btn--primary:active { transform: translateY(0); }
.btn--ghost { background: #fff; color: var(--ink); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.btn--ghost:hover { border-color: var(--muted); background: var(--surface-2); }
.btn--mini { padding: 6px 12px; font-size: 16px; background: #fff; border: 1px solid var(--line-strong); box-shadow: var(--shadow-sm); }
.btn--mini:hover { border-color: var(--muted); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- log ---------------- */
.col-side { min-width: 0; }
.card--log { position: sticky; top: 90px; }
.logbox {
  font-family: var(--mono); font-size: 12px; line-height: 1.7;
  padding: 14px 16px; max-height: 70vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 5px;
}
.logline { display: flex; gap: 9px; padding: 1px 0; }
.logline .t { color: #9aa3ad; flex: none; }
.logline.info .m { color: var(--ink-2); }
.logline.warn .m { color: var(--warn); }
.logline.error .m { color: var(--danger); }
.logline.success .m { color: var(--success); font-weight: 700; }
.logbox:empty::before { content: "مفيش نشاط لسه…"; color: var(--muted); font-family: var(--sans); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; inset-block-end: 24px; inset-inline-start: 50%;
  transform: translateX(50%);
  background: linear-gradient(155deg, #1b2330, #0f1a26); color: #fff;
  padding: 12px 20px; border-radius: 12px;
  font-size: 14px; font-weight: 700; box-shadow: var(--shadow-lg); z-index: 40;
  animation: toast-in .25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(50%) translateY(8px); }
  to { opacity: 1; transform: translateX(50%) translateY(0); }
}

/* ---------------- responsive ---------------- */
@media (max-width: 880px) {
  .grid { grid-template-columns: 1fr; }
  .card--log { position: static; }
  .fill-toggle { margin-inline-start: 0; }
  .connect { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
