/* =========================================================
   Light / Dark theme EXACT colors
   ========================================================= */

:root{
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #111111;
  --muted: #4b4b4b;

  --topbar-h: 64px;
  --grid-min: 180px; /* comfortable */
}

html[data-theme="dark"]{
  --bg: #111111;
  --panel: #111111;
  --text: #ffffff;
  --muted: #cfcfcf;
}

/* Grid sizes */
html[data-grid="compact"]{ --grid-min: 140px; }
html[data-grid="large"]{ --grid-min: 240px; }

/* Base */
*{ box-sizing: border-box; }
html, body{ height: 100%; }

body{
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden{ display: none !important; }
.muted{ color: var(--muted); }

code{
  padding: 2px 6px;
  font-size: 0.92em;
}

.sr-only{
  position:absolute !important;
  width:1px; height:1px;
  padding:0; margin:-1px;
  overflow:hidden; clip:rect(0,0,0,0);
  white-space:nowrap; border:0;
}

.no-scroll{ overflow: hidden; }

/* Topbar sticky */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  background: var(--panel);
}

.topbar-inner{
  height: 100%;
  width: min(1100px, 94vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr minmax(220px, 420px) auto;
  align-items: center;
  gap: 12px;
}

/* Brand */
.brand{
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-dot{
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text);
}

.brand-text{ font-size: 1.05rem; }

/* Search title centered */
.search-title{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 200;
  width: min(700px, 94vw);
  text-align: center;
}

.search-title .search-heading{
  margin: 0;
  font-size: clamp(1.2rem, 4.5vw, 2rem);
  line-height: 1;
  color: var(--text);
  font-weight: 700;
}

/* Controls group */
.controls{
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Sort select (minimal) */
.sort select{
  height: 36px;
  padding: 0 10px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  background: transparent;
  border: none;
}

/* Icon button (grid) */
.icon-btn{
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  transition: transform .12s ease;
}

.icon-btn:hover{
  transform: translateY(-1px);
}

.icon{ font-size: 0.95rem; line-height: 1; }

/* Minimal theme toggle */
.theme-toggle{
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  transition: transform .12s ease;
}

.theme-toggle:hover{
  transform: translateY(-1px);
}

.theme-toggle-icon{
  font-size: 1rem;
  line-height: 1;
}

/* Page layout */
.page{
  width: min(1100px, 94vw);
  margin: 0 auto;
  padding: 22px 0 70px;
}

.panel{
  background: var(--panel);
  padding: clamp(16px, 2.2vw, 22px);
}

.panel-head{
  padding-bottom: 14px;
}

.panel-head h1{
  margin: 0 0 6px 0;
  font-size: clamp(1.25rem, 2vw, 1.55rem);
}

.status{ padding: 18px 4px 8px; }

/* Folder sections */
.folders{
  display: grid;
  gap: 26px;
  padding-top: 18px;
}

.folder{
  padding: 14px 14px 2px;
}

.folder-head{
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px 14px;
}

.folder-title{
  margin: 0 0 6px 0;
  font-size: clamp(1.05rem, 1.6vw, 1.25rem);
}

.folder-desc{
  margin: 0;
  line-height: 1.5;
}

.folder-meta{
  white-space: nowrap;
  font-size: 0.9rem;
  padding-top: 2px;
}

/* Media grid */
.media-grid{
  margin: 0;
  padding: 14px 2px 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--grid-min), 1fr));
  gap: 12px;
}

.media-item{ margin: 0; }

.media-click{
  width: 100%;
  text-align: left;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.media-click:focus-visible{
  outline: 2px solid color-mix(in oklab, var(--text) 35%, transparent);
  outline-offset: 3px;
  border-radius: 12px;
}

.media-frame{
  border-radius: 12px;
  overflow: hidden;
}

/* Default aspect per immagini */
.media-frame-inner{
  width: 100%;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
}

/* Video: placeholder 16:9, poi JS lo rende dinamico */
.media-frame-inner.is-video{
  aspect-ratio: 16 / 9;
}

.media-frame-inner img,
.media-frame-inner video{
  width: 100%;
  height: 100%;
  display: block;
}

/* Immagini: ok il crop */
.media-frame-inner img{
  object-fit: cover;
}

/* Video: evita crop aggressivo */
.media-frame-inner video{
  object-fit: contain;
  background: #000;
}

/* Caption */
.media-caption{
  margin-top: 8px;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -------------------------
   Lightbox
-------------------------- */
.lightbox{
  position: fixed;
  inset: 0;
  z-index: 100;
}

.lightbox-backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}

.lightbox-panel{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(1100px, 94vw);
  max-height: 90vh;
  background: var(--panel);
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
}

.lightbox-close{
  justify-self: end;
  width: 34px;
  height: 34px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
}

.lightbox-content{
  display: grid;
  place-items: center;
  overflow: auto;
  border-radius: 10px;
  padding: 8px;
}

.lightbox-content img{
  max-width: 100%;
  height: auto;
  display: block;
}

.lightbox-content video{
  max-width: 100%;
  height: auto;
  display: block;
  background: #000;
}

.lightbox-caption{
  font-size: 0.95rem;
}

/* Mobile */
@media (max-width: 760px){
  .topbar-inner{
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 0;
  }
  .topbar{ height: auto; }

  .controls{
    flex-wrap: wrap;
    width: 100%;
  }

  .sort{
    flex: 1 1 100%;
  }

  .sort select{
    width: 100%;
  }
}
