:root {
  --bg: #0b0e14;
  --bg-2: #11151d;
  --panel: rgba(15, 19, 27, 0.88);
  --panel-solid: #0f131b;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e8edf5;
  --muted: #8b96a9;
  --faint: #5d687c;
  --photo: #6ea8fe;
  --spend: #f5a524;
  --msg: #4ade80;
  --trip: #ff5d73;
  --accent: #6ea8fe;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

.ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 10px;
  color: var(--muted);
  transition: 120ms ease;
}
.ghost:hover { color: var(--text); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.08); }

.primary {
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, #6ea8fe, #4f7cf7);
  color: #08101f;
  font-weight: 700;
  letter-spacing: 0.01em;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  grid-template-rows: minmax(0, 1fr) 196px;
  background: var(--bg);
}

#map { grid-column: 1; grid-row: 1; background: #0d1118; }

#timeline {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: linear-gradient(180deg, rgba(11, 14, 20, 0.72), #0b0e14 40%);
  border-top: 1px solid var(--line);
  padding: 8px 12px 10px;
  z-index: 4;
}

.timeline-top {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding-bottom: 6px;
}

.zooms { display: flex; gap: 4px; flex-wrap: wrap; }
.zooms button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--faint);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  transition: 120ms ease;
}
.zooms button:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.zooms button.active { color: var(--text); background: rgba(110, 168, 254, 0.14); border-color: rgba(110, 168, 254, 0.35); }

.legend { display: flex; gap: 12px; color: var(--muted); font-size: 11px; margin-left: auto; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.photo { background: var(--photo); }
.dot.spend { background: var(--spend); }
.dot.msg { background: var(--msg); }
.dot.trip { background: var(--trip); box-shadow: 0 0 8px var(--trip); }

.range-nav { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); min-width: 190px; justify-content: flex-end; }
.range-nav #rangeLabel { min-width: 110px; text-align: center; color: var(--text); }

.canvas-wrap { position: relative; flex: 1; min-height: 0; }
#bars { width: 100%; height: 100%; display: block; cursor: crosshair; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(9, 12, 18, 0.96);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -110%);
  white-space: nowrap;
  z-index: 20;
}
.tooltip b { color: #fff; }

.mobile-timeline { display: none; }

#hud {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px 12px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  max-width: min(480px, calc(100% - 300px));
}

.phone {
  width: 54px;
  height: 94px;
  flex: 0 0 auto;
  border: 2px solid #39445a;
  border-radius: 10px;
  background: linear-gradient(160deg, #1a202c, #0d1118);
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.phone::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 50%;
  width: 16px;
  height: 3px;
  border-radius: 3px;
  background: #39445a;
  transform: translateX(-50%);
}
.phone-screen {
  position: absolute;
  inset: 13px 5px 7px;
  border-radius: 5px;
  background: radial-gradient(circle at 50% 10%, #1c2a44, #0a0e15 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  font-size: 7.5px;
  line-height: 1.25;
  text-align: center;
  color: #b9c7dd;
  overflow: hidden;
}

.when { min-width: 0; }
.hud-date { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-place { font-size: 13px; color: #c4cee0; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-doing { font-size: 11px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#topbar {
  position: absolute;
  top: 18px;
  right: calc(390px + 18px);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  backdrop-filter: blur(12px);
}
.brand-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--trip);
  box-shadow: 0 0 12px var(--trip);
}
.brand-sub { color: var(--faint); font-size: 10px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; }

.top-actions { display: flex; gap: 8px; }
#jumpDate {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 9px;
  color: var(--muted);
  font-size: 12px;
  color-scheme: dark;
  backdrop-filter: blur(12px);
}

