:root {
  --orange: #f97316;
  --orange-dark: #ea580c;
  --teal: #2dd4bf;
  --teal-dark: #14b8a6;
  --teal-light: #99f6e4;
  --navy: #0f2744;
  --navy-mid: #1e3a5f;
  --navy-soft: #334155;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #ef4444;
  --success: #22c55e;
  --messenger: #0084ff;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 8px 30px rgba(15, 39, 68, 0.08);
  --sidebar-w: 260px;
  --topbar-h: 72px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Tajawal", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
}

button, input, select, textarea { font: inherit; }
img { max-width: 100%; display: block; }

/* ——— Auth / Geo screens ——— */
.screen {
  display: none;
  min-height: 100dvh;
  padding: 1.5rem;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(45, 212, 191, 0.2), transparent 45%),
    radial-gradient(ellipse at 80% 100%, rgba(249, 115, 22, 0.15), transparent 45%),
    var(--bg);
}
.screen--active { display: flex; }

.splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  background: var(--surface);
  transition: opacity 0.4s, visibility 0.4s;
}
.splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.auth-card, .geo-card, .blocked-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.brand-emoji { line-height: 1; font-size: 2rem; }
.brand-emoji--lg { font-size: 4rem; margin-bottom: 0.5rem; display: block; }

.auth-card h1, .geo-card h2, .blocked-card h2 {
  margin: 0 0 0.35rem; color: var(--navy); font-size: 1.75rem;
}
.auth-card__tagline { color: var(--muted); margin: 0 0 1.5rem; }
.geo-card__icon, .blocked-card__badge { font-size: 3rem; }
.geo-status {
  background: var(--bg); padding: 0.75rem; border-radius: var(--radius);
  font-size: 0.9rem; color: var(--navy-soft); margin: 1rem 0;
}
.distance-info {
  text-align: right; background: #fff7ed; border: 1px solid #fed7aa;
  border-radius: var(--radius); padding: 1rem; margin: 1rem 0;
}

