:root {
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  color: #0b1220;
  background: #f5f6fb;
  --ink: #0b1220;
  --muted: #64748b;
  --line: #e2e8f0;
  --surface: #fff;
  --brand: #4f46e5;
  --brand-light: #818cf8;
  --brand-dark: #312e81;
  --violet: #7c3aed;
  --gold: #f59e0b;
  --soft: #eef2ff;
  --danger: #b91c1c;
  --shadow: 0 18px 50px rgba(49, 46, 129, .11);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 84% 8%, rgba(129,140,248,.12), transparent 28rem), #f5f6fb; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
/* Los contenedores encogen sin trasladar el scroll de tablas a toda la página. */
:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
button, a { touch-action: manipulation; }
h1, h2, p { margin-top: 0; }
h1, h2 { font-weight: 800; letter-spacing: -.035em; }
h1 { margin-bottom: 0; font-size: clamp(1.22rem, 2.4vw, 1.7rem); }
h2 { margin-bottom: 0; }
.eyebrow { display: block; margin-bottom: 4px; font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }

.topbar { position: relative; min-height: 118px; padding: 15px clamp(24px, 5vw, 72px); display: flex; align-items: center; justify-content: space-between; gap: 24px; color: var(--ink); background: rgba(255,255,255,.96); box-shadow: 0 1px 0 rgba(15,23,42,.06); }
.topbar::after { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; content: ""; background: linear-gradient(90deg, var(--brand-light), var(--brand), var(--brand-dark) 72%, var(--gold)); }
.brand-lockup { display: flex; align-items: center; gap: clamp(18px, 3vw, 34px); }
.brand-logo { display: block; width: 145px; height: 96px; object-fit: contain; }
.brand-separator { width: 1px; height: 54px; background: var(--line); }
.suite-name .eyebrow { color: var(--brand); opacity: 1; }
.header-actions, .content-actions { display: flex; align-items: center; gap: 10px; }
.layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); min-height: calc(100vh - 118px); }
.layout > *, .brand-lockup, .tenant-link-card > div { min-width: 0; }
.sidebar { padding: 30px 24px; border-right: 1px solid var(--line); background: rgba(255,255,255,.78); backdrop-filter: blur(14px); }
.content { padding: clamp(28px, 5vw, 64px); overflow: auto; }
.section-heading, .content-heading, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

