:root {
  --bg: #0E2A32;
  --bg-elevated: #123A44;
  --bg-card: #16434F;
  --line: rgba(245, 241, 230, 0.12);
  --gold: #F2B705;
  --coral: #FF6B4A;
  --terracotta: #E08A3C;
  --sage: #8FB996;
  --text: #F5F1E6;
  --text-dim: #AFC4C2;
  --radius: 14px;
  --font-display: "Fraunces", serif;
  --font-body: "Inter", sans-serif;
  --nav-height: 62px;
}

* { box-sizing: border-box; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
#app { min-height: 100vh; padding-bottom: var(--nav-height); }
a { color: inherit; }
.dim { color: var(--text-dim); }

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-weight: 600;
  font-size: 0.9rem;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(0.96); }
button.primary { background: var(--gold); color: #16303a; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--coral); color: #241010; }
button.small { padding: 0.4rem 0.85rem; font-size: 0.82rem; }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

input, textarea, select {
  font-family: var(--font-body);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 0.65rem 0.8rem;
  font-size: 1rem; /* 16px avoids iOS auto-zoom on focus */
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
label { font-size: 0.85rem; color: var(--text-dim); display: block; margin-bottom: 0.3rem; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 2rem;
  background: radial-gradient(circle at 20% 15%, rgba(242,183,5,0.12), transparent 40%),
              radial-gradient(circle at 80% 85%, rgba(255,107,74,0.10), transparent 45%), var(--bg);
  animation: fadeIn 0.4s ease;
}
.login-screen h1 { font-family: var(--font-display); font-size: clamp(2.2rem, 8vw, 4rem); font-weight: 600; margin: 0 0 0.3rem; }
.login-screen .sub { color: var(--text-dim); max-width: 380px; margin-bottom: 2.2rem; }
.google-btn {
  display: inline-flex; align-items: center; gap: 0.6rem;
  background: var(--text); color: #16303a; padding: 0.85rem 1.7rem;
  border-radius: 999px; font-weight: 700; text-decoration: none;
  transition: transform 0.12s ease;
}
.google-btn:active { transform: scale(0.96); }
.pending-notice { margin-top: 2rem; padding: 1rem 1.4rem; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text-dim); max-width: 380px; }

/* ---------- Top bar + bottom nav (mobile-first app shell) ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(14,42,50,0.94);
  backdrop-filter: blur(8px); z-index: 10;
}
.topbar .brand { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; }
.user-chip { display: flex; align-items: center; gap: 0.5rem; }
.topbar img.avatar { width: 28px; height: 28px; border-radius: 50%; }
.loading-msg { padding: 2rem; text-align: center; color: var(--text-dim); }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-height);
  display: flex; background: rgba(18,58,68,0.97); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav .tab {
  flex: 1; background: transparent; border-radius: 0; color: var(--text-dim);
  font-size: 0.78rem; padding: 0.4rem; display: flex; align-items: center; justify-content: center;
  border-top: 2px solid transparent;
}
.bottom-nav .tab.active { color: var(--gold); border-top-color: var(--gold); }
.bottom-nav .tab:active { transform: none; opacity: 0.7; }

main.container { max-width: 640px; margin: 0 auto; padding: 1.1rem 1rem 2rem; }

/* ---------- Calendar accordion ---------- */
.month-block { border-bottom: 1px solid var(--line); }
.month-header {
  width: 100%; display: flex; align-items: center; gap: 0.6rem;
  background: transparent; border: none; border-radius: 0;
  padding: 0.9rem 0.1rem; text-align: left;
}
.month-header:active { transform: none; opacity: 0.8; }
.month-title { font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; color: var(--text); flex: 1; }
.month-badge { font-size: 0.72rem; color: var(--gold); background: rgba(242,183,5,0.12); padding: 2px 8px; border-radius: 999px; }
.chevron { display: inline-block; color: var(--gold); font-size: 1.3rem; line-height: 1; transition: transform 0.25s ease; }
.chevron.open { transform: rotate(180deg); }

.month-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.3s ease; }
.month-body.open { grid-template-rows: 1fr; }
.month-body-inner { overflow: hidden; }
.month-body.open .month-body-inner { padding-bottom: 1rem; animation: slideDown 0.3s ease; }

