:root {
  --rojo: #B71C1C;
  --rojo-oscuro: #7B0000;
  --bg: #F4F5F7;
  --panel: #FFFFFF;
  --texto: #212121;
  --texto-suave: #6B7280;
  --borde: #E3E5E8;
  --verde: #2E7D32;
  --radio: 10px;
  --mobile-topbar-h: 52px;
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganar siempre, aunque la propia clase del elemento
   fije un display explícito (flex/block/etc). Sin esto, cosas como
   .form-card label { display:flex } o .preview-actions { display:flex }
   dejan visible un elemento marcado como hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--texto);
}

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--panel);
  border-radius: var(--radio);
  padding: 2.5rem 3rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
  text-align: center;
  max-width: 420px;
}
.login-card h1 { margin: 0 0 .25rem; }
.subtitle { color: var(--texto-suave); margin-top: 0; }
.telegram-login-wrap { display: flex; justify-content: center; margin: 1.5rem 0; }
.error-box {
  background: #FDECEA; color: var(--rojo-oscuro);
  border: 1px solid #F5C6C0; border-radius: 8px;
  padding: .6rem 1rem; font-size: .9rem;
}
.hint { color: var(--texto-suave); font-size: .85rem; }
.hint a { color: var(--rojo); }

/* ---------- Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #1B1B1F;
  color: #E7E7EA;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
}
.sidebar-brand { font-weight: 700; padding: 0 1.25rem 1rem; font-size: 1.05rem; }
.sidebar-nav { flex: 1; overflow-y: auto; }
.nav-section {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: #8A8A93; padding: .9rem 1.25rem .3rem;
}
.nav-btn {
  display: flex; align-items: center; gap: .5rem;
  width: 100%; text-align: left; background: none; border: none;
  color: #D8D8DC; padding: .6rem 1.25rem; font-size: .92rem; cursor: pointer;
  border-left: 3px solid transparent;
}
.nav-btn:hover { background: #27272C; }
.nav-btn.active { background: #2A1414; color: #fff; border-left-color: var(--rojo); }
.badge {
  background: var(--rojo); color: #fff; border-radius: 999px;
  font-size: .7rem; padding: .05rem .45rem; margin-left: auto;
}
.sidebar-footer { padding: 1rem 1.25rem 0; border-top: 1px solid #2C2C31; margin-top: .5rem; }
.user-name { font-size: .88rem; }
.tag { background: var(--rojo); color: #fff; font-size: .68rem; padding: .1rem .4rem; border-radius: 5px; }
.logout-link { color: #9C9CA5; font-size: .82rem; }

.content { flex: 1; padding: 1.5rem 2rem; min-width: 0; }
.content-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.group-picker { display: flex; align-items: center; gap: .5rem; }
.group-picker select { padding: .4rem .6rem; border-radius: 8px; border: 1px solid var(--borde); min-width: 220px; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
h2:first-child { margin-top: 0; }

.pane-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
.pane-actions { display: flex; align-items: center; gap: .5rem; }

.pill {
  background: #EEF0F3; border-radius: 999px; padding: .25rem .7rem; font-size: .82rem; color: var(--texto-suave);
}

/* ---------- Botones ---------- */
.btn {
  border: 1px solid var(--borde); background: #fff; color: var(--texto);
  padding: .5rem 1rem; border-radius: 8px; cursor: pointer; font-size: .88rem;
}
.btn:hover { background: #F5F5F5; }
.btn-primary { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.btn-primary:hover { background: var(--rojo-oscuro); }
.btn-secondary { background: #1B1B1F; border-color: #1B1B1F; color: #fff; }
.btn-secondary:hover { background: #000; }
.btn-danger { color: var(--rojo-oscuro); border-color: #F0C6C0; }
.btn-danger:hover { background: #FDECEA; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Cards / grid ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-top: 1rem; }
.img-card {
  background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio);
  overflow: hidden; display: flex; flex-direction: column;
}
.img-card img { width: 100%; aspect-ratio: 1/1; object-fit: cover; background: #eee; }
.img-card .img-card-body { padding: .6rem .75rem; font-size: .82rem; }
.img-card .img-card-actions { display: flex; gap: .4rem; padding: 0 .75rem .75rem; }
.img-card .img-card-actions .btn { flex: 1; padding: .35rem .4rem; font-size: .78rem; }

.form-card {
  background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 1.25rem; max-width: 640px; display: flex; flex-direction: column; gap: .9rem; margin-bottom: 1.25rem;
}
.form-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .88rem; }
.form-card input[type=text], .form-card input[type=number], .form-card input[type=time],
.form-card input[type=datetime-local], .form-card textarea, .form-card select {
  padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--borde); font: inherit;
}
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; max-width: none; }
.form-inline label { min-width: 140px; }
.switch-row { flex-direction: row !important; align-items: center; gap: .5rem !important; }

.dias-semana { display: flex; gap: .35rem; flex-wrap: wrap; }
.dias-semana label {
  border: 1px solid var(--borde); border-radius: 8px; padding: .4rem .6rem;
  font-size: .8rem; cursor: pointer; flex-direction: row !important; align-items: center; gap: .3rem !important;
}

.crear-layout { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 1.5rem; align-items: start; }
.crear-preview {
  background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 1rem; text-align: center;
}
.crear-preview img { max-width: 100%; border-radius: 6px; }
.preview-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: 1rem; }

.logo-preview { max-width: 220px; max-height: 100px; display: block; margin-bottom: .5rem; background: #f2f2f2; border-radius: 6px; padding: .3rem; }

.table-scroll { overflow-x: auto; border-radius: var(--radio); }
.data-table { width: 100%; min-width: 480px; border-collapse: collapse; background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); overflow: hidden; }
.data-table th, .data-table td { text-align: left; padding: .55rem .8rem; font-size: .85rem; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.data-table th { background: #FAFAFA; color: var(--texto-suave); font-weight: 600; }
.data-table tr:last-child td { border-bottom: none; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.stat-tile { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 1rem; }
.stat-tile .valor { font-size: 1.7rem; font-weight: 700; }
.stat-tile .etiqueta { color: var(--texto-suave); font-size: .82rem; }

.grupo-panel { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.grupo-panel h3 { margin: 0 0 .4rem; }
.grupo-panel .meta { color: var(--texto-suave); font-size: .82rem; margin-bottom: .6rem; }
.admin-chip { display: inline-flex; align-items: center; gap: .3rem; background: #EEF0F3; border-radius: 999px; padding: .2rem .6rem; font-size: .78rem; margin: .15rem .25rem .15rem 0; }
.admin-chip button { border: none; background: none; cursor: pointer; color: var(--rojo); font-weight: 700; }

#toast-area { position: fixed; top: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { padding: .6rem 1rem; border-radius: 8px; font-size: .85rem; box-shadow: 0 2px 10px rgba(0,0,0,.15); color: #fff; }
.toast.ok { background: var(--verde); }
.toast.err { background: var(--rojo-oscuro); }

dialog { border: none; border-radius: var(--radio); padding: 0; max-width: min(480px, 92vw); width: 100%; max-height: 88vh; overflow-y: auto; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog .form-card { margin: 0; border: none; max-width: none; }

/* ---------- Barra y menú móvil (oculto en escritorio) ---------- */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .mobile-topbar {
    display: flex; align-items: center; gap: .75rem;
    height: var(--mobile-topbar-h); box-sizing: border-box;
    position: sticky; top: 0; z-index: 60;
    background: #1B1B1F; color: #fff; padding: 0 1rem;
  }
  .mobile-topbar-brand { font-weight: 700; font-size: 1rem; }

  .hamburger-btn {
    background: none; border: none; cursor: pointer; padding: .3rem;
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 32px; height: 32px;
  }
  .hamburger-btn span {
    display: block; width: 100%; height: 2px; background: #fff; border-radius: 2px;
    transition: transform .2s ease, opacity .2s ease;
  }
  .hamburger-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .hamburger-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .hamburger-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45);
    z-index: 70; opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }

  .app-shell { flex-direction: column; }

  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(78vw, 280px);
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 80;
    box-shadow: 2px 0 16px rgba(0,0,0,.25);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-brand { display: none; }   /* ya está en la barra superior */
  .sidebar-nav { display: flex; flex-direction: column; }
  .sidebar-footer { display: block; }

  .content { padding: 1rem 1rem 2rem; }
  .content-header { position: sticky; top: var(--mobile-topbar-h); z-index: 40; background: var(--bg); padding: .5rem 0; margin-bottom: .75rem; }
  .group-picker { width: 100%; }
  .group-picker select { flex: 1; min-width: 0; }

  .crear-layout { grid-template-columns: 1fr; }
  .form-inline { flex-direction: column; align-items: stretch; }
  .form-inline label { min-width: 0; width: 100%; }
  .form-inline .btn { width: 100%; text-align: center; }
  .form-inline .pill { align-self: flex-start; }

  #toast-area { left: .75rem; right: .75rem; top: auto; bottom: .75rem; align-items: stretch; }
  .toast { text-align: center; }
}
