/* Colores institucionales Reditum:
   #D9272E rojo (principal) · #77777A gris · blanco */
:root {
  --brand-red: #D9272E;
  --brand-red-dark: #B51F25;
  --brand-red-soft: #FBEAEA;
  --brand-gray: #77777A;
  --brand-gray-dark: #4A4A4D;
  --brand-gray-soft: #F1F1F2;

  --bg: #F6F6F7;
  --surface: #FFFFFF;
  --text: #2B2B2E;
  --muted: #77777A;
  --border: #E2E2E4;
  --primary: var(--brand-red);
  --primary-hover: var(--brand-red-dark);
  --danger-bg: var(--brand-red-soft);
  --danger-text: #A61E24;
  --info-bg: var(--brand-gray-soft);
  --info-text: var(--brand-gray-dark);
  --ok: #1d7a46;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code { background: var(--brand-gray-soft); padding: 1px 6px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }

/* Barra superior */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 20px;
}
.brand { font-weight: 700; color: var(--primary); }
.user { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .92rem; }
.tenant { color: var(--muted); }
.inline { display: inline; margin: 0; }

/* Tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-top: 16px; }

/* Login */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; margin-top: 12px; }
.auth-card h1 { color: var(--primary); }
.auth-wrap .alert { width: 100%; max-width: 400px; }

/* Formularios */
label { display: block; font-weight: 600; font-size: .9rem; margin: 14px 0 6px; }
input[type="email"], input[type="text"], input[type="password"], input[type="date"] {
  width: 100%; padding: 10px 12px; font: inherit; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

/* Botones */
.btn { display: inline-block; font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); padding: 6px 12px; }
.btn-ghost:hover { background: var(--brand-gray-soft); }
.btn-block { width: 100%; margin-top: 20px; }

/* Alertas */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: .95rem; }
.alert-error { background: var(--danger-bg); color: var(--danger-text); }
.alert-info { background: var(--info-bg); color: var(--info-text); }