/* ——— Forms & buttons ——— */
form label, .form-field label {
  display: block; font-weight: 600; margin: 0.75rem 0 0.35rem;
  font-size: 0.88rem; color: var(--navy-mid);
}
form input, form select, form textarea,
.filter-select, .topbar-search {
  width: 100%; padding: 0.7rem 1rem;
  border: 2px solid #e2e8f0; border-radius: var(--radius);
  background: var(--surface); transition: border-color 0.2s, box-shadow 0.2s;
}
form input:focus, form select:focus, form textarea:focus, .topbar-search:focus {
  outline: none; border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.25);
}
.field-hint { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; }
.checkbox-label { display: flex !important; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox-label input { width: auto; }
.form-error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }
.form-success { color: var(--success); font-size: 0.85rem; margin-top: 0.5rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.65rem 1.2rem; border: none; border-radius: var(--radius);
  font-weight: 700; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn--block { width: 100%; }
.btn--sm { padding: 0.45rem 0.85rem; font-size: 0.85rem; }
.btn--primary {
  background: linear-gradient(135deg, var(--orange), var(--orange-dark));
  color: #fff; box-shadow: 0 4px 14px rgba(249, 115, 22, 0.35);
}
.btn--secondary { background: var(--teal); color: var(--navy); }
.btn--ghost { background: #f8fafc; color: var(--navy-soft); border: 2px solid #e2e8f0; }
.btn--danger { background: #fee2e2; color: var(--danger); font-size: 0.8rem; padding: 0.35rem 0.7rem; }
.btn--icon {
  width: 42px; height: 42px; padding: 0; border-radius: 50%;
  background: #f1f5f9; position: relative;
}
.btn--white { background: #fff; color: var(--navy); }
.btn--outline-white { background: transparent; color: #fff; border: 2px solid rgba(255,255,255,0.6); }
.btn--messenger { background: var(--messenger); color: #fff; }
.btn--chat { background: var(--navy-mid); color: #fff; }
.btn--sell-quick { white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.25rem; height: 1.25rem; padding: 0 0.35rem;
  font-size: 0.7rem; font-style: normal; font-weight: 800;
  background: var(--orange); color: #fff; border-radius: 999px;
}
.badge--dot {
  position: absolute; top: 6px; left: 6px;
  min-width: 8px; height: 8px; padding: 0;
}

/* ——— App shell (desktop layout) ——— */
.app-shell {
  display: none;
  min-height: 100dvh;
}
.app-shell:not([hidden]) { display: flex; }

.sidebar {
  display: none;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy) 0%, #0a1f38 100%);
  color: #fff;
  flex-direction: column;
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.sidebar__brand {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 1rem;
}
.sidebar__brand strong { display: block; font-size: 1.1rem; }
.sidebar__brand small { opacity: 0.65; font-size: 0.75rem; }

.sidebar__nav {
  display: flex; flex-direction: column; gap: 0.35rem; flex: 1;
}
.sidebar__link {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.75rem 1rem; border: none; border-radius: var(--radius);
  background: transparent; color: rgba(255,255,255,0.75);
  font-weight: 600; font-size: 0.95rem; cursor: pointer;
  text-align: right; transition: background 0.2s, color 0.2s;
}
.sidebar__link span { font-size: 1.15rem; }
.sidebar__link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar__link--active {
  background: linear-gradient(90deg, rgba(249,115,22,0.35), rgba(249,115,22,0.1));
  color: #fff; border-right: 3px solid var(--orange);
}
.sidebar__link--admin { margin-top: 0.5rem; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 1rem; }

.sidebar__footer { margin-top: auto; padding-top: 1rem; }
.sidebar__user {
  font-size: 0.85rem; opacity: 0.95; margin-bottom: 0.5rem;
  padding: 0 0.5rem;
}
.sidebar__user strong { display: block; font-size: 0.95rem; color: #fff; }
.sidebar__user small { display: block; font-size: 0.72rem; opacity: 0.65; margin-top: 0.15rem; }

.account-info {
  margin: 0 0 1rem; padding: 0.75rem 1rem;
  background: var(--bg); border-radius: var(--radius);
}
.account-info dt { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.account-info dd { margin: 0.15rem 0 0; font-weight: 700; color: var(--navy); }
.account-panel { max-width: 480px; }

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1rem;
  padding: 0.85rem 1rem;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #e2e8f0;
}
.topbar__start { flex: 1; min-width: 140px; }
.topbar__title { margin: 0; font-size: 1.2rem; color: var(--navy); }
.topbar__subtitle { margin: 0; font-size: 0.8rem; color: var(--muted); }
.topbar__center { flex: 2; min-width: 180px; max-width: 480px; }
.topbar__end { display: flex; align-items: center; gap: 0.5rem; }
.topbar-search { margin: 0; }

.content {
  flex: 1;
  padding: 1rem;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; animation: fadeIn 0.25s ease; }
.view--active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.content-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; gap: 0.5rem;
}
.content-header h3 { margin: 0; color: var(--navy); font-size: 1.1rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* Hero */
.hero-banner {
  display: grid; gap: 1rem; margin-bottom: 1.5rem;
  background: linear-gradient(135deg, var(--navy) 0%, #1a4d7a 50%, var(--navy-mid) 100%);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  color: #fff;
  box-shadow: var(--shadow);
}
.hero-banner__text h2 { margin: 0 0 0.5rem; font-size: 1.5rem; }
.hero-banner__text p { margin: 0 0 1rem; opacity: 0.9; max-width: 480px; }
.hero-banner__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.hero-banner__stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.65rem;
}
.hero-stat {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  padding: 0.85rem; text-align: center;
}
.hero-stat strong { display: block; font-size: 1.5rem; color: var(--teal-light); }
.hero-stat span { font-size: 0.75rem; opacity: 0.85; }

/* Listings */
.filters-bar { margin-bottom: 1rem; max-width: 280px; }
.listings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}
.listing-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.listing-card:hover {
  border-color: var(--teal-light);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(15, 39, 68, 0.12);
}
.listing-card__top { display: flex; justify-content: space-between; gap: 0.5rem; }
.listing-card__category {
  font-size: 0.7rem; background: #ecfdf5; color: #047857;
  padding: 0.2rem 0.55rem; border-radius: 999px; font-weight: 700;
}
.listing-card__price { font-weight: 800; color: var(--orange); font-size: 1.1rem; }
.listing-card h4 { margin: 0.5rem 0 0.25rem; color: var(--navy); }
.listing-card p {
  margin: 0; font-size: 0.85rem; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.listing-card__meta {
  margin-top: 0.65rem; font-size: 0.75rem; color: var(--muted);
  display: flex; justify-content: space-between;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.panel__title { margin: 0 0 1rem; color: var(--navy); }
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 1rem;
}
.form-field--full { grid-column: 1 / -1; }

.empty-state { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* Chats */
.chats-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  min-height: 420px;
}
.chats-list ul { list-style: none; padding: 0; margin: 0; }
.chats-list li {
  padding: 0.85rem; border-radius: var(--radius); cursor: pointer;
  border: 2px solid transparent; margin-bottom: 0.35rem;
  transition: background 0.15s, border-color 0.15s;
}
.chats-list li:hover { background: #f8fafc; }
.chats-list li.active { border-color: var(--teal); background: #f0fdfa; }
.chats-list li strong { display: block; color: var(--navy); }
.chats-list li small { color: var(--muted); font-size: 0.78rem; }
.chats-list li p { margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--navy-soft); }

.chat-thread {
  display: flex; flex-direction: column;
  min-height: 360px;
}
.chat-thread__empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--muted);
}
.chat-thread__empty span { font-size: 3rem; opacity: 0.5; }
.chat-thread__active { display: flex; flex-direction: column; flex: 1; }
.chat-thread__header {
  padding-bottom: 0.75rem; border-bottom: 1px solid #e2e8f0; margin-bottom: 0.75rem;
}
.chat-thread__header small { color: var(--muted); display: block; }
.chat-messages {
  flex: 1; overflow-y: auto; max-height: 320px;
  display: flex; flex-direction: column; gap: 0.5rem; padding: 0.5rem 0;
}
.chat-bubble {
  max-width: 85%; padding: 0.6rem 0.9rem; border-radius: var(--radius);
  font-size: 0.9rem; line-height: 1.5;
}
.chat-bubble--mine {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--orange), var(--orange-dark));
  color: #fff; border-bottom-left-radius: 4px;
}
.chat-bubble--theirs {
  align-self: flex-start;
  background: #f1f5f9; color: var(--text); border-bottom-right-radius: 4px;
}
.chat-bubble time { display: block; font-size: 0.65rem; opacity: 0.7; margin-top: 0.25rem; }
.chat-compose {
  display: flex; gap: 0.5rem; margin-top: 0.75rem; padding-top: 0.75rem;
  border-top: 1px solid #e2e8f0;
}
.chat-compose input { flex: 1; margin: 0; }

/* Admin */
.admin-tabs {
  display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem;
}
.admin-tabs__btn {
  padding: 0.55rem 1rem; border: 2px solid #e2e8f0; border-radius: 999px;
  background: var(--surface); font-weight: 600; cursor: pointer;
  color: var(--navy-soft); transition: all 0.2s;
}
.admin-tabs__btn--active {
  background: var(--navy); color: #fff; border-color: var(--navy);
}
.admin-panel-view { display: none; }
.admin-panel-view--active { display: block; }

.dash-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.dash-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border-right: 4px solid var(--orange);
}
.dash-stat--teal { border-right-color: var(--teal); }
.dash-stat--blue { border-right-color: var(--messenger); }
.dash-stat strong { display: block; font-size: 2rem; color: var(--navy); }
.dash-stat span { font-size: 0.85rem; color: var(--muted); }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
.admin-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
.admin-users-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.admin-hint { margin: 0 0 0.75rem; }
.data-table .btn + .btn { margin-right: 0.35rem; }
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.88rem;
}
.data-table th, .data-table td {
  padding: 0.65rem 0.75rem; text-align: right;
  border-bottom: 1px solid #f1f5f9;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
.data-table tr:hover td { background: #f8fafc; }

.quick-list { list-style: none; padding: 0; margin: 0; }
.quick-list li {
  padding: 0.5rem 0; border-bottom: 1px solid #f1f5f9;
  display: flex; justify-content: space-between; font-size: 0.9rem;
}

.coord-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.admin-panel--help { background: #f0fdfa; border: 1px solid var(--teal-light); margin-bottom: 1rem; }
.setup-steps { margin: 0; padding-right: 1.25rem; font-size: 0.9rem; color: var(--navy-soft); }

/* Modal */
.modal { border: none; padding: 0; max-width: 100%; width: 100%; background: transparent; }
.modal::backdrop { background: rgba(15, 23, 42, 0.55); }
.modal__content {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-height: 90dvh; overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 1.5rem;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal__close {
  position: absolute; top: 1rem; left: 1rem;
  width: 36px; height: 36px; border: none; background: #f1f5f9;
  border-radius: 50%; font-size: 1.4rem; cursor: pointer;
}
.modal-detail h3 { margin: 0.5rem 0; padding-left: 2rem; color: var(--navy); }
.modal-detail .price { font-size: 1.5rem; font-weight: 800; color: var(--orange); }
.modal-detail .desc { color: var(--navy-soft); white-space: pre-wrap; margin: 1rem 0; }
.contact-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1.25rem; }

/* Mobile bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.08);
}
.bottom-nav__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.1rem; border: none; background: none;
  color: var(--muted); font-size: 0.62rem; font-weight: 700; cursor: pointer; padding: 0.35rem;
}
.bottom-nav__item span { font-size: 1.2rem; }
.bottom-nav__item--active { color: var(--orange); }

/* ——— Desktop ——— */
@media (min-width: 768px) {
  .listings-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .dash-stats { grid-template-columns: repeat(4, 1fr); }
  .dash-grid { grid-template-columns: 1.2fr 1fr; }
  .admin-split { grid-template-columns: 1fr 1.4fr; }
  .chats-layout { grid-template-columns: 300px 1fr; }
  .hero-banner { grid-template-columns: 1.4fr 1fr; align-items: center; }
}

@media (min-width: 1024px) {
  .sidebar { display: flex; }
  .app-main { padding-bottom: 0; }
  .bottom-nav { display: none; }
  .content { padding: 1.5rem 2rem 2rem; }
  .listings-grid { grid-template-columns: repeat(3, 1fr); }
  .topbar { padding: 1rem 2rem; }
  .btn--sell-quick { display: inline-flex; }

  .modal__content {
    position: fixed; top: 50%; left: 50%; right: auto; bottom: auto;
    transform: translate(-50%, -50%);
    width: min(520px, 92vw);
    max-height: 85vh;
    border-radius: var(--radius-lg);
    animation: none;
  }
}

@media (max-width: 1023px) {
  .topbar__center { order: 3; flex: 1 1 100%; max-width: none; }
  .btn--sell-quick { display: none !important; }
  .topbar__subtitle { display: none; }
  .chats-layout .chat-thread { min-height: 300px; }
}
