/* ── Memora ─────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:          #f0eeea;
  --bg2:         #e8e6e1;
  --surface:     #ffffff;
  --sidebar-bg:  #1c1b18;
  --sidebar-txt: #c8c6c0;
  --sidebar-act: #ffffff;
  --sidebar-hover: rgba(255,255,255,0.08);
  --border:      #e0ddd7;
  --text:        #18170f;
  --muted:       #6e6b62;
  --accent:      #4e6d9e;
  --accent-h:    #3d5880;
  --accent-rgb:  78,109,158;
  --danger:      #b94040;
  --radius:      12px;
  --radius-sm:   8px;
  --sidebar-w:   240px;
  --topbar-h:    56px;
  --font:        'Inter', system-ui, -apple-system, sans-serif;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App shell ──────────────────────────────────────────────────── */

.app-shell {
  display: flex;
  min-height: 100dvh;
}

/* ── Sidebar ────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 30;
  padding: 0;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.25rem 1rem;
}

.sidebar-logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--sidebar-act);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  margin-bottom: 1.75rem;
  display: block;
}
.sidebar-logo:hover { text-decoration: none; }

.sidebar-section {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: 0 0.5rem;
  margin-bottom: 0.35rem;
  margin-top: 1.25rem;
}
.sidebar-section:first-of-type { margin-top: 0; }

.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

.sidebar-nav li + li { margin-top: 2px; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-txt);
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: var(--sidebar-act); text-decoration: none; }
.sidebar-nav a.active { background: rgba(255,255,255,0.12); color: var(--sidebar-act); }

.sidebar-nav .nav-icon {
  width: 18px; height: 18px;
  opacity: 0.7;
  flex-shrink: 0;
}
.sidebar-nav a.active .nav-icon,
.sidebar-nav a:hover .nav-icon { opacity: 1; }

.sidebar-add-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff !important;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.12s;
  margin-bottom: 0.25rem;
}
.sidebar-add-btn:hover { background: var(--accent-h); text-decoration: none; color: #fff !important; }
.sidebar-add-btn .nav-icon { opacity: 1 !important; }

.sidebar-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 1rem 0;
}

.sidebar-profile {
  padding: 0.65rem 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-username {
  font-size: 0.82rem;
  color: var(--sidebar-txt);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-logout {
  display: flex;
  align-items: center;
  color: rgba(255,255,255,0.35);
  transition: color 0.12s;
}
.sidebar-logout:hover { color: rgba(255,255,255,0.7); text-decoration: none; }
.sidebar-logout svg { width: 16px; height: 16px; }

/* ── Main area ──────────────────────────────────────────────────── */

.app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Timeline app-shell overrides ──────────────────────────────── */

/* Blocca lo scroll del body: la pagina non deve mai scorrere sulla timeline */
body.is-timeline {
  overflow: hidden;
  height: 100dvh;
}
body.is-timeline .app-shell { overflow: hidden; }
body.is-timeline .app-main  { overflow: hidden; }

.is-timeline .content--timeline {
  padding: 0;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* l'altezza viene impostata da JS (fixHeights) con valori pixel misurati */
}

/* ── Swiper timeline ────────────────────────────────────────────── */

.timeline-swiper {
  width: 100%;
  overflow: hidden;
  flex-shrink: 0;
  /* altezza impostata da JS */
}

.timeline-swiper .swiper-wrapper { height: 100% !important; }

/* Year slides */
.year-slide {
  height: 100% !important;
  display: flex;
  user-select: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.year-slide:not(.swiper-slide-active) {
  opacity: 0.38;
  transform: scale(0.95);
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .year-slide { transition: none !important; }
}

.year-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  overflow: hidden;
  margin: 0 6px;
}

@media (max-width: 720px) {
  .year-panel { margin: 0; border-radius: 0; }
}

/* Year header */
.year-header {
  flex-shrink: 0;
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 1rem;
}