/* Insignias */
.badge { font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--brand-gray-soft); color: var(--text); }
.badge-superadmin { background: var(--brand-gray-dark); color: #fff; }
.badge-admin { background: var(--primary); color: #fff; }
.badge-cliente { background: var(--brand-gray-soft); color: var(--brand-gray-dark); border: 1px solid var(--border); }
.pill { font-size: .8rem; font-weight: 600; }
.pill.ok { color: var(--ok); }
.pill.off { color: var(--danger-text); }

/* Tablas */
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.card { overflow-x: auto; }
.list { margin: 0; padding-left: 18px; }

/* Errores */
.error-card { max-width: 480px; margin: 40px auto; text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--primary); margin: 0; }

/* ---------- Navegación ---------- */
.topbar-left { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.brand { text-decoration: none; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: .92rem; }
.nav a:hover { background: var(--brand-gray-soft); color: var(--text); }
.nav a.active { background: var(--brand-red-soft); color: var(--primary); }
a { color: var(--primary); }

/* ---------- Encabezados y layout ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.narrow { max-width: 560px; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 4px; }
.field.has-error input, .field.has-error select { border-color: var(--danger-text); }
.field-error { color: var(--danger-text); font-size: .85rem; margin: 4px 0 0; }
.help { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.static { margin: 0; padding: 4px 0; }
select {
  width: 100%; padding: 10px 12px; font: inherit; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
input.upper { text-transform: uppercase; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
fieldset.checks { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px 12px; margin: 16px 0 0; }
fieldset.checks legend { font-weight: 600; font-size: .9rem; padding: 0 6px; }
fieldset.checks ul { list-style: none; margin: 0; padding: 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 8px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; }

/* ---------- Botones extra ---------- */
.btn-sm { padding: 4px 10px; font-size: .82rem; }
.btn-danger-ghost { background: transparent; border-color: #f2c6c6; color: var(--danger-text); }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.alert-success { background: #e3f3ea; color: var(--ok); }

/* ---------- Tablas ---------- */
.table td.actions, .table th.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn, .table td.actions form { margin-left: 4px; }
.perms { max-width: 280px; }
.tag { display: inline-block; font-size: .75rem; background: var(--brand-gray-soft); border-radius: 6px; padding: 1px 7px; margin: 2px 4px 2px 0; }
.pill.warn { color: #9a6700; }
.pill + .pill { margin-left: 6px; }

/* ---------- Filtros ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.chip { font-size: .82rem; font-weight: 600; text-decoration: none; color: var(--muted); border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 12px; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Tarjetas resumen ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-top: 20px; }
.tile { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-decoration: none; color: var(--text); }
a.tile:hover { border-color: var(--primary); }
.tile-num { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1.1; }
.tile-label { font-weight: 600; }
.tile-link { font-size: .85rem; color: var(--primary); margin-top: 8px; }
.tile-disabled { opacity: .7; }

/* ---------- Credenciales ---------- */
.credentials { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 16px 0; }
.credentials dt { font-weight: 600; color: var(--muted); }
.credentials dd { margin: 0; }
code.secret { font-size: 1.1rem; padding: 4px 10px; letter-spacing: .04em; user-select: all; }
.badge, .pill { white-space: nowrap; display: inline-block; }

/* ---------- Identidad Reditum ---------- */
.topbar { border-bottom: 3px solid var(--brand-red); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--brand-gray-dark); }
.brand img { width: 115px; height: 45px; }
.brand-name { font-weight: 800; color: var(--brand-red); letter-spacing: .01em; }
.brand-sub { font-weight: 600; color: var(--brand-gray); margin-left: 10px;}

/* Fondo del login: imagen (fondo-login.jpg es una copia optimizada de fondo.png) */
.auth-page {
  min-height: 100vh;
  background-color: #1d1416;
  background-image: linear-gradient(rgba(20, 10, 12, .35), rgba(20, 10, 12, .35)), url("../img/fondo-login.png");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}
/* El login va centrado */
.auth-page .auth-wrap { width: min(400px, calc(100% - 32px)); margin-left: auto; margin-right: auto; padding-left: 0; padding-right: 0; }
/* Recuadros blancos semitransparentes (efecto vidrio) sobre la imagen */
.auth-page .auth-logo { width: 190px; filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .35)); }
.auth-page .auth-card { background: rgba(255, 255, 255, .45); box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-color: rgba(255, 255, 255, .35);
  border-top-color: var(--brand-red); }
.auth-page .auth-card .muted { color: #2b2b2e; }
.auth-page .auth-card h1, .auth-page .auth-card label { color: #1f1f22; }
.auth-page .auth-foot { color: rgba(255, 255, 255, .85); text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
.auth-logo { width: 190px; height: auto; margin-bottom: 12px; }
.auth-card { border-top: 4px solid var(--brand-red); }
.auth-card h1 { color: var(--brand-gray-dark); font-size: 1.3rem; }
.auth-foot { color: var(--muted); font-size: .8rem; margin-top: 18px; }

/* =====================================================================
   Iconos, tooltips, buscador, ojo de contraseña y copiar
   ===================================================================== */
.card { overflow: visible; }
.table-wrap { width: 100%; }
@media (max-width: 900px) { .table-wrap { overflow-x: auto; } }

.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }
.btn { display: inline-flex; align-items: center; gap: 6px; }
.small { font-size: .8rem; }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Botón de solo ícono */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--brand-gray-dark);
  cursor: pointer; text-decoration: none; position: relative; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--brand-gray-soft); color: var(--text); }
