/* ── Reset & base ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --border:   #334155;
  --text:     #f1f5f9;
  --sub:      #94a3b8;
  --muted:    #64748b;
  --blue:     #3b82f6;
  --blue-dim: #1d4ed8;
  --green:    #22c55e;
  --yellow:   #eab308;
  --red:      #ef4444;
  --radius:   12px;
  --nav-h:    56px;
  --header-h: 52px;
  --slider-h: 56px;
  --sync-h:   18px;
}
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  direction: rtl;
}
a { color: var(--blue); text-decoration: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }

/* ── App layout ───────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100dvh; }

.app-header {
  height: var(--header-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; flex-shrink: 0;
}
.header-title { font-size: 15px; font-weight: 700; }

/* ── Slider bar ────────────────────────────────────────────────────────────────── */
.slider-bar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 6px 16px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.slider-label { font-size: 11px; color: var(--sub); display: flex; justify-content: space-between; }
.slider-label span { color: var(--blue); font-weight: 700; }
#reservist-slider { width: 100%; accent-color: var(--blue); }
.slider-hint { font-size: 10px; color: var(--muted); display: flex; justify-content: space-between; }

/* ── Main / tabs ───────────────────────────────────────────────────────────────── */
#main { flex: 1; overflow: hidden; position: relative; }

.tab-pane {
  display: none; position: absolute; inset: 0;
  overflow-y: auto; padding: 10px 12px;
  padding-bottom: calc(var(--nav-h) + var(--sync-h) + 10px);
  background: var(--bg); color: var(--text);
}
.tab-pane.active { display: block; }

/* ── Bottom nav ────────────────────────────────────────────────────────────────── */
.bottom-nav {
  height: var(--nav-h); background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; flex-shrink: 0;
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 8px 4px; font-size: 10px; color: var(--muted); transition: color .15s;
}
.nav-tab.active { color: var(--blue); }
.nav-icon { font-size: 18px; }

/* ── Sync bar ──────────────────────────────────────────────────────────────────── */
.sync-bar {
  height: var(--sync-h); background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 10px; color: var(--muted); letter-spacing: .02em;
}

/* ── Buttons ───────────────────────────────────────────────────────────────────── */
.btn-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--blue); background: transparent; transition: background .15s;
}
.btn-icon:hover { background: var(--border); }
.btn-primary {
  background: var(--blue); color: #fff; border-radius: 8px;
  padding: 10px 20px; font-size: 14px; font-weight: 600;
  width: 100%; transition: background .15s;
}
.btn-primary:hover { background: var(--blue-dim); }
.btn-back { font-size: 20px; color: var(--sub); padding: 8px; }
.btn-clear {
  font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 8px; white-space: nowrap;
}

/* ── Filters ───────────────────────────────────────────────────────────────────── */
.filters-row {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 10px;
}
.filter-toggles {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.filter-chip {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--sub); white-space: nowrap;
}

/* City chips */
.city-chips {
  display: flex; flex-wrap: wrap; gap: 5px;
}
.city-chip {
  font-size: 12px; padding: 4px 10px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--sub);
  background: transparent; cursor: pointer; transition: all .15s;
  white-space: nowrap;
}
.city-chip:hover { border-color: var(--blue); color: var(--text); }
.city-chip.active { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }

.filter-days-input {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; font: inherit;
  width: 130px; outline: none;
}
.filter-days-input:focus { border-color: var(--blue); }
.filter-days-input::placeholder { color: var(--muted); }

/* ── Sort row ──────────────────────────────────────────────────────────────────── */
.sort-row {
  display: flex; gap: 6px; align-items: center; margin-bottom: 8px; flex-wrap: wrap;
}
.sort-label { font-size: 11px; color: var(--muted); }
.sort-btn {
  font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 99px; padding: 3px 9px; transition: all .15s;
}
.sort-btn.active { color: var(--blue); border-color: var(--blue); background: rgba(59,130,246,.08); }

/* ── Lottery table ─────────────────────────────────────────────────────────────── */
#lottery-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

#lottery-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  white-space: nowrap;
}
#lottery-table thead tr {
  background: rgba(51,65,85,.5);
}
#lottery-table th {
  text-align: right; padding: 9px 12px;
  font-size: 11px; font-weight: 600; color: var(--sub); text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--surface);
}
#lottery-table th:first-child { border-radius: var(--radius) 0 0 0; }
#lottery-table th:last-child  { border-radius: 0 var(--radius) 0 0; }

