:root {
  color-scheme: light dark;
  --bg: #f6f7fb;
  --bg-soft: #f0f1f8;
  --fg: #25283f;
  --fg-soft: #656b83;
  --line: #e3e5ef;
  --primary: #6654d9;
  --primary-soft: #eeebfc;
  --danger: #d93025;
  --danger-soft: #fce8e6;
  --surface: #fff;
  --surface-2: var(--bg-soft);
  --muted: var(--fg-soft);
  --border: var(--line);
  --border-strong: #c8c9dd;
  --accent: var(--primary);
  --accent-hover: #5442c0;
  --accent-soft: var(--primary-soft);
  --on-accent: #fff;
  --ok: #188038;
  --ok-soft: #e6f4ea;
  --warn: #b06000;
  --warn-soft: #fef7e0;
  --info: #6654d9;
  --info-soft: #eeebfc;
  --shadow: 0 4px 20px rgb(35 31 80 / 4%);
  --shadow-lg: 0 16px 48px rgb(35 31 80 / 10%);
  --radius: 20px;
  --radius-sm: 11px;
  --ring: 0 0 0 3px rgb(102 84 217 / 16%);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10121b;
    --bg-soft: #202332;
    --fg: #ececf6;
    --fg-soft: #a4a8c1;
    --line: #2c3043;
    --primary: #b6a9ff;
    --primary-soft: #2e2848;
    --danger: #f28b82;
    --danger-soft: #3c2525;
    --surface: #191c29;
    --surface-2: var(--bg-soft);
    --muted: var(--fg-soft);
    --border: var(--line);
    --border-strong: #484d68;
    --accent: var(--primary);
    --accent-hover: #c8beff;
    --accent-soft: var(--primary-soft);
    --on-accent: #1b1534;
    --ok: #81c995;
    --ok-soft: #203328;
    --warn: #fdd663;
    --warn-soft: #3b321d;
    --info: #b6a9ff;
    --info-soft: #2e2848;
    --shadow: 0 2px 8px rgb(0 0 0 / 30%);
    --shadow-lg: 0 8px 24px rgb(0 0 0 / 45%);
    --ring: 0 0 0 3px rgb(182 169 255 / 22%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 12% 0%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 50%), var(--bg);
  color: var(--fg);
  font: 14px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 28px; line-height: 1.25; font-weight: 700; letter-spacing: -.035em; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 18px; font-weight: 650; letter-spacing: -.02em; margin: 0 0 18px; }
p { margin: 0 0 .6em; }
code { font: .85em ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.sub { color: var(--muted); margin: 4px 0 0; }
.fine { color: var(--muted); font-size: .85rem; text-align: center; margin: 18px 0 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: none; border-radius: 6px; }

.icon { width: 18px; height: 18px; flex: none; }
.logo { width: 28px; height: 28px; color: var(--accent); flex: none; }

/* ----- Barra superior ----- */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 86%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-in { max-width: 1160px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 24px 16px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: -.04em; font-size: 1.2rem; color: var(--fg); }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: 8px 13px; border-radius: 11px; color: var(--muted); font-weight: 550; font-size: 13px; white-space: nowrap; transition: background .18s, color .18s; }
.nav a:hover { color: var(--fg); background: var(--surface-2); text-decoration: none; }
.nav a[aria-current] { color: var(--accent); background: var(--accent-soft); }
.nav-sep { width: 1px; height: 18px; background: var(--border-strong); margin: 0 8px; flex: none; }
.userbox { display: flex; align-items: center; gap: 10px; margin: 0; }
.username { color: var(--muted); font-size: .9rem; }

