:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --ink: #142033;
  --muted: #5b6b80;
  --line: #dde3ea;
  --brand: #0e5a8a;
  --brand-2: #0b4870;
  --accent: #6aa84f;
  --danger: #c0392b;
  --ok: #1f8a5a;
  --pen: #123c99;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Readex Pro", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--brand); }
button, input, textarea, select { font-family: inherit; font-size: 16px; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--brand); color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.top .brand { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.top .grow { flex: 1; }
.top .who { font-size: 13px; opacity: .9; }
.top button, .top a.btn-top {
  background: rgba(255,255,255,.15); color: #fff; border: 0; border-radius: 10px;
  padding: 6px 12px; font-size: 14px; cursor: pointer; text-decoration: none;
}

.wrap { max-width: 860px; margin: 0 auto; padding: 18px 16px 90px; }
h1 { font-size: 22px; margin: 6px 0 4px; }
h2 { font-size: 18px; margin: 0 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 4px; text-align: right;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px; cursor: pointer; color: var(--ink); font-size: 16px;
}
.tile b { font-size: 17px; }
.tile span { color: var(--muted); font-size: 13px; }
.tile:hover { border-color: var(--brand); }
.tile .ic { font-size: 26px; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=password], input[type=date], input[type=time], input[type=number], textarea, select {
  width: 100%; min-height: 46px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(14,90,138,.25); border-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 0;
  background: var(--brand); color: #fff; font-weight: 500; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.light { background: #e8eef4; color: var(--brand-2); }
.btn.danger { background: #fbeaea; color: var(--danger); }
.btn.ok { background: var(--ok); }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.err { background: #fdecea; color: #8a1f17; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.okmsg { background: #e7f6ee; color: #145c3b; border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; }

/* الدخول */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login h1 { text-align: center; }
.login .logo { display: block; margin: 0 auto 10px; height: 46px; }

/* قائمة النماذج */
.search { margin-bottom: 10px; }
.flist { display: flex; flex-direction: column; gap: 6px; }
.fitem {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer;
}
.fitem input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.fitem .code { font-size: 12px; color: var(--muted); direction: ltr; min-width: 64px; text-align: left; }
.fitem.on { border-color: var(--brand); background: #eef5fa; }
.fitem .t { flex: 1; }

.bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  background: #fff; border-top: 1px solid var(--line); padding: 10px 16px;
  display: flex; gap: 10px; align-items: center; justify-content: center;
}
.bar .grow { flex: 1; max-width: 520px; }

/* المحرر */
.ed-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.ed-head .title { flex: 1; font-weight: 600; min-width: 180px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; scrollbar-width: thin; }
.tabs button {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tools {
  position: sticky; top: 52px; z-index: 15;
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  background: var(--bg); padding: 8px 0;
}
.tools button {
  min-height: 40px; min-width: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 15px;
}
.tools button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.tools .sep { width: 1px; height: 28px; background: var(--line); margin: 0 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chips button {
  border: 1px dashed #9db3c6; background: #f7fbff; color: var(--brand-2); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; cursor: pointer;
}
.chips button.on { background: var(--brand); color: #fff; border-style: solid; }

.pages { overflow-x: auto; padding-bottom: 10px; }
.page {
  position: relative; margin: 0 auto 14px; background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.15); touch-action: manipulation; user-select: none;
}
.page img.bg { display: block; width: 100%; height: 100%; pointer-events: none; }
.page .it { position: absolute; color: var(--pen); white-space: pre; line-height: 1.25; cursor: move; touch-action: none; }
.page .it.sel { outline: 1.5px dashed #e67e22; outline-offset: 2px; background: rgba(255, 237, 213, .35); }
.page .it.auto { background: rgba(106, 168, 79, .12); }
.page .it img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; display: block; }
.page .it.mark { font-weight: 700; line-height: 1; }
.page .ph { color: #c0392b; font-size: 10px; border: 1px dashed #c0392b; padding: 0 4px; }
.page textarea.edit {
  position: absolute; z-index: 5; min-height: 0; padding: 1px 3px; border-radius: 4px;
  border: 1.5px solid #e67e22; background: rgba(255,255,255,.95); color: var(--pen);
  font-family: "Noto Naskh Arabic", "Readex Pro", serif; line-height: 1.25; resize: none; overflow: hidden;
}
.selbar {
  position: fixed; bottom: 74px; left: 50%; transform: translateX(-50%); z-index: 30;
  display: flex; gap: 6px; background: #142033; padding: 6px; border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.selbar button { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 10px; min-height: 40px; min-width: 44px; padding: 0 10px; cursor: pointer; font-size: 15px; }
.selbar button.del { background: #c0392b; }

/* التوقيع */
.sigpad { width: 100%; height: 220px; border: 2px dashed #b9c6d3; border-radius: 12px; background: #fff; touch-action: none; display: block; }
.sigprev { height: 90px; max-width: 100%; display: block; margin: 8px 0; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0/16px 16px; border-radius: 8px; }

/* المدير */
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th, table.users td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.users td.ph { direction: ltr; text-align: right; }
.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: #e8eef4; color: var(--brand-2); }
.tag.off { background: #fdecea; color: #8a1f17; }
.scroll-x { overflow-x: auto; }

/* المخالفات */
.fines td, .fines th { padding: 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.fines { width: 100%; border-collapse: collapse; }
.fines input { min-height: 38px; width: 74px; text-align: center; }
.fines .tot { font-weight: 600; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos .ph-it { position: relative; }
.photos img { height: 110px; border-radius: 8px; display: block; }
.photos button { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 8px; padding: 0 8px; cursor: pointer; }

.overlay { position: fixed; inset: 0; background: rgba(20,32,51,.55); z-index: 50; display: grid; place-items: center; padding: 16px; }
.overlay .card { max-width: 420px; width: 100%; text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid #d6e2ec; border-top-color: var(--brand); border-radius: 50%; margin: 6px auto 12px; animation: sp 0.9s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.page .ph.fld { color: #8aa0b4; border-color: #b9c8d6; background: rgba(255,255,255,.7); }
.fgroup { margin: 14px 0 6px; font-weight: 600; color: var(--brand-2); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.fgroup::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.fgroup button { border: 0; background: none; color: var(--brand); font-size: 12px; cursor: pointer; padding: 0; }
