/* app.css — QSO Awards map-first UI */
:root {
  --bg: #0f1720;
  --panel: #16212e;
  --panel-2: #1d2a3a;
  --line: #2a3a4d;
  --text: #e7edf3;
  --muted: #9fb0c0;
  --accent: #4dabf7;
  --never: #5b6b7b;
  --activated: #1c7ed6;
  --recent: #e8590c;
  --good: #51cf66;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #ffd43b;
  outline-offset: 2px;
}

/* ---- layout ---- */
.layout { display: grid; grid-template-rows: auto 1fr; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.modes { display: flex; gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 999px; }
.modes button {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; font-weight: 600;
}
.modes button.active { background: var(--accent); color: #06121f; }
.search { flex: 1; display: flex; gap: 6px; max-width: 460px; }
.search-advanced { position: relative; }
.search input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 7px 10px; border-radius: 8px;
}
.search > button { background: var(--accent); color: #06121f; border: 0; padding: 7px 12px; border-radius: 8px; font-weight: 600; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  max-height: min(560px, 70vh); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 6px 0;
}
.search-section + .search-section { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.search-section-title {
  padding: 6px 10px 4px; color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
}
.search-option {
  display: grid; grid-template-columns: minmax(72px, auto) 1fr; gap: 10px; align-items: center;
  width: 100%; min-height: 44px; padding: 7px 10px; border: 0; border-left: 3px solid transparent;
  background: transparent; color: var(--text); text-align: left;
}
.search-option:hover, .search-option.active { background: var(--panel-2); border-left-color: var(--accent); }
.search-option-main { font-weight: 700; white-space: nowrap; }
.search-option-sub { color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.lang button {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 5px 9px; border-radius: 8px;
}
.lang button.active { color: var(--text); border-color: var(--accent); }
.basemap { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 5px 8px; border-radius: 8px; }

.stage { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }

/* ---- side rail ---- */
.rail {
  position: absolute; top: 12px; left: 12px; bottom: 12px; width: 320px; max-width: 42vw;
  display: flex; flex-direction: column; gap: 12px; z-index: 3; pointer-events: none;
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); pointer-events: auto; overflow: hidden;
}
.card h3 { margin: 0; padding: 10px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); border-bottom: 1px solid var(--line); }
.card .body { padding: 10px 12px; }
.scroll { overflow: auto; }

/* stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.stat .n { font-size: 20px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.coverage-bar { height: 6px; background: var(--panel-2); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.coverage-bar > i { display: block; height: 100%; background: var(--good); }
.kv { display: flex; justify-content: space-between; padding: 2px 0; }
/* collapsed stats strip (mobile only; hidden on desktop) */
.stats-strip { display: none; width: 100%; align-items: center; gap: 10px; background: transparent; border: 0; color: var(--text); padding: 10px 12px; font: inherit; text-align: left; }
.stats-strip b { font-size: 15px; font-weight: 700; }
.stats-strip .chev { margin-left: auto; color: var(--muted); }

/* stats charts: tabbed pie (by mode) / bars (by band) */
.charts { margin-top: 10px; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button { flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); padding: 4px 8px; border-radius: 6px; font-size: 12px; }
.tabs button.active { color: #06121f; background: var(--accent); border-color: var(--accent); }
.pie { width: 96px; height: 96px; display: block; margin: 2px auto 0; }
.pie-wrap { position: relative; width: 96px; margin: 2px auto 0; }
.pie-wrap .pie { margin: 0; }
.pie-wrap .pie { cursor: help; }
.pie-pop {
  display: none; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  margin-top: 6px; min-width: 210px; max-width: 280px; z-index: 6;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); padding: 8px 10px;
  grid-template-columns: 1fr 1fr; gap: 2px 12px; font-size: 12px; color: var(--muted);
}
.pie-wrap:hover .pie-pop { display: grid; }
.pie-pop span { white-space: nowrap; }
.pie-pop .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.pielegend { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.pielegend span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pielegend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* the recent/search panel slot; the geo modal overlays it exactly */
.panel { position: relative; flex: 1; min-height: 120px; display: flex; flex-direction: column; }
/* geolocation "my location" card — an exact overlay copy of the recent panel (closeable) */
.geo-card { position: absolute; inset: 0; z-index: 30; margin: 0; }
.geo-card .body { display: flex; flex-direction: column; gap: 5px; }
.geo-card .kv { align-items: baseline; }
.geo-card .kv > span:last-child { text-align: right; }

/* recent + lists */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; flex-direction: column; gap: 2px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: transparent; border-left: 3px solid transparent; text-align: left;
}
.item:hover { background: var(--panel-2); }
.item.active { border-left-color: var(--accent); background: var(--panel-2); }
.item .row1 { display: flex; justify-content: space-between; gap: 8px; }
.item .code { font-weight: 700; color: var(--text); }
.item .who { color: var(--accent); }
/* code + callsign are separate clickable anchors */
a.code, a.who { text-decoration: none; cursor: pointer; }
a.code:hover, a.who:hover { text-decoration: underline; }
.item .meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; font-size: 11px; color: var(--muted); }

