/* ─────────────────────────────────────────────────────────────────────────────
   App-level styles — usa tokens definidos en theme.css.
   Cubre lo que Material Web Components no aporta: layout, tablas, badges.
   ───────────────────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--md-ref-typeface-plain);
  font-size: 16px;
  color: var(--md-sys-color-on-background);
  background: var(--md-sys-color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

h1, h2, h3, h4, h5, h6 { font-family: var(--md-ref-typeface-brand); margin: 0; }

/* ── Layout shell ─────────────────────────────────────────────────────────── */

.tv-shell {
  display: grid;
  grid-template-columns: 80px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas:
    "topbar topbar"
    "rail   main";
  flex: 1;
  min-height: 100vh;
}

@media (max-width: 768px) {
  .tv-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 64px 1fr 80px;
    grid-template-areas:
      "topbar"
      "main"
      "bottom-nav";
  }
}

/* ── Top app bar ──────────────────────────────────────────────────────────── */

.tv-topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  position: sticky;
  top: 0;
  z-index: 100;
}

.tv-topbar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--md-ref-typeface-brand);
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--md-sys-color-on-surface);
}

.tv-topbar__brand .material-symbols-outlined {
  font-size: 28px;
  color: var(--md-sys-color-primary);
}

.tv-topbar__user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
}

.tv-topbar__user-name {
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

/* ── Navigation rail (desktop) ────────────────────────────────────────────── */

.tv-rail {
  grid-area: rail;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 4px;
  background: var(--md-sys-color-surface);
  border-right: 1px solid var(--md-sys-color-outline-variant);
}

.tv-rail__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
  width: 64px;
  border-radius: var(--md-sys-shape-corner-large);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.tv-rail__item:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
  text-decoration: none;
}

.tv-rail__item .tv-rail__icon-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 32px;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background-color 0.15s;
}

.tv-rail__item.is-active {
  color: var(--md-sys-color-on-surface);
}

.tv-rail__item.is-active .tv-rail__icon-bg {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.tv-rail__item .material-symbols-outlined {
  font-size: 24px;
}

@media (max-width: 768px) {
  .tv-rail { display: none; }
}

/* ── Bottom navigation (mobile) ───────────────────────────────────────────── */

.tv-bottom-nav {
  display: none;
  grid-area: bottom-nav;
  background: var(--md-sys-color-surface-container);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  padding: 12px 8px;
  justify-content: space-around;
  align-items: center;
  position: sticky;
  bottom: 0;
}

.tv-bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 14px;
  border-radius: var(--md-sys-shape-corner-large);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.7rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s;
}

.tv-bottom-nav__item.is-active {
  color: var(--md-sys-color-on-secondary-container);
}

.tv-bottom-nav__item.is-active .tv-bottom-nav__icon-bg {
  background: var(--md-sys-color-secondary-container);
}

.tv-bottom-nav__icon-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 28px;
  border-radius: var(--md-sys-shape-corner-full);
}

.tv-bottom-nav__item .material-symbols-outlined { font-size: 22px; }

@media (max-width: 768px) {
  .tv-bottom-nav { display: flex; }
}

/* ── Main content ─────────────────────────────────────────────────────────── */

.tv-main {
  grid-area: main;
  padding: 32px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .tv-main { padding: 16px; }
}

.tv-page-title {
  font-family: var(--md-ref-typeface-brand);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 24px;
  color: var(--md-sys-color-on-background);
}

/* ── Cards (surface containers) ───────────────────────────────────────────── */

.tv-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 20px;
  box-shadow: var(--md-sys-elevation-level1);
  transition: box-shadow 0.2s;
}

.tv-card--elevated {
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--md-sys-elevation-level2);
}

.tv-card--outlined {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: none;
}

.tv-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--md-ref-typeface-plain);
  font-size: 1rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 16px;
}

.tv-card__header-icon {
  color: var(--md-sys-color-primary);
}

/* ── Stat card ────────────────────────────────────────────────────────────── */

.tv-stat {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 24px;
  text-align: center;
  box-shadow: var(--md-sys-elevation-level1);
}

.tv-stat__value {
  font-family: var(--md-ref-typeface-brand);
  font-size: 2.5rem;
  font-weight: 600;
  line-height: 1.1;
  margin-bottom: 4px;
  color: var(--md-sys-color-on-surface);
}

