/* ====== نظام تصميم شركة الحسن — مبني على ألوان الشعار ====== */
:root {
  --navy: #1d2d6b;
  --navy-dark: #152153;
  --navy-soft: #eef1fa;
  --red: #c2202e;
  --red-soft: #fdeeef;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1a2238;
  --muted: #5d6780;
  --line: #e2e6f0;
  --green: #1c7c4a;
  --green-soft: #e9f6ef;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(21, 33, 83, 0.10), 0 4px 14px rgba(21, 33, 83, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: 17px; }

body {
  margin: 0;
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

.shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px 110px;
}

/* ====== الترويسة ====== */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 2px 10px;
}
.topbar img.logo {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}
.topbar .titles { flex: 1; min-width: 0; }
.topbar .titles h1 {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.35;
}
.topbar .titles span {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}
.iconbtn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.iconbtn:active { background: var(--navy-soft); }
.iconbtn svg { width: 24px; height: 24px; }

/* ====== الأزرار ====== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 54px;
  padding: 10px 22px;
  border-radius: 14px;
  border: none;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.05s ease, background 0.15s ease;
  user-select: none;
}
.btn:active { transform: scale(0.985); }
.btn svg { width: 22px; height: 22px; flex-shrink: 0; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); }
.btn-outline {
  background: var(--card);
  color: var(--navy);
  border: 1.5px solid var(--line);
}
.btn-outline:hover { border-color: var(--navy); }
.btn-danger {
  background: var(--card);
  color: var(--red);
  border: 1.5px solid #f0c9cd;
}
.btn-danger:hover { background: var(--red-soft); }
.btn-red { background: var(--red); color: #fff; }
.btn-block { width: 100%; }

/* ====== البطاقات ====== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

/* بطاقة عقد في القائمة */
.contract-card { cursor: pointer; }
.contract-card .row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.contract-card .buyer {
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--text);
}
.contract-card .date {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.contract-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 8px 0 14px;
}
.contract-card .meta .m { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
.contract-card .meta .m b { color: var(--navy); font-size: 1.05rem; font-weight: 800; }
.contract-card .actions { display: flex; gap: 10px; }
.contract-card .actions .btn { flex: 1; min-height: 50px; }

/* ====== النماذج ====== */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 7px;
  font-size: 0.98rem;
}
.field .hint {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 5px;
}
input[type="text"], input[type="password"], input[type="date"],
input[type="tel"], textarea, select {
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  font-family: inherit;
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card);
  outline: none;
}
textarea { min-height: 100px; resize: vertical; font-weight: 600; }
input:focus, textarea:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(29, 45, 107, 0.12);
}
input::placeholder { color: #a8b0c4; font-weight: 600; }
.words-box {
  margin-top: 8px;
  background: var(--green-soft);
  color: var(--green);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 1.02rem;
  min-height: 48px;
  display: flex;
  align-items: center;
}
.words-box.empty { background: var(--navy-soft); color: var(--muted); font-weight: 600; }

/* ====== البحث ====== */
.searchbar { position: relative; margin: 4px 0 16px; }
.searchbar input { padding-inline-start: 52px; }
.searchbar svg {
  position: absolute;
  inset-inline-start: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  color: var(--muted);
  pointer-events: none;
}

/* ====== شريط التنقل السفلي ====== */
.bottomnav {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  background: var(--card);
  border-top: 1.5px solid var(--line);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.bottomnav .nav-inner {
  display: flex;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}
.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px 12px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}
.bottomnav a svg { width: 26px; height: 26px; }
.bottomnav a.active { color: var(--navy); }
.bottomnav a.fab-link { position: relative; }
.bottomnav a.fab-link .fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -28px;
  box-shadow: 0 4px 14px rgba(194, 32, 46, 0.4);
}
.bottomnav a.fab-link .fab svg { width: 30px; height: 30px; }

/* ====== صفحات فرعية ====== */
.pagehead {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 2px 12px;
}
.pagehead h2 { margin: 0; font-size: 1.25rem; font-weight: 800; color: var(--navy); flex: 1; }

/* صفوف العرض في بطاقة العقد */
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: none; }
.detail-row .k { color: var(--muted); font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.detail-row .v { font-weight: 800; font-size: 1.1rem; text-align: start; }
.detail-row .v.amount { color: var(--navy); font-size: 1.25rem; }
.detail-row .v small { display: block; color: var(--green); font-size: 0.9rem; font-weight: 700; }

/* ====== حالة فارغة ====== */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
}
.empty svg { width: 72px; height: 72px; color: #c3cadd; }
.empty p { font-size: 1.08rem; font-weight: 700; margin: 14px 0 22px; }

/* ====== صفحة الدخول ====== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 36px 28px;
  text-align: center;
}
.login-card img { width: 110px; height: 110px; border-radius: 50%; border: 3px solid var(--navy-soft); }
.login-card h1 { font-size: 1.25rem; color: var(--navy); margin: 14px 0 2px; font-weight: 800; }
.login-card .sub { color: var(--muted); font-weight: 600; font-size: 0.92rem; margin-bottom: 26px; }
.login-card input {
  text-align: center;
  font-size: 1.6rem;
  letter-spacing: 10px;
  font-weight: 800;
}
.login-card .err-msg {
  color: var(--red);
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 26px;
  margin: 10px 0 4px;
}

/* ====== الخارطة ====== */
.map-stage {
  background: #2a3354;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  height: calc(100vh - 270px);
  min-height: 320px;
  touch-action: none;
}
.map-stage img {
  position: absolute;
  top: 0;
  left: 0; /* إحداثيات شاشة — حسابات السحب والتكبير تفترض الزاوية اليسرى */
  transform-origin: 0 0;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
}
.map-tools { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.map-tools .btn { flex: 1; min-width: 150px; white-space: nowrap; }
.map-note { color: var(--muted); font-size: 0.88rem; font-weight: 600; margin-top: 10px; text-align: center; }
.zoom-controls {
  position: absolute;
  bottom: 14px;
  inset-inline-end: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 5;
}
.zoom-controls button {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  color: var(--navy);
  font-size: 1.5rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* ====== إشعار ====== */
#toast {
  position: fixed;
  top: -80px;
  inset-inline: 16px;
  margin: 0 auto;
  max-width: 500px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 14px 18px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  transition: top 0.25s ease;
  z-index: 100;
  font-size: 1rem;
}
#toast.show { top: 14px; }
#toast.err { background: var(--red); }

/* ====== متفرقات ====== */
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 6px 2px 12px;
}
.section-title h2 { margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--navy); }
.count-badge {
  background: var(--navy-soft);
  color: var(--navy);
  border-radius: 999px;
  padding: 3px 14px;
  font-weight: 800;
  font-size: 0.92rem;
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.spacer { height: 8px; }

@media (min-width: 700px) {
  html { font-size: 18px; }
  .topbar { padding-top: 22px; }
  .topbar .titles h1 { font-size: 1.2rem; }
}