/* detail panel (bottom sheet on the right) */
.detail {
  position: absolute; right: 12px; bottom: 12px; width: 360px; max-width: 46vw; max-height: 70%;
  z-index: 4; display: flex; flex-direction: column;
}
.detail .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.detail .title { font-size: 16px; font-weight: 700; }
.detail .sub { color: var(--muted); }
.close { background: transparent; border: 0; color: var(--muted); font-size: 18px; line-height: 1; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }

/* legend + status dots */
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.never { background: #7b8794; }
.recency-leg { margin-top: 10px; }
.ragbar { height: 8px; border-radius: 4px; margin-top: 4px; background: linear-gradient(90deg, #2fb344 0%, #f4d03f 50%, #e03131 100%); }
.raglabels { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); margin-top: 4px; }

.pill { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); padding: 4px 12px; border-radius: 999px; font-weight: 600; }
.pill.active { color: #06121f; background: var(--accent); border-color: var(--accent); }
.muted { color: var(--muted); }
.empty { padding: 14px 12px; color: var(--muted); }
.spin { padding: 14px 12px; color: var(--muted); }
.footer { position: absolute; left: 12px; bottom: 12px; z-index: 2; color: var(--muted); font-size: 11px; pointer-events: none; text-shadow: 0 1px 2px #000; }

/* maplibre popup */
.maplibregl-popup-content { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; font-size: 12px; padding: 8px 10px; }
.maplibregl-popup-content .pc { font-weight: 700; }
.maplibregl-popup-tip { display: none; }

/* ===== mobile (phones): map pinned (top / left), content below / beside, stats collapsed ===== */
/* Shared rules for both phone orientations. Targets the SHORT screen dimension so
   tablets/laptops keep the desktop layout. */
@media (orientation: portrait) and (max-width: 600px),
       (orientation: landscape) and (max-height: 600px) {
  .brand small { display: none; }
  .basemap { display: none; }          /* hide the map-type selector on phones */

  .stage { display: grid; }
  #map { position: relative; inset: auto; width: 100%; height: 100%; }
  .rail { position: static; inset: auto; width: auto; max-width: none; flex-direction: column;
          gap: 8px; padding: 8px; overflow-y: auto; pointer-events: auto; z-index: 1; }
  .footer { display: none; }

  /* statistics hidden entirely on phones */
  .stats { display: none; }

  /* object detail becomes a slide-up sheet */
  .detail { position: fixed; bottom: 0; top: auto; width: auto; max-width: none; z-index: 20;
            border-radius: var(--radius) var(--radius) 0 0; }
}
/* Portrait phones — map on TOP, panel below */
@media (orientation: portrait) and (max-width: 600px) {
  .stage { grid-template-rows: 54vh 1fr; }
  .detail { left: 0; right: 0; max-height: 64vh; }
  /* narrow: wrap the top bar, search drops to its own full-width row */
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .spacer { display: none; }
  .search { order: 9; flex-basis: 100%; max-width: none; }
  .search-results { max-height: 45vh; }
  .search-option { grid-template-columns: 72px 1fr; }
}
/* Landscape phones — map on LEFT, panel on the right */
@media (orientation: landscape) and (max-height: 600px) {
  .stage { grid-template-columns: 60vw 1fr; }
  .detail { right: 0; left: auto; width: 42vw; max-height: 100%; border-radius: var(--radius) 0 0 var(--radius); }
  .search-results { max-height: 50vh; }
}