.tv-stat__value--primary { color: var(--md-sys-color-primary); }
.tv-stat__value--danger  { color: var(--md-sys-color-error); }
.tv-stat__value--success { color: var(--tv-color-success); }
.tv-stat__value--muted   { color: var(--md-sys-color-on-surface-variant); }

.tv-stat__label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-transform: none;
  letter-spacing: 0.007em;
}

/* ── Grid utilities ───────────────────────────────────────────────────────── */

.tv-grid { display: grid; gap: 16px; }
.tv-grid--cols-4 { grid-template-columns: repeat(4, 1fr); }
.tv-grid--cols-3 { grid-template-columns: repeat(3, 1fr); }
.tv-grid--cols-2 { grid-template-columns: repeat(2, 1fr); }
.tv-grid--12     { grid-template-columns: repeat(12, 1fr); }

.tv-col-3  { grid-column: span 3;  }
.tv-col-4  { grid-column: span 4;  }
.tv-col-5  { grid-column: span 5;  }
.tv-col-6  { grid-column: span 6;  }
.tv-col-7  { grid-column: span 7;  }
.tv-col-8  { grid-column: span 8;  }
.tv-col-9  { grid-column: span 9;  }
.tv-col-12 { grid-column: span 12; }

@media (max-width: 992px) {
  .tv-grid--cols-4 { grid-template-columns: repeat(2, 1fr); }
  .tv-grid--cols-3 { grid-template-columns: repeat(2, 1fr); }
  .tv-grid--12     { grid-template-columns: repeat(1, 1fr); }
  .tv-col-3, .tv-col-4, .tv-col-5, .tv-col-6, .tv-col-7, .tv-col-8, .tv-col-9 { grid-column: span 1; }
}

@media (max-width: 576px) {
  .tv-grid--cols-4, .tv-grid--cols-3, .tv-grid--cols-2 { grid-template-columns: 1fr; }
}

/* ── Tables ───────────────────────────────────────────────────────────────── */

.tv-table-wrap {
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container-lowest);
  overflow: hidden;
  box-shadow: var(--md-sys-elevation-level1);
}

.tv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.tv-table thead th {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0.007em;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-size: 0.8125rem;
}

.tv-table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  vertical-align: middle;
}

.tv-table tbody tr:last-child td { border-bottom: none; }

.tv-table tbody tr.is-clickable {
  cursor: pointer;
  transition: background-color 0.15s;
}

.tv-table tbody tr.is-clickable:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 5%, transparent);
}

.tv-table .text-center { text-align: center; }
.tv-table .text-end    { text-align: right; }
.tv-table .text-muted  { color: var(--md-sys-color-on-surface-variant); }
.tv-table .nowrap      { white-space: nowrap; }

.tv-table .descripcion-cell {
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Badges (chips MD3 estáticos) ─────────────────────────────────────────── */

.tv-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.014em;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  line-height: 1.4;
}

.tv-badge--grav-1plus  { background: var(--tv-color-grav-1plus);   color: #FFFFFF; }
.tv-badge--grav-1      { background: var(--tv-color-grav-1);       color: #FFFFFF; }
.tv-badge--grav-1minus { background: var(--tv-color-grav-1minus);  color: #221A14; }
.tv-badge--grav-2      { background: var(--tv-color-grav-2);       color: #FFFFFF; }
.tv-badge--grav-3      { background: var(--tv-color-grav-3);       color: #FFFFFF; }

.tv-badge--neutral { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface-variant); }
.tv-badge--success { background: var(--tv-color-success-container); color: var(--tv-color-success); }
.tv-badge--warning { background: var(--tv-color-warning-container); color: var(--tv-color-warning); }
.tv-badge--info    { background: var(--tv-color-info-container);    color: var(--tv-color-info); }
.tv-badge--danger  { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.tv-badge--primary { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }

/* ── Progress (linear, MD3-flavored) ──────────────────────────────────────── */

.tv-progress {
  width: 100%;
  height: 4px;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
}

.tv-progress__bar {
  height: 100%;
  background: var(--md-sys-color-primary);
  border-radius: var(--md-sys-shape-corner-full);
  transition: width 0.4s ease;
}

.tv-progress__bar--success { background: var(--tv-color-success); }
.tv-progress__bar--warning { background: var(--tv-color-warning); }
.tv-progress__bar--danger  { background: var(--md-sys-color-error); }
.tv-progress__bar--info    { background: var(--tv-color-info); }

/* ── Auth (login) layout ──────────────────────────────────────────────────── */

.tv-auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    radial-gradient(at 80% 10%, color-mix(in srgb, var(--md-sys-color-primary-container) 35%, transparent), transparent 50%),
    radial-gradient(at 20% 90%, color-mix(in srgb, var(--md-sys-color-tertiary-container) 30%, transparent), transparent 50%),
    var(--md-sys-color-background);
}

.tv-auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-extra-large);
  padding: 36px 32px;
  box-shadow: var(--md-sys-elevation-level3);
}

.tv-auth-card__header { text-align: center; margin-bottom: 24px; }

.tv-auth-card__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  margin-bottom: 12px;
}

.tv-auth-card__logo .material-symbols-outlined { font-size: 32px; }

.tv-auth-card__title {
  font-family: var(--md-ref-typeface-brand);
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  color: var(--md-sys-color-on-surface);
}

.tv-auth-card__subtitle {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
}

.tv-auth-tabs {
  display: flex;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}

.tv-auth-tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tv-auth-tab.is-active {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-level1);
}

