:root {
  --bg: #f3eee4;
  --panel: #fffdf8;
  --ink: #121212;
  --muted: #6b665e;
  --line: #e2dbcd;
  --accent: #2b3bff;
  --lime: #d5f33d;
  --ok: #1f8a4c;
  --ok-soft: #e2f3e8;
  --warn: #9a5b00;
  --warn-soft: #fbeed3;
  --error: #c62828;
  --error-soft: #fbe3e1;
  --info: #2b3bff;
  --info-soft: #e4e6ff;
  --sidebar: #121212;
  --sidebar-ink: #f3eee4;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --panel: #1c1b18;
    --ink: #f3eee4;
    --muted: #9a948a;
    --line: #2e2c27;
    --accent: #8c95ff;
    --ok: #5ccf8b;
    --ok-soft: #173323;
    --warn: #f0b758;
    --warn-soft: #3a2c12;
    --error: #ff7a6e;
    --error-soft: #3d1b18;
    --info: #9aa2ff;
    --info-soft: #1f2247;
    --sidebar: #0b0b0a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

/* ---- Controlli */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.btn.approve { border-color: var(--ok); background: var(--ok); color: #fff; }
.btn.danger { border-color: color-mix(in srgb, var(--error) 45%, var(--line)); color: var(--error); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; border-radius: 7px; font-size: 12px; }
.btn.wide { width: 100%; }
.btn:focus-visible, .field:focus-visible, .filter:focus-visible, .day:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.label {
  display: flex;
  justify-content: space-between;
  margin: 12px 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.field {
  display: block;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  resize: vertical;
}
textarea.field { line-height: 1.5; }
.hint { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.count { color: var(--muted); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums; }
.count.over { color: var(--error); font-weight: 700; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.draft { background: var(--info-soft); color: var(--info); }
.badge.changed { background: var(--warn-soft); color: var(--warn); }
.badge.approved { background: var(--ok-soft); color: var(--ok); }
.badge.rejected { background: var(--error-soft); color: var(--error); }

/* ---- Login */

.login { display: grid; place-items: center; height: 100vh; padding: 16px; overflow-y: auto; }
.login-card {
  width: min(360px, 100%);
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}
.login-card h1 { margin-top: 14px; font-size: 22px; letter-spacing: -.01em; }
.login-sub { margin: 2px 0 12px; color: var(--muted); }
.login-card .btn { margin-top: 18px; }
.login-mark {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2b3bff, #ff5b2e 60%, #d5f33d);
}
.form-error { margin: 12px 0 0; color: var(--error); font-weight: 600; }

/* ---- Struttura */

.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
}
.app > * { min-height: 0; }

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 20px 12px 14px;
  overflow-y: auto;
  background: var(--sidebar);
  color: var(--sidebar-ink);
}
.brand { padding: 0 10px 14px; font-size: 16px; font-weight: 700; }
.brand small { display: block; margin-top: 2px; font: 400 12px var(--mono); opacity: .55; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 0 2px 12px; }
.filter {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 8px;
  background: none;
  font-size: 12px;
  cursor: pointer;
}
.filter:hover { background: rgba(255, 255, 255, .08); }
.filter.active { border-color: var(--sidebar-ink); background: var(--sidebar-ink); color: #121212; }
.filter-count { opacity: .6; font-variant-numeric: tabular-nums; }
.days { display: grid; gap: 2px; align-content: start; }
.nav-empty { padding: 8px 10px; opacity: .5; font-size: 13px; }
.day {
  display: grid;
  gap: 1px;
  padding: 8px 10px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}
.day:hover { background: rgba(255, 255, 255, .08); }
.day.active { background: var(--lime); color: #121212; }
.day-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-name { font-weight: 600; }
.day-meta { font-size: 12px; opacity: .6; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; }
.dot.draft { background: #8c95ff; }
.dot.changed { background: #f0b758; }
.dot.approved { background: #5ccf8b; }
.dot.rejected { background: #ff7a6e; }
.day.active .dot { box-shadow: 0 0 0 2px #121212; }
.sidebar-foot { display: flex; gap: 6px; margin-top: auto; padding-top: 14px; }
.side-btn {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.side-btn:hover { background: rgba(255, 255, 255, .08); }

.main { padding: 26px 32px 48px; overflow-y: auto; }
.loading, .empty { color: var(--muted); }
.empty { max-width: 460px; margin: 80px auto; text-align: center; }
.empty h1 { color: var(--ink); font-size: 20px; }
.empty code { padding: 2px 6px; border-radius: 6px; background: var(--panel); font-family: var(--mono); }
.fatal { padding: 16px; color: var(--error); font-family: var(--mono); }

/* ---- Intestazione del giorno */

.day-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px 24px;
  margin-bottom: 14px;
}
.day-header h1 { font-size: 26px; letter-spacing: -.015em; }
.day-header h1::first-letter { text-transform: uppercase; }
.day-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.banners { display: grid; gap: 8px; margin-bottom: 20px; }
.banners:empty { display: none; }
.banner {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 500;
}
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--error-soft); color: var(--error); }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner-note { color: var(--ink); font-weight: 400; font-style: italic; }
.banner a { color: inherit; font-weight: 700; }

/* pannello laterale fisso a destra; le card dei post si dividono lo spazio restante */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  align-items: start;
  gap: 28px;
}
.posts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr));
  align-items: start;
  gap: 24px;
}
.side { display: grid; gap: 16px; }

.panel {
  padding: 16px 18px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}
.panel h2 { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.panel h2 + .field { margin-top: 10px; }
.panel-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ---- Eventi */

.event-group h3 {
  margin: 16px 0 6px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.events { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.event {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}
.event.out .event-body { opacity: .62; }
.rank {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.rank.hi { background: var(--ok-soft); color: var(--ok); }
.rank.mid { background: var(--info-soft); color: var(--info); }
.rank.lo { background: var(--error-soft); color: var(--error); }
.event-body { display: grid; gap: 2px; }
.event-title { font-weight: 600; overflow-wrap: anywhere; }
.event-meta, .event-reason { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.event-reason { font-style: italic; }
.tag { justify-self: start; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tag.manual { color: var(--warn); }
.event-actions { display: grid; align-content: start; gap: 4px; }

/* ---- Card del post (stile feed Instagram) */

.post {
  width: 100%;
  max-width: 480px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}
.post.stale .viewport { opacity: .55; }
.post-header { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.post-heading { display: grid; flex: 1; min-width: 0; }
.post-header small { color: var(--muted); font-size: 12px; }
.avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: linear-gradient(135deg, #2b3bff, #ff5b2e 60%, #d5f33d);
  box-shadow: 0 0 0 2px #ff5b2e;
}
.placeholder, .placeholder-card {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 5;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}
.placeholder { border-top: 1px solid var(--line); }

.viewport {
  position: relative;
  aspect-ratio: 4 / 5;
  max-width: 100%;
  overflow: hidden;
  background: #000;
  cursor: zoom-in;
  touch-action: pan-y;
  user-select: none;
  transition: opacity .2s;
}
.track { display: flex; height: 100%; transition: transform .3s ease; }
.track img { flex: none; width: 100%; height: 100%; object-fit: cover; }
.nav {
  position: absolute;
  top: 50%;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .88);
  color: #121212;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transform: translateY(-50%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.nav.prev { left: 10px; }
.nav.next { right: 10px; }
.counter {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(18, 18, 18, .7);
  color: #fff;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.dots { display: flex; justify-content: center; gap: 4px; padding: 10px 0 4px; }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--line); transition: background .2s; }
.dots span.on { background: var(--accent); }

.caption { padding: 4px 14px 12px; }
.description { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.description.collapsed {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.description.missing { color: var(--muted); font-style: italic; }
.more { padding: 0; border: none; background: none; color: var(--muted); cursor: pointer; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 6px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
}
.thumbs button {
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  aspect-ratio: 4 / 5;
}
.thumbs button.on { border-color: var(--accent); }
.thumbs img { display: block; width: 100%; height: 100%; object-fit: cover; }

/* ---- Lightbox e notifiche */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 8, .92);
}
.lightbox figure { margin: 0; text-align: center; }
.lightbox img { display: block; max-width: 92vw; max-height: 88vh; border-radius: 4px; }
.lightbox figcaption { margin-top: 10px; color: #cfc9bf; font: 12px var(--mono); }
.lb-close, .lb-nav {
  position: absolute;
  border: none;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
}
.lb-close { top: 16px; right: 16px; width: 40px; height: 40px; border-radius: 50%; font-size: 24px; }
.lb-nav { top: 50%; width: 48px; height: 48px; border-radius: 50%; font-size: 30px; transform: translateY(-50%); }
.lb-nav.prev { left: 20px; }
.lb-nav.next { right: 20px; }
.lb-close:hover, .lb-nav:hover { background: rgba(255, 255, 255, .24); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.toast.error { background: var(--error); color: #fff; }

/* ---- Schermi stretti */

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { max-width: 640px; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; height: auto; min-height: 100vh; }
  .sidebar { padding: 12px 16px; }
  .brand { display: flex; align-items: baseline; gap: 10px; padding: 0 0 10px; }
  .brand small { margin: 0; }
  .filters { grid-template-columns: repeat(4, auto); justify-content: start; padding: 0 0 8px; overflow-x: auto; }
  .days { display: flex; gap: 4px; overflow-x: auto; }
  .day { flex: none; }
  .sidebar-foot { padding-top: 8px; }
  .main { padding: 18px 16px 40px; overflow: visible; }
  .day-header h1 { font-size: 21px; }
  .side { max-width: none; }
  .toast { right: 16px; bottom: 16px; left: 16px; max-width: none; }
  .lb-nav.prev { left: 6px; }
  .lb-nav.next { right: 6px; }
}
