/* ═══════════════════════════════════════════════════
   TIMELINE APP — CSS
   Font: Geist via @font-face inline fallback stack
   Theme: Dark by default, togglable to light
═══════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────── */
:root {
  --bg:        #0d0f14;
  --bg2:       #141720;
  --bg3:       #1c2030;
  --bg4:       #232840;
  --border:    rgba(255,255,255,0.07);
  --border2:   rgba(255,255,255,0.12);
  --text:      #e8eaf0;
  --text2:     #9ba3b8;
  --text3:     #626880;
  --accent:    #5b8ff9;
  --accent2:   #7c6eff;
  --green:     #3ecf8e;
  --red:       #f05252;
  --orange:    #f59e0b;
  --yellow:    #fbbf24;
  --pink:      #ec4899;
  --radius:    10px;
  --radius-sm: 6px;
  --header-h: 56px;
  --sidebar-w: 260px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --trans:     all 0.2s cubic-bezier(.4,0,.2,1);
  --spine-color: rgba(91,143,249,0.25);
  --node-size: 14px;
  font-size: 15px;
}

body.light-mode {
  --bg:      #f4f6fb;
  --bg2:     #ffffff;
  --bg3:     #eef0f6;
  --bg4:     #e4e8f4;
  --border:  rgba(0,0,0,0.07);
  --border2: rgba(0,0,0,0.12);
  --text:    #1a1d2e;
  --text2:   #4a5068;
  --text3:   #8890a8;
  --shadow:  0 4px 24px rgba(0,0,0,0.1);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.07);
  --spine-color: rgba(91,143,249,0.3);
}

/* ── Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'SF Pro Display', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  width: 100%;
  transition: border-color 0.2s;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ba3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
svg { fill: none; stroke: currentColor; stroke-width: 2; width: 18px; height: 18px; flex-shrink: 0; vertical-align: middle; }

/* ── Header ─────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 100;
  backdrop-filter: blur(12px);
}
.header-left  { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.header-center{ flex: 1; max-width: 480px; margin: 0 auto; }
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.title-icon { color: var(--accent); font-size: 1.2rem; }

/* Search */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .search-icon {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--text3);
  pointer-events: none;
}
.search-wrap input {
  padding-left: 36px;
  padding-right: 32px;
  background: var(--bg3);
  border-radius: 20px;
  border: 1px solid var(--border);
  height: 36px;
}
.btn-clear-search {
  position: absolute;
  right: 8px;
  color: var(--text3);
  font-size: 12px;
  line-height: 1;
}

/* Buttons */
.btn-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--text2);
  transition: var(--trans);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.btn-icon.btn-danger:hover { background: rgba(240,82,82,0.1); color: var(--red); }
.btn-primary {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  transition: var(--trans);
  white-space: nowrap;
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, black); transform: translateY(-1px); }
.btn-primary svg { width: 16px; height: 16px; stroke: #fff; }
.btn-ghost {
  background: var(--bg3);
  color: var(--text2);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  transition: var(--trans);
}
.btn-ghost:hover { background: var(--bg4); color: var(--text); }
.btn-small {
  background: var(--bg4);
  color: var(--text2);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  transition: var(--trans);
  border: none;
}
.btn-small:hover { background: var(--border2); }

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 90;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(.4,0,.2,1);
  scrollbar-width: thin;
  scrollbar-color: var(--bg4) transparent;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 89;
  display: none;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.sidebar-nav { padding: 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 0.9rem;
  transition: var(--trans);
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(91,143,249,0.12); color: var(--accent); }
.nav-item svg { width: 16px; height: 16px; }
.sidebar-section {
  padding: 16px;
  border-top: 1px solid var(--border);
}
.sidebar-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

/* Stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-item {
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
}
.stat-val { display: block; font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.stat-lbl { display: block; font-size: 0.72rem; color: var(--text3); margin-top: 2px; }

/* Tags cloud */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.76rem;
  cursor: pointer;
  transition: var(--trans);
}
.tag-chip:hover, .tag-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Date filters */
.date-filters { display: flex; flex-direction: column; gap: 8px; }
.date-filters label { font-size: 0.82rem; color: var(--text2); display: flex; flex-direction: column; gap: 4px; }
.date-filters input { padding: 6px 10px; font-size: 0.82rem; }

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--text2);
  margin-bottom: 12px;
  cursor: pointer;
}
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; inset: 0;
  background: var(--bg4);
  border-radius: 20px;
  transition: 0.3s;
}
.toggle .slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; bottom: 3px;
  background: var(--text3);
  border-radius: 50%;
  transition: 0.3s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(16px); background: #fff; }