.tv-auth-tab .material-symbols-outlined { font-size: 18px; }

.tv-auth-form { display: flex; flex-direction: column; gap: 16px; }

.tv-auth-form md-outlined-text-field { width: 100%; }

.tv-auth-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.tv-auth-helper {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  margin: 0 0 8px;
  line-height: 1.5;
}

.tv-otp-input {
  /* fallback estilizado para inputs OTP — usamos input nativo porque
     md-outlined-text-field no centra bien con letter-spacing tan grande. */
  width: 100%;
  text-align: center;
  font-family: var(--md-ref-typeface-brand);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  padding: 14px 12px;
  border-radius: var(--md-sys-shape-corner-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: border-color 0.15s;
}

.tv-otp-input:focus {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 13px 11px;
}

/* ── Alerts ───────────────────────────────────────────────────────────────── */

.tv-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: 0.875rem;
}

.tv-alert--error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.tv-alert--warning {
  background: var(--tv-color-warning-container);
  color: var(--tv-color-warning);
}

.tv-alert--info {
  background: var(--tv-color-info-container);
  color: var(--tv-color-info);
}

.tv-alert .material-symbols-outlined { font-size: 20px; }

/* ── Misc helpers ─────────────────────────────────────────────────────────── */

.tv-text-muted   { color: var(--md-sys-color-on-surface-variant); }
.tv-text-small   { font-size: 0.8125rem; }
.tv-text-strong  { font-weight: 600; }
.tv-mb-0 { margin-bottom: 0; }
.tv-mb-1 { margin-bottom: 8px; }
.tv-mb-2 { margin-bottom: 16px; }
.tv-mb-3 { margin-bottom: 24px; }
.tv-mb-4 { margin-bottom: 32px; }
.tv-mt-2 { margin-top: 16px; }
.tv-mt-3 { margin-top: 24px; }
.tv-mt-4 { margin-top: 32px; }
.tv-d-flex { display: flex; }
.tv-align-center { align-items: center; }
.tv-justify-between { justify-content: space-between; }
.tv-gap-1 { gap: 8px; }
.tv-gap-2 { gap: 12px; }
.tv-gap-3 { gap: 16px; }

/* ── Material Web Components — overrides para mapear nuestros tokens ──────── */

md-filled-button, md-outlined-button, md-text-button, md-elevated-button, md-filled-tonal-button {
  --md-filled-button-container-color: var(--md-sys-color-primary);
  --md-filled-button-label-text-color: var(--md-sys-color-on-primary);
  --md-outlined-button-label-text-color: var(--md-sys-color-primary);
  --md-outlined-button-outline-color: var(--md-sys-color-outline);
  --md-text-button-label-text-color: var(--md-sys-color-primary);
  --md-filled-tonal-button-container-color: var(--md-sys-color-secondary-container);
  --md-filled-tonal-button-label-text-color: var(--md-sys-color-on-secondary-container);
}

md-outlined-text-field {
  --md-outlined-text-field-outline-color: var(--md-sys-color-outline);
  --md-outlined-text-field-focus-outline-color: var(--md-sys-color-primary);
  --md-outlined-text-field-input-text-color: var(--md-sys-color-on-surface);
  --md-outlined-text-field-label-text-color: var(--md-sys-color-on-surface-variant);
  --md-outlined-text-field-focus-label-text-color: var(--md-sys-color-primary);
  width: 100%;
}

