:root {
  --bg: #f3f7f9; --surface: #ffffff; --surface-2: #e9f1f5; --text: #0f2530; --muted: #5b7380; --line: #d5e2e8;
  --primary: #0b5d7a; --primary-ink: #ffffff; --accent: #e0567a; --ok: #1e8a4c; --warn: #b7791f; --bad: #c0392b;
  --radius: 14px; --shadow: 0 1px 2px rgba(15, 37, 48, .06), 0 4px 16px rgba(15, 37, 48, .06);
  --font: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #071820; --surface: #0e2530; --surface-2: #14313e; --text: #e3eef3; --muted: #93aab5; --line: #1f3f4d;
    --primary: #3fb4d8; --primary-ink: #04212c; --accent: #ff7d9c; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #071820; --surface: #0e2530; --surface-2: #14313e; --text: #e3eef3; --muted: #93aab5; --line: #1f3f4d;
  --primary: #3fb4d8; --primary-ink: #04212c; --accent: #ff7d9c; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); padding-bottom: calc(72px + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.35rem; margin: .2rem 0 .6rem; line-height: 1.3; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; color: var(--muted); font-weight: 600; }
i { color: var(--muted); font-size: .9em; }
img { max-width: 100%; }

.topbar { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--primary); color: var(--primary-ink); }
.brand { display: flex; align-items: center; gap: 8px; color: inherit; font-weight: 700; font-size: 1.05rem; }
.topbar-actions { display: flex; gap: 6px; }
.chip { border: 1px solid color-mix(in srgb, var(--primary-ink) 40%, transparent); background: transparent; color: inherit; border-radius: 999px;
  padding: 3px 12px; font: 600 .85rem var(--font); cursor: pointer; }
.env-banner { background: var(--bad); color: #fff; text-align: center; font-size: .8rem; padding: 2px; }

.view { max-width: 860px; margin: 0 auto; padding: 14px 16px; }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.error { border-color: var(--bad); color: var(--bad); }
.card.note { background: var(--surface-2); }
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0; }
.meta { color: var(--muted); margin: .2rem 0 .6rem; }
.warn { color: var(--warn); }

