:root{
  --bg:#f8f9fa;
  --card-bg:#fff;
  --text:#222;
  --muted:#666;
  --accent:#e9511d;
}

*{box-sizing:border-box}
body{
  font-family: "Segoe UI", Roboto, system-ui, Arial, sans-serif;
  margin:0;
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
}

/* Header */
/* Enhanced Header with Flexbox */
header {
  position: sticky;
  top: 0;
  background: white;
  padding: 0.5rem 1.5rem; /* Reduced padding for a sleeker look */
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: space-between; /* Spreads Logo, Search, and User */
  gap: 1rem;
  z-index: 100;
  flex-wrap: nowrap; /* Keep it on one line for desktop */
}

.header-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-logo {
  height: auto;
  width: 120px;
  display: block;
  object-fit: contain;
}

.header-center {
  flex-grow: 1;
  display: flex;
  justify-content: center;
}

#search {
  width: 100%;
  max-width: 520px; /* Stays consistent with your original style */
}

/* User Profile Section */
.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 200px;
}

.user-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 220px; /* Limits the area for long names */
}

.username-display {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* Crucial: Adds "..." for names up to 55 chars */
  width: 100%;
  text-align: right;
}

.user-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 2px;
}

.admin-link {
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: bold;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* User Table Adjustments for admin.php */
.admin-card table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed; /* Forces columns to respect widths */
}

.admin-card th, .admin-card td {
  padding: 10px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Set specific widths to prevent "Acciones" from being pushed out */
.admin-card th:nth-child(1), .admin-card td:nth-child(1) { width: 40%; } /* Usuario */
.admin-card th:nth-child(2), .admin-card td:nth-child(2) { width: 15%; } /* Rol */
.admin-card th:nth-child(3), .admin-card td:nth-child(3) { width: 25%; } /* Última Conexión */
.admin-card th:nth-child(4), .admin-card td:nth-child(4) { width: 20%; text-align: right; } /* Acciones */

/* Mobile Responsive Header */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    padding: 1rem;
  }
  .header-center {
    order: 3; /* Moves search bar below Logo and User on mobile */
    width: 100%;
  }
  .header-right {
    min-width: auto;
  }
}

/* Results grid */
main{padding:1.25rem}
#results{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(260px, 1fr));
  gap:1.1rem;
}

/* Card */
.card{
  background:var(--card-bg);
  border-radius:12px;
  padding:0;
  overflow:hidden;
  box-shadow:0 2px 8px rgba(0,0,0,0.06);
  display:flex;
  flex-direction:column;
  cursor:pointer;
  transition:transform .12s ease, box-shadow .12s ease;
}
.card:hover{transform:translateY(-4px); box-shadow:0 6px 18px rgba(0,0,0,0.10)}
.card-media{
  height:170px;
  background:#fafafa;
  display:flex;
  align-items:center;
  justify-content:center;
  border-bottom:1px solid #f0f0f0;
}
.card-media img{
  max-width:100%;
  max-height:150px;
  object-fit:contain;
}
.card-body{padding:0.9rem 1rem; display:flex;flex-direction:column; gap:0.4rem}
.card-body h3{margin:0;font-size:1rem;color:var(--text)}
.card-body p{margin:0;color:var(--muted);font-size:0.9rem}
.card-body .meta{font-size:0.85rem;color:#777}

/* Modal (details) */
.modal.hidden{display:none}
.modal{
  position:fixed; inset:0; display:flex; align-items:center; justify-content:center;
  background:rgba(0,0,0,0.5); z-index:2000; padding:1rem;
}
.modal-inner{
  width:100%; max-width:1100px; background:white; border-radius:12px; overflow:auto;
  max-height:95vh; position:relative; padding:1rem 1rem 1.5rem;
}
.modal-close{
  position:absolute; right:12px; top:10px; border:none; background:transparent; font-size:28px;
  cursor:pointer; color:#333;
}

/* Modal grid */
.modal-grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:1rem;
}
.gallery{display:flex; flex-direction:column; gap:10px}
.main-image-wrap{background:#f7f7f7; border-radius:8px; padding:8px; display:flex; align-items:center; justify-content:center}
#mainImage{max-width:100%; max-height:60vh; object-fit:contain; border-radius:6px; cursor:zoom-in}

.thumbs{display:flex; gap:8px; flex-wrap:wrap}
.thumbs img{width:72px; height:72px; object-fit:cover; border-radius:6px; cursor:pointer; border:2px solid transparent}
.thumbs img.active{border-color:var(--accent)}

/* Details side */
.details{padding:0.25rem 0.5rem}
.details h2{margin:0 0 0.5rem; font-size:1.15rem}
.resumen{color:var(--muted); margin:0 0 0.8rem}
.description{margin-bottom:1rem}
.files-list a{
  display:inline-block; margin-right:8px; margin-bottom:8px;
  padding:6px 10px; background:var(--accent); color:white; text-decoration:none; border-radius:6px; font-size:0.9rem;
}
.files-list a.secondary{background:#555}

/* Lightbox */
.lightbox.hidden{display:none}
.lightbox{
  position:fixed; inset:0; background:rgba(0,0,0,0.9); display:flex; align-items:center; justify-content:center; z-index:3000;
}
.lightbox img{max-width:95%; max-height:95%; border-radius:8px}

/* Responsive */
@media (max-width:920px){
  .modal-grid{grid-template-columns:1fr}
  #mainImage{max-height:50vh}
}
@media (max-width:600px){
  #results{grid-template-columns:1fr}
  .card-media{height:140px}
  .thumbs img{width:58px;height:58px}
}