.year-number {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

.year-meta {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}

@media (max-width: 720px) {
  .year-header { padding: 1.1rem 1rem 0.85rem; }
  .year-number { font-size: 1.85rem; }
}

/* Memory list inside slide — altezza impostata da JS */
.year-memories-scroll {
  /* NON usare flex:1 qui: l'altezza viene fissata in px da JS */
  flex-shrink: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y; /* mobile: scroll verticale passa al browser, non a Swiper */
  padding: 1rem 1.5rem 1rem;
}

@media (max-width: 720px) {
  .year-memories-scroll { padding: 0.75rem 0.85rem 0.75rem; }
}

/* Compact memory card in timeline */
.tl-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s;
  margin-bottom: 2px;
}
.tl-card:hover {
  background: var(--bg);
  text-decoration: none;
  color: var(--text);
}
.tl-card-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  margin-top: 6px;
  transition: background 0.12s;
}
.tl-card:hover .tl-card-dot { background: var(--accent); }

.tl-card-body { flex: 1; min-width: 0; }

.tl-card-date {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}
.tl-card-title {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-card-excerpt {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tl-card-photo {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
}
.tl-card-photo svg { width: 12px; height: 12px; }

.tl-card-event {
  color: var(--accent);
}

.event-card .tl-card-photo {
  font-size: 0.72rem;
}

/* Slide nav hints (prev/next year) */
.year-nav {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  gap: 0.5rem;
}
.year-nav-btn {
  background: none; border: none; cursor: pointer;
  font-family: var(--font);
  font-size: 0.75rem;
  color: var(--muted);
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  border-radius: 5px;
  transition: color 0.12s, background 0.12s;
}
.year-nav-btn:hover { color: var(--text); background: var(--bg); }
.year-nav-btn svg { width: 14px; height: 14px; }
.year-nav-btn:disabled { opacity: 0.25; cursor: default; }
.year-nav-btn:disabled:hover { background: none; color: var(--muted); }

@media (max-width: 720px) {
  .year-nav { padding: 0.5rem 0.85rem; }
}

/* ── Time scrubber ──────────────────────────────────────────────── */

.time-scrubber {
  flex-shrink: 0;
  height: 44px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 1rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.time-scrubber::-webkit-scrollbar { display: none; }

.scrubber-dot {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 5px;
  border-radius: 5px;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
  font-family: var(--font);
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.scrubber-dot:hover { color: var(--text); background: var(--bg); }
.scrubber-dot.active {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.75rem;
}

/* Density tick below label */
.scrubber-dot::after {
  content: attr(data-tick);
  display: block;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.3;
  margin-top: 2px;
  transition: opacity 0.15s;
}
.scrubber-dot.active::after { opacity: 1; }

/* ── Topbar (inside main, desktop) ─────────────────────────────── */

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}

.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ── Content ────────────────────────────────────────────────────── */

.content {
  padding: 2rem 2rem;
  max-width: 680px;
  width: 100%;
}

/* ── Buttons ────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.12s, box-shadow 0.12s;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-h); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg2); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger {
  background: #fdf0f0;
  color: var(--danger);
  border: 1px solid #f0d0d0;
}
.btn-danger:hover { background: #f7e0e0; }

.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }
.btn-xs { padding: 0.25rem 0.6rem; font-size: 0.75rem; }

/* ── Flash ──────────────────────────────────────────────────────── */

.flash {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.flash-success { background: #edf7ed; color: #285c28; border: 1px solid #bde3bd; }
.flash-error   { background: #fdf0f0; color: #7a2020; border: 1px solid #f0c3c3; }

/* ── Timeline ───────────────────────────────────────────────────── */

.timeline-group { margin-bottom: 0.25rem; }

.timeline-year-marker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.75rem 0 0.75rem;
}
.timeline-year-marker:first-child { margin-top: 0; }

.timeline-year-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.timeline-year-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.memory-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.memory-card:hover {
  border-color: rgba(var(--accent-rgb), 0.4);
  box-shadow: 0 2px 12px rgba(var(--accent-rgb), 0.08);
  transform: translateY(-1px);
  text-decoration: none;
  color: var(--text);
}

.memory-card-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 3px;
  flex-shrink: 0;
  width: 40px;
}
.memory-card-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg2);
  transition: background 0.15s;
  margin-bottom: 4px;
}
.memory-card:hover .memory-card-dot { background: var(--accent); }

.memory-card-body { flex: 1; min-width: 0; }

.memory-card-meta {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.memory-card-title {
  font-weight: 600;
  font-size: 0.93rem;
  margin-bottom: 0.2rem;
  line-height: 1.4;
}

.memory-card-excerpt {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 5rem 2rem;
  color: var(--muted);
}
.empty-icon {
  width: 48px; height: 48px;
  margin-bottom: 1rem;
  opacity: 0.35;
}
.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
}
.empty-state p {
  margin: 0 0 1.5rem;
  font-size: 0.88rem;
}

/* ── Form ───────────────────────────────────────────────────────── */

.form-wrap { max-width: 580px; }

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.form-body { padding: 1.5rem 1.75rem; }

.form-group { margin-bottom: 1.25rem; }
.form-group:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 0.4rem;
  color: var(--muted);
  text-transform: uppercase;
}
label .optional {
  font-weight: 400;
  color: var(--border);
  margin-left: 0.3rem;
  text-transform: none;
}

.content-textarea {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  resize: vertical;
  min-height: 140px;
  line-height: 1.65;
}
.content-textarea::placeholder { color: var(--muted); opacity: 0.6; }
.content-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  padding: 0.55rem 0.8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  line-height: 1.4;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}
input::placeholder { color: var(--muted); opacity: 0.5; }

