:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel-2: #16213a;
  --border: #24324f;
  --text: #e2e8f0;
  --muted: #8fa3c0;
  --accent: #38bdf8;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- 顶部栏 ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(180deg, #131d33, #0e1728);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand h1 { font-size: 20px; letter-spacing: 2px; color: #fff; }
.brand .sub { font-size: 12px; color: var(--muted); margin-left: 10px; }
.stats { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.stats b { color: var(--accent); font-size: 15px; margin-right: 2px; }

/* ---------- 主体 ---------- */
#main { display: flex; flex: 1 1 auto; min-height: 0; }

/* ---------- 侧边栏 ---------- */
#sidebar {
  width: 380px; min-width: 300px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.filters { padding: 12px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.filter-row:last-child { margin-bottom: 0; }
.filter-row label { font-size: 12px; color: var(--muted); width: 36px; flex: 0 0 auto; }
.filter-row.date-row label { width: 56px; }
.filter-row input[type="date"], .filter-row input[type="search"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font-size: 13px; outline: none;
}
.filter-row input[type="date"] { flex: 1 1 auto; min-width: 0; }
.filter-row input[type="search"] { flex: 1 1 auto; width: 100%; }
.filter-row.cats { gap: 6px; }
.cat-toggle {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); color: var(--muted); user-select: none;
  transition: all .15s;
}
.cat-toggle.on { color: #fff; border-color: transparent; }
.cat-toggle.off { opacity: .45; }

.list-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.list-head .list-count { flex: 1 1 auto; }
#btn-clear-filter {
  background: none; border: 1px solid var(--border); color: var(--muted);
  font-size: 11px; padding: 3px 10px; border-radius: 6px; cursor: pointer;
}
#btn-clear-filter:hover { color: var(--text); border-color: var(--accent); }

#event-list { flex: 1 1 auto; overflow-y: auto; padding: 8px; }
#event-list::-webkit-scrollbar { width: 8px; }
#event-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.ev {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 6px;
  border: 1px solid transparent; transition: background .12s;
}
.ev:hover { background: var(--panel-2); border-color: var(--border); }
.ev .ev-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.ev .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.ev .ev-time { font-size: 11px; color: var(--muted); flex: 1 1 auto; }
.ev .ev-cat { font-size: 10px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.ev .ev-name { font-size: 13px; line-height: 1.45; color: var(--text); }
.ev .ev-loc { font-size: 11px; color: var(--muted); margin-top: 3px; }
.ev .ev-loc .nofix { color: #f59e0b; }
.ev.active { background: var(--panel-2); border-color: var(--accent); }

/* ---------- 地图 ---------- */
#map-wrap { flex: 1 1 auto; position: relative; min-width: 0; }
#map { width: 100%; height: 100%; }
#map-controls {
  position: absolute; right: 14px; top: 14px; display: flex; flex-direction: column; gap: 6px;
}
#map-controls button {
  width: 34px; height: 34px; font-size: 16px; cursor: pointer; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
}
#map-controls button:hover { border-color: var(--accent); }

#legend {
  position: absolute; left: 14px; bottom: 14px;
  background: rgba(17, 26, 46, .88); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: 11px;
  display: flex; flex-wrap: wrap; gap: 8px; max-width: 420px;
}
#legend .lg-item { display: flex; align-items: center; gap: 5px; color: var(--muted); }
#legend .lg-dot { width: 9px; height: 9px; border-radius: 50%; }

#market-toggle {
  position: absolute; left: 14px; bottom: 52px; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  background: rgba(17,26,46,.92); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; cursor: pointer;
  user-select: none; font-size: 12px; color: var(--muted);
  transition: all .15s;
}
#market-toggle:hover { border-color: var(--accent); }
#market-toggle.on { border-color: #ef4444; color: var(--text); background: rgba(40,20,26,.92); }
#market-toggle .mt-icon { font-size: 14px; }
#market-toggle .mt-switch {
  width: 30px; height: 16px; border-radius: 999px; background: var(--border);
  position: relative; transition: background .2s; flex: 0 0 auto;
}
#market-toggle .mt-switch i {
  position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--muted); transition: all .2s;
}
#market-toggle.on .mt-switch { background: #ef4444; }
#market-toggle.on .mt-switch i { left: 16px; background: #fff; }
#market-toggle .mt-sub { font-size: 10px; color: var(--muted); }

#map-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 8px; color: var(--muted); font-size: 15px;
  background: rgba(11, 18, 32, .7);
}
#map-empty code { color: var(--accent); background: var(--panel-2); padding: 2px 8px; border-radius: 6px; }

