*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --white:      #ffffff;
  --bg:         #F3F6FA;
  --primary:    #0052CC;
  --primary-dk: #003E99;
  --text:       #172B4D;
  --muted:      #626F86;
  --border:     #DFE1E6;
  --shadow-sm:  0 1px 3px rgba(9,30,66,.12), 0 0 1px rgba(9,30,66,.08);
  --shadow-md:  0 4px 12px rgba(9,30,66,.15), 0 0 2px rgba(9,30,66,.08);
  --avail:      #00875A;
  --avail-bg:   #E3FCEF;
  --partial:    #FF8B00;
  --partial-bg: #FFF7E6;
  --full:       #DE350B;
  --full-bg:    #FFEBE6;
  --radius:     8px;
  --radius-sm:  5px;
  --pad:        16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ─────────────────────────────────────────────────── */
header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--pad);
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(9,30,66,.1);
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  text-decoration: none;
}

.logo-icon {
  width: 30px;
  height: 30px;
  background: var(--primary);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--avail-bg);
  color: var(--avail);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--avail);
  animation: live-pulse 2s infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.hdr-right {
  display: flex;
  align-items: center;
  gap: 8px;
}


/* ── Search section ─────────────────────────────────────────── */
.search-section {
  background: var(--primary);
  padding: 16px var(--pad);
}

.search-label {
  color: rgba(255,255,255,.75);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 10px;
  letter-spacing: 0.3px;
}

.search-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.cfg-label {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,.7);
  letter-spacing: 0.3px;
}

.loc-wrap { position: relative; }

.loc-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
  line-height: 1;
}

#locQuery {
  width: 100%;
  background: white;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom */
  padding: 12px;
  outline: none;
  transition: border-color 0.15s;
}

#locQuery:focus { border-color: #4C9AFF; }
#locQuery::placeholder { color: var(--muted); }

#suggestions {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 200;
  max-height: 240px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-md);
}

.sug-item {
  padding: 12px 14px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
  color: var(--text);
}

.sug-item:last-child { border-bottom: none; }
.sug-item:active { background: var(--bg); }

#loadBtn {
  width: 100%;
  background: #FFAB00;
  color: var(--text);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

#loadBtn:active { background: #FF991F; }
#loadBtn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Notices ─────────────────────────────────────────────────── */
.err-box {
  background: var(--full-bg);
  border-left: 4px solid var(--full);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: #BF2600;
  margin: 12px var(--pad) 0;
  line-height: 1.6;
}

.notice {
  background: #DEEBFF;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: #0747A6;
  margin: 12px var(--pad) 0;
  line-height: 1.6;
}

/* ── Stats ─────────────────────── horizontal scroll on mobile ─ */
#statsBar {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  padding: 12px var(--pad);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#statsBar::-webkit-scrollbar { display: none; }

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  flex-shrink: 0;
  min-width: 90px;
  box-shadow: var(--shadow-sm);
}

.stat-n {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.5px;
  color: var(--text);
}

.stat-l {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  margin-top: 4px;
}

.stat-n.s-avail   { color: var(--avail); }
.stat-n.s-partial { color: var(--partial); }
.stat-n.s-full    { color: var(--full); }
.stat-n.s-long    { color: var(--partial); }

/* ── Toolbar ─────────────────────────────────────────────────── */
#toolBar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 var(--pad) 12px;
}

.search {
  width: 100%;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom */
  padding: 10px 12px;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s;
}