/* ── Breadcrumb ──────────────────────────────────── */
.breadcrumb-bar {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: 38px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 80;
  overflow-x: auto;
  scrollbar-width: none;
  transition: top 0.2s;
}
.breadcrumb-bar::-webkit-scrollbar { display: none; }
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text3);
  white-space: nowrap;
}
.breadcrumb-item {
  cursor: pointer;
  color: var(--text2);
  transition: color 0.15s;
}
.breadcrumb-item:hover { color: var(--accent); }
.breadcrumb-item.active { color: var(--text); font-weight: 600; cursor: default; }
.breadcrumb-sep { color: var(--text3); }

/* ── Drill-down nav bar ──────────────────────────── */
.drill-nav {
  position: fixed;
  top: calc(var(--header-h) + 38px);
  left: 0; right: 0;
  height: 48px;
  background: var(--bg2);
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 79;
  animation: slideDown 0.2s ease;
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
/* Quando drill-nav è visibile, main-content scende di 48px in più */
body.drill-active .main-content {
  margin-top: calc(var(--header-h) + 38px + 48px);
}
body.drill-active .breadcrumb-bar { /* rimane fissa */ }

@media (min-width: 768px) {
  body.drill-active .main-content { margin-left: var(--sidebar-w); }
  .drill-nav { left: var(--sidebar-w); }
}

.drill-back {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--trans);
  white-space: nowrap;
  flex-shrink: 0;
}
.drill-back:hover { background: var(--bg4); color: var(--text); }
.drill-back svg { width: 14px; height: 14px; }

.drill-crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.drill-crumbs::-webkit-scrollbar { display: none; }
.drill-crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.drill-crumb-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.drill-crumb-name {
  font-weight: 600;
  color: var(--text);
}
.drill-crumb-sep { color: var(--text3); }
.drill-crumb-link {
  cursor: pointer;
  color: var(--text2);
  transition: color 0.15s;
}
.drill-crumb-link:hover { color: var(--accent); }

.drill-add-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(91,143,249,0.12);
  border: 1px solid rgba(91,143,249,0.3);
  color: var(--accent);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--trans);
  white-space: nowrap;
  flex-shrink: 0;
}
.drill-add-sub:hover { background: rgba(91,143,249,0.2); }
.drill-add-sub svg { width: 14px; height: 14px; stroke: var(--accent); }

/* Card radice in modalità drill: click = naviga, non apre modal */
.tl-card.drill-root {
  cursor: zoom-in;
}
.tl-card.drill-root:hover .tl-card-title::after {
  content: ' →';
  color: var(--accent);
  opacity: 0.7;
}
/* Card senza figli in modalità drill: comportamento normale */
.tl-card.drill-leaf { cursor: pointer; }

/* Header evento nella sub-timeline */
.drill-event-header {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 28px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.drill-event-header-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
}
.drill-event-header-body { flex: 1; min-width: 0; }
.drill-event-header-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.drill-event-header-meta {
  font-size: 0.82rem;
  color: var(--text2);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 6px;
}
.drill-event-header-desc {
  font-size: 0.84rem;
  color: var(--text2);
  line-height: 1.5;
  margin-top: 6px;
}
.drill-event-header-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Contatore figli nella drill nav */
/* ── Main content ────────────────────────────────── */
.main-content {
  margin-top: calc(var(--header-h) + 38px);
  padding: 32px 24px;
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
  min-height: calc(100vh - var(--header-h) - 38px);
}

/* ══════════════════════════════════════════════════
   TIMELINE VIEW — alternating left / right
══════════════════════════════════════════════════ */
.timeline-container {
  position: relative;
  /* spine centrata */
}

.timeline-spine {
  position: absolute;
  left: 50%;
  transform: translateX(-1px);
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(
    to bottom,
    transparent,
    var(--spine-color) 4%,
    var(--spine-color) 96%,
    transparent
  );
  border-radius: 2px;
  pointer-events: none;
}

