:root {
  --bg: #f4f7f6;
  --panel: #ffffff;
  --ink: #14201e;
  --muted: #5a6a67;
  --line: #dce5e2;
  --accent: #23786b;
  --accent-ink: #ffffff;
  --accent-soft: #dff1ed;
  --danger: #b83227;
  --tile: #e2e9e7;
  --shadow: 0 6px 24px rgba(10, 30, 26, .14);
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514;
    --panel: #162120;
    --ink: #e7efed;
    --muted: #9cb1ad;
    --line: #24332f;
    --accent: #5fcab6;
    --accent-ink: #00241d;
    --accent-soft: #173a34;
    --danger: #ff8070;
    --tile: #1e2b29;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }
svg.i { width: 22px; height: 22px; fill: currentColor; flex: none; display: block; }
svg.i.sm { width: 18px; height: 18px; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel);
  padding: 8px 14px; border-radius: 999px; font-weight: 600;
}
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border: 0; background: transparent;
  border-radius: 50%; color: inherit;
}
.icon-btn:hover { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- acceso ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
}
.login form {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login img { width: 56px; height: 56px; border-radius: 14px; }
.login h1 { margin: 6px 0 0; font-size: 26px; }
.login p { margin: 0; color: var(--muted); }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; color: var(--muted); }
.field input, .field select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 11px 12px; font-size: 15px; color: var(--ink);
}
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.err { color: var(--danger); font-size: 14px; min-height: 1.2em; }

/* ---------- estructura ---------- */
.shell {
  display: grid; grid-template-columns: 236px minmax(0, 1fr); grid-template-rows: 62px minmax(0, 1fr); height: 100%;
}
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; width: 204px; flex: none; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.search {
  flex: 1; min-width: 0; max-width: 560px; display: flex; align-items: center; gap: 8px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; height: 40px;
}
.search input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; }
.spacer { flex: 1; }
.sidebar {
  padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--line);
  background: var(--panel); overflow: auto;
}
.nav {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 999px; text-decoration: none;
  color: var(--ink); font-weight: 600;
}
.nav:hover { background: var(--accent-soft); }
.nav.on { background: var(--accent-soft); color: var(--accent); }
.meter { margin-top: auto; padding: 14px; font-size: 13px; color: var(--muted); }
.meter .bar { height: 6px; border-radius: 3px; background: var(--tile); overflow: hidden; margin: 8px 0 6px; }
.meter .bar > i { display: block; height: 100%; background: var(--accent); }
main { overflow: auto; position: relative; padding: 0 0 80px; }
.menu-btn { display: none; }

.head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 4px; flex-wrap: wrap; }
.head h2 { margin: 0; font-size: 22px; }
.head .sub { color: var(--muted); font-size: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 20px; align-items: center; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 14px;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.filters input[type=date] { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; }

/* barra de selección */
.selbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; padding: 8px 16px;
  background: var(--accent); color: var(--accent-ink);
}
.selbar .icon-btn:hover { background: rgba(255, 255, 255, .22); }
.selbar b { margin: 0 8px; }

/* ---------- galería ---------- */
.day { padding: 18px 20px 6px; font-weight: 700; font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 3px; padding: 0 17px; }
.tile {
  position: relative; aspect-ratio: 1; background: var(--tile); overflow: hidden; cursor: pointer; border-radius: 4px;
  outline-offset: -2px;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .15s; }
.tile.sel img { transform: scale(.86); border-radius: 6px; }
.tile.noimg { display: grid; place-items: center; color: var(--muted); }
.tile .badge {
  position: absolute; right: 6px; top: 6px; background: rgba(0, 0, 0, .62); color: #fff; font-size: 12px; font-weight: 600;
  padding: 2px 8px 2px 4px; border-radius: 999px; display: flex; align-items: center; gap: 2px;
}
.tile .fav { position: absolute; left: 7px; bottom: 7px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6)); }
.tile .chk {
  position: absolute; left: 6px; top: 6px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, .25);
  opacity: 0; display: grid; place-items: center; color: transparent; padding: 0;
}
.tile:hover .chk, .selecting .tile .chk { opacity: 1; }
.tile.sel .chk { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); opacity: 1; }
.tile .chk svg { width: 16px; height: 16px; }
.empty { padding: 70px 24px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin: 14px 0 6px; font-size: 20px; }
.more { padding: 24px; text-align: center; color: var(--muted); }