/* Date pills */
.date-compact {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.date-compact .date-compact-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}

.date-compact .date-compact-head label {
  margin: 0;
}

.date-precision-group {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
}
.precision-option { position: relative; }
.precision-option input[type="radio"] {
  position: absolute; opacity: 0; width: 0; height: 0;
}
.precision-option label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.34rem 0.35rem;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface);
  transition: all 0.12s;
  letter-spacing: 0;
  text-transform: none;
  margin: 0;
  min-height: 30px;
  width: 100%;
  text-align: center;
  white-space: nowrap;
}
.precision-option input[type="radio"]:checked + label {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.precision-option label:hover { border-color: var(--accent); color: var(--accent); }

.date-fields-panel { display: none; margin-top: 0.65rem; }
.date-fields-panel.visible { display: block; }

.date-fields {
  display: grid;
  grid-template-columns: minmax(74px, 1fr) minmax(92px, 1.15fr) minmax(64px, 0.85fr);
  gap: 0.45rem;
}
.date-fields .form-group { flex: 1; min-width: 70px; margin-bottom: 0; }
.date-fields .form-group label {
  font-size: 0.68rem;
  margin-bottom: 0.25rem;
}
.date-fields input,
.date-fields select {
  padding: 0.48rem 0.65rem;
  font-size: 0.84rem;
}

.form-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.75rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

/* ── Show/detail — flat (no card) ──────────────────────────────── */

.memory-flat {
  max-width: 640px;
}

.memory-flat-date {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg2);
  border-radius: 99px;
  padding: 0.22rem 0.75rem;
  margin-bottom: 1rem;
}

.memory-flat-title {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.25;
  margin: 0 0 1.25rem;
  color: var(--text);
}

.memory-flat-content {
  font-size: 1rem;
  line-height: 1.85;
  white-space: pre-wrap;
  color: var(--text);
}

.memory-event-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: -0.35rem 0 1.25rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.memory-event-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--accent);
  background: rgba(var(--accent-rgb), 0.1);
  flex-shrink: 0;
}

.memory-event-icon svg {
  width: 17px;
  height: 17px;
}

.memory-event-link small {
  display: block;
  font-size: 0.68rem;
  line-height: 1.2;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.memory-event-link strong {
  display: block;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--text);
}

.memory-flat-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.collective-share-panel {
  margin-bottom: 1rem;
}

.collective-share-option {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
}

.collective-share-option input {
  margin-top: 0.2rem;
  accent-color: var(--accent);
}

.collective-share-option span {
  display: grid;
  gap: 0.15rem;
}

