@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;0,9..144,700;1,9..144,500&family=Work+Sans:wght@400;500;600;700&display=swap');

:root {
  --wine: #3B1220;
  --wine-light: #5A1C33;
  --paper: #F6EFE4;
  --paper-alt: #EEE3CE;
  --gold: #C89B3C;
  --gold-light: #E4C778;
  --sage: #6B7658;
  --ink: #2A2420;
  --ink-soft: #786C5E;
  --danger: #A33A2E;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(59, 18, 32, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Work Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--wine);
  margin: 0;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
}

a { color: inherit; }

button {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.3rem;
  background: var(--wine);
  color: var(--paper);
  font-weight: 600;
  transition: transform 0.12s ease, background 0.12s ease;
}
button:hover { background: var(--wine-light); }
button:active { transform: scale(0.97); }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
button.secondary {
  background: transparent;
  color: var(--wine);
  border: 1.5px solid var(--wine);
}
button.secondary:hover { background: rgba(59,18,32,0.06); }
button.ghost {
  background: transparent;
  color: var(--ink-soft);
  padding: 0.4rem 0.7rem;
}
button.danger { background: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--paper-alt);
  background: #fff;
  border-radius: 10px;
  color: var(--ink);
}
input:focus, textarea:focus { border-color: var(--gold); outline: none; }
label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field { margin-bottom: 1rem; }

/* ---------- Auth screen ---------- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 15% 20%, rgba(200,155,60,0.14), transparent 45%),
    var(--wine);
}
.auth-card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.4rem;
  width: 100%;
  max-width: 420px;
}
.auth-card .brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}
.auth-card .brand .seal {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--wine);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 1rem;
}
.auth-card h1 { font-size: 1.7rem; }
.auth-card p.tag { color: var(--ink-soft); margin: 0.2rem 0 1.6rem; font-size: 0.95rem; }
.auth-tabs { display: flex; gap: 0.4rem; margin-bottom: 1.4rem; }
.auth-tabs button { flex: 1; background: var(--paper-alt); color: var(--ink-soft); }
.auth-tabs button.active { background: var(--wine); color: var(--paper); }
.auth-error {
  background: rgba(163,58,46,0.1);
  color: var(--danger);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

/* ---------- App shell ---------- */
#app-screen { display: none; min-height: 100vh; }
#app-screen.visible { display: flex; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--wine);
  color: var(--paper);
  padding: 1.6rem 1.1rem;
  display: flex;
  flex-direction: column;
}
.sidebar .brand { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 2rem; }
.sidebar .brand .seal {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gold); color: var(--wine);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif; font-weight: 700;
}
.sidebar .brand span { font-family: 'Fraunces', serif; font-size: 1.15rem; color: var(--paper); }
.nav-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  color: rgba(246,239,228,0.75);
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 0.2rem;
  position: relative;
}
.nav-item:hover { background: rgba(246,239,228,0.08); color: var(--paper); }
.nav-item.active { background: rgba(246,239,228,0.14); color: var(--gold-light); }
.nav-item .badge {
  margin-left: auto;
  background: var(--gold);
  color: var(--wine);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
}
.sidebar .spacer { flex: 1; }
.sidebar .me {
  display: flex; align-items: center; gap: 0.6rem;
  padding-top: 1rem; border-top: 1px solid rgba(246,239,228,0.15);
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--gold-light); color: var(--wine);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-family: 'Fraunces', serif; flex-shrink: 0;
}
.sidebar .me .name { font-size: 0.9rem; font-weight: 600; color: var(--paper); }
.sidebar .me .user { font-size: 0.78rem; color: rgba(246,239,228,0.6); }
.sidebar .logout { margin-left: auto; }

.main { flex: 1; min-width: 0; overflow-y: auto; height: 100vh; }
.topbar {
  padding: 1.4rem 2rem 0.5rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.topbar h2 { font-size: 1.5rem; }
.view { padding: 1.2rem 2rem 2.5rem; }

.search-row { display: flex; gap: 0.6rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.search-row input { flex: 1; min-width: 180px; }
.search-row select { border: 1.5px solid var(--paper-alt); border-radius: 10px; padding: 0.65rem 0.8rem; background: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }

.place-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column;
  border-top: 3px solid var(--gold);
}
.place-card .thumb {
  height: 130px; background: linear-gradient(135deg, var(--paper-alt), var(--paper));
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-size: 2.1rem; font-family: 'Fraunces', serif; position: relative;
  background-size: cover; background-position: center;
}
.place-card .stamp {
  position: absolute; top: 10px; right: 10px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--wine); color: var(--gold-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; border: 2px solid var(--gold);
}
.place-card .body { padding: 0.9rem 1rem 1.1rem; flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.place-card .cat {
  text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.06em;
  color: var(--sage); font-weight: 700;
}
.place-card h3 { font-size: 1.1rem; }
.place-card .meta { font-size: 0.83rem; color: var(--ink-soft); }
.place-card .desc { font-size: 0.87rem; color: var(--ink); flex: 1; }
.place-card .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.4rem; }
.place-card .actions button { flex: 1 1 auto; min-width: 0; font-size: 0.85rem; padding: 0.5rem; white-space: nowrap; }
.place-card .actions > a { flex: 1 1 auto; min-width: 0; }
.place-card .actions > a button { width: 100%; }
.place-card .author { font-size: 0.76rem; color: var(--ink-soft); }
.verify-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.2rem; }
.verified-badge {
  font-size: 0.76rem; font-weight: 700; color: var(--sage);
  background: rgba(107,118,88,0.12); padding: 0.2rem 0.55rem; border-radius: 999px;
}