.tabbar { position: fixed; bottom: 0; inset-inline: 0; z-index: 1000; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; color: var(--muted); font-size: .72rem; }
.tabbar svg { width: 22px; height: 22px; fill: currentColor; }
.tabbar a.active { color: var(--primary); }
.tabbar .tab-add svg { background: var(--accent); fill: #fff; border-radius: 50%; width: 34px; height: 34px; padding: 6px; margin-top: -14px; box-shadow: 0 2px 8px rgba(0,0,0,.25); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.stats b { display: block; font-size: 1.2rem; color: var(--primary); }
.stats span { font-size: .72rem; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.filters > * { flex: 1 1 140px; }
.toggle { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; color: var(--muted); }

input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 50%, transparent); border-color: var(--primary); }
.form label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: .9rem; }
.form.inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.form.inline > * { flex: 1 1 140px; width: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; border: 0; border-radius: 10px; padding: 10px 16px; font: 600 .95rem var(--font); cursor: pointer; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-ink); width: 100%; margin-top: 14px; }
.btn.accent { background: var(--accent); color: #fff; width: 100%; margin: 10px 0; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn.small { padding: 6px 12px; font-size: .85rem; width: auto; margin-top: 6px; }
.file-btn { width: 100%; cursor: pointer; }
.link { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; float: inline-end; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-bottom: 8px; }
.photos figure { position: relative; margin: 0; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photos img { width: 100%; height: 100%; object-fit: cover; }
.photos button { position: absolute; top: 4px; inset-inline-end: 4px; border: 0; border-radius: 50%; width: 24px; height: 24px; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.sp-results button { display: block; width: 100%; text-align: start; background: var(--surface-2); border: 0; border-radius: 8px; padding: 8px 10px; margin-top: 4px; font: inherit; color: var(--text); cursor: pointer; }
.sp-results small { color: var(--muted); font-style: italic; }
.sp-chosen { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); border-radius: 10px; padding: 10px 12px; margin-top: 6px; }

.card.ai { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.ai-head { display: flex; justify-content: space-between; color: var(--accent); font-weight: 600; font-size: .85rem; margin-bottom: 4px; }
.card.ai h3 { color: var(--text); font-size: 1.1rem; margin: 0; }

.map { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
.map.big { height: calc(100vh - 270px); min-height: 360px; }
.map.pick { height: 300px; }
.map.small { height: 240px; margin: 10px 0; }
.dot span { display: block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.3); }
.pop { min-width: 150px; font-family: var(--font); }
.pop img { width: 100%; height: 100px; object-fit: cover; border-radius: 6px; margin-bottom: 4px; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.st-verified, .conf-high { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.st-pending, .conf-medium, .conf-low { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.st-rejected, .conf-insufficient { background: color-mix(in srgb, var(--bad) 13%, transparent); color: var(--bad); }

.gallery { display: flex; gap: 8px; overflow-x: auto; margin: -4px -4px 12px; padding: 4px; scroll-snap-type: x mandatory; }
.gallery img { height: 220px; border-radius: 10px; scroll-snap-align: start; object-fit: cover; }
.sighting-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 10px 0; }
.facts dt { color: var(--muted); font-size: .85rem; }
.facts dd { margin: 0; }
.notes { background: var(--surface-2); padding: 10px; border-radius: 10px; white-space: pre-wrap; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sp-card { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; color: var(--text); }
.sp-card .thumb { aspect-ratio: 4/3; border-radius: 10px; overflow: hidden; display: grid; place-items: center; margin-bottom: 4px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 35%, var(--surface-2)), var(--surface-2)); color: var(--muted); font-size: .8rem; }
.sp-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.sp-card i, .sp-card small { font-size: .78rem; color: var(--muted); }

.s-list { list-style: none; margin: 0; padding: 0; }
.s-list li { border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.s-list li:last-child { border-bottom: 0; }
.s-list a { display: flex; align-items: center; gap: 10px; padding: 8px 0; color: var(--text); flex: 1; min-width: 0; }
.s-list a > div { flex: 1; min-width: 0; }
.s-list small { display: block; color: var(--muted); font-size: .78rem; }
.s-list img, .s-list .ph { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex: none; background: color-mix(in srgb, var(--c, #888) 35%, var(--surface-2)); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.kpis div { background: var(--surface-2); border-radius: 10px; padding: 8px; }
.kpis span { display: block; font-size: .75rem; color: var(--muted); }
.kpis b { font-size: 1rem; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar span { display: block; width: 100%; background: color-mix(in srgb, var(--primary) 55%, transparent); border-radius: 4px 4px 0 0; }
.bar.hi span { background: var(--accent); }
.bar small { font-size: .62rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; max-width: 100%; }
.hotspots { padding-inline-start: 20px; margin: 0; font-size: .9rem; }
.conf-line { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .85rem; }

.chance-list { list-style: none; padding: 0; margin: 0; }
.chance-list a { display: grid; grid-template-columns: minmax(0, 1.3fr) 1fr 44px; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.cl-name small { display: block; color: var(--muted); font-size: .75rem; }
.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.meter.big { height: 10px; margin-top: 8px; }
.pct { text-align: end; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font: 600 .9rem var(--font); color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.leaders { list-style: none; padding: 0; margin: 0; }
.leaders li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; }
.leaders li.me { border-color: var(--primary); }
.leaders li > div { flex: 1; min-width: 0; }
.leaders small { display: block; color: var(--muted); font-size: .78rem; }
.leaders .pos { width: 28px; text-align: center; font-weight: 700; }
.leaders .pts { color: var(--primary); }
.plog { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.plog li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.plog small { color: var(--muted); float: inline-end; }
.plog .neg { color: var(--bad); }

.toast { position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); transition: .25s; z-index: 2000; font-size: .9rem; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.leaflet-container { font-family: var(--font); }

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: 1fr 1fr; }
  .map.big { height: calc(100vh - 330px); }
}
