@font-face {
  font-family: 'Oswald';
  src: url('/static/fonts/Oswald-Bold.ttf') format('truetype');
  font-weight: 700;
}
@font-face {
  font-family: 'JBMono';
  src: url('/static/fonts/JetBrainsMono-Regular.ttf') format('truetype');
  font-weight: 400;
}
@font-face {
  font-family: 'JBMono';
  src: url('/static/fonts/JetBrainsMono-Bold.ttf') format('truetype');
  font-weight: 700;
}

:root{
  --bg: #131211;
  --panel: #1c1a18;
  --panel-2: #201e1b;
  --line: #34302b;
  --ink: #ece7dd;
  --muted: #8f887b;
  --amber: #e0912f;
  --amber-ink: #17140d;
  --teal: #6fa79c;
  --radius: 3px;
}

*{ box-sizing: border-box; }

/* el atributo hidden siempre debe ganar, sin importar que otra regla
   (como .lightbox, .tray, .load-more) también declare `display` */
[hidden]{ display: none !important; }

body{
  margin:0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'JBMono', monospace;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 40px;
}

/* sprocket holes, como una tira de negativos */
.sprocket{
  height: 14px;
  background-image: repeating-linear-gradient(
    90deg,
    var(--panel) 0px, var(--panel) 10px,
    transparent 10px, transparent 22px
  );
  background-color: #0c0b0a;
}