#lottery-table td {
  padding: 9px 12px; border-bottom: 1px solid rgba(51,65,85,.35);
  vertical-align: middle; color: var(--text);
}
#lottery-table tbody tr:last-child td { border-bottom: none; }
#lottery-table tbody tr:nth-child(even) { background: rgba(255,255,255,.02); }
#lottery-table tr { cursor: pointer; transition: background .1s; }
#lottery-table tbody tr:hover { background: rgba(59,130,246,.08); }

.td-city { font-weight: 600; }
.td-hood { font-size: 11px; color: var(--sub); }
.odds-high  { color: var(--green); font-weight: 700; }
.odds-mid   { color: var(--yellow); font-weight: 600; }
.odds-low   { color: var(--sub); }
.discount-high { color: var(--green); font-weight: 700; }
.discount-mid  { color: var(--yellow); }
.discount-low  { color: var(--sub); }
.tag-religious { font-size: 10px; color: var(--muted); background: var(--border); border-radius: 4px; padding: 1px 5px; }
.days-urgent { color: var(--red); font-weight: 700; }
.days-soon   { color: var(--yellow); }

/* ── City cards ────────────────────────────────────────────────────────────────── */
.city-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 12px 14px; margin-bottom: 8px;
  cursor: pointer; transition: border-color .15s;
}
.city-card:hover { border-color: var(--blue); }
.city-card-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.city-name { font-size: 15px; font-weight: 700; color: var(--text); }
.city-agg-odds { font-size: 18px; font-weight: 800; }
.city-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.city-stat { font-size: 11px; color: var(--sub); }
.city-stat strong { color: var(--text); font-weight: 600; }

/* ── Sweet Spot scatter ────────────────────────────────────────────────────────── */
.scatter-hint { font-size: 11px; color: var(--muted); margin-bottom: 8px; text-align: center; }
#scatter-wrap { position: relative; width: 100%; }
#scatter-svg { width: 100%; display: block; }

.scatter-tooltip {
  position: absolute; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px;
  max-width: 200px; line-height: 1.5; z-index: 10;
  display: none;
}

/* ── Detail panel ──────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; z-index: 40; transition: opacity .25s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.detail-panel {
  position: fixed; inset: 0 0 0 auto;
  width: min(440px, 100vw);
  background: var(--bg); z-index: 50;
  transform: translateX(100%); transition: transform .25s;
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  direction: rtl;
}
.detail-panel.open { transform: translateX(0); }

.detail-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.detail-title-wrap { flex: 1; min-width: 0; }
.detail-company { font-size: 16px; font-weight: 700; }
.detail-role    { font-size: 12px; color: var(--sub); }
.detail-body { flex: 1; overflow-y: auto; padding: 16px; }

.row-section { margin-bottom: 16px; }
.row-section-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.row-field { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid rgba(51,65,85,.4); font-size: 13px; }
.row-field-label { color: var(--sub); }
.row-field-val { font-weight: 500; }
.big-odds { font-size: 28px; font-weight: 800; color: var(--green); text-align: center; padding: 12px 0; }
.big-odds-label { font-size: 11px; color: var(--muted); text-align: center; margin-top: -8px; margin-bottom: 12px; }

/* ── Settings panel ────────────────────────────────────────────────────────────── */
.settings-note { font-size: 12px; color: var(--sub); margin-bottom: 12px; line-height: 1.6; }
.market-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid rgba(51,65,85,.4);
  gap: 8px;
}
.market-city { font-size: 13px; flex: 1; }
.market-input {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 8px; font-size: 13px; font: inherit;
  width: 90px; text-align: left; outline: none;
}
.market-input:focus { border-color: var(--blue); }
.market-discount { font-size: 11px; color: var(--green); min-width: 36px; text-align: left; }

/* ── Misc ──────────────────────────────────────────────────────────────────────── */
.empty-state { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 0; }
.error       { color: var(--red); font-size: 14px; text-align: center; padding: 20px 0; }

.toast {
  position: fixed; bottom: calc(var(--nav-h) + var(--sync-h) + 12px); left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 16px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 100; white-space: nowrap; border: 1px solid var(--border);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