.collective-share-option strong {
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text);
}

.collective-share-option small {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.event-flat-description {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  margin: -0.35rem 0 1rem;
}

.event-memory-count {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 1.1rem;
}

.event-add-memory-btn {
  width: 100%;
  justify-content: center;
  margin: 0.25rem 0 1.35rem;
}

.event-shared-feed {
  display: grid;
  gap: 0.65rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.event-shared-memory {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
}

.event-shared-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  font-size: 0.74rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.event-shared-author,
.event-shared-date {
  min-width: 0;
}

.event-shared-author {
  color: var(--text);
  font-weight: 600;
}

.event-shared-date {
  text-align: right;
  white-space: nowrap;
}

.event-shared-title {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.event-shared-content {
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.event-empty-shared {
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

/* ── Helper: visibilità desktop/mobile ──────────────────────────── */

.desktop-only { display: initial; }
@media (max-width: 720px) { .desktop-only { display: none !important; } }

/* ── Mobile topbar: icone back / dots ───────────────────────────── */

.mobile-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 6px;
  -webkit-tap-highlight-color: transparent;
}
.mobile-icon-btn:hover { background: var(--bg); }

/* La transizione show è ora gestita da #memoryLayer in memory-nav.js */

/* ── Context menu bottom sheet ──────────────────────────────────── */

.context-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  z-index: 70; /* stesso livello del add-panel */
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: max(env(safe-area-inset-bottom), 8px);
  /* visibile solo su mobile */
  display: none;
}
@media (max-width: 720px) {
  .context-sheet { display: block; }
}
.context-sheet.open { transform: translateY(0); }

.context-sheet-body {
  padding: 0.5rem 0.75rem;
}
.context-sheet-cancel {
  padding: 0 0.75rem 0;
}

.context-action {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 1rem 0.75rem;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.context-action:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.context-action--danger { color: var(--danger); }
.context-action--danger:hover { background: #fdf0f0; color: var(--danger); }

.context-cancel-btn {
  color: var(--muted);
  font-weight: 600;
  border-top: 1px solid var(--border);
  border-radius: 0;
  margin-top: 0.25rem;
  padding-top: 1rem;
}

/* ── Back link ──────────────────────────────────────────────────── */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  font-weight: 500;
}
.back-link:hover { color: var(--text); text-decoration: none; }
.back-link svg { width: 14px; height: 14px; }

/* ── Photo upload zone ──────────────────────────────────────────── */

.photo-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  transition: border-color 0.15s, background 0.15s;
}
.photo-zone.drag-over {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.04);
}

.photo-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  padding: 0.35rem 0;
  background: none;
  border: none;
  font-family: var(--font);
}
.photo-add-btn svg { width: 16px; height: 16px; }
.photo-add-btn:hover { opacity: 0.75; }

.photo-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* Preview grid — shared between panel and form */
.photo-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.photo-preview-grid:empty { display: none; }

.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg2);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb-remove {
  position: absolute;
  top: 3px; right: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  padding: 0;
  transition: background 0.12s;
}
.photo-thumb-remove:hover { background: rgba(180,40,40,0.85); }
.photo-thumb-remove svg { width: 10px; height: 10px; }

/* ── Photo grid (show/edit pages) ───────────────────────────────── */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.photo-grid-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg2);
  cursor: pointer;
}
.photo-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.photo-grid-item:hover img { transform: scale(1.04); }

.photo-edit-grid:empty,
.photo-edit-grid.is-empty {
  display: none;
}

.photo-grid-delete,
.photo-grid-move {
  position: absolute;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s, background 0.12s;
}
.photo-grid-delete {
  top: 5px;
  right: 5px;
}
.photo-grid-move-controls {
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 5px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.photo-grid-move {
  position: static;
  pointer-events: auto;
}
.photo-grid-item:hover .photo-grid-delete,
.photo-grid-item:hover .photo-grid-move { opacity: 1; }
.photo-grid-delete:hover { background: rgba(180,40,40,0.85); }
.photo-grid-move:hover { background: rgba(0,0,0,0.75); }
.photo-grid-move:disabled {
  opacity: 0.25 !important;
  cursor: default;
}
.photo-grid-delete svg,
.photo-grid-move svg { width: 12px; height: 12px; }

@media (min-width: 721px) {
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
  .photo-grid,
  .photo-preview-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .photo-edit-grid .photo-grid-delete,
  .photo-edit-grid .photo-grid-move {
    opacity: 0.95;
  }
}

/* ── Timeline photo badge ───────────────────────────────────────── */

.memory-card-photo-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.35rem;
}
.memory-card-photo-badge svg { width: 12px; height: 12px; }