/* ── Row struttura: 3 colonne (sx | nodo | dx) ── */
.tl-event {
  display: grid;
  grid-template-columns: 1fr 52px 1fr;
  margin-bottom: 14px;
  position: relative;
  animation: fadeUp 0.28s ease both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Colonna nodo — sempre in centro griglia */
.tl-node-col {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 18px;
  position: relative;
  z-index: 2;
}

/* Spacer colonna vuota */
.tl-spacer {
  grid-row: 1;
}
.tl-event.side-right .tl-spacer { grid-column: 1; }
.tl-event.side-left  .tl-spacer { grid-column: 3; }

/* Card wrap */
.tl-card-wrap {
  grid-row: 1;
  min-width: 0; /* evita overflow */
}
.tl-event.side-right .tl-card-wrap {
  grid-column: 3;
  padding-left: 18px;
}
.tl-event.side-left .tl-card-wrap {
  grid-column: 1;
  padding-right: 18px;
}

/* Sub-eventi: stessa parte del padre, rientranza verso l'esterno */
.tl-event.side-right.is-sub .tl-card-wrap { padding-left:  calc(18px + var(--sub-indent)); }
.tl-event.side-left.is-sub  .tl-card-wrap { padding-right: calc(18px + var(--sub-indent)); }

/* Livelli di rientranza */
.tl-event[data-sub-depth="1"] { --sub-indent: 14px; }
.tl-event[data-sub-depth="2"] { --sub-indent: 28px; }
.tl-event[data-sub-depth="3"] { --sub-indent: 42px; }
.tl-event[data-sub-depth="4"] { --sub-indent: 56px; }

/* Connettore orizzontale nodo→card */
.tl-card-wrap::before {
  content: '';
  position: absolute;
  top: 26px;
  height: 1px;
  background: var(--spine-color);
  pointer-events: none;
}
.tl-event.side-right .tl-card-wrap::before {
  left: 52px; /* inizio dopo il nodo */
  width: 14px;
}
.tl-event.side-left .tl-card-wrap::before {
  right: 52px;
  width: 14px;
}
/* Sub-eventi: connettore più corto */
.tl-event.is-sub.side-right .tl-card-wrap::before { width: 10px; }
.tl-event.is-sub.side-left  .tl-card-wrap::before { width: 10px; }

/* ── Node marker ──────────────────────────────── */
.tl-node {
  width: var(--node-size);
  height: var(--node-size);
  border-radius: 50%;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 2px var(--spine-color);
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s;
  flex-shrink: 0;
}
.tl-node:hover {
  transform: scale(1.35);
  box-shadow: 0 0 0 3px var(--accent);
}
.tl-node.milestone {
  border-radius: 3px;
  transform: rotate(45deg);
}
.tl-node.milestone:hover { transform: rotate(45deg) scale(1.35); }

/* Sub-nodi leggermente più piccoli */
.tl-event.is-sub .tl-node {
  width: 10px;
  height: 10px;
  margin-top: 2px;
}

/* ── Card ─────────────────────────────────────── */
.tl-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: var(--trans);
  position: relative;
}
/* Bordo colorato: a sinistra per card a destra, a destra per card a sinistra */
.tl-event.side-right .tl-card { border-left:  3px solid var(--accent); }
.tl-event.side-left  .tl-card { border-right: 3px solid var(--accent); }

.tl-card:hover {
  background: var(--bg3);
  border-color: var(--border2);
  box-shadow: var(--shadow-sm);
}
.tl-event.side-right .tl-card:hover { transform: translateX( 3px); }
.tl-event.side-left  .tl-card:hover { transform: translateX(-3px); }

.tl-card.compact { padding: 8px 12px; }

/* ── Card internals ───────────────────────────── */
.tl-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  justify-content: space-between;
}
.tl-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  flex: 1;
}
/* Sub-event title leggermente più piccolo */
.tl-event.is-sub .tl-card-title { font-size: 0.88rem; }

.tl-card-badges { display: flex; gap: 6px; align-items: center; flex-shrink: 0; flex-wrap: wrap; }
.badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge-type      { background: var(--bg4); color: var(--text2); }
.badge-milestone { background: rgba(251,191,36,0.15); color: var(--yellow); }
.badge-media     { background: rgba(91,143,249,0.12); color: var(--accent); }