.container { max-width: 1160px; margin: 0 auto; padding: 40px 24px calc(72px + env(safe-area-inset-bottom)); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.crumb { display: inline-block; margin-bottom: 14px; color: var(--muted); font-size: .9rem; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* ----- Tarjetas y layout ----- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); }
.card + .card, .card + .table-card, details.card + .card { margin-top: 18px; }
.card + .grid-2, .alert + .grid-2, .alert + .card { margin-top: 18px; }
.grid-2 > .card + .card { margin-top: 0; }
.table-card { padding: 0; overflow: hidden; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin-bottom: 18px; }
.grid-2.start { align-items: start; gap: 18px; }
.card .grid-2 { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-lg { display: flex; flex-direction: column; gap: 18px; }
.stack-lg > .card + .card { margin-top: 0; }
.actions { margin-top: 18px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.danger-zone h2 { color: var(--danger); }
.empty { text-align: center; padding: 48px 22px; }
.empty h2 { margin-top: 12px; }
.empty .btn { margin-top: 8px; }

/* ----- Pantallas centradas (login, errores) ----- */
.is-shell { display: grid; place-items: center; }
.shell { width: 100%; padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.auth-card { max-width: 460px; margin: 0 auto; padding: 38px; box-shadow: var(--shadow-lg); border-top: 3px solid color-mix(in srgb, var(--accent) 70%, var(--border)); }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 1.15rem; margin-bottom: 22px; }
.auth-card h1 { text-align: center; font-size: 1.45rem; }
.auth-card .sub { text-align: center; margin-bottom: 20px; }
.shell-foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 18px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 3px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--fg); font-weight: 600; vertical-align: middle; }
.state { text-align: center; margin-bottom: 20px; }
.state h1 { margin-top: 12px; }
.state-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.state-icon .icon { width: 26px; height: 26px; }
.state-icon.danger { background: var(--danger-soft); color: var(--danger); }
.state-icon.ok { background: var(--ok-soft); color: var(--ok); }
.spinner { display: inline-block; width: 36px; height: 36px; border: 3px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Formularios ----- */
[hidden] { display: none !important; }
.sso-fields { border: 0; padding: 0; margin: 0; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 12px; font-weight: 500; }
.hint { color: var(--muted); font-size: 12px; font-weight: 400; }
input:not([type=checkbox]), select, textarea {
  width: 100%; min-height: 44px; font: inherit; padding: 10px 12px; color: var(--fg);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 64px; }
input:not([type=checkbox]):focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 60%, transparent); }
.input-group { position: relative; display: block; }
.input-group input { padding-right: 44px; }
.input-group .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.input-group .when-shown, .input-group.shown .when-hidden { display: none; }
.input-group.shown .when-shown { display: inline; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.check-label { display: block; font-weight: 600; font-size: .92rem; }
.check .hint { display: block; }
.checklist { display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow: auto; margin: 0 -6px; }
.person-check { padding: 6px; border-radius: 8px; align-items: center; }
.person-check:hover { background: var(--surface-2); }

/* ----- Botones ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; font: inherit; font-weight: 600; padding: 9px 17px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--fg);
  cursor: pointer; transition: background .18s, border-color .18s, box-shadow .18s; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: 0 4px 10px color-mix(in srgb, var(--accent) 18%, transparent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 26%, transparent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn.sm { padding: 5px 11px; font-size: .86rem; }
.btn.lg { padding: 12px 18px; font-size: 1rem; }
.btn.block { display: flex; width: 100%; }
.btn.loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ''; position: absolute; width: 16px; height: 16px; border: 2px solid currentColor; border-color: var(--on-accent) transparent var(--on-accent) transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn:not(.primary).loading::after { border-color: var(--fg) transparent var(--fg) transparent; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn .icon { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.icon-btn.done { color: var(--ok); }

/* ----- Avisos y badges ----- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius-sm); font-size: .92rem; margin-bottom: 16px; border: 1px solid transparent; transition: opacity .4s; }
.alert .icon { margin-top: 2px; }
.alert.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert.info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert.fade { opacity: 0; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); margin-right: 4px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ----- Avatares ----- */
.avatar { display: inline-grid; place-items: center; flex: none; border-radius: 50%; color: #fff; font-weight: 700; }
.avatar.sm { width: 28px; height: 28px; font-size: .8rem; }
.avatar.md { width: 36px; height: 36px; }
.avatar.lg { width: 48px; height: 48px; font-size: 1.2rem; border-radius: 14px; }
.avatar.xl { width: 72px; height: 72px; font-size: 1.8rem; border-radius: 20px; }
img.avatar { object-fit: cover; background: var(--surface-2); }
.chip img.avatar.sm { width: 22px; height: 22px; }
.chip .avatar.sm { width: 22px; height: 22px; font-size: .7rem; }
.av-0 { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.av-1 { background: linear-gradient(135deg, #0ea5e9, #6366f1); }
.av-2 { background: linear-gradient(135deg, #10b981, #0ea5e9); }
.av-3 { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.av-4 { background: linear-gradient(135deg, #ec4899, #8b5cf6); }
.av-5 { background: linear-gradient(135deg, #14b8a6, #22c55e); }
.av-6 { background: linear-gradient(135deg, #f97316, #ec4899); }
.av-7 { background: linear-gradient(135deg, #3b82f6, #14b8a6); }
.person { display: flex; align-items: center; gap: 10px; color: inherit; min-width: 0; }
.person:hover { text-decoration: none; }
.person > span:last-child { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.person .muted { font-size: .83rem; font-weight: 400; }
.person.big { gap: 14px; }
.person.big > div { display: block; }

/* ----- Portal ----- */
.portal-categories { display: grid; gap: 34px; }
.portal-category { min-width: 0; }
.portal-category-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 14px; }
.portal-category-head h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.portal-category-head .muted { font-size: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: 20px; }
.tile { --tile-accent: #8171dd; position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 24px; min-height: 280px; min-width: 0; padding: 25px; overflow: hidden; background: linear-gradient(155deg, color-mix(in srgb, var(--tile-accent) 7%, var(--surface)), var(--surface) 60%); border: 1px solid var(--border); border-radius: 22px; color: var(--fg); box-shadow: var(--shadow); transition: transform .22s, box-shadow .22s, border-color .22s; }
.tile::before { content: ''; position: absolute; top: 0; left: 26px; right: 26px; height: 3px; border-radius: 0 0 4px 4px; background: var(--tile-accent); opacity: .6; transition: opacity .22s; }
.tile-tone-1, .tile-tone-7 { --tile-accent: #428daf; }
.tile-tone-2, .tile-tone-5 { --tile-accent: #2f9f8b; }
.tile-tone-3, .tile-tone-6 { --tile-accent: #d18a51; }
.tile-tone-4 { --tile-accent: #b46caa; }
.tile:hover, .tile:focus-visible { transform: translateY(-5px); border-color: color-mix(in srgb, var(--tile-accent) 60%, var(--border)); box-shadow: 0 14px 32px rgb(35 31 80 / 9%); text-decoration: none; }
.tile:hover::before { opacity: 1; }
.tile-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.tile-top .avatar { width: 64px; height: 64px; font-size: 26px; border-radius: 19px; box-shadow: 0 5px 12px color-mix(in srgb, var(--tile-accent) 18%, transparent); }
.tile-top .badge { margin: 2px 0 0; font-size: 10px; padding: 4px 8px; }
.tile-body { display: flex; flex-direction: column; gap: 7px; min-width: 0; flex: 1; line-height: 1.5; }
.tile-body > strong { font-size: 19px; font-weight: 700; letter-spacing: -.025em; overflow-wrap: anywhere; }
.tile-body .muted { font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.tile-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-top: 1px solid var(--border); padding-top: 16px; }
.tile-domain { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-go { display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--surface-2); color: var(--muted); transition: color .2s, background .2s, transform .2s; }
.tile:hover .tile-go, .tile:focus-visible .tile-go { color: var(--on-accent); background: var(--accent); transform: rotate(-35deg); }

/* ----- Cuenta ----- */
.profile h2 { margin: 0 0 2px; }
.profile p { margin: 0 0 6px; }
.profile .kv { margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ----- Tablas ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 17px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.dim td { opacity: .6; }
td.go { width: 40px; text-align: right; }
td.go a { color: var(--muted); display: inline-grid; }

/* ----- Desplegables ----- */
details.collapsible { margin-bottom: 18px; }
details.collapsible:not([open]) { background: none; border: 0; box-shadow: none; padding: 0; }
details.collapsible > summary { list-style: none; cursor: pointer; display: inline-block; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible[open] > summary { margin-bottom: 18px; }
details.collapsible[open] > summary .btn { background: var(--surface-2); color: var(--fg); border-color: var(--border-strong); }
details.advanced { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 10px 14px; }
details.advanced > summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--muted); }
details.advanced[open] > summary { margin-bottom: 14px; }

/* ----- Copiar valores ----- */
.copy-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.copy-row:last-of-type { border-bottom: 0; }
.copy-row .label { color: var(--muted); font-weight: 500; }
.copy-row code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; overflow-x: auto; white-space: nowrap; scrollbar-width: thin; }
.copy-row form { margin: 0; }

/* ----- Responsive ----- */
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-in { flex-wrap: wrap; gap: 8px 14px; padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); }
  .nav { order: 3; flex-basis: 100%; }
  .userbox { margin-left: auto; }
  .username { display: none; }
  .container { padding: 20px max(14px, env(safe-area-inset-right)) calc(56px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .copy-row { grid-template-columns: 1fr auto; }
  .copy-row .label { grid-column: 1 / -1; }
  .auth-card { padding: 26px 20px; }
  h1 { font-size: 25px; }
  .tiles { gap: 16px; }
  .tile { min-height: 260px; }
  input:not([type=checkbox]), select, textarea { font-size: 16px; }
  .btn.sm { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .tile:hover, .tile:focus-visible, .tile:hover .tile-go, .tile:focus-visible .tile-go { transform: none; }
}

/* ----- Subida de imágenes ----- */
.uploader { display: flex; align-items: center; gap: 16px; padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.profile .uploader { border-bottom: 0; margin-bottom: 8px; padding-bottom: 0; }
.uploader-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.uploader-actions { display: flex; gap: 8px; margin-top: 6px; }
.uploader-actions label.btn { cursor: pointer; }
.upload-error { color: var(--danger); font-size: .85rem; }

.card h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 4px 0 -6px; }
