/* TEMCO: capa de profundidad. Objetos 3D (canvas de temco-3d.js), escenario del inicio,
   orbe del asistente y tarjetas con inclinación. Solo presentación de pantalla. */

:root {
  --temco-3d: #2a7465;
  --temco-3d-hi: #1b4e46;
  --stage-grid: #24645a14;
  --stage-glow: #24645a1f;
  --stage-bg: linear-gradient(160deg, #ffffff 0%, #f6faf8 100%);
}
:is(:root[data-theme="dark"], html.theme-dark) {
  --temco-3d: #3f7a6c;
  --temco-3d-hi: #c4eadd;
  --stage-grid: #87b8a912;
  --stage-glow: #87b8a922;
  --stage-bg: linear-gradient(160deg, #282828 0%, #222 100%);
}
canvas[data-temco-3d] { display: block; pointer-events: none; }

/* Escenario del inicio ------------------------------------------------------ */
.home-header {
  position: relative; isolation: isolate; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 38%);
  grid-template-areas: "copy stage" "badge stage"; align-items: end; row-gap: 22px;
  min-height: 268px; padding: 34px 38px; border: 1px solid var(--border); border-radius: 26px;
  background:
    radial-gradient(620px 300px at 78% 40%, var(--stage-glow), transparent 70%),
    var(--stage-bg);
  box-shadow: var(--card-shadow), var(--hairline);
}
.home-header::after {
  content: ""; position: absolute; z-index: -1; left: 30%; right: -10%; bottom: -40%; height: 90%;
  background-image: linear-gradient(var(--stage-grid) 1px, transparent 1px), linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px);
  background-size: 34px 34px;
  transform: perspective(520px) rotateX(62deg); transform-origin: 50% 0;
  -webkit-mask-image: radial-gradient(closest-side, #000 30%, transparent);
  mask-image: radial-gradient(closest-side, #000 30%, transparent);
}
.home-header-copy { grid-area: copy; position: relative; z-index: 1; }
.home-header-badge { grid-area: badge; position: relative; z-index: 1; justify-self: start; }
.home-stage { grid-area: stage; position: relative; align-self: stretch; margin: -34px -38px -34px -20px; min-height: 260px; }
.home-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.home-stage::before {
  content: ""; position: absolute; inset: 18% 22%; border-radius: 50%;
  background: radial-gradient(closest-side, var(--stage-glow), transparent); filter: blur(10px);
  animation: stage-breathe 6s var(--ease-soft) infinite;
}
@keyframes stage-breathe { 50% { transform: scale(1.12); opacity: .7; } }

@media (max-width: 720px) {
  .home-header { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "copy" "badge"; padding: 0 20px 22px; min-height: 0; row-gap: 16px; }
  .home-stage { margin: 0 -20px -6px; min-height: 190px; }
  .home-header::after { left: -20%; right: -20%; top: 0; bottom: auto; height: 210px; }
}

/* Figura de las páginas interiores (la inserta temco-3d.js desde 900 px). */
.page-header .page-stage { position: relative; flex: none; align-self: center; width: 180px; height: 132px; margin: -24px 8px -24px auto; }
.page-header .page-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page-header .page-stage::before { content: ""; position: absolute; inset: 20%; border-radius: 50%; background: radial-gradient(closest-side, var(--stage-glow), transparent); }
@media (max-width: 899px) { .page-header .page-stage { display: none; } }

/* Tarjetas con inclinación ------------------------------------------------- */
.dash-metrics-strip, .billing-choice-grid { perspective: 1100px; }
.dash-metric-card, .billing-choice { rotate: none; transition: transform 280ms var(--ease-out), box-shadow 280ms var(--ease-out), border-color 180ms, rotate 700ms var(--ease-out); }
.dash-metric-card.is-tilting, .billing-choice.is-tilting { transition: transform 280ms var(--ease-out), box-shadow 280ms var(--ease-out), border-color 180ms, rotate 90ms linear; }
.dash-metric-card .metric-value, .billing-choice h2 { translate: var(--px, 0) var(--py, 0); transition: translate 600ms var(--ease-out); }
.dash-metric-card.is-tilting .metric-value, .billing-choice.is-tilting h2 { transition-duration: 120ms; }
.billing-choice { position: relative; overflow: hidden; isolation: isolate; }
/* Brillo que sigue al puntero por toda la tarjeta (anula el cuadrado de 220 px de venpisa.css).
   Va detrás del contenido y es tenue: ilumina la tarjeta sin tapar textos ni iconos. */
html .billing-choice::after {
  content: ""; display: block; position: absolute; inset: 0; width: auto; height: auto; z-index: -1;
  pointer-events: none; border-radius: inherit; opacity: 0;
  background:
    radial-gradient(300px circle at var(--gx, 50%) var(--gy, 0%), #ffffff0a, transparent 65%),
    radial-gradient(480px circle at var(--gx, 50%) var(--gy, 0%), var(--kind-glow, #ffffff10), transparent 70%);
  transition: opacity 360ms var(--ease-out);
}
html .billing-choice:hover::after { opacity: 0; }
html .billing-choice.is-tilting::after { opacity: 1; }
:root:not(.theme-dark):not([data-theme="dark"]) .billing-choice::after {
  background:
    radial-gradient(480px circle at var(--gx, 50%) var(--gy, 0%), var(--kind-glow, #24645a12), transparent 70%);
  mix-blend-mode: normal;
}
.choice-icon { position: relative; }
html.temco-3d .billing-choice .choice-icon { width: 64px; height: 64px; border-radius: 20px; overflow: hidden; background: radial-gradient(circle at 50% 60%, var(--stage-glow), transparent 75%), var(--surface-subtle); }
html.temco-3d .billing-choice .choice-icon svg { display: none; }
.billing-choice .choice-icon canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.billing-choice:hover .choice-icon { transform: none; }
.local-choice .choice-icon { --temco-3d: #b89150; --temco-3d-hi: #6b4d1d; }
:is(:root[data-theme="dark"], html.theme-dark) .local-choice .choice-icon { --temco-3d: #7a6744; --temco-3d-hi: #ecdcb2; }
html.temco-3d .local-choice .choice-icon { background: radial-gradient(circle at 50% 60%, #c8b58624, transparent 75%), var(--surface-subtle); }

/* Orbe del asistente --------------------------------------------------------- */
html.temco-3d .assistant-orb svg, html.temco-3d .assistant-launch > svg { display: none; }
.assistant-orb {
  position: relative; width: 104px; height: 104px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, var(--stage-glow), transparent 68%);
  box-shadow: none; animation: orb-float 5s var(--ease-soft) infinite;
}
:is(:root[data-theme="dark"], html.theme-dark) .assistant-orb { box-shadow: none; }
html:not(.temco-3d) .assistant-orb { width: 56px; height: 56px; border-radius: 18px; background: var(--accent-grad); }
.assistant-orb::before {
  content: ""; position: absolute; inset: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff24, transparent 55%);
  box-shadow: 0 0 46px -6px var(--stage-glow), inset 0 0 0 1px #ffffff0d;
}
html:not(.temco-3d) .assistant-orb::before { display: none; }
.assistant-orb canvas { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); }
.assistant-shell[data-thinking="true"] .assistant-orb::before { animation: orb-pulse 1.2s var(--ease-soft) infinite; }
@keyframes orb-pulse { 50% { box-shadow: 0 0 70px 4px var(--stage-glow), inset 0 0 0 1px #ffffff1f; } }
@keyframes orb-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* Lanzador: orbe vivo sobre el botón (colores en contraste con su fondo). */
.assistant-launch { --temco-3d: #9fd6c6; --temco-3d-hi: #ffffff; }
:is(:root[data-theme="dark"], html.theme-dark) .assistant-launch { --temco-3d: #2c6b5d; --temco-3d-hi: #0d221d; }
.assistant-launch .launch-3d { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; }
.assistant-shell:not([data-open="true"]) .assistant-launch::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; pointer-events: none;
  border: 1px solid var(--brand); opacity: 0; animation: launch-ring 3.6s var(--ease-out) infinite 1.2s;
}
@keyframes launch-ring { 0% { opacity: .55; transform: scale(.9); } 70%, 100% { opacity: 0; transform: scale(1.35); } }

/* Acceso ------------------------------------------------------------------- */
.auth-3d { position: fixed; inset: 0; z-index: 0; width: 100vw; height: 100vh; opacity: .85; }
.auth-page main, .auth-page footer { position: relative; z-index: 1; }
.auth-card { background: color-mix(in srgb, var(--surface, #fff) 82%, transparent); -webkit-backdrop-filter: blur(16px) saturate(1.2); backdrop-filter: blur(16px) saturate(1.2); }
:is(:root[data-theme="dark"], html.theme-dark) .auth-card { background: #242424d1; }

/* Colores por tipo: Vivienda en azul, Local en amarillo ----------------------- */
:root {
  --housing: #2563c9; --housing-soft: #eaf1fd; --housing-line: #c8d9f7; --housing-glow: #2563c91f;
  --local: #a26a00; --local-soft: #fdf4dd; --local-line: #f0dca6; --local-glow: #e0a1201f;
}
:is(:root[data-theme="dark"], html.theme-dark) {
  --housing: #8fb5f6; --housing-soft: #1d2a40; --housing-line: #2d4266; --housing-glow: #5b8de826;
  --local: #f2c55c; --local-soft: #382e17; --local-line: #574621; --local-glow: #e6b14a24;
}
.housing-choice, .kind-vivienda, .section-vivienda .page-stage, .badge-housing {
  --kind: var(--housing); --kind-soft: var(--housing-soft); --kind-line: var(--housing-line); --kind-glow: var(--housing-glow);
  --temco-3d: #6b9ae6; --temco-3d-hi: #1e4fa6;
}
.local-choice, .kind-local, .section-local .page-stage, .badge-local {
  --kind: var(--local); --kind-soft: var(--local-soft); --kind-line: var(--local-line); --kind-glow: var(--local-glow);
  --temco-3d: #d9a640; --temco-3d-hi: #855600;
}
:is(:root[data-theme="dark"], html.theme-dark) :is(.housing-choice, .kind-vivienda, .section-vivienda .page-stage) { --temco-3d: #3d5f98; --temco-3d-hi: #d3e3ff; }
:is(:root[data-theme="dark"], html.theme-dark) :is(.local-choice, .kind-local, .section-local .page-stage) { --temco-3d: #8a6a26; --temco-3d-hi: #ffe2a0; }
.section-vivienda .page-stage, .section-local .page-stage { --stage-glow: var(--kind-glow); }

/* Tarjetas Vivienda / Local */
html:root .billing-choice.housing-choice::before, html:root .billing-choice.local-choice::before { background: radial-gradient(420px 140px at 18% 0%, var(--kind-glow), transparent 75%); opacity: 1; }
html:root .billing-choice:is(.housing-choice, .local-choice) { border-top: 2px solid var(--kind); }
html.temco-3d:root .billing-choice:is(.housing-choice, .local-choice) .choice-icon,
html:root .billing-choice:is(.housing-choice, .local-choice) .choice-icon {
  color: var(--kind); background: radial-gradient(circle at 50% 60%, var(--kind-glow), transparent 75%), var(--kind-soft);
  border: 1px solid var(--kind-line); box-shadow: 0 6px 18px -8px var(--kind-glow);
}
html:root .billing-choice:is(.housing-choice, .local-choice) .choice-kicker { color: var(--kind); }
html:root .billing-choice:is(.housing-choice, .local-choice) .choice-kicker .status-dot { background: var(--kind); box-shadow: 0 0 0 3px var(--kind-soft); }
html:root .billing-choice:is(.housing-choice, .local-choice) .choice-kicker .status-dot::after { color: var(--kind); }
html:root .billing-choice:is(.housing-choice, .local-choice) .action-mini-icon { color: var(--kind); background: var(--kind-soft); border-color: var(--kind-line); }
html:root .billing-choice:is(.housing-choice, .local-choice) .choice-actions a:hover { border-color: var(--kind-line); }
html:root .billing-choice:is(.housing-choice, .local-choice) .choice-actions a:hover .action-chevron { color: var(--kind); }
html:root .billing-choice:is(.housing-choice, .local-choice):hover { border-color: var(--kind-line); border-top-color: var(--kind); box-shadow: var(--card-shadow-hover), 0 0 28px -6px var(--kind-glow); }

/* Etiquetas y marcas de tipo */
html :is(.badge-housing, .badge-local) { color: var(--kind); background: var(--kind-soft); border: 1px solid var(--kind-line); }
html .badge-housing::before, html .badge-local::before { background: var(--kind); }
.compact-invoice-table .secondary-cell .badge { margin-right: 4px; padding: 1px 7px; font-size: 10px; vertical-align: 1px; }
.dashboard-upcoming .kind-tag {
  display: inline-block; margin-right: 8px; padding: 1px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 650;
  letter-spacing: .04em; text-transform: uppercase; vertical-align: 2px;
  color: var(--kind); background: var(--kind-soft); border: 1px solid var(--kind-line);
}
.dashboard-upcoming li time::before { background: var(--kind) !important; }
.dashboard-upcoming li { border-left: 3px solid var(--kind); padding-left: 14px !important; }
.section-vivienda .page-header .eyebrow { color: var(--housing); }
.section-local .page-header .eyebrow { color: var(--local); }
.sidebar .nav-family:nth-of-type(1) .nav-family-title .nav-icon { color: var(--housing); }
.sidebar .nav-family:nth-of-type(2) .nav-family-title .nav-icon { color: var(--local); }
.section-vivienda .sidebar .nav-family.active-family a.active { box-shadow: inset 2px 0 0 var(--housing); }
.section-local .sidebar .nav-family.active-family a.active { box-shadow: inset 2px 0 0 var(--local); }
.status-dot.status-dot-pending { background: var(--local); }
.status-dot.status-dot-pending::after { color: var(--local) !important; }

.chat-choice[data-choice="vivienda"] { --kind: var(--housing); --kind-soft: var(--housing-soft); --kind-line: var(--housing-line); }
.chat-choice[data-choice="local"] { --kind: var(--local); --kind-soft: var(--local-soft); --kind-line: var(--local-line); }
.chat-choice:is([data-choice="vivienda"], [data-choice="local"]) svg { color: var(--kind); stroke: var(--kind); }
.chat-choice:is([data-choice="vivienda"], [data-choice="local"]):is(:hover, :focus-visible) { border-color: var(--kind-line); background: var(--kind-soft); }

/* Móvil: tablas en tarjetas y textos que no deben cortarse ---------------------- */
@media (max-width: 720px) {
  .metric-pill { white-space: normal; }
  .stack-table, .compact-invoice-table { min-width: 0 !important; width: 100%; }
  .stack-table thead, .compact-invoice-table thead { display: none; }
  .stack-table tbody, .compact-invoice-table tbody { display: grid; gap: 12px; padding: 12px; }
  .stack-table tr, .compact-invoice-table tr {
    display: grid; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--hairline);
  }
  /* Etiqueta flotando a la izquierda y contenido a la derecha: sirve aunque la celda tenga varias líneas. */
  .stack-table td, .scheduled-table td:not(:first-child):not(:last-child) {
    display: block !important; min-width: 0; padding: 8px 0 !important;
    border-bottom: 1px solid var(--border-subtle); text-align: right; overflow-wrap: break-word; white-space: normal !important;
  }
  .stack-table td::after, .scheduled-table td:not(:first-child):not(:last-child)::after { content: ""; display: block; clear: both; }
  .stack-table td:last-child { border-bottom: 0; padding-bottom: 0 !important; }
  .stack-table td:first-child { padding-top: 0 !important; }
  .stack-table td::before, .scheduled-table td:not(:first-child):not(:last-child)::before {
    float: left; margin-right: 16px; max-width: 40%; content: attr(data-label); text-align: left; color: var(--text-muted);
    font-size: .65rem; font-weight: 650; letter-spacing: .055em; text-transform: uppercase; padding-top: 2px;
  }
  .stack-table td .page-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
  .stack-table td:last-child .btn { margin: 4px 0 0 6px; }
  .scheduled-table td * { white-space: normal; }
  .stack-table .primary-cell, .stack-table .secondary-cell { text-align: right; }
  .compact-invoice-table tr { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; }
  .compact-invoice-table td { padding: 0 !important; border: 0 !important; min-width: 0; }
  .compact-invoice-table td:nth-child(1) { grid-column: 1; }
  .compact-invoice-table td:nth-child(2) { grid-column: 1; grid-row: 2; }
  .compact-invoice-table td:nth-child(3) { display: none; }
  .compact-invoice-table td:nth-child(4) { grid-column: 2; grid-row: 1; text-align: right; }
  .compact-invoice-table td:nth-child(5) { grid-column: 2; grid-row: 2; text-align: right; }
  .compact-invoice-table .table-wrap, .recent-table-card .table-wrap { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .home-stage::before, .assistant-orb, .assistant-orb::before, .assistant-launch::after { animation: none !important; }
}
@media print {
  canvas[data-temco-3d], .home-stage, .page-stage { display: none !important; }
  .home-header { display: block; min-height: 0; padding: 0; border: 0; background: none; box-shadow: none; }
  .home-header::after { display: none; }
}