.empty {
  text-align: center; padding: 3rem 1rem; color: var(--ink-soft);
}
.empty .display { font-size: 1.3rem; margin-bottom: 0.4rem; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(42,36,32,0.55);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 1000;
}
.modal {
  background: var(--paper); border-radius: var(--radius); padding: 1.8rem;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal h2 { margin-bottom: 1.2rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.8rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; }

/* ---------- Friends ---------- */
.friend-row {
  display: flex; align-items: center; gap: 0.8rem;
  background: #fff; border-radius: 12px; padding: 0.7rem 1rem; margin-bottom: 0.6rem;
  box-shadow: var(--shadow);
}
.friend-row .info { flex: 1; min-width: 0; }
.friend-row .info .name { font-weight: 600; }
.friend-row .info .user { font-size: 0.82rem; color: var(--ink-soft); }
.friend-row .row-actions { display: flex; gap: 0.4rem; }
.friend-row .row-actions button { padding: 0.45rem 0.8rem; font-size: 0.85rem; }
.section-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--sage); font-weight: 700; margin: 1.4rem 0 0.6rem; }

/* ---------- Chat ---------- */
.chat-layout {
  display: flex;
  height: calc(100vh - 90px);
  height: calc(100dvh - 90px);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #fff;
}
.map-canvas {
  height: calc(100vh - 220px);
  height: calc(100dvh - 220px);
  min-height: 360px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.chat-list { width: 280px; flex-shrink: 0; border-right: 1px solid var(--paper-alt); overflow-y: auto; }
.chat-list .conv {
  display: flex; gap: 0.7rem; padding: 0.8rem 1rem; cursor: pointer; border-bottom: 1px solid var(--paper-alt);
}
.chat-list .conv:hover, .chat-list .conv.active { background: var(--paper); }
.chat-list .conv .info { flex: 1; min-width: 0; }
.chat-list .conv .name { font-weight: 600; font-size: 0.93rem; }
.chat-list .conv .preview { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-window { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header { padding: 0.9rem 1.2rem; border-bottom: 1px solid var(--paper-alt); font-weight: 600; flex-shrink: 0; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; }
.bubble { max-width: 65%; padding: 0.6rem 0.9rem; border-radius: 14px; font-size: 0.92rem; line-height: 1.4; }
.bubble.mine { align-self: flex-end; background: var(--wine); color: var(--paper); border-bottom-right-radius: 4px; }
.bubble.theirs { align-self: flex-start; background: var(--paper-alt); color: var(--ink); border-bottom-left-radius: 4px; }
.bubble.place-share { border: 1.5px solid var(--gold); background: #fff; color: var(--ink); }
.bubble.place-share .p-name {
  font-family: 'Fraunces', serif; color: var(--wine); font-weight: 600;
  display: block; margin-bottom: 0.15rem;
  text-decoration: underline; text-underline-offset: 2px;
}
.bubble.place-share .p-name:visited { color: var(--wine); }
.bubble.place-share .p-name:hover { color: var(--gold); }
.chat-input { display: flex; gap: 0.6rem; padding: 0.9rem; border-top: 1px solid var(--paper-alt); flex-shrink: 0; }
.chat-input input { flex: 1; }

.toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 0.7rem 1.2rem; border-radius: 999px;
  font-size: 0.88rem; box-shadow: var(--shadow); z-index: 1100;
}

/* ---------- Mobile ---------- */
.tabbar { display: none; }
@media (max-width: 820px) {
  .sidebar { display: none; }
  #app-screen.visible { flex-direction: column; }
  .main { height: auto; padding-bottom: 84px; }
  .form-grid { grid-template-columns: 1fr; }
  .chat-layout {
    height: calc(100vh - 175px - env(safe-area-inset-bottom));
    height: calc(100dvh - 175px - env(safe-area-inset-bottom));
    flex-direction: column;
  }
  .chat-list { width: 100%; max-height: none; flex: 1; }
  .chat-layout.show-list .chat-window { display: none; }
  .chat-layout.show-conversation .chat-list { display: none; }
  .chat-layout.show-conversation .chat-window { flex: 1; }
  .map-canvas {
    height: 52vh;
    height: 52dvh; /* dvh = alto real de pantalla en móvil, sin contar barras del navegador que aparecen/desaparecen */
    min-height: 280px;
  }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--wine); padding: 0.6rem 0.3rem calc(0.6rem + env(safe-area-inset-bottom));
    z-index: 40; justify-content: space-around;
  }
  .tabbar .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem;
    color: rgba(246,239,228,0.65); font-size: 0.74rem; font-weight: 600; cursor: pointer; position: relative;
    padding: 0.4rem 0.6rem; border-radius: 12px; min-width: 60px; min-height: 52px;
  }
  .tabbar .tab span { font-size: 1.55rem; line-height: 1; }
  .tabbar .tab.active { color: var(--gold-light); background: rgba(246,239,228,0.1); }
  .tabbar .tab .dot {
    position: absolute; top: 2px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--gold);
  }
}

/* ---------- Banner de instalar la app ---------- */
#pwa-install-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  background: var(--wine);
  color: var(--paper);
  padding: 0.6rem 1rem;
  padding-top: calc(0.6rem + env(safe-area-inset-top));
  font-size: 0.85rem;
  position: sticky;
  top: 0;
  z-index: 60;
}
#pwa-install-banner button#btn-install-pwa {
  background: var(--gold);
  color: var(--wine);
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
}
#pwa-install-banner button.ghost {
  background: transparent;
  padding: 0.4rem 0.6rem;
}
