:root {
  --bg: #f6f4f0;
  --card: #ffffff;
  --ink: #1c1a17;
  --muted: #6b675f;
  --accent: #7b1fa2;
  --accent-soft: #f3e7fa;
  --line: #e5e0d8;
  --ok: #1b7f3b;
  --warn: #b45309;
  --err: #b3261e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: linear-gradient(135deg, #7b1fa2, #a13bc8);
  color: #fff; font-weight: 700; font-size: 17px;
}
.offline-banner {
  background: #fff3d6; color: #7a4d00; border-bottom: 1px solid #f0dfae;
  padding: 8px 16px; font-size: 13px; font-weight: 600; text-align: center;
}
.map-tile-note {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 900;
  background: rgba(255, 243, 214, .95); color: #7a4d00; border-radius: 999px;
  padding: 5px 14px; font-size: 12px; font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.header-title { letter-spacing: .3px; }
.icon-btn {
  background: rgba(255,255,255,.16); color: #fff; border: 0; border-radius: 8px;
  width: 34px; height: 34px; font-size: 17px; cursor: pointer;
}

.main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tab-page { display: none; flex-direction: column; height: 100%; min-height: 0; }
.tab-page.active { display: flex; }

.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px calc(var(--safe-bottom) + 84px); }

.loading { color: var(--muted); padding: 24px; text-align: center; }

/* Auth */
.auth { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { text-align: center; max-width: 340px; }
.auth-card .brand { font-size: 56px; }
.auth-card h1 { margin: 4px 0 4px; font-size: 28px; }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; }
.btn {
  display: inline-flex; align-items: center; gap: 10px; text-decoration: none;
  padding: 12px 20px; border-radius: 12px; font-weight: 600; font-size: 15px;
}
.google-btn { background: #fff; color: #333; border: 1px solid #d8d3cc; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tiny { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* Day cards */
.day-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; overflow: hidden; }
.day-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer;
  user-select: none;
}
.day-head .num {
  background: var(--accent-soft); color: var(--accent); font-weight: 800;
  border-radius: 10px; min-width: 44px; padding: 6px 8px; text-align: center; font-size: 13px;
}
.day-head .title { flex: 1; font-weight: 600; font-size: 15px; }
.day-head .date { color: var(--muted); font-size: 12px; }
.day-head .chev { color: var(--muted); font-size: 12px; transition: transform .15s; }
.day-card.open .chev { transform: rotate(180deg); }

.activity { padding: 0 14px 12px; }
.activity.item { border-left: 3px solid var(--accent); padding-left: 10px; margin: 0 0 10px; }
.activity .a-name { font-weight: 600; font-size: 14px; }
.activity .a-time { color: var(--accent); font-weight: 600; font-size: 13px; }
.activity .a-site { color: var(--muted); font-size: 13px; margin-top: 2px; }
.activity .a-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.activity.transit { border-left-color: #94a3b8; }
.activity.untimed { border-left-color: #cbd5e1; }

/* Today */
.today-hero {
  background: linear-gradient(135deg, #7b1fa2, #4a148c); color: #fff;
  border-radius: 16px; padding: 18px 16px; margin-bottom: 14px;
}
.today-hero .big { font-size: 22px; font-weight: 800; }
.today-hero .small { opacity: .85; font-size: 13px; margin-top: 2px; }
.day-tag { display: inline-block; background: rgba(255,255,255,.18); border-radius: 999px; padding: 3px 10px; font-size: 12px; margin-top: 8px; }

/* Search */
.search-row { padding: 10px 14px 4px; }
.search-row input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  font-size: 15px; background: var(--card);
}

/* Map */
#map { flex: 1; min-height: 0; }
.leaflet-popup-content .p-name { font-weight: 700; font-size: 14px; }
.leaflet-popup-content .p-meta { color: var(--muted); font-size: 12px; }
.leaflet-popup-content .p-desc { font-size: 13px; margin-top: 4px; }

/* Chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; }
.chat-welcome { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 14px; }
.bubble { max-width: 85%; padding: 10px 13px; border-radius: 14px; font-size: 14.5px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.error { align-self: flex-start; background: #fdecea; color: var(--err); border-color: #f3c1bc; }
.bubble.thinking { align-self: flex-start; color: var(--muted); font-size: 13px; }

.plan-card { align-self: stretch; background: #fffdf5; border: 1px solid #f0e3b8; border-radius: 14px; padding: 12px 14px; }
.plan-card .p-label { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.plan-card .p-row { font-size: 13px; color: var(--ink); padding: 2px 0; border-top: 1px dashed #eee0b0; }
.plan-card .p-row:first-of-type { border-top: 0; }
.plan-card .p-before { color: var(--err); text-decoration: line-through; font-size: 12px; }
.plan-card .p-after { color: var(--ok); font-size: 12.5px; }
.plan-card .p-btns { display: flex; gap: 8px; margin-top: 10px; }
.plan-card button { flex: 1; padding: 10px; border-radius: 10px; border: 0; font-weight: 700; font-size: 14px; cursor: pointer; }
.plan-card .apply { background: var(--ok); color: #fff; }
.plan-card .cancel { background: #edeade; color: var(--muted); }
.plan-card .p-status { font-size: 12.5px; color: var(--ok); margin-top: 8px; font-weight: 600; }

.chat-form { display: flex; gap: 8px; padding: 10px 12px calc(var(--safe-bottom) + 10px); background: var(--bg); border-top: 1px solid var(--line); }
.chat-form input {
  flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  font-size: 15px; background: var(--card);
}
.send-btn {
  width: 48px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-size: 17px; cursor: pointer;
}

/* Settings */
.settings-title { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.settings-sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.settings-list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px 0; margin-bottom: 12px; }
.member-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; border-top: 1px solid var(--line); font-size: 14.5px;
}
.member-row:first-child { border-top: 0; }
.member-email { word-break: break-all; font-weight: 600; }
.member-tag {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 700; margin-left: 6px;
}
.remove-btn {
  border: 1px solid #e2b6b2; background: #fdf2f0; color: var(--err);
  border-radius: 9px; padding: 6px 12px; font-size: 12.5px; font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.muted { color: var(--muted); }
.add-row { display: flex; gap: 8px; }
.add-row input {
  flex: 1; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); font-size: 15px; background: var(--card);
}
.add-btn {
  border: 0; border-radius: 12px; background: var(--accent); color: #fff;
  padding: 0 18px; font-size: 14.5px; font-weight: 700; cursor: pointer;
}
.settings-msg { margin-top: 10px; font-size: 13px; color: var(--ok); font-weight: 600; }
.settings-msg.error { color: var(--err); }

/* Tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: flex; background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom);
}
.tabbar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 6px; border: 0; background: none; font-size: 20px; color: var(--muted); cursor: pointer;
}
.tabbar .tab span { font-size: 10.5px; font-weight: 600; }
.tabbar .tab.active { color: var(--accent); }

@media (min-width: 700px) {
  #app { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}