/* Paleta sacada de flexi.com.mx (CSS de producción + logo oficial),
   no inventada: --primary/--secondary del tema = #c4262e; grises y
   bordes son sus propios tokens (#212529, #6c7079, #dee2e6, #f4f4f4). */
:root {
  --accent: #c4262e;
  --accent-tint: #fff1f1;
  --accent-tint-border: #ffd7d9;
  --ink: #212529;
  --ink-soft: #6c7079;
  --ink-faint: #9aa1a9;
  --border: #dee2e6;
  --bg: #f4f4f4;
  --surface: #fff;
  --hero-bg: #faf9f7;
  --danger: #db0002;
  --radius: 10px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }

/* El atributo HTML `hidden` y una clase con `display` propio empatan en
   especificidad — gana la que esté después en la hoja, no el `hidden`.
   Esto se hizo cargo de eso una vez, para todo el sitio, en vez de
   acordarse de evitarlo en cada clase (así se nos coló en
   .modal-backdrop: el modal vacío se veía siempre, encima de todo). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Manrope', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--ink); }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
::selection { background: var(--accent); color: #fff; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.badge-accent {
  color: var(--accent);
  background: var(--accent-tint);
  border: 1px solid var(--accent-tint-border);
  text-transform: uppercase;
}
.badge .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
}

.btn-primary {
  height: 48px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-primary.btn-sm { height: 38px; font-size: 13px; border-radius: 9px; }

.btn-secondary {
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: #4b4f59;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: none;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-faint);
}

.error-banner {
  background: var(--accent-tint);
  border: 1px solid var(--accent-tint-border);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 8px;
  margin: 2px 0;
}

/* ---------- Login ---------- */

.login-layout {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}

.login-hero {
  flex: 1 1 420px;
  min-width: 320px;
  background: var(--hero-bg);
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-start; /* sin esto, un hijo con width:auto (el logo) se estira
                               a todo el ancho del panel — así se deformó el logo */
  border-right: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.login-hero-glow {
  position: absolute; left: -60px; bottom: 120px;
  width: 420px; height: 420px; border-radius: 50%;
  background: var(--accent); opacity: 0.05;
}
.login-logo { height: 34px; width: auto; position: relative; }
.login-hero-copy { position: relative; max-width: 420px; }
.login-hero-copy h1 {
  font-size: 38px; line-height: 1.18; margin: 16px 0; font-weight: 800; letter-spacing: -0.5px;
}
.login-hero-copy p { font-size: 16px; line-height: 1.6; color: var(--ink-soft); margin: 0; }
.login-hero-stats { position: relative; display: flex; gap: 32px; font-size: 13px; color: var(--ink-soft); }
.login-hero-stats strong { display: block; color: var(--accent); font-weight: 800; font-size: 22px; }

.login-form-panel {
  flex: 1 1 420px;
  min-width: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 32px;
  background: var(--surface);
}
.login-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 18px; }
.login-form h2 { font-size: 24px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }
.login-form .muted { font-size: 14px; color: var(--ink-soft); margin: -12px 0 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: #333640; }
.field input {
  height: 46px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); padding: 0 14px; font-size: 14px; color: var(--ink); outline: none;
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--ink-faint); }

.input-with-action { position: relative; display: flex; align-items: center; }
.input-with-action input { flex: 1; padding-right: 44px; }
.input-with-action .icon-btn { position: absolute; right: 6px; }

.note-box {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  font-size: 13px; color: var(--ink-soft);
}
.note-box svg { flex-shrink: 0; margin-top: 1px; }

/* ---------- App shell ---------- */

.app-layout { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 64px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px; flex-wrap: wrap;
}
.topbar-brand { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.topbar-logo { height: 22px; width: auto; }
.app-name { font-weight: 700; font-size: 14px; }
.divider-v { width: 1px; height: 20px; background: var(--border); }

.topbar-search { flex: 1 1 320px; max-width: 520px; position: relative; display: flex; align-items: center; color: var(--ink-faint); }
.topbar-search svg { position: absolute; left: 14px; }
.topbar-search input {
  width: 100%; height: 40px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); padding: 0 14px 0 38px; font-size: 13px; outline: none; color: var(--ink);
}

