/* ============== App shell ============== */
.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}
@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; height: 100vh; transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; }
  .sidebar-backdrop.open { display: block; }
}

/* ============== Sidebar (siempre oscuro, identidad de marca) ============== */
.sidebar {
  background:
    radial-gradient(520px 380px at 0% 0%, rgba(212,175,55,.10), transparent 60%),
    linear-gradient(180deg, var(--petrol-800), var(--petrol-900));
  border-right: 1px solid rgba(212,175,55,.14);
  color: #f3efe4;
  display: flex; flex-direction: column;
  padding: 22px 16px 16px;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.sidebar-logo .mark {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--gold-200), var(--gold-600));
  color: #1a1203; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
}
.sidebar-logo .name { font-family: var(--font-display); font-weight: 600; letter-spacing: .05em; line-height: 1.15; }
.sidebar-logo .name small { display: block; font-family: var(--font); font-weight: 500; font-size: .68rem; color: var(--gold-200); letter-spacing: .14em; text-transform: uppercase; }

.nav-group { margin-top: 14px; }
.nav-group .label { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: rgba(243,239,228,.4); padding: 0 10px 8px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 2px;
  color: rgba(243,239,228,.78); text-decoration: none; font-size: .9rem; font-weight: 500;
  border: 1px solid transparent;
}
.nav-link svg { width: 17px; height: 17px; flex: 0 0 auto; opacity: .85; }
.nav-link:hover { background: rgba(212,175,55,.08); color: #fff; }
.nav-link.active {
  background: linear-gradient(90deg, rgba(212,175,55,.16), rgba(212,175,55,.04));
  border-color: rgba(212,175,55,.3);
  color: var(--gold-200);
}
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(212,175,55,.14); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.sidebar-user .av {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  background: var(--petrol-600); border: 1px solid rgba(212,175,55,.35);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--gold-200); font-size: .8rem;
}
.sidebar-user .who { font-size: .82rem; line-height: 1.3; }
.sidebar-user .who b { display: block; color: #fff; }
.sidebar-user .who span { color: rgba(243,239,228,.5); font-size: .74rem; }
.logout-link { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 9px 8px; font-size: .82rem; color: rgba(243,239,228,.55); text-decoration: none; border-radius: 8px; }
.logout-link:hover { color: #fff; background: rgba(255,255,255,.06); }

/* ============== Contenido / Topbar ============== */
.content { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.15rem; }
.menu-btn { display: none; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); align-items: center; justify-content: center; cursor: pointer; }
@media (max-width: 920px) { .menu-btn { display: flex; } }
.main { padding: 26px 28px 60px; max-width: 1280px; }

/* ============== Tarjetas / KPI ============== */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card-title { font-size: .95rem; font-weight: 700; margin-bottom: 4px; }
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1080px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.kpi { padding: 18px 20px; }
.kpi .label { font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); margin-bottom: 10px; }
.kpi .value { font-size: 1.7rem; font-weight: 800; }
.kpi .delta { font-size: .78rem; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; }
.delta.up { color: var(--ok); } .delta.down { color: var(--danger); }

/* ============== Badges / niveles ============== */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .02em; border: 1px solid var(--border);
}
.badge.gold { background: linear-gradient(135deg, var(--gold-200), var(--gold-600)); color: var(--on-gold); border: none; }
.badge.bronze { background: rgba(166,124,55,.18); color: #c99a56; }
.badge.silver { background: rgba(192,192,200,.18); color: #c3c7d1; }
.badge.gold-lvl { background: rgba(212,175,55,.18); color: var(--gold-hi); }
.badge.centurion { background: linear-gradient(135deg, var(--gold-200), var(--gold-700)); color: var(--on-gold); border: none; }
.badge.green { background: rgba(76,175,125,.15); color: var(--ok); }
.badge.red { background: rgba(194,84,80,.15); color: var(--danger); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); }

/* ============== Barra de progreso ============== */
.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold-600), var(--gold-300)); }
.progress.thin { height: 5px; }

/* ============== Botones ============== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; font-size: .86rem; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--gold); }
.btn.primary { background: linear-gradient(135deg, var(--gold-300), var(--gold-600)); color: var(--on-gold); border: none; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 12px; font-size: .78rem; }
.btn svg { width: 16px; height: 16px; }

/* ============== Tabla ============== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.selected { background: var(--surface-2); box-shadow: inset 2px 0 0 var(--gold); }

/* ============== Formularios ============== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .78rem; font-weight: 600; color: var(--text-2); }
.field input, .field select, .field textarea {
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; color: var(--text); font-size: .88rem; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--gold); }
.field textarea { resize: vertical; min-height: 72px; }

/* ============== Modal ============== */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(2,6,6,.6); backdrop-filter: blur(3px);
  z-index: 60; align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-close { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); cursor: pointer; }

/* ============== Lista de desafíos / eventos ============== */
.challenge-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
}
.challenge-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.challenge-card h3 { font-size: 1rem; }
.challenge-card p { font-size: .85rem; color: var(--text-2); }
.challenge-card .meta { display: flex; flex-wrap: wrap; gap: 14px; font-size: .78rem; color: var(--text-3); }

.event-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.event-row:last-child { border-bottom: none; }
.event-date { width: 52px; height: 52px; flex: 0 0 auto; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.event-date b { font-size: 1.1rem; line-height: 1; color: var(--gold); }
.event-date span { font-size: .62rem; text-transform: uppercase; color: var(--text-3); }

/* ============== Login ============== */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; box-shadow: var(--shadow); padding: 34px 30px 28px; position: relative; z-index: 2;
}
.login-banner { border-radius: 16px; overflow: hidden; margin-bottom: 22px; border: 1px solid var(--border); }
.role-switch { display: flex; gap: 8px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.role-switch button {
  flex: 1; padding: 9px; border-radius: 9px; border: none; background: transparent; color: var(--text-2);
  font-weight: 700; font-size: .82rem; cursor: pointer;
}
.role-switch button.active { background: linear-gradient(135deg, var(--gold-300), var(--gold-600)); color: var(--on-gold); }

.top-fixed-toggle { position: fixed; top: 18px; right: 18px; z-index: 50; }