/* ── Material Symbols defaults ────────────────────────────────────────────── */

.material-symbols-outlined {
  font-variation-settings:
    'FILL' 0,
    'wght' 400,
    'GRAD' 0,
    'opsz' 24;
  vertical-align: middle;
  user-select: none;
}

.material-symbols-outlined.filled { font-variation-settings: 'FILL' 1; }

/* ─── Form controls (select / date inputs) MD3-styled ─────────────────────── */

.tv-form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tv-form-label {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.014em;
  color: var(--md-sys-color-on-surface-variant);
  padding-left: 4px;
}

.tv-input, .tv-select {
  appearance: none;
  font-family: var(--md-ref-typeface-plain);
  font-size: 0.875rem;
  font-weight: 400;
  padding: 10px 12px;
  border-radius: var(--md-sys-shape-corner-small);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: border-color 0.15s, background-color 0.15s;
  min-width: 0;
}

.tv-input:hover, .tv-select:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 4%, var(--md-sys-color-surface));
}

.tv-input:focus, .tv-select:focus {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 9px 11px;
}

.tv-select {
  background-image:
    url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2351453A'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 32px;
}

/* ─── Filters bar ─────────────────────────────────────────────────────────── */

.tv-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  background: var(--md-sys-color-surface-container-low);
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-large);
  margin-bottom: 16px;
}

.tv-filters .tv-form-group { flex: 1 1 160px; min-width: 140px; }

.tv-filters__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
  align-self: flex-end;
}

/* ─── Pagination ──────────────────────────────────────────────────────────── */

.tv-pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
}

.tv-pagination__current {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
  padding: 0 12px;
}

/* ─── Back link ───────────────────────────────────────────────────────────── */

.tv-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background-color 0.15s;
}

.tv-back:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
  text-decoration: none;
}

.tv-back .material-symbols-outlined { font-size: 20px; }

/* ─── Detail meta (definition list MD3) ────────────────────────────────────── */

.tv-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  font-size: 0.875rem;
}

.tv-meta dt {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
}

.tv-meta dd { margin: 0; color: var(--md-sys-color-on-surface); }

/* ─── Timeline ────────────────────────────────────────────────────────────── */

.tv-timeline {
  position: relative;
  padding-left: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.tv-timeline::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
}

.tv-timeline__item {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.875rem;
}

.tv-timeline__item::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  border: 2px solid var(--md-sys-color-surface);
  box-shadow: 0 0 0 2px var(--md-sys-color-primary);
}

.tv-timeline__field {
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.tv-timeline__change {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface);
  margin-top: 2px;
}

.tv-timeline__old {
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: line-through;
  margin-right: 4px;
}

.tv-timeline__arrow {
  color: var(--md-sys-color-on-surface-variant);
  margin: 0 4px;
}

.tv-timeline__meta {
  text-align: right;
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ─── Media grid + thumbs ─────────────────────────────────────────────────── */

.tv-media-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.tv-media-thumb {
  width: 88px;
  height: 88px;
  border-radius: var(--md-sys-shape-corner-medium);
  overflow: hidden;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: transform 0.15s;
}

.tv-media-thumb:hover { transform: scale(1.05); }

.tv-media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tv-media-thumb .material-symbols-outlined {
  font-size: 36px;
  color: var(--md-sys-color-primary);
}

.tv-media-thumb__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  color: #fff;
}

.tv-media-thumb__overlay .material-symbols-outlined { color: #fff; font-size: 32px; }

/* ─── Lightbox / video modal ──────────────────────────────────────────────── */

.tv-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.tv-lightbox.is-open { display: flex; }

.tv-lightbox__inner {
  position: relative;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.tv-lightbox__img,
.tv-lightbox__video {
  max-width: 95vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--md-sys-shape-corner-medium);
}

.tv-lightbox__topbar {
  position: absolute;
  top: -8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 0.875rem;
  transform: translateY(-100%);
}

.tv-lightbox__close,
.tv-lightbox__nav {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s;
}

.tv-lightbox__close:hover,
.tv-lightbox__nav:hover { background: rgba(255,255,255,0.22); }

.tv-lightbox__nav--prev { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); }
.tv-lightbox__nav--next { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }

