/* ════════════════════════════════════════════════════════════════════
   ui-refresh.css — unified design-system layer (loaded LAST)
   Clínica de Valle · clinical-professional refresh 2026-07
   Scope: tokens, typography, focus, buttons, inputs, tables, toast,
          motion + reduced-motion, mobile foundations.
   Rules here refine the three legacy sheets without renaming any
   class/id the JS depends on.
   ════════════════════════════════════════════════════════════════════ */

:root {
  /* type scale (major third-ish, 16px base) */
  --fs-xs: 0.75rem;
  --fs-sm: 0.855rem;
  --fs-base: 1rem;
  --fs-md: 1.125rem;
  --fs-lg: 1.375rem;
  --fs-xl: 1.75rem;
  --fs-2xl: 2.25rem;

  /* spacing rhythm (4px grid) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  /* elevation scale — one system for every card/panel/modal */
  --elev-1: 0 1px 2px rgba(4, 43, 55, 0.05), 0 2px 8px rgba(4, 43, 55, 0.05);
  --elev-2: 0 2px 6px rgba(4, 43, 55, 0.06), 0 10px 24px rgba(4, 43, 55, 0.08);
  --elev-3: 0 8px 20px rgba(4, 43, 55, 0.1), 0 24px 48px rgba(4, 43, 55, 0.12);

  /* motion tokens */
  --dur-fast: 150ms;
  --dur-base: 220ms;
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.55, 0, 0.55, 0.2);

  /* focus ring */
  --focus-ring: 0 0 0 3px rgba(119, 194, 206, 0.55);
  --focus-ring-inverse: 0 0 0 3px rgba(255, 255, 255, 0.45);

  /* refreshed semantic tints */
  --success-soft: rgba(47, 143, 91, 0.12);
  --warning-soft: rgba(198, 122, 35, 0.12);
  --danger-soft: rgba(182, 72, 61, 0.1);
  --line: rgba(2, 77, 94, 0.12);
  --line-soft: rgba(2, 77, 94, 0.08);
}

/* ── Global typography & rendering ──────────────────────────────────── */

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

::selection {
  background: rgba(119, 194, 206, 0.45);
  color: var(--brand-dark-strong);
}

/* subtle, brand-consistent scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(2, 77, 94, 0.28) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: rgba(2, 77, 94, 0.24);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-track {
  background: transparent;
}

/* ── Focus visibility (one ring to rule them all) ───────────────────── */

:focus {
  outline: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ── Interactive primitives ─────────────────────────────────────────── */

button,
a,
input,
select,
textarea,
[role="button"] {
  touch-action: manipulation;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:active:not(:disabled) {
  transform: scale(0.985);
}

button:disabled,
.button-primary:disabled,
.button-secondary:disabled,
.button-ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Buttons: consistent sizing, weight, feedback ───────────────────── */

.button-primary,
.button-secondary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  font-weight: 600;
  letter-spacing: 0.01em;
  font-size: var(--fs-base);
  transition:
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out),
    background var(--dur-base) var(--ease-out),
    filter var(--dur-base) var(--ease-out);
}

