/* Estilos comunes de Torvixion Studio (fase A del CRM): identidad visual, temas claro y oscuro,
   componentes compartidos y navegación. Cada página carga este archivo y añade solo sus reglas propias.
   Paleta de marca: azul marino #344B60, azul suave #829FB3, arena #D8C6B7, crema #F7F3ED, melocotón #E6A48D.
   Tema: <html data-theme="light|dark">; sin atributo se sigue el del dispositivo (lo decide un script en <head>). */

/* ---------- Tokens: tema claro (por defecto) ---------- */
:root {
  --navy: #344B60; --soft-blue: #829FB3; --sand: #D8C6B7; --cream: #F7F3ED; --peach: #E6A48D;

  --bg: #F7F3ED;          /* fondo: crema */
  --surface: #FFFFFF;     /* tarjetas */
  --surface-2: #F1EBE3;   /* campos y bloques secundarios */
  --fg: #22313F;          /* texto principal (marino oscurecido para leer mejor) */
  --muted: #5B6B79;       /* texto secundario */
  --line: #E3D8CC;        /* bordes (arena clara) */
  --accent: #344B60;      /* estados seleccionados: marino */
  --accent-ink: #F7F3ED;  /* texto sobre --accent */
  --accent-text: #344B60; /* enlaces y etiquetas destacadas */
  --highlight: #E6A48D;   /* detalles de marca: melocotón (indicadores, nunca texto pequeño) */
  --on-highlight: #22313F;
  --primary: #344B60;     /* botón principal */
  --on-primary: #F7F3ED;
  --primary-hover: #2A3E50;
  --sky: #344B60;         /* anillo de foco */
  --warn: #8A5A00;
  --error: #B3261E;
  --backdrop: rgba(34, 49, 63, .55);
  --font-display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --nav-h: 64px;          /* barra inferior en móvil */
  --side-w: 232px;        /* menú lateral en escritorio */
  color-scheme: light;
}

/* ---------- Tema oscuro: elegido o del dispositivo ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18222D; --surface: #22303E; --surface-2: #1C2835; --fg: #F7F3ED; --muted: #A9B8C5; --line: #344B60;
    --accent: #829FB3; --accent-ink: #18222D; --accent-text: #A9C1D2; --highlight: #E6A48D; --on-highlight: #18222D;
    --primary: #829FB3; --on-primary: #18222D; --primary-hover: #93AEC0; --sky: #E6A48D;
    --warn: #E8C27A; --error: #F2A99B; --backdrop: rgba(8, 12, 17, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #18222D; --surface: #22303E; --surface-2: #1C2835; --fg: #F7F3ED; --muted: #A9B8C5; --line: #344B60;
  --accent: #829FB3; --accent-ink: #18222D; --accent-text: #A9C1D2; --highlight: #E6A48D; --on-highlight: #18222D;
  --primary: #829FB3; --on-primary: #18222D; --primary-hover: #93AEC0; --sky: #E6A48D;
  --warn: #E8C27A; --error: #F2A99B; --backdrop: rgba(8, 12, 17, .7);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { padding-top: env(safe-area-inset-top, 0px); }
img { max-width: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0; -webkit-tap-highlight-color: transparent; background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.45; padding-inline: 16px; padding-block: 0;
}
.eyebrow { font-family: var(--font-display); font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-text); }
h1 { font-family: var(--font-display); font-weight: 600; font-size: 28px; line-height: 1.15; margin: 0; text-wrap: balance; color: var(--fg); }
.lede { margin: 0; color: var(--muted); }
.back { color: var(--muted); text-decoration: none; font-size: 14px; padding: 6px 0; background: none; border: 0; font-family: inherit; cursor: pointer; align-self: flex-start; }
.back:hover { color: var(--fg); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible,
.switch input:focus-visible + .track, .seg input:focus-visible + span { outline: 2px solid var(--sky); outline-offset: 2px; }

/* ---------- Componentes ---------- */
.btn {
  font: 600 15px/1 var(--font-body); border-radius: 10px; padding: 13px 16px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
}
.btn.primary { background: var(--primary); color: var(--on-primary); border: 1px solid var(--primary); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { background: transparent; color: var(--fg); border: 1px solid var(--line); }
.btn.secondary:hover { border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--error); border: 1px solid var(--error); }
.btn.small { padding: 10px 14px; font-size: 14px; }
.btn:disabled { opacity: .6; cursor: progress; }
.chip { font: inherit; font-size: 13px; font-weight: 500; color: var(--fg); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip.ghost { color: var(--muted); }
.chip.danger { color: var(--error); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg);
  font: 600 15px/1 var(--font-display); cursor: pointer; display: grid; place-items: center; flex: none;
}
.icon-btn:hover:not(:disabled) { border-color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, legend { font-size: 13px; font-weight: 500; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
input[type="text"], input[type="number"], input[type="search"], input[type="tel"], input[type="email"], input[type="password"], select, textarea {
  font: inherit; color: var(--fg); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 64px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: inline-block; font-size: 13px; font-weight: 500; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; cursor: pointer; }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg input:disabled + span { opacity: .45; cursor: default; }
.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.track { width: 46px; height: 28px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); position: relative; transition: background .15s; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--accent-ink); }
.inline-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--fg); padding: 0;
}
dialog::backdrop { background: var(--backdrop); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.status { font-size: 13px; color: var(--accent-text); margin: 0; min-height: 1.2em; overflow-wrap: anywhere; }
.status.error { color: var(--error); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: 2px; }

/* ---------- Navegación común (la pinta app-shell.js) ----------
   Móvil: barra inferior fija. Escritorio (≥ 900 px): menú lateral fijo.
   Las páginas con navegación llevan <html class="tvx-shell">; así el hueco se reserva antes de pintarla. */
html.tvx-shell { --nav-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); --nav-left: 0px; }
html.tvx-shell body { padding-bottom: var(--nav-bottom); }
.tvx-nav {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; height: var(--nav-bottom);
  padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--surface); border-top: 1px solid var(--line);
  display: flex;
}
.tvx-brand { display: none; }
.tvx-nav ul { list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); flex: 1; }
.tvx-nav a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--nav-h);
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 500;
}
.tvx-nav a svg { width: 22px; height: 22px; }
.tvx-nav a[aria-current="page"] { color: var(--fg); font-weight: 600; }
.tvx-nav a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 50%; width: 32px; height: 3px; margin-left: -16px; border-radius: 0 0 3px 3px; background: var(--highlight); }
.tvx-nav a:hover { color: var(--fg); }
.tvx-nav a:focus-visible { outline-offset: -4px; }