.tv-lightbox__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tv-lightbox__download {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  padding: 8px 14px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tv-lightbox__download:hover { background: rgba(255,255,255,0.22); text-decoration: none; color: #fff; }

/* ─── Header con título + meta a la derecha ───────────────────────────────── */

.tv-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.tv-page-header .tv-page-title { margin-bottom: 0; }

/* ─── Surface container divider ───────────────────────────────────────────── */

.tv-divider {
  border: none;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  margin: 16px 0;
}

/* ─── Small "kpi" pill inline (badge con valor numérico grande) ───────────── */

.tv-kpi {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.tv-kpi__value {
  font-family: var(--md-ref-typeface-brand);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.tv-kpi__label {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* ─── Breadcrumbs ─────────────────────────────────────────────────────────── */

.tv-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin-bottom: 16px;
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
  list-style: none;
  padding: 0;
}

.tv-breadcrumb li { display: inline-flex; align-items: center; gap: 4px; }
.tv-breadcrumb li::after {
  content: "/";
  color: var(--md-sys-color-outline);
  margin: 0 4px;
}
.tv-breadcrumb li:last-child::after { content: none; }
.tv-breadcrumb a { color: var(--md-sys-color-primary); text-decoration: none; }
.tv-breadcrumb a:hover { text-decoration: underline; }
.tv-breadcrumb .is-current { color: var(--md-sys-color-on-surface); font-weight: 500; }

/* ─── Segmented buttons ───────────────────────────────────────────────────── */

.tv-segmented {
  display: inline-flex;
  border-radius: var(--md-sys-shape-corner-full);
  border: 1px solid var(--md-sys-color-outline);
  overflow: hidden;
}

.tv-segmented a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  background: transparent;
  border-right: 1px solid var(--md-sys-color-outline);
  transition: background-color 0.15s, color 0.15s;
}

.tv-segmented a:last-child { border-right: none; }

.tv-segmented a:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
  text-decoration: none;
}

.tv-segmented a.is-active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.tv-segmented .material-symbols-outlined { font-size: 18px; }

/* ─── Apto cells (grilla de apartamentos) ─────────────────────────────────── */

.tv-apto-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  position: relative;
  transition: transform 0.12s, box-shadow 0.15s;
  box-shadow: var(--md-sys-elevation-level1);
}

.tv-apto-cell:hover {
  transform: scale(1.06);
  box-shadow: var(--md-sys-elevation-level2);
  text-decoration: none;
}

.tv-apto-cell sup {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 0.65rem;
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 2px 5px;
  font-weight: 600;
  border: 1px solid var(--md-sys-color-outline-variant);
  line-height: 1;
}

/* Score colors (mapeados a tokens MD3) */
.tv-bg-success { background: var(--tv-color-success); color: #fff; }
.tv-bg-info    { background: var(--tv-color-info);    color: #fff; }
.tv-bg-warning { background: var(--tv-color-warning); color: #fff; }
.tv-bg-danger  { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }
.tv-bg-neutral { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface-variant); }

.tv-apto-cell.tv-bg-success sup,
.tv-apto-cell.tv-bg-info sup,
.tv-apto-cell.tv-bg-warning sup,
.tv-apto-cell.tv-bg-danger sup {
  background: rgba(255,255,255,0.92);
  color: var(--md-sys-color-on-surface);
  border-color: transparent;
}

/* ─── Area pills (botones de área común) ──────────────────────────────────── */

.tv-area-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  transition: filter 0.15s;
}

.tv-area-pill:hover { filter: brightness(0.95); text-decoration: none; }
.tv-area-pill .material-symbols-outlined { font-size: 16px; }

.tv-area-pill__counter {
  background: rgba(255,255,255,0.92);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
}

/* ─── Legend (badges leyenda) ─────────────────────────────────────────────── */

.tv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
  font-size: 0.8125rem;
}

.tv-legend__label {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  margin-right: 4px;
}

/* ─── Header bar con stat pill ────────────────────────────────────────────── */

.tv-stat-pill {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 12px 18px;
  text-align: right;
}

.tv-stat-pill__primary {
  font-family: var(--md-ref-typeface-brand);
  font-size: 1.25rem;
  font-weight: 600;
  display: inline-block;
}

.tv-stat-pill__secondary {
  display: block;
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
}

/* Proyecto card (lista) */
.tv-project-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  box-shadow: var(--md-sys-elevation-level1);
  transition: box-shadow 0.2s, transform 0.15s;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.tv-project-card:hover {
  box-shadow: var(--md-sys-elevation-level3);
  transform: translateY(-2px);
}

.tv-project-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  font-weight: 500;
  font-size: 1rem;
}