/* ---------------- topbar ---------------- */
.topbar{
  padding: 22px 28px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.topbar__brand{ margin-bottom: 16px; }
h1{
  font-family: 'Oswald', sans-serif;
  font-weight: 700;
  text-transform: uppercase;
  font-size: clamp(26px, 4vw, 36px);
  margin: 0;
  letter-spacing: 0.01em;
}
h1 .slash{ color: var(--amber); }
.topbar__tag{
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.topbar__logout{
  float: right;
  font-size: 10.5px;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.05em;
}
.topbar__logout:hover{ color: var(--amber); }

.searchbar{
  display:flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.searchbar__input{
  flex: 1 1 320px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 12px 14px;
  font-family: 'JBMono', monospace;
  font-size: 14px;
  border-radius: var(--radius);
}
.searchbar__input:focus{ outline: 2px solid var(--amber); outline-offset: 1px; }

.source-pills{ display:flex; gap: 6px; }
.pill{
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: 'JBMono', monospace;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius);
}
.pill.is-active{ border-color: var(--amber); color: var(--amber); }

.btn{
  font-family: 'JBMono', monospace;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  padding: 11px 18px;
  text-decoration: none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap: 8px;
}
.btn:hover{ border-color: var(--amber); }
.btn--shutter{
  background: var(--amber);
  color: var(--amber-ink);
  border-color: var(--amber);
}
.btn--shutter:hover{ background:#f0a548; border-color:#f0a548; }
.btn--outline{ background: transparent; }
.btn--ghost{
  background: none; border: none; color: var(--muted);
}
.btn--ghost:hover{ color: var(--ink); border:none; }
.btn--full{ width: 100%; }
.btn:disabled{ opacity: 0.5; cursor: default; }

.spinner{
  width: 12px; height:12px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  display:none;
}
.spinner.spin{ display:inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin{ to{ transform: rotate(360deg); } }

.filters{
  display:flex; align-items:center; gap: 8px; margin-top: 14px; flex-wrap: wrap;
}
.chip{
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  padding: 7px 12px;
  cursor: pointer;
  border-radius: 999px;
}
.chip.is-active{ border-color: var(--teal); color: var(--teal); }
.result-count{ margin-left: auto; font-size: 11px; color: var(--muted); }

/* ---------------- contact sheet grid ---------------- */
.contact-sheet{
  padding: 22px 28px 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.empty-state{
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  padding: 60px 10px;
  text-align: center;
  border: 1px dashed var(--line);
}

.card{
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
}
.card__img{
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display:block;
  background:
    linear-gradient(45deg, #2a2723 25%, transparent 25%),
    linear-gradient(-45deg, #2a2723 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2723 75%),
    linear-gradient(-45deg, transparent 75%, #2a2723 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}
.card__badges{
  position:absolute; top:8px; left:8px;
  display:flex; gap:4px; z-index:2;
}
.badge{
  font-size: 9px;
  letter-spacing: 0.04em;
  padding: 3px 6px;
  background: rgba(19,18,17,0.82);
  border: 1px solid var(--line);
  color: var(--ink);
}
.badge--alpha{ color: var(--teal); border-color: var(--teal); }
.badge--clean{ color: var(--amber); border-color: var(--amber); }

.card__star{
  position:absolute; top:8px; right:8px; z-index:2;
  width: 28px; height: 28px;
  background: rgba(19,18,17,0.82);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor:pointer;
  font-size: 14px;
  line-height:1;
}
.card__star:hover{ border-color: var(--amber); color: var(--amber); }
.card__star.is-selected{ color: var(--amber); border-color: var(--amber); }

.card__foot{
  display:flex; justify-content: space-between;
  padding: 6px 8px;
  font-size: 10px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.load-more{
  display:block;
  margin: 10px auto 0;
}

/* ---------------- tray de selección ---------------- */
.tray{
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--amber);
  padding: 10px 14px;
  display:flex; align-items:center; gap: 12px;
  font-size: 12px;
  z-index: 40;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* ---------------- lightbox editor ---------------- */
.lightbox{
  position: fixed; inset: 0;
  background: rgba(8,7,6,0.9);
  z-index: 100;
  display:flex; align-items:center; justify-content:center;
  padding: 20px;
}
.lightbox__panel{
  background: var(--panel);
  border: 1px solid var(--line);
  max-width: 1100px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
}
.lightbox__close{
  position:absolute; top:10px; right:10px; z-index:5;
  width: 34px; height:34px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  cursor:pointer;
  font-size: 16px;
}
.lightbox__close:hover{ border-color: var(--amber); color: var(--amber); }

.editor{
  display:grid;
  grid-template-columns: 1fr 300px;
}
@media (max-width: 780px){
  .editor{ grid-template-columns: 1fr; }
}

.editor__canvas-wrap{
  position: relative;
  background:
    linear-gradient(45deg, #201e1b 25%, transparent 25%),
    linear-gradient(-45deg, #201e1b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #201e1b 75%),
    linear-gradient(-45deg, transparent 75%, #201e1b 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #100f0e;
  display:flex; align-items:center; justify-content:center;
  min-height: 320px;
  overflow: hidden;
  user-select: none;
}
.editor__img{
  max-width: 100%;
  max-height: 78vh;
  display:block;
}
.crop-box{
  position:absolute;
  border: 2px dashed var(--amber);
  background: rgba(224,145,47,0.12);
  cursor: move;
}
.crop-handle{
  position:absolute;
  width: 12px; height:12px;
  background: var(--amber);
}
.crop-handle--nw{ top:-6px; left:-6px; cursor: nwse-resize; }
.crop-handle--ne{ top:-6px; right:-6px; cursor: nesw-resize; }
.crop-handle--sw{ bottom:-6px; left:-6px; cursor: nesw-resize; }
.crop-handle--se{ bottom:-6px; right:-6px; cursor: nwse-resize; }

.editor__side{
  padding: 18px;
  display:flex;
  flex-direction: column;
  gap: 16px;
  border-left: 1px solid var(--line);
}
.editor__meta{
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
}
.tag-label{
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}
.editor__group{ display:flex; flex-direction: column; gap: 8px; }
.editor__group--grow{ flex: 1; }
.editor__hint{ font-size: 10.5px; color: var(--muted); line-height:1.5; margin:0; }
.editor__crop-actions{ display:flex; gap: 8px; }
.editor__source-link{
  font-size: 10.5px; color: var(--muted); text-decoration:none;
  border-top: 1px solid var(--line); padding-top: 12px;
}
.editor__source-link:hover{ color: var(--amber); }
.editor__actions-final{ gap: 10px; }

@media (prefers-reduced-motion: reduce){
  .spinner.spin{ animation: none; }
}

/* ---------------- login ---------------- */
.login-wrap{
  min-height: calc(100vh - 28px);
  display:flex; align-items:center; justify-content:center;
  padding: 20px;
}
.login-card{
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 30px 26px;
  display:flex;
  flex-direction: column;
  gap: 6px;
}
.login-card h1{
  text-align:center;
  margin-bottom: 2px;
}
.login-card__tag{
  text-align:center;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  margin: 0 0 18px;
}
.login-card .tag-label{ margin-top: 10px; }
.login-card__submit{ margin-top: 22px; }
.login-card__error{
  background: rgba(224,60,47,0.12);
  border: 1px solid #a5372a;
  color: #f0a48f;
  font-size: 12px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