@media (min-width: 900px) {
  html.tvx-shell { --nav-bottom: 0px; --nav-left: var(--side-w); }
  html.tvx-shell body { padding-left: calc(var(--side-w) + 24px); padding-right: 24px; }
  .tvx-nav {
    top: 0; right: auto; width: var(--side-w); height: auto; padding: 20px 12px; flex-direction: column; gap: 18px;
    border-top: 0; border-right: 1px solid var(--line);
  }
  .tvx-brand { display: block; padding: 4px 12px; font: 600 17px/1.2 var(--font-display); color: var(--fg); }
  .tvx-brand small { display: block; margin-top: 4px; font: 500 11px/1 var(--font-body); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
  .tvx-nav ul { grid-auto-flow: row; grid-auto-rows: auto; align-content: start; gap: 2px; }
  .tvx-nav a { flex-direction: row; justify-content: flex-start; gap: 12px; height: 42px; padding: 0 12px; border-radius: 10px; font-size: 15px; }
  .tvx-nav a svg { width: 20px; height: 20px; }
  .tvx-nav a[aria-current="page"] { background: var(--surface-2); }
  .tvx-nav a[aria-current="page"]::before { top: 9px; left: 0; width: 3px; height: 24px; margin-left: 0; border-radius: 0 3px 3px 0; }
}

/* Navegación compacta (fase B, Presupuestos): en móvil no hay barra inferior; la lista de módulos se abre
   como panel desde el botón «Menú» de la página. En escritorio sigue el menú lateral. */
.tvx-sheet-head, .tvx-backdrop { display: none; }
@media (max-width: 899px) {
  html.tvx-nav-compact { --nav-bottom: 0px; }
  html.tvx-nav-compact .tvx-nav { display: none; }
  html.tvx-nav-compact .tvx-nav.tvx-open {
    display: flex; flex-direction: column; gap: 6px; z-index: 41; height: auto; max-height: 80dvh; overflow: auto;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px)); border-radius: 16px 16px 0 0; border-top: 1px solid var(--line);
  }
  html.tvx-nav-compact .tvx-nav.tvx-open .tvx-sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 6px; font: 600 16px/1.2 var(--font-display); }
  html.tvx-nav-compact .tvx-nav.tvx-open ul { grid-auto-flow: row; grid-auto-rows: auto; gap: 2px; }
  html.tvx-nav-compact .tvx-nav.tvx-open a { flex-direction: row; justify-content: flex-start; gap: 12px; height: 48px; padding: 0 12px; border-radius: 10px; font-size: 15px; }
  html.tvx-nav-compact .tvx-nav.tvx-open a[aria-current="page"] { background: var(--surface-2); }
  html.tvx-nav-compact .tvx-nav.tvx-open a[aria-current="page"]::before { top: 12px; left: 0; width: 3px; height: 24px; margin-left: 0; border-radius: 0 3px 3px 0; }
  html.tvx-nav-compact .tvx-backdrop.tvx-open { display: block; position: fixed; inset: 0; z-index: 40; background: var(--backdrop); }
}

@media (prefers-reduced-motion: reduce) { .track, .track::after { transition: none; } }