.tv-project-card__body {
  padding: 20px;
  flex: 1;
}

.tv-project-card__metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
  margin-bottom: 12px;
}

.tv-project-card__metric-value {
  font-family: var(--md-ref-typeface-brand);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--md-sys-color-on-surface);
}

.tv-project-card__metric-label {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 2px;
}

.tv-project-card__footer {
  padding: 12px 20px;
  background: var(--md-sys-color-surface-container);
  text-align: right;
}

.tv-project-card__footer-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
  text-align: right;
  margin-bottom: 8px;
}

/* ─── Section card con accent border-left ─────────────────────────────────── */

.tv-section-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  border-left: 4px solid var(--md-sys-color-outline-variant);
  padding: 16px 20px;
  box-shadow: var(--md-sys-elevation-level1);
  margin-bottom: 12px;
}

.tv-section-card.accent-success { border-left-color: var(--tv-color-success); }
.tv-section-card.accent-info    { border-left-color: var(--tv-color-info); }
.tv-section-card.accent-warning { border-left-color: var(--tv-color-warning); }
.tv-section-card.accent-danger  { border-left-color: var(--md-sys-color-error); }
.tv-section-card.accent-primary { border-left-color: var(--md-sys-color-primary); }
.tv-section-card.accent-neutral { border-left-color: var(--md-sys-color-outline); }

/* ─── Card header con banda de color (para semana.html) ───────────────────── */

.tv-banded-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  overflow: hidden;
  box-shadow: var(--md-sys-elevation-level1);
  margin-bottom: 20px;
}

.tv-banded-card__header {
  padding: 12px 20px;
  font-weight: 500;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tv-banded-card__header.is-success { background: var(--tv-color-success); }
.tv-banded-card__header.is-primary { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.tv-banded-card__header.is-warning { background: var(--tv-color-warning); }
.tv-banded-card__header.is-info    { background: var(--tv-color-info); }

/* ─── Fase cells (matriz pisos x etapas) ──────────────────────────────────── */

.tv-fase-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  padding: 6px 4px;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: 0.7rem;
  font-weight: 600;
}

.tv-fase-cell .material-symbols-outlined { font-size: 14px; }

.tv-fase-cell.is-completada { background: var(--tv-color-success); color: #fff; }
.tv-fase-cell.is-en_curso   { background: var(--md-sys-color-primary); color: var(--md-sys-color-on-primary); }
.tv-fase-cell.is-bloqueada  { background: var(--md-sys-color-error); color: var(--md-sys-color-on-error); }
.tv-fase-cell.is-pendiente  { background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-on-surface-variant); }

.tv-fase-cell__desvio {
  font-size: 0.6rem;
  background: rgba(255,255,255,0.85);
  color: var(--md-sys-color-on-surface);
  padding: 1px 4px;
  border-radius: var(--md-sys-shape-corner-extra-small);
  font-weight: 600;
}

/* ─── Etapa color dot ─────────────────────────────────────────────────────── */

.tv-etapa-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: var(--md-sys-shape-corner-extra-small);
  vertical-align: middle;
}

/* ─── Matrix table (bordered, compact) ────────────────────────────────────── */

.tv-table--matrix {
  font-size: 0.8rem;
}

.tv-table--matrix th,
.tv-table--matrix td {
  text-align: center;
  padding: 8px 4px;
}

.tv-table--matrix tbody td {
  border-left: 1px solid var(--md-sys-color-outline-variant);
}

.tv-table--matrix tbody td:first-child {
  text-align: left;
  font-weight: 600;
  padding: 8px 12px;
  border-left: none;
}

.tv-table--matrix thead th {
  background: var(--md-sys-color-surface-container-high);
  padding: 8px 4px;
  vertical-align: middle;
}

.tv-table--matrix thead th:first-child { text-align: left; padding-left: 12px; }

/* ─── Dropdown / popup menu (simple) ──────────────────────────────────────── */