/* ── Lightbox ───────────────────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.lightbox.open {
  opacity: 1;
  pointer-events: auto;
}
.lightbox img {
  max-width: 92vw;
  max-height: 90dvh;
  border-radius: var(--radius-sm);
  object-fit: contain;
  box-shadow: 0 8px 48px rgba(0,0,0,0.5);
}
.lightbox-close {
  position: fixed;
  top: 1rem; right: 1rem;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.lightbox-close svg { width: 18px; height: 18px; }

.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }
.lightbox-nav:hover,
.lightbox-close:hover {
  background: rgba(255,255,255,0.2);
}
.lightbox-nav svg {
  width: 22px;
  height: 22px;
}
.lightbox-nav[hidden] {
  display: none;
}

@media (min-width: 721px) {
  .device-frame .lightbox,
  .device-frame .lightbox-close,
  .device-frame .lightbox-nav {
    position: absolute;
  }
}

@media (max-width: 720px) {
  .lightbox img {
    max-width: 84vw;
  }
  .lightbox-nav {
    width: 38px;
    height: 38px;
  }
  .lightbox-prev { left: 0.5rem; }
  .lightbox-next { right: 0.5rem; }
}

/* ── Panel overlay ──────────────────────────────────────────────── */

.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 65; /* sopra topbar/bottom-nav (60) */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  backdrop-filter: blur(1px);
}
.panel-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── App dialog / toast ───────────────────────────────────────── */

.app-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 85;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.app-dialog-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.app-dialog-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  transform: translateY(100%);
  transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: max(env(safe-area-inset-bottom), 10px);
  box-shadow: 0 -8px 36px rgba(0,0,0,0.18);
}
.app-dialog-sheet.open { transform: translateY(0); }

.app-dialog-body {
  padding: 0.9rem 1.25rem 0.75rem;
}
.app-dialog-body h2 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  line-height: 1.3;
  color: var(--text);
}
.app-dialog-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}
.app-dialog-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.65rem;
  padding: 0.5rem 1.25rem 0;
}
.app-dialog-actions .btn {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  justify-content: center;
  padding: 0.68rem 0.75rem;
  font-size: 0.9rem;
  line-height: 1.15;
  white-space: normal;
  text-align: center;
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  z-index: 95;
  max-width: min(360px, calc(100vw - 2rem));
  transform: translate(-50%, 12px);
  opacity: 0;
  background: var(--text);
  color: #fff;
  border-radius: 999px;
  padding: 0.65rem 0.95rem;
  font-size: 0.84rem;
  line-height: 1.35;
  box-shadow: 0 10px 26px rgba(0,0,0,0.18);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.app-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 721px) {
  .device-frame .app-dialog-overlay,
  .device-frame .app-dialog-sheet,
  .device-frame .app-toast,
  .device-frame .mobile-info-sheet {
    position: absolute;
  }

  .device-frame .app-toast {
    width: max-content;
  }
}

/* ── Add panel: drawer desktop / bottom sheet mobile ────────────── */

.add-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 440px;
  max-width: 100vw;
  background: var(--surface);
  z-index: 70; /* sopra tutto: topbar(60), bottom-nav(60), overlay(65) */
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 32px rgba(0,0,0,0.14);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.add-panel.open {
  transform: translateX(0);
}

.panel-handle { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
  margin: 0;
}
.panel-close-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: none; background: var(--bg);
  border-radius: 50%;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
  padding: 0;
}
.panel-close-btn:hover { background: var(--bg2); color: var(--text); }