.search::placeholder { color: var(--muted); }
.search:focus { border-color: #4C9AFF; }

.filter-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: white;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.filter-group::-webkit-scrollbar { display: none; }

.fbtn {
  background: white;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 16px;
  min-height: 42px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s;
}

.fbtn:last-child { border-right: none; }
.fbtn:active { background: var(--bg); }

.fbtn.on                   { background: var(--primary); color: white; font-weight: 600; }
.fbtn.on[data-f="avail"]   { background: var(--avail); }
.fbtn.on[data-f="partial"] { background: var(--partial); }
.fbtn.on[data-f="full"]    { background: var(--full); }

.sort-sel {
  width: 100%;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px;
  min-height: 42px;
  outline: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* ── Content ─────────────────────────────────────────────────── */
.main { padding: 0 var(--pad) 32px; }

#count {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 10px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card-bar { height: 4px; }
.card-bar.avail   { background: var(--avail); }
.card-bar.partial { background: var(--partial); }
.card-bar.full    { background: var(--full); }

.card-top {
  padding: 14px 14px 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.card-info { flex: 1; min-width: 0; }

.card-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
}

.card-op {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  font-weight: 500;
}

.pill {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}

.pill-avail { background: var(--avail-bg);   color: var(--avail); }
.pill-occ   { background: var(--partial-bg); color: var(--partial); }
.pill-full  { background: var(--full-bg);    color: var(--full); }

/* ── Connector rows ──────────────────────────────────────────── */
.evse-list { border-top: 1px solid var(--border); }

.evse-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #F4F5F7;
  gap: 12px;
}

.evse-row:last-child { border-bottom: none; }

.evse-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-avail   { background: var(--avail); }
.dot-full    { background: var(--full); }
.dot-partial {
  background: var(--partial);
  animation: dot-ring 2s infinite;
}

@keyframes dot-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,139,0,.4); }
  50%       { box-shadow: 0 0 0 4px rgba(255,139,0,0); }
}

.evse-info { min-width: 0; }

.evse-type {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.evse-count {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.evse-right { text-align: right; flex-shrink: 0; }

.avail-count {
  font-size: 22px;
  font-weight: 700;
  color: var(--avail);
  line-height: 1;
}

.dur-val {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.dur-val.occ  { color: var(--partial); }
.dur-val.full { color: var(--full); }

.dur-since {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

/* ── States ──────────────────────────────────────────────────── */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  gap: 14px;
  text-align: center;
  padding: 40px 24px;
}

.state-title + .state-sub { margin-top: -8px; }

.state-icon {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  background: white;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: var(--shadow-sm);
}

.state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.state-sub {
  font-size: 13px;
  max-width: 340px;
  line-height: 1.75;
  color: var(--muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── Pagination ──────────────────────────────────────────────── */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 0;
}

.pgbtn {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.pgbtn:active { background: var(--bg); }
.pgbtn:disabled { opacity: 0.35; cursor: not-allowed; }

.pginfo {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  padding: 0 6px;
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(9,30,66,.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: var(--pad);
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.modal-close:hover { background: var(--bg); }

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.how-block {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.how-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.how-text { flex: 1; }

.how-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.how-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.65;
}

.status-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.leg-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
}

.leg-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.modal-footer {
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}

.info-btn {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  cursor: pointer;
  white-space: nowrap;
}

.info-btn:active { background: var(--bg); }

@media (min-width: 400px) {
  .info-btn { display: block; }
}

/* ── Tablet (640px+) ─────────────────────────────────────────── */
@media (min-width: 640px) {
  :root { --pad: 24px; }

  header { height: 60px; }
  .logo { font-size: 15px; }
  .logo-icon { width: 32px; height: 32px; font-size: 15px; border-radius: 8px; }
  .hdr-right { gap: 12px; }

  .search-section { padding: 24px var(--pad) 22px; }
  .search-row { flex-direction: row; align-items: flex-end; gap: 8px; }
  .search-main { flex: 1; width: auto; }
  #locQuery { font-size: 14px; padding: 10px 12px; }

  #loadBtn { width: auto; font-size: 14px; padding: 10px 22px; }

  #statsBar { flex-wrap: wrap; overflow-x: visible; padding: 16px var(--pad); }
  .stat-card { flex: 1; flex-shrink: 1; }

  #toolBar { flex-direction: row; flex-wrap: wrap; padding: 0 var(--pad) 14px; }
  .search { flex: 1; min-width: 160px; width: auto; font-size: 13px; }
  .filter-group { overflow-x: visible; }
  .fbtn { font-size: 12px; padding: 8px 14px; min-height: auto; }
  .sort-sel { width: auto; font-size: 12px; padding: 8px 10px; min-height: auto; }
}

/* ── Desktop (1024px+) ───────────────────────────────────────── */
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
  .card { transition: box-shadow 0.15s, transform 0.12s; }
  .card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
  .fbtn:hover { background: var(--bg); color: var(--text); }
  .pgbtn:hover:not(:disabled) { background: var(--bg); }
  #loadBtn:hover:not(:disabled) { background: #FF991F; }
  .sug-item:hover { background: var(--bg); }
}
