:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel-soft: #f2f6fb;
  --text: #18202b;
  --muted: #647083;
  --line: #dce4ee;
  --primary: #1769e0;
  --primary-strong: #0f56bd;
  --accent: #138a75;
  --glow: rgba(23, 105, 224, 0.18);
  --warn: #c56a14;
  --danger: #c43d4b;
  --success: #21865b;
  --shadow: 0 12px 32px rgba(20, 31, 48, 0.12);
}

[data-theme="dark"] {
  --bg: #0c1118;
  --panel: #141b25;
  --panel-soft: #1d2733;
  --text: #ecf2f7;
  --muted: #a6b3c2;
  --line: #2c3948;
  --primary: #6ca4ff;
  --primary-strong: #94bcff;
  --accent: #54c7ad;
  --glow: rgba(108, 164, 255, 0.2);
  --warn: #e3a146;
  --danger: #ff7582;
  --success: #67d59d;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--primary) 10%, transparent), transparent 340px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; }
.database-status { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 13px; }
.database-status > span { flex: 1 1 240px; overflow-wrap: anywhere; }
.database-status[data-status="connected"] { color: var(--success); }
.database-status[data-status="offline"], .database-status[data-status="conflict"] { color: var(--danger); }
.database-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.database-actions .btn { font-size: 13px; min-height: 40px; }
[hidden] { display: none !important; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 260px minmax(220px, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 64px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; color: white; background: linear-gradient(135deg, #1769e0, #138a75); box-shadow: 0 0 24px var(--glow); }
.searchbar { display: flex; gap: 8px; }
.searchbar input, .field, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
}
textarea { resize: vertical; min-height: 88px; }
.top-actions { display: flex; align-items: center; justify-content: end; gap: 8px; }
.theme-switch { width: auto; min-height: 38px; border-radius: 999px; padding: 7px 12px; border: 1px solid var(--line); background: var(--panel-soft); color: var(--text); font-weight: 800; }
.icon-btn, .btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  min-height: 38px;
  border-radius: 8px;
  padding: 8px 11px;
}
.btn { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn.ghost { background: transparent; }
.badge { display: inline-flex; align-items: center; min-height: 22px; border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 800; background: var(--panel-soft); color: var(--muted); }
.badge.success { color: var(--success); }
.badge.warn { color: var(--warn); }
.badge.danger { color: var(--danger); }
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 720px) 300px;
  gap: 18px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px;
}
.sidebar, .rightbar { position: sticky; top: 82px; align-self: start; display: grid; gap: 12px; }
.rightbar { height: calc(100vh - 100px); min-height: 520px; }
.main { display: grid; gap: 14px; min-width: 0; }
.panel, .card, .modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel, .card { outline: 1px solid color-mix(in srgb, var(--primary) 8%, transparent); }
.panel { padding: 14px; }
.nav-list { display: grid; gap: 6px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; border: 0; background: transparent; color: var(--text); padding: 10px; border-radius: 8px; text-align: left; }
.nav-item.active, .nav-item:hover { background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 12%, var(--panel-soft)), var(--panel-soft)); }
.name-link { border: 0; background: transparent; color: inherit; padding: 0; font-weight: 800; text-align: left; }
.name-link:hover, .name-link:focus-visible { color: var(--primary-strong); text-decoration: underline; }
.message.mine .name-link { color: white; }
.composer { display: grid; gap: 10px; }
.composer-tools, .row, .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.location-picker { display: grid; gap: 7px; padding: 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-soft); }
.location-picker > label { font-size: 13px; font-weight: 800; }
.optional { color: var(--muted); font-size: 11px; font-weight: 600; margin-left: 5px; }
.location-suggestion { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.hashtag-toggle { display: inline-flex; align-items: center; gap: 4px; color: var(--primary-strong); }
.hashtag-toggle input { accent-color: var(--primary); }
.field-hint { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; background: var(--panel-soft); border: 2px solid var(--panel); }
.avatar.lg { width: 96px; height: 96px; }
.post { padding: 14px; display: grid; gap: 12px; }
.post-head { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.post-meta { color: var(--muted); font-size: 13px; }
.post-context { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.post-context button { border: 0; padding: 0; background: transparent; color: var(--primary-strong); font-weight: 750; }
.post-body { line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.media-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.media-grid img, .media-grid video, .cover { width: 100%; border-radius: 8px; object-fit: cover; background: var(--panel-soft); }
.media-grid img, .media-grid video { max-height: 320px; }
.link-preview { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 4px; background: var(--panel-soft); }
.reaction-bar { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--line); padding-top: 10px; }
.reaction { border: 1px solid var(--line); border-radius: 999px; padding: 6px 9px; background: var(--panel); }
.reaction.active { border-color: var(--primary); color: var(--primary); font-weight: 800; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 22%, transparent); }
.reaction-count { margin-left: 4px; font-size: .82rem; font-weight: 800; }
.comment-reactions { flex-wrap: wrap; overflow: visible; }
.comment-reaction { display: inline-flex; align-items: center; gap: 2px; padding: 5px 7px; }
.comment-reaction.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.reaction-with-tooltip { position: relative; overflow: visible; }
.reaction-with-tooltip::after {
  content: attr(data-reaction-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 1100;
  width: max-content;
  max-width: min(260px, 75vw);
  padding: 6px 9px;
  border-radius: 7px;
  background: #172033;
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: normal;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s ease;
}
.reaction-with-tooltip:hover::after,
.reaction-with-tooltip:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}
[data-theme="dark"] .reaction,
[data-theme="dark"] .reaction.active { color: #fff; }
.comments { display: grid; gap: 8px; }
.comment { display: grid; grid-template-columns: 34px 1fr; gap: 8px; }
.comment .avatar { width: 34px; height: 34px; }
.bubble { background: var(--panel-soft); border-radius: 8px; padding: 8px 10px; }
.reply { margin-left: 42px; }
.reply-stack { display: grid; gap: 8px; margin-top: 8px; }
.reply-toggle { width: fit-content; border: 0; background: transparent; color: var(--primary-strong); padding: 6px 0; font-weight: 800; }
.reply-toggle:hover, .reply-toggle:focus-visible { text-decoration: underline; }
.comment-composer { display: grid; gap: 8px; margin-top: 8px; }
.reply-composer { margin-left: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: color-mix(in srgb, var(--panel) 72%, var(--panel-soft)); }
.comment-input-row { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; }
.emoji-menu { position: relative; }
.emoji-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(5, 36px);
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .14s ease, transform .14s ease;
}
.emoji-menu:hover .emoji-popover, .emoji-menu:focus-within .emoji-popover { opacity: 1; pointer-events: auto; transform: translateY(0); }
.chip { min-height: 36px; min-width: 36px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text); }
.comment-attachments { display: grid; gap: 6px; margin-top: 8px; }
.comment-image { max-width: min(260px, 100%); max-height: 180px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }
.comment-link { display: grid; gap: 2px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.tab { white-space: nowrap; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 800; }
.tab.active { color: var(--text); background: var(--panel-soft); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.profile-cover { height: 210px; border-radius: 8px; background-size: cover; background-position: center; }
.profile-head { display: flex; align-items: end; gap: 14px; margin-top: -52px; padding: 0 18px 16px; }
.messages { display: grid; grid-template-columns: 260px 1fr; min-height: 520px; overflow: hidden; }
.conversation-list { border-right: 1px solid var(--line); overflow: auto; }
.conversation-list button { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); padding: 12px; text-align: left; }
.conversation-list button.active { background: var(--panel-soft); }
.thread { display: grid; grid-template-rows: 1fr auto; min-height: 520px; }
.message-stream { padding: 14px; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.message { max-width: 72%; border-radius: 8px; padding: 9px 11px; background: var(--panel-soft); }
.message.mine { align-self: end; background: var(--primary); color: white; }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(9, 13, 20, .55); display: grid; place-items: center; padding: 18px; }
.modal-box { width: min(620px, 100%); max-height: 88vh; overflow: auto; padding: 18px; }
.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--panel); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); max-width: 320px; }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, rgba(23,105,224,.18), rgba(19,138,117,.16)); }
.auth-card { width: min(980px, 100%); display: grid; grid-template-columns: 1fr 420px; overflow: hidden; }
.auth-hero { padding: 42px; background: #102033; color: white; display: grid; align-content: center; gap: 14px; }
.auth-panels { min-width: 0; }
.auth-form { padding: 28px; display: grid; gap: 12px; }
.auth-note { color: rgba(255,255,255,.75); font-size: 14px; }
.auth-link { color: var(--primary); font-size: 13px; font-weight: 750; text-align: center; text-decoration: underline; text-underline-offset: 3px; }
.consent-copy { padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-soft); color: var(--muted); font-size: 12px; line-height: 1.45; }
.consent-copy strong { color: var(--text); font-size: 13px; }
.consent-copy p { margin: 6px 0 0; }
.consent { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.consent input { width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--primary); flex: 0 0 auto; }
.consent strong { color: var(--text); }
.admin-import { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; padding: 16px; border-radius: 8px; background: var(--panel-soft); }
.admin-import h3 { margin: 0 0 4px; }
.admin-import p { margin: 0; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.mobile-nav { display: none; }
.mobile-map-toggle, .map-drawer-close, .mobile-map-backdrop { display: none; }
.map-panel { height: 100%; padding: 0; overflow: hidden; }
.map-panel > summary { display: none; }
.map-content { height: 100%; display: grid; grid-template-rows: auto minmax(280px, 4fr) minmax(72px, 1fr); }
.map-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.map-heading h3, .map-heading p { margin: 0; }
.map-heading p { margin-top: 2px; color: var(--muted); font-size: 12px; }
.map-reset { min-height: 32px; padding: 5px 8px; font-size: 12px; }
#cebu-activity-map { width: 100%; height: 150%; min-height: 320px; background: #dce9e2; isolation: isolate; }
.map-trending { align-self: stretch; display: grid; align-content: center; gap: 7px; padding: 11px 12px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.map-trending > span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.map-trending > div { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: thin; }
.map-trend-chip { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px; background: var(--panel-soft); color: var(--primary-strong); font-size: 11px; font-weight: 800; }
.map-trend-chip b { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 3px; border-radius: 999px; background: var(--primary); color: white; font-size: 10px; }
.map-empty, .map-unavailable { margin: 0; padding: 14px; color: var(--muted); font-size: 12px; }
.map-unavailable { display: grid; height: 100%; place-items: center; text-align: center; background: var(--panel-soft); }
.activity-marker-shell { background: transparent; border: 0; }
.activity-marker { position: relative; display: grid; place-items: center; width: 38px; height: 38px; border: 3px solid white; border-radius: 50% 50% 50% 12%; transform: rotate(-45deg); background: linear-gradient(135deg, var(--primary), var(--accent)); color: white; font-size: 13px; font-weight: 900; box-shadow: 0 5px 14px rgba(9, 28, 48, .35); }
.activity-marker b { transform: rotate(45deg); color: white; line-height: 1; }
.map-popup { display: grid; gap: 5px; font-family: Inter, ui-sans-serif, system-ui, sans-serif; }
.map-popup > span, .map-popup > small { color: #647083; font-size: 12px; }
.popup-tags { display: grid; gap: 4px; margin-top: 3px; }
.popup-tags button { display: flex; justify-content: space-between; gap: 12px; border: 0; border-radius: 6px; padding: 6px 8px; background: #eef3f8; color: #0f56bd; text-align: left; font-weight: 750; }
@media (max-width: 1080px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr); }
  .rightbar { display: block; grid-column: 2; position: static; height: auto; min-height: 0; }
  .map-panel { height: auto; }
  .map-panel > summary { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; list-style: none; }
  .map-panel > summary::-webkit-details-marker { display: none; }
  .map-panel > summary span:first-child { display: grid; gap: 2px; }
  .map-panel > summary small { color: var(--muted); font-weight: 500; }
  .map-chevron { transition: transform .18s ease; }
  .map-panel[open] .map-chevron { transform: rotate(180deg); }
  .map-panel[open] > summary { border-bottom: 1px solid var(--line); }
  .map-content { height: 440px; }
}
@media (max-width: 760px) {
  body { background: var(--bg); }
  .topbar { grid-template-columns: 1fr auto; gap: 10px; min-height: 56px; padding: 8px 12px; border-bottom-color: color-mix(in srgb, var(--primary) 16%, var(--line)); }
  .brand { font-size: 17px; }
  .brand-mark { width: 32px; height: 32px; }
  .top-actions .btn { display: none; }
  .top-actions .mobile-map-toggle { display: inline-flex; min-height: 36px; border-radius: 999px; padding: 6px 10px; }
  .theme-switch { min-height: 34px; max-width: 94px; padding: 6px 9px; }
  .searchbar { grid-column: 1 / -1; order: 3; }
  .searchbar input { min-height: 42px; border-radius: 999px; background: var(--panel-soft); }
  .searchbar .btn { min-width: 44px; border-radius: 999px; }
  .layout { display: block; padding: 8px 8px 86px; }
  .sidebar { display: none; }
  .main { margin-top: 8px; gap: 10px; }
  .rightbar.mobile-map-drawer { position: fixed; inset: 0 0 0 auto; z-index: 50; display: block; width: min(94vw, 430px); height: 100dvh; min-height: 0; margin: 0; transform: translateX(105%); transition: transform .26s ease, visibility 0s linear .26s; background: var(--panel); box-shadow: -18px 0 42px rgba(9, 20, 35, .3); visibility: hidden; }
  .rightbar.mobile-map-drawer.open { transform: translateX(0); visibility: visible; transition-delay: 0s; }
  .mobile-map-backdrop { position: fixed; inset: 0; z-index: 49; border: 0; padding: 0; background: rgba(9, 20, 35, .48); opacity: 0; pointer-events: none; transition: opacity .26s ease; }
  .mobile-map-backdrop.open { display: block; opacity: 1; pointer-events: auto; }
  .map-drawer-close { position: absolute; top: 10px; right: 10px; z-index: 55; display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--text); font-size: 28px; line-height: 1; box-shadow: var(--shadow); }
  .rightbar .map-panel { height: 100%; border: 0; border-radius: 0; }
  .rightbar .map-panel > summary { min-height: 62px; padding-right: 64px; pointer-events: none; }
  .rightbar .map-chevron { display: none; }
  .map-content { height: calc(100dvh - 62px); }
  .map-heading { display: none; }
  #cebu-activity-map { height: 100%; min-height: 0; }
  .panel, .card { border-radius: 8px; box-shadow: 0 8px 22px rgba(17, 28, 43, 0.1); }
  .panel { padding: 12px; }
  .post { padding: 12px; gap: 10px; }
  .composer-tools { display: grid; grid-template-columns: 1fr 1fr; }
  .composer-tools textarea, .composer-tools .primary { grid-column: 1 / -1; }
  .post-head { align-items: flex-start; }
  .actions { gap: 6px; }
  .icon-btn, .btn { min-height: 42px; }
  .reaction-bar { display: grid; grid-template-columns: repeat(3, 1fr); }
  .reaction { min-height: 40px; padding: 7px 6px; }
  .comment-input-row { grid-template-columns: 1fr auto; }
  .comment-input-row .btn { grid-column: 1 / -1; justify-content: center; }
  .emoji-popover { right: 0; grid-template-columns: repeat(5, 34px); }
  .reply { margin-left: 18px; }
  .auth-card { grid-template-columns: 1fr; }
  .auth-screen { align-items: stretch; padding: 0; }
  .auth-card { min-height: 100vh; border: 0; border-radius: 0; }
  .auth-hero { padding: 28px 20px; align-content: end; min-height: 34vh; }
  .auth-form { padding: 20px; }
  .admin-import { align-items: flex-start; flex-direction: column; }
  .profile-cover { height: 150px; border-radius: 0 0 8px 8px; }
  .profile-head { align-items: center; margin-top: -42px; }
  .messages { grid-template-columns: 1fr; }
  .conversation-list { max-height: 180px; border-right: 0; border-bottom: 1px solid var(--line); }
  .mobile-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 25; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 8px 8px max(8px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--panel) 92%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(16px); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); min-height: 52px; padding: 7px 4px; border-radius: 8px; font-size: 11px; font-weight: 800; }
  .mobile-nav button.active { background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 16%, var(--panel-soft)), var(--panel-soft)); color: var(--primary-strong); }
  .toast-region { left: 12px; right: 12px; bottom: 78px; }
  .toast { max-width: none; }
}
