/* =========================================================
   Tareas · estilos base (responsive: celular → TV)
   ========================================================= */
:root {
  --primary: #2f5bea;
  --primary-600: #2349c9;
  --primary-50: #eef2ff;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1c2434;
  --muted: #6b7489;
  --border: #e3e7f0;
  --ok: #16a36a;     --ok-50: #e7f7ef;
  --warn: #d98a00;   --warn-50: #fff5e0;
  --danger: #dc3545; --danger-50: #fdecee;
  --info: #0b84c6;   --info-50: #e6f4fb;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 4px 16px rgba(20, 30, 60, .06);
  --topbar-h: 60px;
  --sidebar-w: 240px;
  font-size: 15px;
}
@media (min-width: 1800px) { :root { font-size: 16px; } }
@media (min-width: 2400px) { :root { font-size: 19px; } }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); margin: 0; }
.center { text-align: center; }
code { background: var(--primary-50); padding: 1px 6px; border-radius: 5px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo-mark {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--primary); color: #fff; font-weight: 800;
}
.empresa-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--primary-50); color: var(--primary-600);
  padding: 5px 12px; border-radius: 999px; font-weight: 600; font-size: .9rem;
  max-width: 40vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.empresa-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.chip-link { font-weight: 500; font-size: .8rem; opacity: .8; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta small { color: var(--muted); }
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: #dfe6ff; color: var(--primary-600); font-weight: 700; font-size: .8rem;
}
.icon-btn {
  border: 0; background: transparent; font-size: 1.3rem; cursor: pointer;
  width: 38px; height: 38px; border-radius: 9px; color: var(--text);
}
.icon-btn:hover { background: var(--bg); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column;
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h));
}
.sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text); font-weight: 500;
}
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.active { background: var(--primary-50); color: var(--primary-600); font-weight: 600; }
.sidebar .ico { width: 22px; text-align: center; }
.logout-form { margin-top: auto; }
.sidebar-backdrop { display: none; }
.content { flex: 1; min-width: 0; padding: 24px clamp(14px, 2.5vw, 40px) 48px; }

@media (min-width: 1024px) { .menu-toggle { display: none; } }
@media (max-width: 1023px) {
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .menu-open .sidebar { transform: none; }
  .menu-open .sidebar-backdrop {
    display: block; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 35;
    background: rgba(15, 20, 35, .35);
  }
}
@media (max-width: 640px) {
  .user-meta { display: none; }
  .empresa-chip { max-width: 46vw; }
  .chip-link { display: none; }
  .brand span:last-child { display: none; }
  h1 { font-size: 1.35rem; }
}

/* ---------- Componentes ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 18px;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
  margin-bottom: 18px;
}
.card-title { font-size: 1.05rem; }
.two-cols { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.two-cols .card { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 6px 11px; font-size: .87rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap;
}
.badge-ok { background: var(--ok-50); color: var(--ok); }
.badge-off { background: #eef0f4; color: var(--muted); }
.badge-superadmin { background: #f1e8ff; color: #7a3fd6; }
.badge-admin { background: var(--primary-50); color: var(--primary-600); }
.badge-editor { background: var(--warn-50); color: #a86a00; }
.badge-visor { background: var(--info-50); color: var(--info); }

.alert {
  padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px;
  border: 1px solid transparent; transition: opacity .4s;
}
.alert.fade { opacity: 0; }
.alert-success { background: var(--ok-50); color: #0e6b46; border-color: #bfe9d4; }
.alert-error { background: var(--danger-50); color: #a1222e; border-color: #f6c6cc; }
.alert-warning { background: var(--warn-50); color: #8a5800; border-color: #f5dca6; }
.alert-info { background: var(--info-50); color: #075c8b; border-color: #b9e0f3; }

/* ---------- Formularios ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; width: 100%; min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-50); border-color: var(--primary); }
.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: 1 / -1; }
fieldset { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 12px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.pass-wrap { position: relative; display: block; }
.pass-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; cursor: pointer; font-size: 1rem; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search] { flex: 1 1 240px; width: auto; }
.toolbar select { width: auto; flex: 0 1 200px; }
.inline-note { background: var(--primary-50); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 16px; }

/* ---------- Tarjetas de entidades ---------- */
.grid-cards {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
}
.entity-card { margin: 0; display: flex; flex-direction: column; gap: 12px; }
.entity-card header { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.entity-card.is-off { opacity: .65; }
.entity-card.is-current { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-50); }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 0; }
.meta dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.meta dd { margin: 0; font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* ---------- KPIs y tablero ---------- */
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.kpi span { color: var(--muted); font-size: .85rem; display: block; }
.kpi strong { font-size: 1.8rem; }
.kpi--ok { border-left-color: var(--ok); }
.kpi--warn { border-left-color: var(--warn); }
.kpi--danger { border-left-color: var(--danger); }

.empty-state {
  text-align: center; padding: 40px 20px; margin-bottom: 18px;
  border: 2px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}
.empty-ico { font-size: 2.4rem; color: var(--primary); }

.team-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.team-list li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); background: var(--bg); }
.team-list li > span:nth-child(2) { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.team-list small, .user-cell small { color: var(--muted); }

.roles-help { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 16px; font-size: .9rem; color: var(--muted); }

/* ---------- Tablas (se convierten en tarjetas en móvil) ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfe; }
.table tr:last-child td { border-bottom: 0; }
.table tr.is-off td { opacity: .6; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell > span:last-child { display: flex; flex-direction: column; }
@media (max-width: 760px) {
  .table-responsive thead { display: none; }
  .table-responsive tr { display: block; padding: 10px 4px; border-bottom: 1px solid var(--border); }
  .table-responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 12px; }
  .table-responsive td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; }
  .table-responsive td[data-label="Usuario"]::before { display: none; }
  .table-responsive td.actions { justify-content: flex-end; }
}

/* ---------- Modal ---------- */
.modal {
  border: 0; padding: 0; border-radius: var(--radius); width: min(620px, 94vw);
  box-shadow: 0 20px 60px rgba(15, 20, 40, .25); color: var(--text);
}
.modal::backdrop { background: rgba(15, 20, 35, .45); backdrop-filter: blur(2px); }
.modal-body { padding: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
@media (max-width: 560px) {
  .modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .modal-foot { position: sticky; bottom: 0; background: #fff; padding-top: 10px; }
  .modal-foot .btn { flex: 1; }
}

/* ---------- Login / instalador ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #eef2ff, #f7f9fc 60%); }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border-radius: 18px;
  padding: 28px; box-shadow: 0 10px 40px rgba(20, 30, 70, .12);
}
.auth-card--wide { width: min(640px, 100%); }
.auth-card h1 { margin-top: 14px; }
.auth-card .form-stack, .auth-card .form-grid { margin-top: 18px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; }
.section-title { font-size: 1rem; margin: 18px 0 4px; color: var(--primary-600); }
.req-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; }
.req-list .ok { color: var(--ok); }
.req-list .fail { color: var(--danger); font-weight: 600; }
