/* ===== CRITICAL FIX: منع أي عنصر من الخروج عن عرض الشاشة ===== */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
}
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  min-width: 0;
}

/* ===== BASE ===== */
html { scroll-behavior: smooth; }
body {
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  direction: rtl;
  background: #F4F6F8;
  color: #1a1a2e;
  font-size: 15px;
  padding-bottom: 65px;
  width: 100%;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
img { max-width: 100%; }

/* ===== VARIABLES ===== */
:root {
  --red: #C0392B;
  --red-d: #96281B;
  --red-l: #FADBD8;
  --gray-bg: #F4F6F8;
  --gray-border: #E0E0E0;
  --gray: #868E96;
  --text: #1a1a2e;
}

/* ===== NAVBAR ===== */
.navbar {
  background: var(--red);
  position: sticky;
  top: 0;
  z-index: 200;
  width: 100%;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
}
.logo {
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
}
.logo span {
  background: #fff;
  color: var(--red);
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 13px;
  font-weight: 700;
}
.nav-links {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow: hidden;
}
.nav-btn {
  color: rgba(255,255,255,.85);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
  transition: background .15s;
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}
.nav-btn:hover, .nav-btn.active {
  background: rgba(255,255,255,.2);
  color: #fff;
}
.nav-auth {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.btn-login {
  border: 1.5px solid rgba(255,255,255,.6);
  color: #fff;
  background: transparent;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.btn-register {
  background: #fff;
  color: var(--red);
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
}
.btn-contact{border:1.5px solid rgba(255,255,255,.6);color:#fff;background:transparent;padding:5px 10px;border-radius:6px;font-size:16px;display:flex;align-items:center;text-decoration:none;transition:background .15s;flex-shrink:0}
.btn-contact:hover{background:rgba(255,255,255,.15)}
.hamburger {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 26px;
  padding: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.mobile-menu {
  display: none;
  flex-direction: column;
  background: var(--red-d);
  width: 100%;
}
.mobile-menu a {
  color: #fff;
  padding: .875rem 1.25rem;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  text-decoration: none;
}
.mobile-menu.open { display: flex; }
.mobile-menu-contact{margin:.5rem .75rem .75rem;background:rgba(255,255,255,.15);border:1.5px solid rgba(255,255,255,.4);border-radius:8px;color:#fff !important;padding:.7rem 1rem !important;display:flex;align-items:center;gap:8px;font-size:14px;font-weight:600;text-decoration:none;transition:background .15s}
.mobile-menu-contact:hover{background:rgba(255,255,255,.28) !important}
.mobile-menu-contact i{font-size:18px}

/* ===== HERO ===== */
.hero {
  background: var(--red);
  color: #fff;
  padding: 1.75rem 1rem 1.5rem;
  text-align: center;
  width: 100%;
}
.hero h1 { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.hero p { font-size: 13px; opacity: .85; margin-bottom: 1rem; }
.city-pills {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 .5rem;
}
.city-pill {
  background: rgba(255,255,255,.15);
  border: 1.5px solid rgba(255,255,255,.35);
  color: #fff;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  transition: all .15s;
  flex-shrink: 0;
}
.city-pill:hover, .city-pill.active {
  background: #fff;
  color: var(--red);
  border-color: #fff;
}

/* ===== STATS ===== */
.stats-bar {
  background: #fff;
  display: flex;
  justify-content: center;
  gap: 2rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--gray-border);
  width: 100%;
}
.stat { text-align: center; }
.stat-num { display: block; font-size: 19px; font-weight: 700; color: var(--red); }
.stat-label { font-size: 11px; color: var(--gray); }

/* ===== DISTRICT BAR ===== */
.district-bar {
  background: #fff;
  border-bottom: 2px solid var(--red-l);
  padding: .55rem 1rem;
  position: sticky;
  top: 56px;
  z-index: 100;
  width: 100%;
  box-shadow: 0 2px 4px rgba(0,0,0,.05);
}
.district-bar-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.district-bar-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.district-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 3px;
  scrollbar-width: thin;
  scrollbar-color: var(--red-l) transparent;
  flex: 1;
}
.district-scroll::-webkit-scrollbar { height: 3px; }
.district-scroll::-webkit-scrollbar-thumb { background: var(--red-l); border-radius: 10px; }
.dpill {
  border: 1.5px solid var(--gray-border);
  background: #fff;
  color: var(--text);
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 12px;
  white-space: nowrap;
  transition: all .15s;
  flex-shrink: 0;
}
.dpill:hover { border-color: var(--red); color: var(--red); }
.dpill.active { background: var(--red); color: #fff; border-color: var(--red); }

/* ===== LOCATION FILTER ===== */
.location-filter {
  display: flex;
  gap: 10px;
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--gray-border);
  padding: .875rem 1rem;
  margin-bottom: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  width: 100%;
}
.lf-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 130px; }
.lf-group label { font-size: 12px; color: var(--gray); font-weight: 600; display: flex; align-items: center; gap: 4px; }
.lf-group select {
  width: 100%;
  border: 1.5px solid var(--gray-border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  outline: none;
  background: #fff;
}
.lf-group select:focus { border-color: var(--red); }

/* ===== LAYOUT ===== */
.container { max-width: 980px; margin: 0 auto; padding: 1.25rem 1rem; width: 100%; }
.main-grid {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 1.25rem;
  align-items: start;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 3px;
  background: #fff;
  border-radius: 10px;
  padding: 5px;
  border: 1px solid var(--gray-border);
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  width: 100%;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: none;
  background: transparent;
  padding: 7px 11px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--gray);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all .15s;
  flex-shrink: 0;
}
.tab:hover { background: var(--gray-bg); }
.tab.active { background: var(--red); color: #fff; }
.tab i { font-size: 14px; }

/* ===== WRITE BOX ===== */
.write-box {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--gray-border);
  padding: 1rem;
  margin-bottom: 1rem;
  width: 100%;
}
.write-top { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--red-l);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--red); font-size: 13px;
  flex-shrink: 0;
}
.write-input {
  flex: 1;
  border: 1px solid var(--gray-border);
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 14px;
  outline: none;
  background: var(--gray-bg);
  color: var(--gray);
  cursor: pointer;
  width: 100%;
}
.write-actions {
  display: flex;
  gap: 4px;
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--gray-border);
  flex-wrap: wrap;
}
.write-btn {
  border: none; background: transparent;
  color: var(--gray); font-size: 12px;
  display: flex; align-items: center; gap: 4px;
  padding: 5px 7px; border-radius: 6px; transition: background .15s;
  white-space: nowrap;
}
.write-btn:hover { background: var(--gray-bg); }

/* ===== POST CARD ===== */
.post-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--gray-border);
  margin-bottom: 1rem;
  overflow: hidden;
  width: 100%;
}
.post-header { display: flex; align-items: flex-start; gap: 10px; padding: 1rem 1rem .5rem; }
.post-meta { flex: 1; min-width: 0; overflow: hidden; }
.post-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.post-info { font-size: 11px; color: var(--gray); margin-top: 3px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.b-job { background: #E8F5E9; color: #2E7D32; }
.b-question { background: #E3F2FD; color: #1565C0; }
.b-sell { background: #FFF3E0; color: #E65100; }
.b-service { background: #F3E5F5; color: #6A1B9A; }
.b-news { background: var(--red-l); color: var(--red-d); }
.b-event { background: #E0F2F1; color: #00695C; }
.anon-badge { background: #F5F5F5; color: #757575; border: 1px solid #E0E0E0; font-size: 10px; padding: 1px 6px; border-radius: 8px; font-weight: 400; }
.post-title { font-weight: 600; margin-bottom: 5px; font-size: 14px; line-height: 1.4; }
.post-body-text { font-size: 13px; line-height: 1.7; color: #333; padding: 0 1rem .75rem; word-break: break-word; }
.post-price { color: var(--red); font-weight: 700; font-size: 14px; padding: 0 1rem .5rem; display: flex; align-items: center; gap: 4px; }
.district-tag { display: inline-flex; align-items: center; gap: 3px; background: var(--red-l); color: var(--red); padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }

/* POST FOOTER */
.post-footer { display: flex; border-top: 1px solid var(--gray-border); }
.pf-btn { flex: 1; border: none; background: transparent; color: var(--gray); font-size: 12px; padding: .6rem 4px; display: flex; align-items: center; justify-content: center; gap: 4px; transition: all .15s; }
.pf-btn:hover { background: var(--gray-bg); color: var(--red); }
.pf-btn.liked { color: var(--red); }
.pf-btn i { font-size: 16px; }
.pf-delete { color: #e57373 !important; }
.pf-delete:hover { background: #FDECEA !important; color: #C62828 !important; }

/* COMMENTS */
.comments-box { display: none; padding: .75rem 1rem 1rem; border-top: 1px solid var(--gray-border); }
.comments-box.open { display: block; }
.comment { display: flex; gap: 8px; margin-bottom: .6rem; }
.comment-bubble { background: var(--gray-bg); border-radius: 10px; padding: .5rem .75rem; flex: 1; font-size: 13px; min-width: 0; word-break: break-word; }
.comment-author { font-weight: 600; font-size: 12px; color: var(--red); margin-bottom: 2px; }
.comment-row { display: flex; gap: 7px; margin-top: .5rem; align-items: center; }
.comment-input { flex: 1; border: 1px solid var(--gray-border); border-radius: 20px; padding: 8px 13px; font-size: 13px; outline: none; min-width: 0; }
.comment-input:focus { border-color: var(--red); }
.send-btn { background: var(--red); color: #fff; border: none; border-radius: 20px; padding: 8px 14px; font-size: 13px; flex-shrink: 0; }

/* SIDEBAR */
.sidebar { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 70px; }
.side-card { background: #fff; border-radius: 12px; border: 1px solid var(--gray-border); overflow: hidden; }
.side-title { font-size: 14px; font-weight: 600; padding: .75rem 1rem; border-bottom: 1px solid var(--gray-border); display: flex; align-items: center; gap: 6px; }
.side-title i { color: var(--red); }
.side-item { display: flex; align-items: center; gap: 8px; padding: .65rem 1rem; font-size: 13px; border-bottom: 1px solid var(--gray-border); transition: background .15s; text-decoration: none; color: var(--text); }
.side-item:last-child { border-bottom: none; }
.side-item:hover { background: var(--gray-bg); }
.side-item i { color: var(--red); font-size: 15px; }
.side-badge { margin-right: auto; background: var(--red-l); color: var(--red); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 10px; }
.promo-card { background: var(--red); border-color: var(--red); color: #fff; padding: 1.25rem; text-align: center; }
.promo-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.promo-sub { font-size: 12px; opacity: .85; margin-bottom: 1rem; }

/* PAGE HEADER */
.page-header { background: var(--red); color: #fff; padding: 1.5rem 1rem; text-align: center; width: 100%; }
.page-header h1 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.page-header p { font-size: 13px; opacity: .85; }

/* EMPTY */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--gray); }
.empty i { font-size: 44px; display: block; margin-bottom: .75rem; opacity: .5; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid var(--gray-border);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
  width: 100%;
}
.bnav-btn {
  flex: 1; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 5px; font-size: 10px; color: var(--gray);
  text-decoration: none;
}
.bnav-btn.active, .bnav-btn:hover { color: var(--red); }
.bnav-btn i { font-size: 21px; }
.bnav-post {
  background: var(--red) !important;
  color: #fff !important;
  border-radius: 50%;
  width: 48px; height: 48px;
  padding: 0 !important;
  margin-top: -12px;
  box-shadow: 0 3px 12px rgba(192,57,43,.4);
  flex: none;
  border: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 9px;
  cursor: pointer;
}
.bnav-post i { font-size: 22px; }

/* ===== MODALS ===== */
.modal-overlay {
  display: flex;
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  transition: opacity .2s, visibility .2s;
}
.modal-overlay.open {
  visibility: visible;
  pointer-events: all;
  opacity: 1;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1.25rem 1rem 1.5rem;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
.modal::before { display: none; }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; font-size: 16px; font-weight: 700;
}
.modal-close { background: none; border: none; font-size: 22px; color: var(--gray); line-height: 1; padding: 4px; }
.tab-sw { display: flex; border: 1px solid var(--gray-border); border-radius: 8px; overflow: hidden; margin-bottom: 1.25rem; }
.tsw { flex: 1; padding: 9px; border: none; background: transparent; font-size: 14px; transition: all .15s; }
.tsw.active { background: var(--red); color: #fff; }
.fg { margin-bottom: .875rem; }
.fg label { display: block; font-size: 13px; color: var(--gray); margin-bottom: 4px; font-weight: 500; }
.fg input, .fg textarea, .fg select {
  width: 100%;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  background: #fff;
  color: var(--text);
  font-size: 16px; /* منع zoom في iOS */
  -webkit-appearance: none;
}
.fg input:focus, .fg textarea:focus, .fg select:focus { border-color: var(--red); }
.fg textarea { resize: vertical; min-height: 90px; line-height: 1.6; }
.post-type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 1rem; }
.type-btn {
  border: 1.5px solid var(--gray-border); background: #fff;
  border-radius: 9px; padding: 10px 4px; text-align: center;
  font-size: 12px; transition: all .15s;
  display: flex; flex-direction: column; align-items: center; gap: 5px; color: var(--text);
}
.type-btn i { font-size: 22px; }
.type-btn:hover { border-color: var(--red); color: var(--red); }
.type-btn.sel { border-color: var(--red); background: var(--red-l); color: var(--red); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.anon-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: .65rem .875rem; background: #F8F9FA;
  border-radius: 8px; border: 1px solid var(--gray-border);
  margin-bottom: .875rem; cursor: pointer;
}
.anon-toggle input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--red); flex-shrink: 0; }
.anon-toggle-text { font-size: 13px; color: var(--text); line-height: 1.4; }
.anon-toggle-sub { font-size: 11px; color: var(--gray); display: block; margin-top: 1px; }
.btn-full {
  width: 100%; background: var(--red); color: #fff;
  border: none; border-radius: 9px; padding: 12px;
  font-size: 15px; font-weight: 600; transition: background .15s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-full:hover { background: var(--red-d); }
.btn-full:disabled { opacity: .6; cursor: not-allowed; }
.form-note { text-align: center; margin-top: .75rem; font-size: 13px; color: var(--gray); }
.form-note a { color: var(--red); }

/* ===== POST IMAGES ===== */
.post-images{display:flex;gap:6px;padding:0 1rem .75rem;flex-wrap:wrap}
.post-images img{width:calc(50% - 3px);max-width:100%;border-radius:8px;object-fit:cover;max-height:220px;cursor:zoom-in;transition:opacity .15s}
.post-images img:only-child{width:100%;max-height:300px}
.post-images img:hover{opacity:.9}

/* Image upload in modal */
.img-upload-btn{width:100%;border:2px dashed var(--gray-border);background:#F8F9FA;border-radius:8px;padding:.875rem;font-size:13px;color:var(--gray);display:flex;align-items:center;justify-content:center;gap:6px;transition:all .15s;cursor:pointer}
.img-upload-btn:hover{border-color:var(--red);color:var(--red);background:var(--red-l)}
.img-upload-btn i{font-size:18px}
.img-preview-grid{display:flex;gap:8px;margin-top:8px;flex-wrap:wrap}
.img-preview-item{position:relative;width:calc(50% - 4px)}
.img-preview-item img{width:100%;height:100px;object-fit:cover;border-radius:8px;border:1.5px solid var(--gray-border)}
.img-preview-item button{position:absolute;top:4px;left:4px;background:rgba(0,0,0,.6);color:#fff;border:none;border-radius:50%;width:22px;height:22px;font-size:12px;display:flex;align-items:center;justify-content:center;cursor:pointer;line-height:1}
.img-preview-item button:hover{background:var(--red)}

/* TOAST */
.toast {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e; color: #fff;
  padding: 10px 20px; border-radius: 20px;
  font-size: 13px; z-index: 99999;
  opacity: 0; transition: opacity .3s; pointer-events: none;
  white-space: nowrap; max-width: 85vw; text-align: center;
}
.toast.show { opacity: 1; }

/* PAGINATION */
.pagination { display: flex; gap: 6px; justify-content: center; padding: 1.25rem 0; flex-wrap: wrap; }
.page-btn { border: 1px solid var(--gray-border); background: #fff; padding: 6px 14px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.page-btn.active, .page-btn:hover { background: var(--red); color: #fff; border-color: var(--red); }

@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ===== DESKTOP فقط ===== */
@media (min-width: 769px) {
  body { padding-bottom: 0; }
  .bottom-nav { display: none !important; }
  .hamburger { display: none; }
  .nav-links { display: flex !important; }
  .nav-auth { display: flex !important; }
  /* Modal في المنتصف على الديسكتوب */
  .modal-overlay { align-items: center; padding: 1rem; }
  .modal { border-radius: 16px; max-width: 460px; }
  .modal::before { display: none; }
  .two-col { grid-template-columns: 1fr 1fr; }
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .nav-auth { display: none; }
  .hamburger { display: block; }
  .main-grid { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .bottom-nav { display: flex !important; }
  .two-col { grid-template-columns: 1fr; }
  .hero h1 { font-size: 19px; }
  .stats-bar { gap: 1.25rem; }
  .stat-num { font-size: 17px; }
  /* Modal من الأسفل على الموبايل */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 20px 20px 0 0; max-width: 100%; padding: 1rem 1rem 2rem; }
  .modal::before { display: block; content: ''; width: 40px; height: 4px; background: #E0E0E0; border-radius: 4px; margin: 0 auto .875rem; }
  .post-type-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .type-btn { padding: 9px 3px; font-size: 11px; }
  .type-btn i { font-size: 20px; }
  .tabs { padding: 4px; }
  .tab { padding: 6px 9px; font-size: 12px; }
}

@media (max-width: 380px) {
  .hero h1 { font-size: 17px; }
  .city-pill { padding: 4px 10px; font-size: 11px; }
  .post-type-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-bar { gap: .75rem; }
  .stat-num { font-size: 15px; }
  .tab { padding: 5px 7px; font-size: 11px; }
}