.weekday-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 6px; }
.weekday-row div { text-align: center; font-size: 0.72rem; color: var(--text-dim); }
.day-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.day-cell {
  background: var(--bg-card); border-radius: 10px; min-height: 64px; padding: 0.35rem;
  border: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px;
  align-items: flex-start; text-align: left; width: 100%;
}
.day-cell:active { transform: scale(0.95); border-color: var(--gold); }
.day-cell.empty { background: transparent; border: none; }
.day-cell .day-num { font-size: 0.78rem; color: var(--text-dim); font-weight: 600; }
.day-cell.today .day-num { color: var(--gold); }
.day-cell.today { box-shadow: 0 0 0 1.5px var(--gold) inset; }
.presence-count { font-size: 0.65rem; color: var(--sage); }
.event-pill {
  font-size: 0.62rem; padding: 2px 5px; border-radius: 5px; color: #1a1310; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.more-pill { background: transparent !important; color: var(--text-dim) !important; font-weight: 400 !important; padding: 0 !important; }
.level-CISTA { background: var(--sage); }
.level-DANONPERDERE { background: var(--terracotta); }
.level-IRRIPETIBILE { background: var(--coral); }

/* ---------- Modal: bottom sheet on mobile ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,20,24,0);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; transition: background 0.22s ease;
}
.modal-backdrop.visible { background: rgba(6,20,24,0.7); }
.modal-backdrop.closing { background: rgba(6,20,24,0); }
.modal {
  background: var(--bg-elevated); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  max-width: 640px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 0.6rem 1.3rem 1.6rem;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal-backdrop.visible .modal { transform: translateY(0); }
.modal-backdrop.closing .modal { transform: translateY(100%); }
.modal-handle { width: 36px; height: 4px; background: var(--line); border-radius: 999px; margin: 0.6rem auto 0.8rem; }
.modal h2 { font-family: var(--font-display); margin: 0; font-size: 1.3rem; }
.close-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.3rem; gap: 0.6rem; }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 1rem; }
  .modal { border-radius: var(--radius); transform: translateY(12px) scale(0.98); opacity: 0; }
  .modal-backdrop.visible .modal { transform: translateY(0) scale(1); opacity: 1; }
  .modal-handle { display: none; }
}

.event-card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: 12px;
  padding: 0.9rem 1rem; margin-bottom: 0.8rem; animation: fadeIn 0.25s ease;
}
.event-card .title-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.event-card h3 { margin: 0; font-size: 1.02rem; }
.event-card p.desc { color: var(--text-dim); font-size: 0.86rem; margin: 0.4rem 0; }
.event-card .participants { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.4rem; }
.event-card .actions { display: flex; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }

.presence-list { list-style: none; padding: 0; margin: 0.5rem 0; }
.presence-list li { font-size: 0.85rem; padding: 0.35rem 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }

.form-grid { display: grid; gap: 0.75rem; margin-bottom: 1rem; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.68rem; font-weight: 700; }
.badge.pending { background: var(--terracotta); color: #241505; }
.badge.approved { background: var(--sage); color: #0e2018; }
.badge.rejected { background: var(--coral); color: #241010; }

.admin-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 0; border-bottom: 1px solid var(--line); gap: 0.6rem; flex-wrap: wrap;
  animation: fadeIn 0.25s ease;
}
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.section-title.small-title { font-size: 1.05rem; margin: 1.1rem 0 0.6rem; }
.section-title { font-family: var(--font-display); font-size: 1.35rem; margin: 1.4rem 0 0.8rem; color: var(--gold); }
.section-title:first-child { margin-top: 0; }

.empty-state { color: var(--text-dim); padding: 1.5rem 0; text-align: center; animation: fadeIn 0.25s ease; }

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
main.container { animation: fadeIn 0.22s ease; }

@media (min-width: 640px) {
  .day-cell { min-height: 76px; }
}