.icon-btn:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.icon-btn.warn:hover { color: #9a6700; border-color: #e8cf8f; background: #fdf6e3; }
.icon-btn.ok:hover { color: var(--ok); border-color: #b7dfc6; background: #e9f6ee; }
.icon-btn.danger { color: var(--brand-red); }
.icon-btn.danger:hover { background: var(--brand-red-soft); border-color: #f2c6c6; }
.icon-btn.copied { color: var(--ok); border-color: #b7dfc6; background: #e9f6ee; }
.table td.actions { white-space: nowrap; }
.table td.actions .inline, .table td.actions .icon-btn { margin-left: 4px; }

/* Tooltip: texto al pasar el mouse (o al enfocar con teclado) */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%) translateY(4px);
  background: #2B2B2E; color: #fff; font-size: .75rem; font-weight: 600; line-height: 1.2;
  padding: 5px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity .12s, transform .12s; z-index: 50;
}
[data-tip]::before {
  content: ""; position: absolute; left: 50%; bottom: calc(100% + 2px); transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: #2B2B2E; border-bottom: 0;
  opacity: 0; visibility: hidden; transition: opacity .12s; z-index: 50; pointer-events: none;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after,
[data-tip]:hover::before, [data-tip]:focus-visible::before { opacity: 1; visibility: visible; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { transform: translateX(-50%) translateY(0); }

/* Barra de herramientas + buscador */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.toolbar .filters { margin-top: 0; }
.search { display: flex; align-items: center; gap: 6px; position: relative; margin-left: auto; flex: 0 1 380px; }
.search input[type="search"] {
  width: 100%; padding: 8px 34px 8px 34px; font: inherit; font-size: .92rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.search input[type="search"]::-webkit-search-cancel-button { display: none; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); display: flex; pointer-events: none; }
.search-clear { position: absolute; right: 78px; top: 50%; transform: translateY(-50%); color: var(--muted); display: flex; }
.search-clear:hover { color: var(--text); }
@media (max-width: 640px) { .search { flex-basis: 100%; } }

/* Ojo para mostrar / ocultar contraseña */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer;
}
.pw-toggle:hover { color: var(--text); background: var(--brand-gray-soft); }
.pw-toggle:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--primary); }
.pw-toggle[data-tip]::after { left: auto; right: 0; transform: translateY(4px); }
.pw-toggle[data-tip]:hover::after, .pw-toggle[data-tip]:focus-visible::after { transform: translateY(0); }
.pw-toggle[data-tip]::before { left: auto; right: 10px; transform: none; }

/* Credenciales con copiar */
.copy-row { display: flex; align-items: center; gap: 8px; }

/* Eliminar */
.btn-danger { background: var(--brand-red); color: #fff; }
.btn-danger:hover { background: var(--brand-red-dark); }
.danger-card { border-top: 4px solid var(--brand-red); }
.help-list { color: var(--muted); font-size: .9rem; padding-left: 18px; }
.help-list li { margin: 4px 0; }

/* Bitácora */
.table-audit td { vertical-align: top; }
.audit-detail { max-width: 380px; word-break: break-word; font-size: .88rem; }
.audit-action { font-weight: 600; font-size: .85rem; white-space: nowrap; }
.audit-usuario_eliminado, .audit-cuenta_bloqueada, .audit-login_bloqueado_ip, .audit-cliente_desactivado, .audit-usuario_desactivado { color: var(--brand-red); }
.audit-login_fallido, .audit-login_cuenta_bloqueada, .audit-login_inactivo, .audit-cambio_clave_fallido { color: #9a6700; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; }

/* =====================================================================
   Menú lateral (minimizado por defecto, expandible)
   ===================================================================== */
:root { --sb-collapsed: 72px; --sb-expanded: 248px; }

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

.sidebar {
  position: sticky; top: 0; height: 100vh; flex: 0 0 var(--sb-collapsed); width: var(--sb-collapsed);
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border-right: 1px solid var(--border);
  box-shadow: inset -3px 0 0 var(--brand-red);
  padding: 14px 10px; z-index: 40;
}
.sb-expanded .sidebar { flex-basis: var(--sb-expanded); width: var(--sb-expanded); }
.sb-ready .sidebar { transition: width .2s ease, flex-basis .2s ease; }

/* Logo: siempre visible (completo al expandir, símbolo al minimizar) */
.sidebar-head { display: flex; align-items: center; justify-content: center; min-height: 64px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.sidebar-logo { display: flex; align-items: center; justify-content: center; width: 100%; }
.sidebar-logo .logo-full { display: none; width: 100%; max-width: 150px; height: auto; }
.sidebar-logo .logo-mini { display: block; width: 40px; height: 40px; }
.sb-expanded .sidebar-logo .logo-full { display: block; }
.sb-expanded .sidebar-logo .logo-mini { display: none; }

/* Botón expandir / minimizar */
.sidebar-toggle {
  align-self: center; display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; margin: 4px 0; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--muted); cursor: pointer;
}
.sidebar-toggle:hover { color: var(--brand-red); border-color: var(--brand-red); }
.sidebar-toggle .icon { transform: rotate(180deg); transition: transform .2s; }
.sb-expanded .sidebar-toggle { align-self: flex-end; }
.sb-expanded .sidebar-toggle .icon { transform: none; }

/* Enlaces */
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; }
.side-bottom { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--border); }
.side-bottom form { margin: 0; }
.side-link {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 44px; padding: 0 14px;
  border-radius: 10px; color: var(--brand-gray-dark); text-decoration: none; font: inherit; font-weight: 600; font-size: .94rem;
  background: transparent; border: 0; cursor: pointer; text-align: left; white-space: nowrap;
}
.side-link:hover { background: var(--brand-gray-soft); color: var(--text); }
.side-link.active { background: var(--brand-red-soft); color: var(--brand-red); }
.side-link.active .icon { color: var(--brand-red); }
.side-logout:hover { color: var(--brand-red); }
.side-label { overflow: hidden; text-overflow: ellipsis; }
html:not(.sb-expanded) .side-label { display: none; }
html:not(.sb-expanded) .side-link { justify-content: center; padding: 0; }

/* Tooltips a la derecha (solo cuando está minimizado) */
.sidebar [data-tip]::after {
  left: calc(100% + 10px); bottom: auto; top: 50%; transform: translate(4px, -50%);
}
.sidebar [data-tip]:hover::after, .sidebar [data-tip]:focus-visible::after { transform: translate(0, -50%); }
.sidebar [data-tip]::before {
  left: calc(100% + 4px); bottom: auto; top: 50%; transform: translateY(-50%);
  border: 6px solid transparent; border-right-color: #2B2B2E; border-left: 0;
}
.sb-expanded .side-link[data-tip]::after, .sb-expanded .side-link[data-tip]::before { display: none; }

/* Área principal */
.main-area { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.appbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  min-height: 60px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.appbar-title { font-weight: 700; color: var(--brand-gray-dark); }
.appbar .user { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .92rem; }

/* Celular: el menú expandido se superpone al contenido */
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
.sidebar-backdrop[hidden] { display: none; }
@media (max-width: 768px) {
  :root { --sb-collapsed: 60px; }
  .sidebar { padding: 12px 8px; }
  .sb-expanded .sidebar { position: fixed; left: 0; top: 0; box-shadow: 4px 0 24px rgba(0,0,0,.18), inset -3px 0 0 var(--brand-red); }
  .sb-expanded .main-area { margin-left: var(--sb-collapsed); }
  .appbar { padding: 10px 16px; }
  .appbar-title { display: none; }
}
.main-area > main { min-width: 0; max-width: 100%; width: 100%; }

/* =====================================================================
   Mensajes con botón cerrar y cierre automático
   ===================================================================== */
.alerts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.alerts .alert { margin-bottom: 0; }
.alert {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 16px; border-radius: 10px; border: 1px solid transparent;
  transition: opacity .25s ease, transform .25s ease;
}
.alert-text { flex: 1 1 auto; }
.alert-success { border-color: #c4e6d1; }
.alert-info { border-color: var(--border); }
.alert-error { border-color: #f2c6c6; }
.alert-close {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent;
  color: inherit; opacity: .7; cursor: pointer;
}
.alert-close:hover { opacity: 1; background: rgba(0,0,0,.06); }
.alert-close:focus-visible { outline: none; box-shadow: 0 0 0 2px currentColor; opacity: 1; }
.alert.closing { opacity: 0; transform: translateY(-6px); }
/* Barra de tiempo restante (se detiene al pasar el mouse) */
.alert.autoclose::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
  background: currentColor; opacity: .35; transform-origin: left;
  animation: alert-timer var(--alert-ms, 8s) linear forwards;
}
.alert.autoclose:hover::after { animation-play-state: paused; }
@keyframes alert-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .alert.autoclose::after { animation: none; } }

/* =====================================================================
   Enlace "Volver"
   ===================================================================== */
.back-link {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 14px;
  padding: 7px 14px 7px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--brand-gray-dark); font-weight: 600; font-size: .9rem; text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
}
.back-link .icon { transition: transform .15s; }
.back-link:hover { color: var(--brand-red); border-color: var(--brand-red); background: var(--brand-red-soft); }
.back-link:hover .icon { transform: translateX(-3px); }
.back-link:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--brand-red); }