/* álbumes */
.albums { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; padding: 16px 20px; }
.album { cursor: pointer; text-align: left; border: 0; background: transparent; padding: 0; }
.album .cover { aspect-ratio: 1; border-radius: 14px; background: var(--tile); overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.album .cover img { width: 100%; height: 100%; object-fit: cover; }
.album .t { font-weight: 600; margin-top: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album .n { font-size: 13px; color: var(--muted); }

/* tablas */
.table { width: calc(100% - 40px); margin: 12px 20px; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .act { text-align: right; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-all; }

/* ---------- visor ---------- */
html.lb-open, html.lb-open body { overflow: hidden; }
.lb { position: fixed; inset: 0; z-index: 50; background: #050808; display: flex; color: #fff; }
/* La foto y sus controles ocupan todo el ancho que deja el panel de información (si está abierto). */
.lb-main { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lb-top { display: flex; align-items: center; gap: 2px; padding: 8px 10px; background: linear-gradient(#000a, #0000); position: absolute; left: 0; right: 0; top: 0; z-index: 2; transition: opacity .2s; }
.lb-top .t { flex: 1; min-width: 0; padding: 0 10px; }
.lb-top .t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-top .t span { font-size: 13px; opacity: .75; }
.lb-top .icon-btn:hover { background: rgba(255, 255, 255, .18); }
/* La foto llena el escenario y se ajusta entera (contain): no depende del tamaño original. */
.lb-stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.lb-stage img, .lb-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.lb-stage img { cursor: zoom-in; }
/* Ampliada (100 %): se desplaza con la rueda, las barras o arrastrando. margin:auto centra sin
   dejar partes inalcanzables (place-items:center cortaba el borde izquierdo y el superior). */
.lb-scroll { position: absolute; inset: 0; overflow: auto; display: flex; cursor: grab; }
.lb-scroll.drag { cursor: grabbing; user-select: none; }
.lb-scroll img { position: static; width: auto; height: auto; max-width: none; max-height: none; margin: auto; flex: none; cursor: zoom-out; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 52px; height: 52px; background: rgba(0, 0, 0, .35); color: #fff; }
.lb-nav.l { left: 10px; } .lb-nav.r { right: 10px; }
.lb-nav:hover { background: rgba(0, 0, 0, .6); }
.lb.hide .lb-top, .lb.hide .lb-nav { opacity: 0; pointer-events: none; }
/* Columna propia al lado de la foto: no tapa la barra de botones. */
.lb-info { flex: none; width: 340px; background: var(--panel); color: var(--ink); padding: 10px 22px 22px; overflow: auto; border-left: 1px solid var(--line); }
.lb-info .head { display: flex; align-items: center; gap: 6px; margin: 0 -12px 8px; }
.lb-info .head b { flex: 1; font-size: 16px; }
.lb-info h3 { margin: 0 0 12px; word-break: break-word; }
.lb-info dl { display: grid; grid-template-columns: 96px 1fr; gap: 10px 12px; margin: 0; }
.lb-info dt { color: var(--muted); font-size: 13px; } .lb-info dd { margin: 0; word-break: break-word; }

/* ---------- ventanas, avisos y subidas ---------- */
.veil { position: fixed; inset: 0; z-index: 60; background: rgba(5, 12, 10, .55); display: grid; place-items: center; padding: 16px; }
.modal { width: min(440px, 100%); max-height: 90vh; overflow: auto; background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); padding: 22px; display: grid; gap: 14px; }
.modal h3 { margin: 0; font-size: 19px; }
.modal p { margin: 0; color: var(--muted); }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.radio { display: flex; gap: 10px; align-items: center; padding: 6px 2px; }
.pick { max-height: 300px; overflow: auto; display: grid; gap: 4px; }
.pick button { display: flex; align-items: center; gap: 12px; border: 0; background: transparent; padding: 8px; border-radius: 10px; text-align: left; }
.pick button:hover { background: var(--accent-soft); }
.pick img, .pick .ph { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--tile); flex: none; }
.copy { display: flex; gap: 8px; }
.copy input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 9px 10px; font-size: 13px; }

.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { background: #1d2a28; color: #fff; padding: 11px 18px; border-radius: 12px; box-shadow: var(--shadow); display: flex; gap: 16px; align-items: center; pointer-events: auto; }
.toast button { border: 0; background: transparent; color: #7fe0cd; font-weight: 700; padding: 0; }
.toast.bad { background: #7a2018; } .toast.bad button { color: #ffd2cc; }

.drop { position: fixed; inset: 0; z-index: 80; background: rgba(35, 120, 107, .85); color: #fff; display: grid; place-items: center; font-size: 26px; font-weight: 700; pointer-events: none; }
.uploads { position: fixed; right: 16px; bottom: 16px; z-index: 70; width: min(380px, calc(100% - 32px)); background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden; }
.uploads header { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.uploads header span { flex: 1; }
.uploads header .icon-btn:hover { background: rgba(255, 255, 255, .2); }
.uploads ul { list-style: none; margin: 0; padding: 4px 0; max-height: 280px; overflow: auto; }
.uploads li { padding: 8px 16px; display: grid; gap: 4px; font-size: 13px; }
.uploads li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.uploads li .st { color: var(--muted); }
.uploads li.bad .st { color: var(--danger); }
.uploads .bar { height: 4px; background: var(--tile); border-radius: 2px; overflow: hidden; }
.uploads .bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- pantallas pequeñas ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 62px; bottom: 0; left: 0; width: 250px; z-index: 40; transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-grid; }
  .brand { width: auto; } .brand span { display: none; }
  /* En pantallas estrechas la información se superpone (no hay sitio al lado); se cierra con su botón. */
  .lb-info { position: absolute; right: 0; top: 0; bottom: 0; width: min(340px, 100%); z-index: 5; box-shadow: var(--shadow); }
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .btn .lbl { display: none; }
  .topbar .btn.primary { padding: 0 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); padding: 0 8px; }
  .day, .head, .filters { padding-left: 12px; padding-right: 12px; }
  .table { width: calc(100% - 16px); margin: 8px; font-size: 14px; }
  .table th:nth-child(n+4), .table td:nth-child(n+4) { display: none; }
  .table .act { display: table-cell !important; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