.button-primary {
  background: linear-gradient(150deg, #036780 0%, var(--primary) 55%, var(--primary-strong) 100%);
  color: #f4fbfc;
  box-shadow: 0 1px 2px rgba(1, 43, 54, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.button-primary:hover {
  background: linear-gradient(150deg, #047591 0%, #036177 55%, var(--primary) 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(2, 77, 94, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.button-primary:active:not(:disabled) {
  transform: translateY(0) scale(0.985);
  box-shadow: 0 1px 2px rgba(1, 43, 54, 0.3);
}

.button-secondary {
  background: rgba(2, 77, 94, 0.07);
  color: var(--primary-strong);
  border: 1px solid rgba(2, 77, 94, 0.14);
}

.button-secondary:hover {
  background: rgba(2, 77, 94, 0.11);
  border-color: rgba(2, 77, 94, 0.22);
}

.button-ghost {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  color: var(--primary);
  border-radius: 999px;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

/* inline text links keep their compact form */
.entry-inline-link {
  min-height: 0;
  text-underline-offset: 3px;
}

.entry-inline-link:hover {
  text-decoration: underline;
}

/* ── Form fields: comfortable, consistent, accessible ───────────────── */

input,
select,
textarea {
  min-height: 44px;
  padding: 10px 14px;
  font-size: var(--fs-base);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

textarea {
  min-height: 124px;
}

input::placeholder,
textarea::placeholder {
  color: rgba(75, 108, 118, 0.62);
}

input:hover:not(:focus):not(:disabled),
select:hover:not(:focus):not(:disabled),
textarea:hover:not(:focus):not(:disabled) {
  border-color: rgba(2, 77, 94, 0.3);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
  background: #ffffff;
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: rgba(223, 238, 241, 0.4);
}

input[readonly] {
  background: rgba(223, 238, 241, 0.35);
  color: var(--ink-soft);
}

/* native select affordance */
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23336b7a' stroke-width='2.4' 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 12px center;
  padding-right: 38px;
}

input[type="checkbox"],
input[type="radio"] {
  min-height: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

input[type="file"] {
  border-style: dashed;
  cursor: pointer;
}

label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
}

/* ── Tables: readable data everywhere ───────────────────────────────── */

table {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

thead th {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

tbody tr {
  transition: background var(--dur-fast) var(--ease-out);
}

/* ── Toast: elevated, safe-area aware ───────────────────────────────── */

.toast {
  box-shadow: var(--elev-3);
  font-weight: 600;
  border-radius: var(--radius-md);
  max-width: min(92vw, 480px);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

/* ── Status messages (entry screens + portals) ──────────────────────── */

.entry-status-message {
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: var(--fs-sm);
  line-height: 1.45;
}

/* ── Card surfaces: one elevation system ────────────────────────────── */

.card {
  box-shadow: var(--elev-1);
  border: 1px solid var(--line-soft);
}

/* ── Images never overflow ──────────────────────────────────────────── */

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

/* ── Motion discipline ──────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Client portal refinements ──────────────────────────────────────── */

/* hero: clinical dot texture parity with the auth brand panels */
.client-hero {
  background-image:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0),
    linear-gradient(150deg, #011e26 0%, #013847 48%, #024d5e 100%);
  background-size: 22px 22px, 100% 100%;
}

.client-icon-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-weight: 600;
  transition:
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.client-icon-button:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.32);
  transform: translateY(-1px);
}

.client-icon-button:focus-visible {
  box-shadow: var(--focus-ring-inverse);
}

.client-copy-button {
  font-weight: 600;
  border-radius: 999px;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.client-copy-button:hover {
  transform: translateY(-1px);
}

/* floating profile action: clearly elevated, never glued to screen edge */
.client-profile-fab {
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 6px 14px rgba(1, 30, 38, 0.28), 0 20px 44px rgba(2, 77, 94, 0.3);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.client-profile-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(1, 30, 38, 0.3), 0 26px 52px rgba(2, 77, 94, 0.34);
}

/* settings drawer: readable action rows with intent colors */
.client-settings-action {
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), padding-left var(--dur-fast) var(--ease-out);
}

.client-settings-action:hover:not(:disabled) {
  background: rgba(2, 77, 94, 0.06);
  padding-left: 26px;
}

#client-settings-cancel:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

/* profile header back button */
.client-back-button {
  min-height: 42px;
  border-radius: 999px;
  font-weight: 600;
  transition: background var(--dur-fast) var(--ease-out);
}

.client-back-button:hover {
  background: rgba(2, 77, 94, 0.12);
}

/* keep content clear of the floating action on small screens */
@media (max-width: 640px) {
  .client-portal-main {
    width: calc(100vw - 24px);
    margin-top: -110px;
    padding-bottom: 118px;
  }

  .client-hero {
    padding: 24px 18px 150px;
  }

  .client-avatar-button {
    width: 72px;
    height: 72px;
    border-radius: 20px;
  }

  .client-profile-fab {
    right: 16px;
    left: auto;
  }
}

/* ── Admin portal: layout robustness fixes ──────────────────────────── */

/* membership price editor: the current-price card and the update form
   were forced side-by-side even when the panel is narrow, crushing the
   price input to ~50px. Let them wrap instead. */
.adminlite-membership-price-shell {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

/* toolbar filter rows: wrap instead of crushing fields when the panel is
   narrow (e.g. the ambassadors search toolbar in a half-width panel).
   Below 1181px the legacy sheet stacks these to one column — keep that. */
@media (min-width: 1181px) {
  .adminlite-form-grid-toolbar {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

/* a panel immediately followed by a full-width panel has no row partner —
   let it use the whole row instead of leaving a dead half-column
   (e.g. the "Crear razón social" form) */
.adminlite-page-grid > .adminlite-panel:nth-child(odd):has(+ .adminlite-panel-wide),
.adminlite-page-grid > .adminlite-panel:last-child:nth-child(odd),
.adminlite-page-grid > .adminlite-panel-wide + .adminlite-panel:last-child {
  grid-column: 1 / -1;
}

/* ── Admin portal: mobile shell fixes ───────────────────────────────── */

@media (max-width: 900px) {
  /* the nav strip scrolls horizontally — show a fade affordance and
     comfortable touch targets */
  .adminlite-sidebar-nav {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 32px), transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 32px), transparent 100%);
  }

  .adminlite-sidebar-nav::-webkit-scrollbar {
    display: none;
  }

  .adminlite-sidebar-item {
    min-height: 40px;
    padding: 9px 13px;
  }

  /* restore session controls (logout!) as a compact segment of the strip */
  .adminlite-sidebar-footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 8px 4px;
    margin: 0;
    border-top: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
  }

  .adminlite-sidebar-user-info {
    display: none;
  }

  .adminlite-sidebar-logout {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 0.78rem;
    white-space: nowrap;
  }
}

/* ── Admin portal: responsive framework (Phase A) ───────────────────── */

/* Grid blowout prevention: grid/flex items default to min-width:auto,
   which lets deep min-content (rigid card rows, long tokens) push the
   whole main column wider than the viewport. Zero it along the chain. */
.adminlite-main,
.adminlite-body,
.adminlite-page-shell,
.adminlite-page-stack,
.adminlite-page-grid,
.adminlite-block,
.adminlite-panel,
.adminlite-subcard,
.adminlite-hero,
.adminlite-form,
.adminlite-form-grid,
.adminlite-field,
.adminlite-quick-grid,
.adminlite-quick-card,
.adminlite-process-strip,
.adminlite-process-step,
.adminlite-metric-grid,
.adminlite-metric-card,
.adminlite-info-grid,
.adminlite-info-card {
  min-width: 0;
}

/* KPI / metric / info tiles: the legacy sheets declare these grids with
   no column template, so every stat card stacked full-width. Give them
   responsive columns at zero specificity so any intentional per-context
   override (compound selectors in the legacy sheets) still wins. */
:where(.adminlite-metric-grid) {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: stretch;
}

:where(.adminlite-metric-grid.compact) {
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}

:where(.adminlite-info-grid) {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  align-items: stretch;
}

:where(.adminlite-info-grid.compact) {
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}

/* metric cards inside a shared row should fill their track height */
.adminlite-metric-card,
.adminlite-info-card {
  height: 100%;
  box-sizing: border-box;
}

/* Form section labels always own their full row, whatever the column
   count of the grid they sit in. */
.adminlite-form-grid > .adminlite-form-section-label {
  grid-column: 1 / -1;
}

/* Forms are grids stretched to their parent cell's height; without this
   the leftover height lands on the actions row and the submit button
   renders as a giant block (e.g. "Guardar precio mensual"). */
.adminlite-form,
.adminlite-subform {
  align-content: start;
}

.adminlite-form-actions .button-primary,
.adminlite-form-actions .button-secondary {
  align-self: center;
}

/* Analytics cards live in equal-height split-grid rows; without this the
   card's grid rows distribute the extra height and an empty-state or a
   short bar list stretches into a giant hollow box. */
.adminlite-analytics-card,
.adminlite-membership-section {
  align-content: start;
}

/* Laptop range (861–1180px): the legacy sheet collapses EVERY grid to a
   single column at ≤1180px, so common laptops got the stacked-mobile
   layout. Keep two-column forms and wrapping card rows in this range. */
@media (min-width: 861px) and (max-width: 1180px) {
  .adminlite-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .adminlite-form-grid-toolbar {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .adminlite-analytics-trend-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

/* Tablet/laptop: keep paired stat tiles and plan cards in two columns
   instead of the legacy single-column collapse. */
@media (min-width: 641px) {
  .adminlite-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 641px) and (max-width: 1180px) {
  .adminlite-membership-selector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Mobile topbar: the breadcrumb had flex-shrink:0, pushing the refresh
   button past the right edge (12px page overflow on 375px screens). */
@media (max-width: 900px) {
  .adminlite-topbar {
    gap: 10px;
  }

  .adminlite-topbar-brand {
    flex: 1 1 auto;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
  }

  .adminlite-topbar-crumb {
    min-width: 0;
    flex-wrap: nowrap;
  }

  .adminlite-topbar-crumb-page {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .adminlite-topbar-meta {
    flex-shrink: 0;
  }
}

/* ── Mobile foundations (per-surface rules live with each surface) ──── */

@media (max-width: 640px) {
  .entry-shell {
    padding: 16px 14px calc(24px + env(safe-area-inset-bottom, 0px));
    align-items: start;
  }

  .button-row,
  .entry-button-stack {
    gap: 10px;
  }

  .entry-button-stack .button-primary,
  .entry-button-stack .button-secondary {
    width: 100%;
  }
}