.topbar-actions { display: flex; align-items: center; gap: 14px; margin-left: auto; flex-shrink: 0; }
.user-menu { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #4b4f59; text-transform: uppercase;
}
.user-name { font-weight: 600; font-size: 13px; line-height: 1.1; }
#logout-link { font-size: 11px; color: var(--ink-faint); font-weight: 600; }

.app-body { flex: 1; display: flex; flex-wrap: wrap; }

.sidebar {
  width: 240px; flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-title {
  font-size: 11px; font-weight: 700; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: 0.5px; padding: 0 12px; margin-bottom: 8px;
}
.navitem {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: #4b4f59;
  cursor: pointer; user-select: none;
  transition: background-color .15s ease, color .15s ease, transform .1s ease;
}
.navitem:hover:not(.active) { background: var(--bg); color: var(--ink); }
.navitem:active { transform: scale(0.98); }
.navitem .count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--ink-faint); }
.navitem.active { background: var(--accent-tint); color: var(--accent); }

.content { flex: 1 1 640px; min-width: 0; padding: 24px 28px; }

.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-faint); font-weight: 600; margin-bottom: 4px; }
.breadcrumb .current { color: var(--ink); }

.content-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.content-head h1 { font-size: 22px; font-weight: 800; margin: 0; letter-spacing: -0.3px; }
.content-actions { display: flex; align-items: center; gap: 8px; }

.sort-control { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.sort-control select {
  height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); padding: 0 10px; font-size: 13px; color: var(--ink);
  font-family: inherit;
}
#sort-dir-btn { border: 1px solid var(--border); background: var(--surface); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; display: flex; flex-direction: column; }

.upload-card {
  border: 1.5px dashed #c7c9cd; background: #fbfbfb;
  align-items: center; justify-content: center; min-height: 190px;
  gap: 8px; color: var(--ink-faint); text-align: center; padding: 16px;
}
.upload-card-title { font-size: 12px; font-weight: 700; color: #4b4f59; }
.upload-card-sub { font-size: 11px; }
.upload-card.dragover { border-color: var(--accent); background: var(--accent-tint); }

.thumb { aspect-ratio: 1 / 1; display: block; width: 100%; object-fit: cover; background: var(--bg); }
.thumb-fallback {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--ink-faint);
}
.card-body { padding: 10px 12px 12px; }
.card-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { font-size: 11px; color: var(--ink-faint); margin-top: 2px; display: flex; justify-content: space-between; gap: 6px; }
.card-meta button { background: none; border: none; color: var(--ink-faint); padding: 0; font-size: 11px; font-weight: 600; transition: color .15s ease; }
.card-meta button:hover { color: var(--accent); }
.card-meta button:disabled,
.uploaded-url-row button:disabled { color: #2f9e63; cursor: default; }

.load-more-wrap { display: flex; justify-content: center; margin-top: 28px; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(21,23,28,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 24px; width: 100%; max-width: 440px; max-height: 80vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.modal h3 { margin: 0; font-size: 17px; }
.modal .muted { font-size: 13px; color: var(--ink-soft); margin: -8px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.search-empty {
  grid-column: 1 / -1; padding: 40px 16px; text-align: center;
  color: var(--ink-faint); font-size: 13px;
}

.uploaded-list { display: flex; flex-direction: column; gap: 12px; }
.uploaded-row { display: flex; flex-direction: column; gap: 6px; }
.uploaded-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uploaded-url-row { display: flex; gap: 8px; }
.uploaded-url-input {
  flex: 1; min-width: 0; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); padding: 0 10px; font-size: 12px; color: var(--ink-soft);
  font-family: ui-monospace, monospace;
}

@media (max-width: 720px) {
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); flex-direction: row; overflow-x: auto; }
  .navitem .count { display: none; }
}

/* ---------- Usuarios ---------- */

.users-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th {
  text-align: left; font-size: 11px; font-weight: 700; color: var(--ink-faint);
  text-transform: uppercase; letter-spacing: 0.4px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.users-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table .muted { color: var(--ink-soft); }

.link-btn {
  background: none; border: none; color: var(--accent); font-size: 13px;
  font-weight: 600; padding: 0; cursor: pointer;
}
.link-btn-danger { color: var(--ink-faint); }
.link-btn-danger:hover { color: var(--danger); }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; }
.checkbox-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 2px 12px; margin-top: 6px; max-height: 180px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--bg);
}
