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

:root {
  --border: 1px solid #e0e0e0;
  --sidebar: 210px;
  --topbar: 50px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 6px;
}

html, body { height: 100%; font-family: var(--font); font-size: 14px; color: #111; background: #fff; overflow: hidden; }
.hidden { display: none !important; }

/* ── Cover ───────────────────────────────────────────────── */
#cover-page { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #111; z-index: 50; }
#cover-bg { position: absolute; inset: 0; background-size: cover; background-position: center; background-color: #222; }
#cover-bg::after { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,0.48); }
#cover-count { position: absolute; top: 20px; right: 20px; font-size: 12px; color: rgba(255,255,255,0.6); background: rgba(0,0,0,0.3); padding: 5px 12px; border-radius: 20px; z-index: 2; }
#cover-content { position: relative; z-index: 2; text-align: center; padding: 32px 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
#cover-title { font-size: clamp(28px, 6vw, 52px); font-weight: 600; color: #fff; line-height: 1.1; letter-spacing: -0.02em; }
#cover-subtitle { font-size: clamp(13px, 2vw, 16px); color: rgba(255,255,255,0.6); }
#cover-btn { margin-top: 12px; padding: 14px 36px; font-size: 15px; font-weight: 500; background: #fff; color: #111; border: none; border-radius: var(--radius); cursor: pointer; }
#cover-btn:hover { opacity: 0.9; }

/* ── App ─────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Admin bar ───────────────────────────────────────────── */
#admin-bar { display: flex; align-items: center; gap: 8px; padding: 6px 16px; background: #f5f5f5; border-bottom: var(--border); flex-shrink: 0; }
.admin-bar-label { font-size: 10px; color: #aaa; text-transform: uppercase; letter-spacing: 0.07em; margin-right: 4px; }
#btn-new-event { padding: 5px 12px; font-size: 12px; font-weight: 500; border-radius: var(--radius); cursor: pointer; background: #111; color: #fff; border: none; }
#btn-new-event:hover { background: #333; }
#btn-manage-events { padding: 5px 12px; font-size: 12px; font-weight: 500; border-radius: var(--radius); cursor: pointer; background: transparent; border: 1px solid #ddd; color: #555; }
#btn-manage-events:hover { border-color: #aaa; color: #111; }

/* ── Topbar ──────────────────────────────────────────────── */
#topbar { display: flex; align-items: center; gap: 8px; padding: 0 16px; height: var(--topbar); border-bottom: var(--border); flex-shrink: 0; background: #fff; }
#logo { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; white-space: nowrap; flex-shrink: 0; }
.dot { width: 8px; height: 8px; background: #111; border-radius: 50%; }
#breadcrumb { display: flex; align-items: center; gap: 3px; font-size: 12px; color: #aaa; overflow: hidden; flex: 1; min-width: 0; }
.crumb { cursor: pointer; white-space: nowrap; color: #aaa; }
.crumb:hover { color: #111; }
.crumb.current { color: #111; font-weight: 500; }
.sep { color: #ddd; flex-shrink: 0; padding: 0 2px; }

#topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
#sel-info { font-size: 12px; color: #555; font-weight: 500; white-space: nowrap; }

.btn-top { padding: 6px 12px; font-size: 12px; border-radius: var(--radius); border: 1px solid #ddd; background: transparent; color: #555; cursor: pointer; white-space: nowrap; }
.btn-top:hover { border-color: #aaa; color: #111; }
.btn-top-primary { background: #111; color: #fff; border-color: #111; }
.btn-top-primary:hover { background: #333; border-color: #333; }

#sort-select { padding: 6px 8px; font-size: 12px; border-radius: var(--radius); border: 1px solid #ddd; background: #fff; color: #555; cursor: pointer; outline: none; }
#sort-select:hover { border-color: #aaa; }

/* ── Main ────────────────────────────────────────────────── */
#main { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar { width: var(--sidebar); flex-shrink: 0; background: #fafafa; border-right: var(--border); overflow-y: auto; padding: 10px 0; }
.tree-section { font-size: 10px; color: #bbb; padding: 8px 14px 4px; letter-spacing: 0.07em; text-transform: uppercase; }
.tree-item { display: flex; align-items: center; gap: 5px; padding: 6px 14px; font-size: 12px; cursor: pointer; color: #666; border-left: 2px solid transparent; user-select: none; }
.tree-item:hover { background: #f0f0f0; color: #111; }
.tree-item.active { color: #111; font-weight: 500; background: #efefef; border-left-color: #111; }
.tree-arrow { font-size: 9px; color: #bbb; width: 10px; flex-shrink: 0; transition: transform 0.15s; }
.tree-item.open > .tree-arrow { transform: rotate(90deg); }
.tree-children { display: none; }
.tree-children.open { display: block; }

/* ── Content ─────────────────────────────────────────────── */
#content { flex: 1; overflow-y: auto; padding: 16px; background: #fff; }
.folder-header { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: #bbb; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid #eee; padding-bottom: 8px; margin-bottom: 16px; }

/* ── JS Masonry Grid ─────────────────────────────────────── */
.grid {
  position: relative;
  margin-bottom: 24px;
  min-height: 100px;
}

.thumb {
  position: absolute;
  cursor: pointer;
  border: 1px solid #111;
  border-radius: 2px;
  overflow: hidden;
  background: #f5f5f5;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

.thumb img {
  width: 100%; height: auto;
  display: block; transition: opacity 0.2s;
}
.thumb img.loading { opacity: 0; }

.thumb:hover { border-color: #555; }

/* Selected state — bordo blu 4px, nessun overlay */
.thumb.selected { border: 4px solid #0061fe; }

/* Check button — pallino sempre visibile, pieno se selezionato */
.check-btn {
  position: absolute; top: 7px; right: 7px;
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  background: rgba(0,0,0,0.25);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 3;
  transition: background 0.15s, border-color 0.15s;
}
.check-btn svg { width: 11px; height: 11px; opacity: 0; transition: opacity 0.15s; }
.thumb:hover .check-btn { background: rgba(0,0,0,0.4); }
.thumb.selected .check-btn { background: #0061fe; border-color: #0061fe; }
.thumb.selected .check-btn svg { opacity: 1; }

/* Enlarge button */
.enlarge-btn {
  position: absolute; bottom: 7px; right: 7px;
  width: 26px; height: 26px; border-radius: 4px;
  border: none;
  background: rgba(0,0,0,0.45);
  color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 3; opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1;
}
.thumb:hover .enlarge-btn { opacity: 1; }
.enlarge-btn:hover { background: rgba(0,0,0,0.7); }

/* Filename label */
.thumb-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 4px 34px 4px 7px;
  font-size: 10px; color: #fff;
  background: rgba(0,0,0,0.5);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity 0.15s; pointer-events: none;
}
.thumb:hover .thumb-label { opacity: 1; }

/* ── Empty / Spinner ─────────────────────────────────────── */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: #ccc; font-size: 13px; gap: 10px; }
.spinner { width: 28px; height: 28px; border: 2px solid #eee; border-top-color: #111; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Image view ──────────────────────────────────────────── */
#image-view { position: fixed; inset: 0; background: #fff; display: flex; flex-direction: column; z-index: 30; }
#iv-topbar { display: flex; align-items: center; gap: 12px; padding: 0 16px; height: var(--topbar); border-bottom: var(--border); flex-shrink: 0; }
#iv-back { font-size: 13px; cursor: pointer; border: 1px solid #ddd; border-radius: var(--radius); background: transparent; padding: 6px 14px; color: #555; }
#iv-back:hover { color: #111; border-color: #aaa; }
#iv-name { font-size: 13px; color: #888; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#iv-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-iv { padding: 7px 16px; font-size: 12px; font-weight: 500; border-radius: var(--radius); border: 1px solid #ddd; background: transparent; color: #555; cursor: pointer; }
.btn-iv:hover { border-color: #aaa; color: #111; }
.btn-iv-dl { background: #111; color: #fff; border-color: #111; }
.btn-iv-dl:hover { background: #333; }
.btn-iv.selected-state { background: #0061fe; color: #fff; border-color: #0061fe; }

#iv-body {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: #f8f8f8; overflow: hidden;
}

/* Click zones left/right */
.iv-zone {
  position: absolute; top: 0; bottom: 0; width: 50%;
  z-index: 2; cursor: pointer;
}
#iv-zone-prev { left: 0; }
#iv-zone-next { right: 0; }

#iv-content {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; padding: 24px 80px;
}

#iv-img {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  display: block;
  object-fit: contain;
}

/* Arrow buttons overlay */
#iv-arrows {
  position: absolute; inset: 0;
  display: flex; align-items: center;
  justify-content: space-between;
  pointer-events: none; z-index: 3;
  padding: 0 12px;
}

.iv-arrow-btn {
  width: 52px; height: 52px;
  background: rgba(0,0,0,0.12);
  border: none; border-radius: 50%;
  font-size: 32px; color: #111;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; pointer-events: all;
  transition: background 0.15s;
  line-height: 1;
}
.iv-arrow-btn:hover { background: rgba(0,0,0,0.22); }
.iv-arrow-btn:disabled { opacity: 0.2; cursor: default; }

/* ── Modal download ──────────────────────────────────────── */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
#modal { background: #fff; border: 1px solid #ddd; border-radius: 10px; width: 100%; max-width: 340px; padding: 24px; box-shadow: 0 12px 40px rgba(0,0,0,0.15); }
#modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
#modal-sub { font-size: 12px; color: #aaa; margin-bottom: 20px; }
.modal-label { font-size: 10px; color: #aaa; text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 10px; }
.opt-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.opt-row:last-of-type { border-bottom: none; }
.checkbox { width: 18px; height: 18px; border-radius: 4px; border: 1.5px solid #ccc; display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer; }
.checkbox.on { background: #111; border-color: #111; }
.checkbox svg { width: 10px; height: 10px; }
.opt-label { font-size: 13px; color: #222; flex: 1; }
.opt-tag { font-size: 10px; padding: 2px 8px; border-radius: 4px; background: #f0f0f0; color: #888; }
#modal-note { font-size: 11px; color: #bbb; margin-top: 14px; padding-top: 10px; border-top: 1px solid #f0f0f0; }
.modal-footer { margin-top: 20px; display: flex; gap: 8px; justify-content: flex-end; }
#btn-cancel, #ne-cancel, #ee-cancel { padding: 9px 16px; font-size: 13px; border-radius: var(--radius); border: 1px solid #ddd; background: transparent; color: #888; cursor: pointer; }
#btn-confirm, #ne-confirm, #ee-confirm { padding: 9px 20px; font-size: 13px; font-weight: 500; border-radius: var(--radius); border: none; background: #111; color: #fff; cursor: pointer; }
#btn-confirm:disabled { background: #ccc; cursor: not-allowed; }

/* ── ZIP ─────────────────────────────────────────────────── */
#zip-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 110; padding: 16px; }
#zip-modal { background: #fff; border-radius: 10px; padding: 28px 32px; width: 100%; max-width: 320px; text-align: center; }
#zip-title { font-size: 15px; font-weight: 500; margin-bottom: 20px; }
#zip-bar-wrap { height: 6px; background: #f0f0f0; border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
#zip-bar { height: 100%; background: #111; border-radius: 3px; width: 0%; transition: width 0.3s ease; }
#zip-info { font-size: 12px; color: #aaa; }

/* ── Admin modals ────────────────────────────────────────── */
#new-event-overlay, #edit-event-overlay, #manage-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
#new-event-modal, #edit-event-modal { background: #fff; border: 1px solid #ddd; border-radius: 10px; width: 100%; max-width: 420px; padding: 28px; box-shadow: 0 12px 40px rgba(0,0,0,0.15); }
#new-event-modal h2, #edit-event-modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
#new-event-modal p { font-size: 12px; color: #aaa; margin-bottom: 20px; }
#manage-modal { background: #fff; border: 1px solid #ddd; border-radius: 10px; width: 100%; max-width: 600px; max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,0.15); }
#manage-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid #eee; flex-shrink: 0; }
#manage-header h2 { font-size: 16px; font-weight: 600; }
#manage-close { font-size: 16px; cursor: pointer; border: none; background: transparent; color: #aaa; padding: 4px 8px; }
#manage-close:hover { color: #111; }
#events-list { flex: 1; overflow-y: auto; padding: 16px 24px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.field input[type=text] { width: 100%; padding: 9px 12px; font-size: 13px; border: 1px solid #ddd; border-radius: var(--radius); font-family: var(--font); outline: none; }
.field input[type=text]:focus { border-color: #111; }
.field input[type=file] { width: 100%; font-size: 13px; }

.folder-list { border: 1px solid #ddd; border-radius: var(--radius); max-height: 200px; overflow-y: auto; background: #fafafa; margin-top: 4px; }
.folder-row { display: flex; align-items: center; gap: 4px; padding: 7px 12px; font-size: 12px; color: #555; cursor: pointer; user-select: none; border-bottom: 1px solid #f0f0f0; }
.folder-row:last-child { border-bottom: none; }
.folder-row:hover { background: #f0f0f0; color: #111; }
.folder-row.selected { background: #111; color: #fff; }
.folder-row-arrow { font-size: 9px; width: 10px; flex-shrink: 0; }

.link-preview { padding: 10px 12px; font-size: 12px; color: #0061fe; font-family: monospace; background: #f0f5ff; border: 1px solid #d0e0ff; border-radius: var(--radius); margin-top: 12px; word-break: break-all; }

.event-card { border: 1px solid #e8e8e8; border-radius: 8px; padding: 14px 16px; display: flex; align-items: center; gap: 14px; margin-bottom: 10px; background: #fff; }
.event-card:hover { border-color: #ccc; }
.card-icon { width: 36px; height: 36px; background: #f0f0f0; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.card-info { flex: 1; min-width: 0; }
.card-name { font-size: 13px; font-weight: 500; margin-bottom: 3px; }
.card-path { font-size: 11px; color: #bbb; margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-link { font-size: 11px; color: #0061fe; font-family: monospace; background: #f0f5ff; padding: 3px 8px; border-radius: 4px; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 10px; color: #ccc; flex-shrink: 0; white-space: nowrap; }
.card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-card { padding: 6px 12px; font-size: 11px; border-radius: 5px; border: 1px solid #ddd; background: transparent; color: #555; cursor: pointer; }
.btn-card:hover { border-color: #aaa; color: #111; }
.btn-card-del { border-color: #fdd; color: #e44; padding: 6px 10px; }
.btn-card-del:hover { background: #fff0f0; }

#ee-cover-preview { margin-top: 8px; }
#ee-cover-preview img { max-width: 100%; max-height: 120px; border-radius: 4px; border: 1px solid #eee; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #topbar { padding: 0 10px; gap: 4px; overflow-x: auto; }
  #logo { font-size: 12px; }
  .btn-top { padding: 6px 8px; font-size: 11px; }
  #btn-dl-folder { display: none; }
  #content { padding: 10px; }
  #iv-content { padding: 16px 52px; }
  .iv-arrow-btn { width: 40px; height: 40px; font-size: 26px; }
}
@media (max-width: 480px) {
  .grid { columns: 2; }
  #sort-select { display: none; }
}