/* Stato "salvataggio in corso" — blocca l'interazione e oscura il form */
.panel-saving .panel-scroll {
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.15s;
}
.panel-saving .panel-save-btn {
  position: relative;
  overflow: hidden;
}
.panel-saving .panel-save-btn::after {
  content: '';
  position: absolute;
  left: -100%;
  top: 0; bottom: 0;
  width: 60%;
  background: rgba(255,255,255,0.25);
  animation: panelSaveShimmer 0.9s linear infinite;
}
@keyframes panelSaveShimmer {
  to { left: 160%; }
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  -webkit-overflow-scrolling: touch;
}
.panel-scroll .form-group { margin-bottom: 1.25rem; }
.panel-scroll .form-group:last-child { margin-bottom: 0; }

.panel-content-textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.97rem;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  line-height: 1.65;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.panel-content-textarea::placeholder { color: var(--muted); opacity: 0.55; }
.panel-content-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.12);
}

.panel-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.panel-errors { margin-bottom: 1rem; }
.panel-errors .flash { margin-bottom: 0.5rem; }
.panel-errors .flash:last-child { margin-bottom: 0; }

/* ── Mobile: bottom sheet ────────────────────────────────────────── */

@media (max-width: 720px) {
  .add-panel {
    top: auto;
    left: 0; right: 0;
    width: 100%;
    height: 88dvh;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .add-panel.open { transform: translateY(0); }

  .panel-handle {
    display: block;
    width: 40px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
  }
  .panel-header { padding-top: 0.85rem; }
}

/* ── Auth ───────────────────────────────────────────────────────── */

.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.25rem 2rem;
  width: 100%;
  max-width: 400px;
}
.auth-logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  text-align: center;
  margin-bottom: 1.75rem;
  color: var(--text);
}
.auth-box h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 1.5rem;
  text-align: center;
  color: var(--text);
}
.auth-footer {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.auth-footer a { color: var(--accent); }

/* ── Mobile topbar ──────────────────────────────────────────────── */

.mobile-topbar {
  display: none;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: stretch;
  position: sticky;
  top: 0;
  z-index: 60; /* sopra memory-layer (50) e panel-overlay (40) */
}
.mobile-topbar-logo {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}
.mobile-topbar-section {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
}

/* Dual topbar variants */
.mtop-a,
.mtop-b {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  width: 100%;
  position: relative; /* per mobile-topbar-section absolute */
}

/* B nascosta di default; A si nasconde su is-show e memory-open */
.mtop-b { display: none; }

body.is-show .mtop-a,
body.memory-open .mtop-a { display: none; }

body.is-show .mtop-b,
body.memory-open .mtop-b { display: flex; }

/* ── Memory layer — slide da destra ─────────────────────────────── */

.memory-layer {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 60px;
  left: 0;
  z-index: 50; /* sotto topbar/bottom-nav (60) — rimane visibile la nav */
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* solo mobile */
  display: none;
}
@media (max-width: 720px) {
  .memory-layer { display: block; }
}
.memory-layer.open { transform: translateX(0); }

@media (prefers-reduced-motion: reduce) {
  .memory-layer { transition: none !important; }
}

.memory-layer-inner {
  padding: 1.25rem 1rem;
}

/* ── Mobile bottom nav ──────────────────────────────────────────── */

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 60; /* uguale a topbar, sopra layer */
  align-items: stretch;
  justify-content: stretch;
}

.mobile-bottom-nav a,
.mobile-bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 500;
  text-decoration: none;
  font-family: var(--font);
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
  transition: color 0.12s;
}
.mobile-bottom-nav a:hover,
.mobile-bottom-nav button:hover { text-decoration: none; }
.mobile-bottom-nav a.active { color: var(--accent); }
.mobile-bottom-nav a svg,
.mobile-bottom-nav button svg { width: 21px; height: 21px; }