/* Eliminar cliente: lista de usuarios afectados */
.affected { margin: 8px 0 12px; font-size: .9rem; }
.affected summary { cursor: pointer; font-weight: 600; color: var(--brand-gray-dark); }
.affected ul { margin: 8px 0 0; padding-left: 18px; max-height: 180px; overflow-y: auto; }

/* Desplegables: flecha propia con espacio a la derecha */
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2377777A' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 16px 16px;
  cursor: pointer;
}
select:focus { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23D9272E' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
select::-ms-expand { display: none; }

/* =====================================================================
   Tickets (portal del cliente)
   ===================================================================== */
textarea {
  width: 100%; padding: 10px 12px; font: inherit; line-height: 1.5; resize: vertical; min-height: 96px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.narrow-lg { max-width: 820px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* Estados y prioridades */
.tstatus, .tprio { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.tstatus::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tstatus-nuevo { background: #EEF1F6; color: #3D5A80; }
.tstatus-asignado { background: #EEF0FB; color: #4B4FA8; }
.tstatus-en_proceso { background: #FDF3E1; color: #8A5A00; }
.tstatus-esperando_cliente { background: #FBEAEA; color: #B51F25; }
.tstatus-resuelto { background: #E6F4EC; color: #1D7A46; }
.tstatus-cerrado { background: var(--brand-gray-soft); color: var(--brand-gray-dark); }
.tprio { background: transparent; border: 1px solid var(--border); color: var(--brand-gray-dark); font-weight: 600; }
.tprio-alta { border-color: #F0C2A6; color: #A4440F; }
.tprio-critica { border-color: var(--brand-red); background: var(--brand-red); color: #fff; }

/* Avisos */
.notice { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0 0; padding: 12px 16px; border-radius: 10px; background: var(--brand-gray-soft); border: 1px solid var(--border); }
.notice > span { flex: 1 1 260px; }
.notice a { font-weight: 600; }
.notice-warn { background: #FFF6E5; border-color: #F1D9A7; color: #6B4700; }
.notice-ok { background: #E9F6EE; border-color: #C4E6D1; color: #155C35; }

/* Lista */
.chip-count { display: inline-block; min-width: 18px; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: rgba(0,0,0,.07); font-size: .75rem; text-align: center; }
.chip.active .chip-count { background: rgba(255,255,255,.25); }
.ticket-code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .85rem; font-weight: 600; color: var(--brand-red); text-decoration: none; }
.row-main { color: var(--text); font-weight: 600; text-decoration: none; }
.row-link:hover td { background: #FAFAFB; }
.row-link:hover .row-main { color: var(--brand-red); }
.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 32px 12px; color: var(--muted); text-align: center; }
.empty p { margin: 0; }

/* Selector de archivos */
.dropzone { position: relative; border: 1.5px dashed #CFCFD4; border-radius: 10px; background: #FCFCFD; transition: border-color .15s, background .15s; }
.dropzone.dragover { border-color: var(--brand-red); background: var(--brand-red-soft); }
.dropzone-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone-label { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 0; padding: 18px 12px; text-align: center; font-weight: 400; cursor: pointer; color: var(--brand-gray-dark); }
.dropzone-label strong { color: var(--brand-red); }
.dropzone-input:focus-visible + .dropzone-label { outline: 2px solid var(--brand-red); outline-offset: -2px; border-radius: 10px; }
.file-list { list-style: none; margin: 0; padding: 0 12px; }
.file-list:not(:empty) { padding-bottom: 10px; }
.file-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin-top: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-size: .88rem; }
.file-list li.bad { border-color: #F2C6C6; background: var(--brand-red-soft); }
.file-list .fname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .fsize, .file-list .ferr { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.file-list .ferr { color: var(--danger-text); }
.file-remove { border: 0; background: transparent; color: var(--muted); cursor: pointer; display: inline-flex; padding: 2px; border-radius: 4px; }
.file-remove:hover { color: var(--brand-red); }

/* Detalle */
.ticket-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.ticket-head h1 { margin-top: 2px; }
.ticket-code-lg { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 700; color: var(--brand-red); font-size: .9rem; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; margin-top: 16px; }
@media (max-width: 960px) { .ticket-layout { grid-template-columns: 1fr; } }
.ticket-side { display: flex; flex-direction: column; gap: 16px; }
.ticket-side .card { margin-top: 0; }
.side-card h2, .reply-card h2 { font-size: 1rem; margin-bottom: 12px; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 10px 12px; margin: 0; font-size: .9rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.side-action { margin-top: 14px; }

.conversation { display: flex; flex-direction: column; gap: 14px; }
.msg { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.msg-staff { border-left: 4px solid var(--brand-red); }
.msg-mine { border-left: 4px solid var(--brand-gray); }
.msg-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.msg-avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; color: #fff; background: var(--brand-gray); }
.msg-staff .msg-avatar { background: var(--brand-red); }
.msg-author { font-weight: 700; }
.msg-org { color: var(--muted); font-weight: 600; }
.msg-time { color: var(--muted); font-size: .82rem; margin-left: auto; }
.msg-tag { font-size: .72rem; font-weight: 700; color: var(--brand-gray-dark); background: var(--brand-gray-soft); padding: 2px 8px; border-radius: 999px; }
.msg-body { white-space: pre-wrap; word-break: break-word; line-height: 1.6; }

.attachments { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attachments li { display: inline-flex; align-items: center; gap: 4px; }
.attachment { display: inline-flex; align-items: center; gap: 8px; max-width: 320px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: #FCFCFD; color: var(--text); text-decoration: none; font-size: .88rem; }
.attachment:hover { border-color: var(--brand-red); color: var(--brand-red); }
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-size { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.icon-btn-sm { width: 30px; height: 30px; }
.reply-card { margin-top: 16px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: 12px; padding-bottom: 14px; }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 4px; top: 14px; bottom: 0; width: 2px; background: var(--border); }
.tl-dot { flex: 0 0 10px; width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: var(--brand-red); }
.tl-title { font-size: .88rem; font-weight: 600; }
.tl-meta { font-size: .78rem; color: var(--muted); }

/* Menú lateral fijo a toda la altura (también en páginas largas) */
.sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: auto; overflow: visible; }
.main-area { margin-left: var(--sb-collapsed); }
.sb-expanded .main-area { margin-left: var(--sb-expanded); }
.sb-ready .main-area { transition: margin-left .2s ease; }
@media (max-width: 768px) {
  .sb-expanded .main-area { margin-left: var(--sb-collapsed); }
}
.ticket-layout { grid-template-columns: minmax(0, 1fr) 330px; }
@media (max-width: 960px) { .ticket-layout { grid-template-columns: 1fr; } }
.details { grid-template-columns: max-content minmax(0, 1fr); }

/* =====================================================================
   Aviso de sesión por expirar
   ===================================================================== */
.session-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20, 20, 24, .45); }
.session-modal[hidden] { display: none; }
.session-dialog { width: 100%; max-width: 420px; background: var(--surface); border-radius: 14px; border-top: 4px solid var(--brand-red); padding: 26px 24px 22px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.session-icon { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 50%; background: var(--brand-red-soft); color: var(--brand-red); margin-bottom: 10px; }
.session-dialog h2 { font-size: 1.2rem; margin: 0 0 8px; }
.session-dialog p { color: var(--muted); margin: 0 0 18px; }
.session-countdown { color: var(--brand-red); font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.session-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* =====================================================================
   Bandeja de atención (Reditum)
   ===================================================================== */
.side-icon { position: relative; display: inline-flex; }
.side-badge { position: absolute; top: -7px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--brand-red); color: #fff; font-size: .68rem; font-weight: 700; line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--surface); }
.inline-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-filters select { width: auto; min-width: 200px; padding-top: 8px; padding-bottom: 8px; font-size: .92rem; }
.row-critical td:first-child { box-shadow: inset 3px 0 0 var(--brand-red); }

.side-form { margin-bottom: 12px; }
.side-form label { margin: 0 0 6px; font-size: .82rem; color: var(--muted); }
.side-form select { padding-top: 8px; padding-bottom: 8px; }
.side-sub { font-size: .85rem; margin: 16px 0 8px; color: var(--muted); }
.mini-list { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.mini-list li { padding: 6px 0; border-top: 1px solid var(--border); }
.mini-list a { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 600; color: var(--brand-red); text-decoration: none; margin-right: 6px; }
.break { word-break: break-all; }

/* Notas internas */
.msg-internal { background: #FFFBEA; border-color: #F1E3A7; border-left: 4px solid #C99A06; }
.msg-internal .msg-avatar { background: #C99A06; }
.msg-tag-internal { display: inline-flex; align-items: center; gap: 4px; background: #F7E9B0; color: #6B5200; }

/* Responder / nota interna */
.reply-tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.reply-tab { margin: 0; font-weight: 600; font-size: .9rem; }
.reply-tab input { position: absolute; opacity: 0; pointer-events: none; }
.reply-tab span { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); color: var(--brand-gray-dark); cursor: pointer; }
.reply-tab input:checked + span { background: var(--brand-red); border-color: var(--brand-red); color: #fff; }
.reply-tab-internal input:checked + span { background: #C99A06; border-color: #C99A06; }
.reply-tab input:focus-visible + span { box-shadow: 0 0 0 2px var(--text); }
.reply-tab input:disabled + span { opacity: .5; cursor: not-allowed; }
.reply-hint { margin: 0 0 8px; }
.staff-reply:not(.is-internal) .reply-hint[data-for="interno"],
.staff-reply.is-internal .reply-hint[data-for="publico"],
.staff-reply.is-internal [data-only="publico"] { display: none; }
.staff-reply.is-internal textarea { background: #FFFBEA; border-color: #F1E3A7; }
.reply-actions { align-items: flex-end; justify-content: space-between; }
.after-field { margin: 0; min-width: 260px; }
.after-field label { margin-top: 0; font-size: .82rem; color: var(--muted); }

/* Categorías por cliente */
.category-add { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; gap: 0 14px; align-items: start; }
.category-add .field label { margin-top: 0; }
.category-add-btn { padding-top: 26px; }
@media (max-width: 760px) { .category-add { grid-template-columns: 1fr; } .category-add-btn { padding-top: 12px; } }

/* Reglas de acceso por cliente */
.access-rules .field { margin-top: 8px; }
.access-rules .check { align-items: flex-start; }
.access-rules .check input { margin-top: 3px; flex: 0 0 auto; }
.access-cell { max-width: 260px; }
.tag-strong { background: var(--brand-red-soft); color: var(--brand-red); font-weight: 700; }
.source-pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--brand-gray-dark); white-space: nowrap; }
.source-reditum_user, .source-reditum_admin { border-color: #F2C6C6; color: var(--brand-red); background: var(--brand-red-soft); }
.source-local { background: var(--brand-gray-soft); }

/* Ficha de datos (cambiar cliente) */
.info-list { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.2rem; margin: 0 0 1rem; }
.info-list dt { color: var(--muted, #77777A); font-size: .85rem; }
.info-list dd { margin: 0; }

/* Tickets anteriores (cliente anterior, solo consulta) */
.previous-tickets { margin-top: 1.25rem; }
.previous-tickets h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.tag-move { background: #fdecec; color: #D9272E; text-decoration: none; font-weight: 600; }
.tag-move:hover { background: #D9272E; color: #fff; }
.narrow-wide { max-width: 900px; }

/* Correos */
.mail-top { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.mail-top h2 { font-size: 1.05rem; margin: 0 0 .9rem; }
@media (max-width: 900px) { .mail-top { grid-template-columns: 1fr; } }
.tag-ok { background: #e7f5ec; color: #1e7a3d; }
.tag-missing { background: #fdecec; color: #b3261e; }
.pill.mail-pendiente, .pill.mail-enviando { color: #9a6700; }
.pill.mail-enviado { color: var(--ok); }
.pill.mail-error { color: var(--danger-text); }
.mail-error { color: #b3261e; margin-top: .25rem; max-width: 380px; }

/* Categorías generales */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head-row h2 { margin: 0; }
.tag-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.tag-list .tag { font-size: .9rem; padding: 4px 10px; }
.client-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 18px; margin: .5rem 0 1rem; }
.mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .mode-options { grid-template-columns: 1fr; } }
.mode-option { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 10px;
  border: 2px solid var(--border, #e4e4e7); background: #fff; cursor: pointer; font: inherit; color: inherit; }
.mode-option span { color: var(--muted); font-size: .9rem; }
.mode-option:hover { border-color: #c9c9cc; }
.mode-option.active { border-color: var(--brand-red); background: #fdf3f3; }
.mode-option.active strong::after { content: " ✓"; color: var(--brand-red); }

/* Reporte de tickets (portal del cliente) */
.report-menu { position: relative; }
.report-menu > summary { list-style: none; cursor: pointer; }
.report-menu > summary::-webkit-details-marker { display: none; }
.report-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 30; width: 320px; max-width: calc(100vw - 32px);
  background: var(--surface, #fff); border: 1px solid var(--border, #e4e4e7); border-top: 3px solid var(--brand-red);
  border-radius: 12px; padding: 16px; box-shadow: 0 14px 36px rgba(0, 0, 0, .16); }
.report-panel h3 { margin: 0 0 12px; font-size: 1rem; }
.report-panel label { display: block; font-weight: 600; font-size: .85rem; margin: 0 0 4px; }
.report-panel select, .report-panel input { width: 100%; margin-bottom: 10px; box-sizing: border-box; }
.report-dates { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.report-dates > div { min-width: 0; }
.report-panel input[type="date"] { min-width: 0; padding: 10px 8px; }
.report-panel .help { margin: 0 0 12px; }
@media (max-width: 600px) { .report-panel { right: auto; left: 0; } }