.tv-menu {
  position: relative;
  display: inline-block;
}

.tv-menu__trigger {
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-on-surface);
  padding: 6px 12px;
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background-color 0.15s;
}

.tv-menu__trigger:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.tv-menu__trigger .material-symbols-outlined { font-size: 16px; }

.tv-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 180px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-small);
  box-shadow: var(--md-sys-elevation-level3);
  padding: 4px 0;
  z-index: 50;
  display: none;
  list-style: none;
  margin: 0;
}

.tv-menu.is-open .tv-menu__panel { display: block; }

.tv-menu__item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  font-family: inherit;
}

.tv-menu__item:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }

/* ─── Timeline card (piso.html — fase con info, fechas, materiales) ──────── */

.tv-fase-row {
  display: grid;
  grid-template-columns: 1.5fr 2fr 1.4fr 1.6fr;
  gap: 16px;
  align-items: center;
}

@media (max-width: 992px) {
  .tv-fase-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

.tv-fase-row__info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tv-fase-row__dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.8125rem;
}

.tv-fase-row__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

@media (max-width: 992px) {
  .tv-fase-row__actions { justify-content: flex-start; }
}

/* ─── Form row para planificar ────────────────────────────────────────────── */

.tv-form-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  gap: 8px;
}

/* ─── Progress block más alto para piso.html y proyecto.html ──────────────── */

.tv-progress--lg { height: 8px; }

/* ─── Form check (checkbox MD3) ───────────────────────────────────────────── */

.tv-form-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.tv-form-check input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, border-color 0.15s;
}

.tv-form-check input[type="checkbox"]:checked {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}

.tv-form-check input[type="checkbox"]:checked::after {
  content: "✓";
  color: var(--md-sys-color-on-primary);
  font-size: 14px;
  font-weight: 700;
}

.tv-form-check label {
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
}

/* ─── Dialog (md-dialog) overrides ────────────────────────────────────────── */

md-dialog {
  --md-dialog-container-color: var(--md-sys-color-surface-container);
  --md-dialog-headline-color: var(--md-sys-color-on-surface);
  --md-dialog-supporting-text-color: var(--md-sys-color-on-surface-variant);
}

.tv-dialog-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 300px;
}

.tv-dialog-form .tv-form-group { gap: 6px; }

.tv-dialog-form textarea.tv-input {
  resize: vertical;
  min-height: 70px;
  font-family: var(--md-ref-typeface-plain);
}

/* ─── Tendencia chart card ─────────────────────────────────────────────────── */

.tv-chart-card {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--md-sys-elevation-level1);
}

/* ─── Card single-form (tarea_form) ───────────────────────────────────────── */

.tv-card--form {
  max-width: 640px;
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 32px;
  box-shadow: var(--md-sys-elevation-level1);
}

.tv-card--form md-outlined-text-field { width: 100%; }

.tv-card--form .tv-form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 600px) {
  .tv-card--form .tv-form-grid-2 { grid-template-columns: 1fr; }
}

.tv-card--form .tv-input,
.tv-card--form .tv-select,
.tv-card--form textarea.tv-input {
  width: 100%;
  font-size: 0.9375rem;
  padding: 12px 14px;
}

.tv-form-text {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
  padding-left: 4px;
}

/* ─── Pager between months ────────────────────────────────────────────────── */

.tv-month-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.tv-month-nav h1 {
  flex: 1;
  text-align: center;
  margin: 0;
}

/* ─── Utilities globales (sin dependencia Bootstrap) ──────────────────────── */

.text-center  { text-align: center; }
.text-end     { text-align: right; }
.text-start   { text-align: left; }
.text-nowrap,
.nowrap       { white-space: nowrap; }
.text-muted   { color: var(--md-sys-color-on-surface-variant); }
.text-success { color: var(--tv-color-success); }
.text-danger  { color: var(--md-sys-color-error); }
.text-warning { color: var(--tv-color-warning); }
.text-info    { color: var(--tv-color-info); }
.text-primary { color: var(--md-sys-color-primary); }
.fw-bold,
.fw-semibold  { font-weight: 600; }
.w-100        { width: 100%; }
.h-100        { height: 100%; }
.ms-auto      { margin-left: auto; }
.d-inline     { display: inline; }
.d-inline-block { display: inline-block; }
.d-block      { display: block; }
.d-none       { display: none; }