.tl-card-date {
  font-size: 0.78rem;
  color: var(--text3);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tl-card-desc {
  font-size: 0.84rem;
  color: var(--text2);
  margin-top: 6px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tl-card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tl-card-tag {
  background: var(--bg4);
  color: var(--text3);
  padding: 1px 7px;
  border-radius: 12px;
  font-size: 0.7rem;
}
.tl-card-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.tl-children-count {
  font-size: 0.76rem;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 4px;
}
.tl-media-icons { display: flex; gap: 4px; }
.media-type-icon {
  width: 22px; height: 22px;
  border-radius: 4px;
  background: var(--bg4);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
}

/* ── Separatori anno / mese ───────────────────── */
.tl-separator {
  grid-column: 1 / -1;   /* attraversa tutta la griglia */
  display: flex;
  align-items: center;
  gap: 0;
  margin: 28px 0 16px;
}
.tl-separator-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}
.tl-separator-label {
  background: var(--bg);
  color: var(--text3);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

/* ── RESPONSIVE — mobile: spine a sinistra, tutto a destra ── */
@media (max-width: 640px) {
  .timeline-spine {
    left: 20px;
    transform: none;
  }
  .tl-event {
    grid-template-columns: 44px 1fr;
  }
  .tl-node-col {
    grid-column: 1;
    padding-top: 16px;
    justify-content: center;
  }
  .tl-card-wrap,
  .tl-event.side-right .tl-card-wrap,
  .tl-event.side-left  .tl-card-wrap {
    grid-column: 2;
    grid-row: 1;
    padding-left: 12px;
    padding-right: 0;
  }
  .tl-spacer { display: none; }
  .tl-event.side-right .tl-card,
  .tl-event.side-left  .tl-card {
    border-left:  3px solid var(--accent);
    border-right: 1px solid var(--border);
  }
  .tl-event.side-right .tl-card:hover,
  .tl-event.side-left  .tl-card:hover { transform: translateX(3px); }
  .tl-card-wrap::before,
  .tl-event.side-right .tl-card-wrap::before,
  .tl-event.side-left  .tl-card-wrap::before {
    left: 44px; right: auto; width: 8px;
  }
  .tl-event.is-sub.side-right .tl-card-wrap,
  .tl-event.is-sub.side-left  .tl-card-wrap {
    padding-left: calc(12px + var(--sub-indent));
  }
  .tl-separator { grid-column: 1 / -1; }
}

/* ══════════════════════════════════════════════════
   TREE VIEW
══════════════════════════════════════════════════ */
.tree-container { padding: 8px 0; }
.tree-node {
  user-select: none;
}
.tree-node-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.tree-node-row:hover { background: var(--bg3); }
.tree-node-row.selected { background: rgba(91,143,249,0.1); }
.tree-toggle {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--text3);
  font-size: 10px;
  transition: transform 0.2s;
  border-radius: 4px;
}
.tree-toggle:hover { background: var(--bg4); }
.tree-toggle.open { transform: rotate(90deg); }
.tree-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tree-label { font-size: 0.88rem; color: var(--text); flex: 1; }
.tree-meta { font-size: 0.74rem; color: var(--text3); }
.tree-children { padding-left: 22px; border-left: 1px solid var(--border); margin-left: 13px; }

/* ══════════════════════════════════════════════════
   GRID VIEW
══════════════════════════════════════════════════ */
.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.grid-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: var(--trans);
  border-top: 3px solid var(--accent);
}
.grid-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border2);
}
.grid-card-title { font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; }
.grid-card-date  { font-size: 0.76rem; color: var(--text3); margin-bottom: 8px; }
.grid-card-desc  {
  font-size: 0.82rem;
  color: var(--text2);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════
   MODALS
══════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 680px;
  margin: auto;
  box-shadow: var(--shadow);
  animation: modalIn 0.22s cubic-bezier(.4,0,.2,1);
}
.modal-wide { max-width: 900px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-title-wrap { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.modal-title { font-size: 1.05rem; font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-event-color { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.modal-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.modal-body { padding: 20px; overflow-y: auto; max-height: calc(90vh - 80px); }

/* Event meta info */
.event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 14px;
  font-size: 0.84rem;
  color: var(--text2);
}
.meta-item { display: flex; align-items: center; gap: 5px; }
.meta-item svg { width: 14px; height: 14px; color: var(--text3); }

.event-description {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 14px;
  white-space: pre-wrap;
}
.event-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }

.event-ancestors {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 14px;
  font-size: 0.8rem;
  color: var(--text3);
}
.ancestor-item {
  cursor: pointer;
  color: var(--accent);
}
.ancestor-item:hover { text-decoration: underline; }

.event-children { margin-bottom: 14px; }
.children-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.child-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}
.child-item:hover { background: var(--bg4); }
.child-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.child-date { font-size: 0.75rem; color: var(--text3); margin-left: auto; }

/* ── Section label ── */
.section-label {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

/* ══════════════════════════════════════════════════
   MEDIA SECTION
══════════════════════════════════════════════════ */
.media-section { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.media-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  margin-bottom: 14px;
}
.media-tabs::-webkit-scrollbar { display: none; }
.media-tab {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text2);
  background: var(--bg3);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--trans);
  border: none;
}
.media-tab.active { background: var(--accent); color: #fff; }
.media-tab:hover:not(.active) { background: var(--bg4); }

/* Image grid */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.media-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg3);
  cursor: pointer;
  position: relative;
  transition: transform 0.2s;
}
.media-thumb:hover { transform: scale(1.03); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .media-delete {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border-radius: 50%;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.2s;
  cursor: pointer;
}
.media-thumb:hover .media-delete { opacity: 1; }
.media-thumb .thumb-play {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  background: rgba(0,0,0,0.35);
  color: white;
}

/* List for non-image media */
.media-list { display: flex; flex-direction: column; gap: 6px; }
.media-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.media-list-item:hover { background: var(--bg4); }
.media-type-badge {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.media-list-info { flex: 1; min-width: 0; }
.media-list-name { font-size: 0.85rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-list-meta { font-size: 0.74rem; color: var(--text3); margin-top: 2px; }
.media-list-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* Video / Audio player */
.media-player { width: 100%; border-radius: var(--radius-sm); margin-top: 8px; background: #000; }
audio.media-player { background: var(--bg3); }

/* Upload zone */
.upload-area { margin-top: 16px; }
.upload-drop-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  transition: var(--trans);
  color: var(--text3);
  cursor: pointer;
}
.upload-drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(91,143,249,0.05);
  color: var(--accent);
}
.upload-icon { width: 32px; height: 32px; margin: 0 auto 10px; display: block; }
.upload-drop-zone p { font-size: 0.88rem; line-height: 1.5; }
.upload-link {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}
.upload-hint { font-size: 0.76rem !important; color: var(--text3) !important; margin-top: 4px !important; }
.upload-progress { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.upload-item { background: var(--bg3); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 0.82rem; }
.upload-item-name { margin-bottom: 6px; color: var(--text); }
.progress-bar { height: 4px; background: var(--bg4); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.3s; border-radius: 2px; }

/* ══════════════════════════════════════════════════
   FORM MODAL
══════════════════════════════════════════════════ */
.modal-form { max-width: 600px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: var(--text2); letter-spacing: 0.02em; }
.hint { font-weight: 400; color: var(--text3); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input { width: auto; }

/* Color presets */
.color-pick-wrap { display: flex; gap: 8px; align-items: center; }
.color-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.color-preset {
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s;
}
.color-preset:hover { transform: scale(1.15); }
.color-preset.selected { border-color: var(--text); }

/* ══════════════════════════════════════════════════
   PDF VIEWER
══════════════════════════════════════════════════ */
.pdf-body { text-align: center; padding: 20px; }
.pdf-body canvas { max-width: 100%; box-shadow: var(--shadow); }
.pdf-pages { font-size: 0.85rem; color: var(--text2); padding: 0 4px; }

/* ══════════════════════════════════════════════════
   TOAST NOTIFICATIONS
══════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 240px;
  max-width: 360px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast-icon { font-size: 16px; flex-shrink: 0; }

/* ══════════════════════════════════════════════════
   LOADING
══════════════════════════════════════════════════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 1rem; color: var(--text2); margin-bottom: 8px; }
.empty-state p  { font-size: 0.88rem; }

/* ══════════════════════════════════════════════════
   FULLSCREEN IMAGE VIEWER
══════════════════════════════════════════════════ */
.img-viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.img-viewer-overlay img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.img-viewer-close {
  position: absolute;
  top: 16px; right: 16px;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  background: rgba(255,255,255,0.1);
  border-radius: 50%;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
}

/* ══════════════════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ══════════════════════════════════════════════════
   RESPONSIVE — MOBILE
══════════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root { --header-h: 96px; }  /* header alto 2 righe su mobile */

  .app-header {
    flex-wrap: wrap;
    height: auto;
    padding: 0 12px;
    row-gap: 0;
  }
  .header-left  { height: 52px; flex: 1; }
  .header-right { height: 52px; flex-shrink: 0; }

  /* Cerca: seconda riga, full width */
  .header-center {
    order: 3;
    width: 100%;
    padding: 8px 0;
    max-width: 100%;
    margin: 0;
    border-top: 1px solid var(--border);
  }
  .search-wrap { width: 100%; }
  .search-wrap input { width: 100%; }

  .main-content { padding: 16px 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; border-radius: 14px 14px 0 0; }
  .grid-container { grid-template-columns: 1fr 1fr; }
  .btn-primary span { display: none; }
  .app-title span:not(.title-icon) { display: none; }
}

@media (max-width: 400px) {
  .grid-container { grid-template-columns: 1fr; }
}

/* ══════════════════════════════════════════════════
   TABLET
══════════════════════════════════════════════════ */
@media (min-width: 768px) {
  .sidebar { transform: none; }
  .sidebar-overlay { display: none !important; }
  .main-content {
    margin-left: var(--sidebar-w);
    padding: 32px 40px;
  }
  .breadcrumb-bar { left: var(--sidebar-w); }
  #btnSidebar { display: none; }
}

@media (min-width: 1200px) {
  .main-content { max-width: calc(1000px + var(--sidebar-w)); padding: 40px 60px; }
}

/* ── Scroll top / bottom buttons ────────────────── */
.scroll-nav {
  position: fixed;
  right: 20px;
  bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
}
.scroll-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  transition: background 0.15s, color 0.15s, transform 0.15s, opacity 0.2s;
  opacity: 0;
  pointer-events: none;
}
.scroll-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
}
.scroll-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: scale(1.1);
}
.scroll-nav.visible .scroll-btn {
  opacity: 1;
  pointer-events: auto;
}