/* ---------- 详情卡 ---------- */
#info-card {
  position: absolute; right: 16px; bottom: 16px; width: 380px; max-width: calc(100vw - 420px);
  max-height: 62vh; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: 12px; padding: 14px 16px; box-shadow: 0 8px 30px rgba(0,0,0,.5);
  z-index: 20;
}
#info-card::-webkit-scrollbar { width: 8px; }
#info-card::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cat-chip { font-size: 11px; padding: 2px 10px; border-radius: 999px; color: #fff; }
.card-time { font-size: 12px; color: var(--muted); flex: 1 1 auto; }
#card-close {
  background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer;
}
#card-close:hover { color: #fff; }
#info-card h3 { font-size: 16px; line-height: 1.5; margin-bottom: 8px; color: #fff; }
.card-desc { font-size: 13px; line-height: 1.6; color: var(--text); margin-bottom: 10px; }
.card-section { margin-bottom: 10px; }
.card-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
#card-locs .loc-item { font-size: 12px; padding: 3px 0; color: var(--text); }
#card-locs .loc-item .c { color: var(--muted); }
#card-kws .kw { display: inline-block; font-size: 11px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; margin: 0 5px 5px 0; color: var(--muted); }
#card-time-note { font-size: 12px; color: var(--muted); line-height: 1.5; }
#card-source a { color: var(--accent); font-size: 12px; text-decoration: none; word-break: break-all; }
#card-source a:hover { text-decoration: underline; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--accent); color: var(--text);
  padding: 8px 18px; border-radius: 8px; font-size: 13px; z-index: 50;
}
.hidden { display: none !important; }

/* ================= 手机端适配（<=768px） ================= */
.drawer-bar, .drawer-btn { display: none; }

@media (max-width: 768px) {
  html, body { height: 100%; overflow: hidden; }
  #topbar { padding: 8px 12px; align-items: center; gap: 8px; }
  .brand h1 { font-size: 16px; letter-spacing: 2px; }
  .brand .sub { display: none; }
  .stats {
    gap: 10px; font-size: 10px; flex-wrap: nowrap; overflow-x: auto;
    max-width: 62vw; white-space: nowrap; scrollbar-width: none;
  }
  .stats::-webkit-scrollbar { display: none; }
  .stats b { font-size: 13px; }
  .stats .stat.hide-m { display: none; }

  #main { flex-direction: column; }
  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; min-width: 0;
    height: 66vh; z-index: 30; display: flex; flex-direction: column;
    border-right: none; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,.5);
    transform: translateY(calc(100% - 48px));
    transition: transform .22s ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #sidebar.open { transform: translateY(0); }
  /* 把手（list-head）提到最前，收起时露出的就是它 */
  .list-head {
    order: -1; flex: 0 0 auto; height: 48px; padding: 0 12px;
    cursor: pointer; position: relative;
    background: var(--panel-2); border-radius: 16px 16px 0 0;
    border-bottom: 1px solid var(--border);
  }
  .filters { order: 0; flex: 0 0 auto; max-height: 34vh; overflow-y: auto; }
  #event-list { order: 1; flex: 1 1 auto; min-height: 0; }
  .drawer-bar {
    display: block; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
    width: 42px; height: 4px; border-radius: 2px; background: var(--border);
  }
  .drawer-btn {
    display: inline-block; background: none; border: none; color: var(--muted);
    font-size: 12px; padding: 4px 8px; cursor: pointer;
  }
  .list-title { font-size: 13px; }
  .filters { padding: 10px 12px; }
  .filter-row.date-row label { width: 52px; font-size: 11px; }
  #event-list { padding: 6px 8px 60px; }
  .ev { padding: 10px 10px; }
  .ev .ev-name { font-size: 14px; }

  #map-wrap { flex: 1 1 auto; min-height: 0; height: calc(100vh - 52px); height: calc(100dvh - 52px); }
  #map-controls { right: 10px; top: 10px; gap: 8px; }
  #map-controls button { width: 40px; height: 40px; font-size: 18px; }
  #market-toggle { left: 10px; top: 10px; bottom: auto; font-size: 11px; padding: 6px 10px; }
  #market-toggle .mt-sub { display: none; }
  #legend { display: none; }

  #info-card {
    left: 8px; right: 8px; bottom: 56px; width: auto; max-width: none;
    max-height: 58vh; border-radius: 14px; padding: 12px 14px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  #info-card h3 { font-size: 15px; }
}