.search-field, label { display: grid; gap: 7px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.search-field { margin: 24px 0 18px; }
input, select, textarea { min-width: 0; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; color: var(--ink); background: var(--surface); }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.13); }
.tenant-list { display: grid; gap: 8px; }
.tenant-button { width: 100%; padding: 14px; display: grid; gap: 3px; text-align: left; border: 1px solid transparent; border-radius: 12px; color: var(--ink); background: transparent; }
.tenant-button:hover, .tenant-button.active { background: var(--soft); }
.tenant-button.active { border-color: #c7d2fe; box-shadow: inset 3px 0 0 var(--brand); }
.tenant-button strong { font-size: .94rem; }
.tenant-button span { color: var(--muted); font-size: .78rem; }
.tenant-button .tenant-url { margin-top: 4px; color: var(--brand); font-weight: 700; }
.tenant-button, #tenant-name, #tenant-login-url, .user-name, .dialog-form small { overflow-wrap: anywhere; }

.empty-state { min-height: 55vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-icon { margin: 0 auto 20px; width: 72px; height: 72px; padding: 10px; display: grid; place-items: center; border-radius: 22px; background: white; box-shadow: 0 14px 34px rgba(49,46,129,.16); }
.empty-icon img { width: 100%; height: 100%; }
.empty-state h2 { margin-bottom: 8px; color: var(--ink); }
.notice { margin: 24px 0; padding: 13px 16px; border: 1px solid #c7d2fe; border-left: 4px solid var(--gold); border-radius: 12px; color: var(--brand-dark); background: var(--soft); font-size: .88rem; }
.tenant-link-card { margin-top: 24px; padding: 16px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid #c7d2fe; border-radius: 14px; background: white; box-shadow: 0 10px 30px rgba(49,46,129,.06); }
.tenant-link-card a:not(.button) { color: var(--brand); font-size: .9rem; font-weight: 800; text-decoration: none; }
.link-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.button[aria-disabled="true"] { pointer-events: none; opacity: .5; }
.count-pill { padding: 7px 11px; border-radius: 999px; color: var(--brand-dark); background: var(--soft); font-size: .82rem; font-weight: 800; }

/* El texto accesible absoluto debe quedar dentro del área desplazable, no del documento. */
.table-shell { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: #f8fafc; font-size: .73rem; letter-spacing: .06em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.user-name { display: grid; gap: 3px; min-width: 180px; }
.user-name span { color: var(--muted); font-size: .8rem; }
.role-badge, .status-badge, .access-badge { display: inline-flex; border-radius: 999px; font-size: .75rem; font-weight: 800; }
.role-badge { padding: 6px 9px; color: var(--violet); background: #f3e8ff; }
.status-badge { padding: 6px 9px; color: #047857; background: #ecfdf5; }
.status-badge.inactive { color: var(--danger); background: #fbedee; }
.access-list { display: flex; flex-wrap: wrap; gap: 6px; min-width: 220px; }
.access-badge { padding: 5px 8px; color: var(--brand-dark); background: var(--soft); }
.area-dropdown { min-width: 220px; width: 100%; border: 1px solid #c7d2fe; border-radius: 10px; background: white; font-size: .82rem; }
.area-dropdown summary { padding: 10px 12px; cursor: pointer; color: var(--brand-dark); font-weight: 800; }
.area-dropdown summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 8px; }
.area-dropdown[open] summary { border-bottom: 1px solid var(--line); background: var(--soft); }
.area-dropdown-content { padding: 12px; }
.area-help { margin: 0 0 10px; max-width: 360px; font-size: .73rem; line-height: 1.5; color: var(--muted); }
.area-checklist { max-height: 320px; overflow-y: auto; display: grid; gap: 4px; }
.area-item { display: flex; align-items: center; gap: 9px; padding: 9px 6px; font-size: .79rem; border-bottom: 1px solid #f1f5f9; }
.area-item:last-child { border-bottom: 0; }
.area-item input { flex: 0 0 auto; width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--brand); }
.area-item-text { display: grid; gap: 3px; color: var(--ink); }
.area-item-text small { color: var(--muted); font-size: .7rem; font-weight: 500; line-height: 1.4; }
.area-item.unavailable .area-item-text { color: var(--muted); }

.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 800; text-align: center; text-decoration: none; }
.button:disabled { cursor: wait; opacity: .65; }
.button.primary { color: white; background: linear-gradient(135deg, var(--brand), var(--violet)); box-shadow: 0 8px 18px rgba(79,70,229,.2); }
.button.primary:hover { background: linear-gradient(135deg, var(--brand-dark), var(--brand)); }
.button.secondary { border: 1px solid var(--line); color: var(--brand-dark); background: white; }
.topbar .button.secondary:hover { border-color: #c7d2fe; color: var(--brand); background: var(--soft); }
.content .button.secondary, dialog .button.secondary { border-color: var(--line); color: var(--ink); background: white; }
.icon-button { flex: 0 0 auto; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; color: var(--brand); background: white; font-size: 1.1rem; }

dialog { width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; padding: 0; border: 0; border-radius: 18px; color: var(--ink); background: var(--surface); box-shadow: 0 28px 90px rgba(11,18,32,.3); }
dialog::backdrop { background: rgba(11,18,32,.62); backdrop-filter: blur(4px); }
.dialog-form { display: grid; gap: 24px; padding: 28px; }
.dialog-form .dialog-form { padding: 0; }
.dialog-feedback { padding: 12px; border-radius: 10px; color: var(--brand-dark) !important; background: var(--soft); overflow-wrap: anywhere; }
.dialog-feedback.error { color: var(--danger) !important; background: #fbedee; }
.dialog-form p { margin: 7px 0 0; color: var(--muted); }
.dialog-form h3 { margin: 0; color: var(--brand-dark); font-size: .9rem; letter-spacing: .02em; }
.form-section { display: grid; gap: 14px; padding-top: 20px; border-top: 1px solid var(--line); }
.domain-field { display: flex; align-items: stretch; }
.domain-field input { border-radius: 10px 0 0 10px; }
.domain-field span { padding: 11px 12px; display: flex; align-items: center; border: 1px solid var(--line); border-left: 0; border-radius: 0 10px 10px 0; color: var(--brand-dark); background: var(--soft); white-space: nowrap; }
label small { color: var(--brand); font-size: .75rem; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid > *, .domain-field { min-width: 0; }
.full { grid-column: 1 / -1; }
.checkbox { display: flex; align-items: center; gap: 9px; }
.checkbox input { width: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.account-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 16px; }
.pagination span { color: var(--muted); font-size: .8rem; text-align: center; }
.pagination .button { padding: 8px 10px; font-size: .8rem; }
.company-form { margin-top: 24px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.form-feedback { padding: 12px; color: var(--danger) !important; background: #fbedee; border-radius: 10px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.field-label { display: block; margin-bottom: 9px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.key-dialog-heading { display: flex; align-items: flex-start; gap: 16px; }
.key-dialog-heading img { width: 52px; height: 52px; flex: 0 0 auto; }
#tenant-dialog { width: min(760px, calc(100vw - 32px)); overflow: hidden; }
#tenant-dialog .dialog-form { max-height: min(860px, calc(100vh - 32px)); max-height: min(860px, calc(100dvh - 32px)); overflow-y: auto; }
.toast { position: fixed; z-index: 30; right: 24px; bottom: 24px; max-width: min(420px, calc(100vw - 32px)); overflow-wrap: anywhere; padding: 13px 16px; border-radius: 12px; color: white; background: var(--brand-dark); box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 820px) {
  .topbar { min-height: auto; padding: 12px 16px; gap: 16px; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; }
  .brand-logo { width: 104px; height: 69px; }
  .brand-separator, .suite-name { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { padding: 22px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .tenant-list { max-height: 240px; overflow-y: auto; overscroll-behavior: contain; }
  .content { padding: 24px 16px; }
  .content-actions { align-items: flex-end; flex-direction: column; }
  .tenant-link-card { align-items: flex-start; flex-direction: column; }
  .link-actions, .dialog-actions { flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
}

@media (max-width: 460px) {
  .topbar { align-items: flex-start; }
  .brand-logo { width: 86px; height: 57px; }
  .header-actions { align-items: stretch; flex-direction: column; gap: 5px; }
  .topbar .button { padding: 8px 10px; font-size: .78rem; }
  .content-heading { align-items: flex-start; flex-direction: column; }
  .content-actions { width: 100%; align-items: center; flex-direction: row; justify-content: space-between; }
  .dialog-form { padding: 20px 16px; gap: 20px; }
  .dialog-actions > .button { flex: 1 1 130px; }
  .account-tabs > .button { flex: 1 1 180px; }
  .domain-field span { padding-inline: 8px; font-size: .75rem; }
  .toast { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
}