.panel {
  grid-column: 2;
  grid-row: 1 / 3;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(180deg, #0e121a, #0b0e14);
  border-left: 1px solid var(--line);
  padding: 18px 18px 40px;
  z-index: 5;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: #232a36; border-radius: 3px; }

.panel-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.day-date { font-size: 20px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.2; }
.day-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.only-mobile { display: none; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 14px; }
.badge {
  font-size: 10px;
  letter-spacing: 0.02em;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  white-space: nowrap;
}
.badge.trip { color: #ffd0d6; border-color: rgba(255, 93, 115, 0.35); background: rgba(255, 93, 115, 0.1); }
.badge.period { color: #d9e4ff; border-color: rgba(110, 168, 254, 0.3); background: rgba(110, 168, 254, 0.1); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.stat {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
}
.stat .k { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.07em; }
.stat .v { font-size: 17px; font-weight: 700; margin-top: 2px; }
.stat .v small { font-size: 10px; color: var(--muted); font-weight: 500; margin-left: 3px; }

.photos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-bottom: 18px; }
.photo {
  margin: 0;
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: #151b26;
  border: 1px solid var(--line);
  aspect-ratio: 1 / 1;
  cursor: zoom-in;
}
.photo:first-child { grid-column: span 2; aspect-ratio: 16 / 10; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 220ms ease; }
.photo:hover img { transform: scale(1.04); }
.photo figcaption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 8px 6px;
  font-size: 10px;
  color: #e6edf8;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 0;
  transition: 160ms ease;
}
.photo:hover figcaption { opacity: 1; }
.empty {
  grid-column: 1 / -1;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 22px 14px;
  color: var(--faint);
  font-size: 12px;
  text-align: center;
}

#txBlock h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); margin: 0 0 8px; }
.tx-list { display: flex; flex-direction: column; gap: 1px; }
.tx {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 12px;
}
.tx .time { color: var(--faint); font-variant-numeric: tabular-nums; }
.tx .what { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #cbd5e1; }
.tx .what small { display: block; color: var(--faint); font-size: 10px; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-variant-numeric: tabular-nums; color: var(--spend); }
.tx .amt.income { color: var(--msg); }
.tx-empty { color: var(--faint); font-size: 12px; padding: 8px 0; }

.prov { margin-top: 14px; color: var(--faint); font-size: 10px; line-height: 1.6; border-top: 1px solid var(--line); padding-top: 10px; }
.prov span { margin-right: 6px; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(4, 6, 10, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: min(1200px, 94vw); max-height: 82vh; border-radius: 12px; box-shadow: 0 20px 80px rgba(0, 0, 0, 0.7); }
.lightbox #lightboxClose {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 22px;
  line-height: 1;
}
#lightboxCap { margin-top: 12px; color: var(--muted); font-size: 12px; text-align: center; }

/* login */
.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 500px at 20% 0%, rgba(110, 168, 254, 0.14), transparent 60%),
    radial-gradient(700px 500px at 90% 100%, rgba(255, 93, 115, 0.1), transparent 60%),
    #0b0e14;
  padding: 20px;
}
.login-card {
  width: min(380px, 100%);
  background: rgba(15, 19, 27, 0.9);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 26px 26px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
}
.login-brand { display: flex; align-items: center; gap: 9px; font-size: 24px; font-weight: 800; letter-spacing: 0.01em; }
.login-lead { color: var(--muted); font-size: 13px; margin: 8px 0 24px; }
.login-card label { display: block; margin-bottom: 14px; }
.login-card label span { display: block; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.login-card input {
  width: 100%;
  background: #0a0d13;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  transition: 120ms ease;
}
.login-card input:focus { border-color: rgba(110, 168, 254, 0.7); box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.12); }
.login-error { margin-top: 12px; color: #ff9aa9; font-size: 12px; text-align: center; }

/* mobile */
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 38vh minmax(0, 1fr); }
  #map { grid-column: 1; grid-row: 1; }
  #timeline { grid-column: 1; grid-row: 2; min-height: 0; padding: 6px 10px calc(10px + env(safe-area-inset-bottom)); }
  .panel {
    grid-column: 1;
    grid-row: 1 / 3;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 76vh;
    border-left: 0;
    border-top: 1px solid var(--line-strong);
    border-radius: 18px 18px 0 0;
    transform: translateY(104%);
    transition: transform 240ms ease;
    z-index: 30;
    padding-bottom: calc(30px + env(safe-area-inset-bottom));
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  }
  .panel.open { transform: translateY(0); }
  .only-mobile { display: inline-flex; }
  #hud { top: 10px; left: 10px; padding: 8px 10px; gap: 9px; max-width: calc(100% - 86px); border-radius: 13px; }
  .phone { width: 42px; height: 72px; border-radius: 8px; }
  .phone::before { top: 4px; width: 12px; height: 2px; }
  .phone-screen { inset: 10px 4px 6px; font-size: 6.5px; border-radius: 4px; }
  .hud-date { font-size: 15px; }
  .hud-place { font-size: 11px; }
  .hud-doing { font-size: 10px; }
  #topbar { top: 10px; right: 10px; gap: 6px; }
  .brand { display: none; }
  .top-actions { gap: 6px; }
  #jumpDate { display: none; }
  #btnLogout { padding: 6px 8px; font-size: 11px; }
  .timeline-top { gap: 6px; }
  .zooms { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .zooms::-webkit-scrollbar { display: none; }
  .zooms button { padding: 4px 6px; font-size: 11px; white-space: nowrap; }
  .legend { display: none; }
  .range-nav { flex: 1 1 100%; min-width: 0; justify-content: space-between; }
  .range-nav #rangeLabel { min-width: 0; font-size: 11px; }
  .canvas-wrap { display: none; }
  .mobile-timeline { display: block; overflow-y: auto; overscroll-behavior: contain; flex: 1; min-height: 0; padding-right: 2px; }
  .mt-row {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr) 54px;
    gap: 8px;
    align-items: center;
    padding: 7px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    cursor: pointer;
  }
  .mt-row:hover, .mt-row.selected { background: rgba(110, 168, 254, 0.08); }
  .mt-label { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mt-row.selected .mt-label { color: var(--text); }
  .mt-bars { display: flex; flex-direction: column; gap: 2px; }
  .mt-bar { height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
  .mt-bar i { display: block; height: 100%; border-radius: 2px; }
  .mt-bar.photos i { background: var(--photo); }
  .mt-bar.spend i { background: var(--spend); }
  .mt-bar.msg i { background: var(--msg); }
  .mt-count { font-size: 10px; color: var(--faint); text-align: right; font-variant-numeric: tabular-nums; }
  .mt-count b { color: var(--text); font-weight: 600; }
  .mt-trip { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--trip); box-shadow: 0 0 6px var(--trip); vertical-align: middle; }
}