/* ══════════════════════════════════════════════════
   CATTURA DIRETTA (foto / video / audio)
══════════════════════════════════════════════════ */
.capture-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 10px 0 4px;
  flex-wrap: wrap;
}
.btn-capture {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg4);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--trans);
}
.btn-capture svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-capture:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.modal-capture { width: min(560px, 96vw); max-height: 90vh; }
.capture-body  { display: flex; flex-direction: column; gap: 14px; }

.capture-preview {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#captureVideo { width: 100%; max-height: 320px; object-fit: cover; display: block; }

.audio-visualizer {
  width: 100%;
  padding: 16px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
}
#audioCanvas { width: 100%; max-width: 400px; height: 80px; border-radius: 6px; }

.capture-timer {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--red);
  letter-spacing: 0.05em;
}
.rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s ease infinite;
}
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0; } }

.capture-result  { text-align: center; }
#resultPhoto     { max-width: 100%; max-height: 280px; border-radius: var(--radius); object-fit: contain; background: #000; }
#resultVideo     { width: 100%; max-height: 280px; border-radius: var(--radius); }
#resultAudio     { width: 100%; }
.capture-result-label { font-size: 0.78rem; color: var(--text3); margin-top: 6px; }

.capture-device-row { display: flex; justify-content: center; }
.capture-select {
  background: var(--bg3); border: 1px solid var(--border2); color: var(--text);
  border-radius: var(--radius-sm); padding: 5px 10px; font-size: 0.8rem;
  max-width: 300px; width: 100%;
}
.capture-action-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn-capture-action {
  padding: 8px 20px; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border2); background: var(--bg4); color: var(--text);
  transition: var(--trans); display: inline-flex; align-items: center; gap: 5px;
}
.btn-capture-action:hover        { background: var(--bg3); border-color: var(--accent); }
.btn-capture-action.btn-rec      { background: rgba(240,82,82,0.1); border-color: var(--red); color: var(--red); }
.btn-capture-action.btn-rec:hover{ background: rgba(240,82,82,0.2); }
.btn-capture-action.btn-stop     { background: rgba(245,158,11,0.1); border-color: var(--orange); color: var(--orange); }
.btn-capture-action.btn-primary  { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-capture-action.btn-primary:hover { background: var(--accent2); }

/* ── Pannello overlay timbro ───────────────────────── */
.overlay-panel {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.overlay-panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.overlay-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.overlay-field        { display: flex; flex-direction: column; gap: 4px; }
.overlay-field-sm     { grid-column: span 1; }
.overlay-field label  { font-size: 0.72rem; color: var(--text3); font-weight: 600; }
.overlay-field input,
.overlay-field select {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.8rem;
  padding: 5px 8px;
}
.overlay-field input:focus,
.overlay-field select:focus {
  outline: none;
  border-color: var(--accent);
}
/* Prima colonna (data) occupa tutto */
.overlay-fields .overlay-field:first-child { grid-column: span 2; }

@media (max-width: 480px) {
  .overlay-fields { grid-template-columns: 1fr; }
  .overlay-fields .overlay-field:first-child { grid-column: span 1; }
}