.mobile-bottom-nav .nav-add {
  background: var(--accent);
  color: #fff;
  border-radius: 18px;
  margin: -8px 7px 8px;
  flex: 0 0 58px;
  width: 58px;
  height: 54px;
  padding: 0;
  box-shadow: 0 10px 22px rgba(var(--accent-rgb),0.32);
}
.mobile-bottom-nav .nav-add:hover { background: var(--accent-h); color: #fff; }
.mobile-bottom-nav .nav-add svg { width: 29px; height: 29px; }

.mobile-info-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: max(env(safe-area-inset-bottom), 10px);
  box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
}
.mobile-info-sheet.open { transform: translateY(0); }
.mobile-info-sheet-body {
  padding: 0.9rem 1.25rem 0.85rem;
}
.mobile-info-sheet-body h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  line-height: 1.3;
  color: var(--text);
}
.mobile-info-sheet-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}
.mobile-profile-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.2rem;
}
.mobile-info-sheet-actions {
  display: flex;
  padding: 0.5rem 1.25rem 0;
}
.mobile-info-sheet-actions .btn {
  width: 100%;
  justify-content: center;
}
.mobile-info-sheet-actions--split {
  gap: 0.65rem;
}
.mobile-info-sheet-actions--split .btn {
  flex: 1;
}

/* ── Responsive ─────────────────────────────────────────────────── */

@media (min-width: 721px) {
  body {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 2rem;
    background: #f6f6f4;
    overflow: hidden;
  }

  body.is-timeline,
  body.is-show {
    height: 100dvh;
    overflow: hidden;
  }

  .device-frame {
    width: min(430px, calc(92dvh * 9 / 16), calc(100vw - 4rem));
    aspect-ratio: 9 / 16;
    min-height: 0;
    max-height: 92dvh;
    position: relative;
    overflow: hidden;
    background: var(--bg);
    border: 1px solid rgba(24, 23, 15, 0.08);
    border-radius: 30px;
    box-shadow:
      0 28px 70px rgba(28, 27, 24, 0.18),
      0 10px 24px rgba(28, 27, 24, 0.08);
    transform: translateZ(0);
  }

  .sidebar { display: none; }
  .topbar { display: none; }
  .mobile-topbar { display: flex; }
  .mobile-bottom-nav { display: flex; }

  .mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }

  .app-shell {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    padding-top: 52px;
    padding-bottom: 60px;
  }

  .app-main {
    height: 100%;
    margin-left: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.is-timeline .app-shell,
  body.is-timeline .app-main {
    height: 100%;
  }

  .device-frame .content {
    padding: 1.25rem 1rem;
    max-width: 100%;
  }

  .desktop-only { display: none !important; }
  .date-fields { flex-direction: column; }
  .memory-detail-actions { flex-wrap: wrap; }
  .memory-card-left { display: none; }
  .form-footer { flex-wrap: wrap; }

  .memory-layer {
    display: block;
  }

  .add-panel {
    top: auto;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    height: 88%;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .add-panel.open {
    transform: translateY(0);
  }

  .panel-handle {
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
  }

  .panel-header {
    padding-top: 0.85rem;
  }

  .context-sheet {
    display: block;
  }
}

@media (max-width: 720px) {
  .sidebar        { display: none; }
  .app-main       { margin-left: 0; }
  .topbar         { display: none; }
  .mobile-topbar  { display: flex; }
  .mobile-bottom-nav { display: flex; }

  .content {
    padding: 1.25rem 1rem 80px; /* bottom padding per nav */
    max-width: 100%;
  }

  .date-fields { flex-direction: column; }
  .memory-detail-actions { flex-wrap: wrap; }
  .memory-card-left { display: none; }
  .form-footer { flex-wrap: wrap; }

  body.is-show {
    height: 100dvh;
    overflow: hidden;
  }

  body.is-show .mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }

  body.is-show .app-shell {
    height: 100dvh;
    overflow: hidden;
    padding-top: 52px;
    padding-bottom: 60px;
  }

  body.is-show .app-main {
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.is-show .content {
    padding: 1.25rem 1rem;
  }
}

@media (min-width: 721px) and (max-width: 1100px) {
  :root { --sidebar-w: 200px; }
  .content { padding: 1.5rem; }
}
