/* ============================================================
   Cootrachica — design system
   Paleta corporativa: navy primary + slate sidebar + greys neutros
   ============================================================ */

:root {
  /* Marca */
  --cc-primary:        #1e3a8a;   /* indigo-900 */
  --cc-primary-hover:  #1e40af;
  --cc-primary-soft:   #e0e7ff;
  --cc-accent:         #f59e0b;   /* amber para acentos discretos */

  /* Sidebar */
  --cc-sidebar-bg:       #0f172a; /* slate-900 */
  --cc-sidebar-bg-hover: #1e293b; /* slate-800 */
  --cc-sidebar-text:     #cbd5e1; /* slate-300 */
  --cc-sidebar-text-act: #ffffff;
  --cc-sidebar-divider:  #1e293b;

  /* App */
  --cc-bg:               #f5f7fb;
  --cc-bg-card:          #ffffff;
  --cc-border:           #e5e7eb;
  --cc-border-soft:      #f1f3f6;
  --cc-text:             #0f172a;
  --cc-text-muted:       #64748b;
  --cc-shadow-sm:        0 1px 2px 0 rgb(15 23 42 / .04);
  --cc-shadow-md:        0 1px 3px 0 rgb(15 23 42 / .06), 0 1px 2px 0 rgb(15 23 42 / .04);
  --cc-shadow-lg:        0 10px 25px -5px rgb(15 23 42 / .08), 0 8px 10px -6px rgb(15 23 42 / .06);

  /* Bootstrap overrides */
  --bs-body-font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --bs-body-color:       var(--cc-text);
  --bs-body-bg:          var(--cc-bg);
  --bs-primary:          var(--cc-primary);
  --bs-primary-rgb:      30, 58, 138;
  --bs-border-color:     var(--cc-border);
}

html, body {
  font-family: var(--bs-body-font-family);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -.005em;
}
.tabular-nums { font-variant-numeric: tabular-nums; }
h1, h2, h3, h4, h5, h6 { letter-spacing: -.015em; color: var(--cc-text); }

/* ------------------------------------------------------------
   Sidebar oscuro
   ------------------------------------------------------------ */
.cc-sidebar {
  background-color: var(--cc-sidebar-bg);
  color: var(--cc-sidebar-text);
  border-right: 1px solid var(--cc-sidebar-divider) !important;
  width: 260px;
  flex-shrink: 0;
}

/* En móvil (<md) el sidebar es offcanvas. Bootstrap pone width 400px por defecto;
   bajamos a 260px para coherencia con el desktop */
@media (max-width: 767.98px) {
  .cc-sidebar.offcanvas-md {
    width: 260px;
    --bs-offcanvas-width: 260px;
  }
  .cc-sidebar .cc-nav { overflow-y: auto; flex: 1; }
}

/* En desktop, anular los overrides agresivos de Bootstrap sobre .offcanvas-md
   (background transparent, width auto) que rompen nuestro sidebar oscuro */
@media (min-width: 768px) {
  .cc-sidebar.offcanvas-md {
    background-color: var(--cc-sidebar-bg) !important;
    width: 260px !important;
    flex-grow: 0;
    display: flex;
    flex-direction: column;
  }
  .cc-sidebar .btn-close { display: none; }
}
.cc-brand {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--cc-sidebar-divider);
  display: flex;
  align-items: center;
  gap: .65rem;
}
.cc-brand-mark {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgb(15 23 42 / .35);
  overflow: hidden;
}
.cc-brand-mark img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
.cc-brand-text { color: #fff; font-weight: 600; line-height: 1.1; }
.cc-brand-sub  { color: #94a3b8; font-size: .72rem; margin-top: 2px; }

.cc-nav { padding: .75rem .65rem; flex: 1; }
.cc-nav-section {
  font-size: .68rem; font-weight: 600; color: #64748b;
  text-transform: uppercase; letter-spacing: .08em;
  padding: .85rem .85rem .35rem;
}
.cc-nav-link {
  display: flex; align-items: center; gap: .75rem;
  color: var(--cc-sidebar-text);
  padding: .55rem .8rem;
  border-radius: 8px;
  font-size: .9rem;
  text-decoration: none;
  transition: background-color .12s ease, color .12s ease;
  position: relative;
}
.cc-nav-link i { width: 18px; font-size: 1rem; opacity: .85; }
.cc-nav-link:hover {
  background-color: var(--cc-sidebar-bg-hover);
  color: var(--cc-sidebar-text-act);
}
.cc-nav-link.active {
  background-color: rgb(255 255 255 / .08);
  color: var(--cc-sidebar-text-act);
  font-weight: 600;
}
.cc-nav-link.active::before {
  content: ''; position: absolute; left: -.65rem; top: .35rem; bottom: .35rem;
  width: 3px; background: var(--cc-accent); border-radius: 0 3px 3px 0;
}
.cc-nav-link.active i { opacity: 1; color: #fff; }

.cc-sidebar-footer {
  padding: .75rem 1.25rem; border-top: 1px solid var(--cc-sidebar-divider);
  font-size: .72rem; color: #64748b;
}

/* ------------------------------------------------------------
   Topbar
   ------------------------------------------------------------ */
.cc-topbar {
  background: var(--cc-bg-card);
  border-bottom: 1px solid var(--cc-border);
  padding: .65rem 1.5rem;
}
.cc-user-trigger {
  display: inline-flex; align-items: center; gap: .65rem;
  background: transparent; border: 0; padding: .35rem .55rem; border-radius: 8px;
  color: var(--cc-text); cursor: pointer;
}
.cc-user-trigger:hover { background: var(--cc-border-soft); }
.cc-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--cc-primary-soft); color: var(--cc-primary);
  font-weight: 600; font-size: .8rem;
  flex-shrink: 0;
}
.cc-avatar.cc-avatar-sm { width: 26px; height: 26px; font-size: .68rem; }

/* ------------------------------------------------------------
   Cards
   ------------------------------------------------------------ */
.card {
  border: 1px solid var(--cc-border) !important;
  box-shadow: var(--cc-shadow-sm) !important;
  border-radius: 12px !important;
  background: var(--cc-bg-card);
}
.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--cc-border) !important;
  padding: .85rem 1.1rem;
  font-weight: 500;
}
.card-body { padding: 1.1rem; }

/* KPI cards */
.cc-kpi-label {
  font-size: .72rem; font-weight: 600; color: var(--cc-text-muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.cc-kpi-value {
  font-size: 1.6rem; font-weight: 700; line-height: 1.2; margin-top: .25rem;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.cc-kpi-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
}
.cc-kpi-icon.cc-tone-primary   { background: var(--cc-primary-soft); color: var(--cc-primary); }
.cc-kpi-icon.cc-tone-success   { background: #d1fae5; color: #047857; }
.cc-kpi-icon.cc-tone-warning   { background: #fef3c7; color: #b45309; }
.cc-kpi-icon.cc-tone-danger    { background: #fee2e2; color: #b91c1c; }
.cc-kpi-icon.cc-tone-info      { background: #cffafe; color: #0e7490; }
.cc-kpi-icon.cc-tone-neutral   { background: #e5e7eb; color: #374151; }

/* ------------------------------------------------------------
   Botones
   ------------------------------------------------------------ */
.btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: .875rem;
  padding: .45rem 1rem;
  letter-spacing: -.005em;
  transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.btn-primary {
  background-color: var(--cc-primary);
  border-color: var(--cc-primary);
}
.btn-primary:hover, .btn-primary:focus {
  background-color: var(--cc-primary-hover);
  border-color: var(--cc-primary-hover);
}
.btn-outline-primary {
  color: var(--cc-primary);
  border-color: var(--cc-primary);
}
.btn-outline-primary:hover {
  background-color: var(--cc-primary);
  border-color: var(--cc-primary);
}
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }

/* ------------------------------------------------------------
   Tablas
   ------------------------------------------------------------ */
.table {
  --bs-table-color: var(--cc-text);
  margin-bottom: 0;
}
.table thead th {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--cc-text-muted);
  background: #fafbfc !important;
  border-bottom: 1px solid var(--cc-border) !important;
  padding: .7rem .9rem;
}
.table tbody td {
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--cc-border-soft);
  vertical-align: middle;
}
.table tbody tr:hover { background-color: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }

/* ------------------------------------------------------------
   Inputs / forms
   ------------------------------------------------------------ */
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--cc-border);
  font-size: .9rem;
  padding: .55rem .75rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--cc-primary);
  box-shadow: 0 0 0 3px rgb(30 58 138 / .12);
}
.form-label {
  font-weight: 500;
  font-size: .85rem;
  margin-bottom: .35rem;
  color: var(--cc-text);
}
.form-text { font-size: .78rem; color: var(--cc-text-muted); }

/* ------------------------------------------------------------
   Badges
   ------------------------------------------------------------ */
.badge {
  font-weight: 500;
  font-size: .72rem;
  padding: .35em .6em;
  border-radius: 6px;
}

/* ------------------------------------------------------------
   Login (guest layout)
   ------------------------------------------------------------ */
.cc-auth { height: 100vh; display: flex; overflow: hidden; }
.cc-auth-side {
  flex: 1;
  height: 100vh;
  background: linear-gradient(180deg, #0a0e1f 0%, #11173a 50%, #1a1f4e 100%);
  color: #fff;
  display: none;
  flex-direction: column;
  padding: 1.5rem 0;
  position: relative;
  overflow: hidden;
  gap: .75rem;
}
.cc-auth-side-pad { padding: 0 2.5rem; }
.cc-auth-side .cc-auth-illustration {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cc-auth-side .cc-auth-illustration svg {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}
.cc-auth-side::after {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgb(255 255 255 / .12), transparent 45%),
    radial-gradient(circle at 80% 70%, rgb(255 255 255 / .08), transparent 40%);
  pointer-events: none;
}
.cc-auth-side > * { position: relative; z-index: 1; }
.cc-auth-side h1, .cc-auth-side h2, .cc-auth-side h3 { color: #ffffff; }
@media (min-width: 992px) { .cc-auth-side { display: flex; } }
.cc-auth-illustration {
  width: 100%;
}
.cc-auth-illustration svg { width: 100%; height: auto; display: block; }

.cc-auth-form  { flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem; background: var(--cc-bg-card); overflow-y: auto; }
.cc-auth-card  { width: 100%; max-width: 380px; }
.cc-auth-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 2.5rem; }
.cc-auth-brand-mark {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 8px 16px rgb(15 23 42 / .35);
  overflow: hidden;
}
.cc-auth-brand-mark img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }

/* ------------------------------------------------------------
   Cards de maestros (clickable hover)
   ------------------------------------------------------------ */
.maestro-card { transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; cursor: pointer; }
.maestro-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--cc-shadow-lg) !important;
  border-color: var(--cc-primary) !important;
}

/* ------------------------------------------------------------
   Page header
   ------------------------------------------------------------ */
.cc-page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.cc-page-sub   { color: var(--cc-text-muted); font-size: .9rem; margin: .15rem 0 0; }
.cc-back-link  {
  display: inline-flex; align-items: center; gap: .35rem;
  color: var(--cc-text-muted); font-size: .82rem; text-decoration: none;
  margin-bottom: .5rem;
}
.cc-back-link:hover { color: var(--cc-primary); }

/* ------------------------------------------------------------
   Empty states
   ------------------------------------------------------------ */
.cc-empty {
  text-align: center; padding: 3rem 1rem;
}
.cc-empty-icon {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--cc-border-soft);
  color: var(--cc-text-muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
  margin: 0 auto 1rem;
}
.cc-empty h3 { font-size: 1rem; font-weight: 600; margin: 0 0 .35rem; }
.cc-empty p  { color: var(--cc-text-muted); font-size: .88rem; margin: 0; }

/* ------------------------------------------------------------
   Acciones inline de tabla (botones de icono uniformes)
   ------------------------------------------------------------ */
.cc-row-actions { display: inline-flex; gap: .35rem; align-items: center; }
.cc-icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--cc-border);
  background: #fff;
  color: var(--cc-text-muted);
  font-size: .85rem;
  text-decoration: none;
  cursor: pointer;
  transition: all .12s ease;
  padding: 0;
}
.cc-icon-btn:hover { color: var(--cc-text); border-color: #cbd5e1; background: var(--cc-border-soft); }
.cc-icon-btn.cc-tone-primary:hover { color: var(--cc-primary); border-color: var(--cc-primary); background: var(--cc-primary-soft); }
.cc-icon-btn.cc-tone-danger:hover  { color: #b91c1c; border-color: #fca5a5; background: #fee2e2; }
.cc-icon-btn.cc-tone-success:hover { color: #047857; border-color: #6ee7b7; background: #d1fae5; }
form.d-inline-flex { display: inline-flex; }

/* ------------------------------------------------------------
   Tablas responsivas en móvil — se transforman en tarjetas
   Uso: <table class="cc-mobile-cards"> + <td data-label="Etiqueta">
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
  .cc-mobile-cards thead { display: none; }
  .cc-mobile-cards, .cc-mobile-cards tbody { display: block; }
  .cc-mobile-cards tr {
    display: block;
    background: #fff;
    border: 1px solid var(--cc-border);
    border-radius: 12px;
    margin: .5rem .75rem;
    padding: .85rem 1rem;
    box-shadow: 0 1px 2px rgb(15 23 42 / .04);
  }
  .cc-mobile-cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    border: none !important;
    padding: .35rem 0 !important;
    text-align: right;
  }
  .cc-mobile-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--cc-text-muted);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    flex-shrink: 0;
    text-align: left;
  }
  .cc-mobile-cards td[data-label=""]::before { display: none; }
  .cc-mobile-cards td.cc-mobile-actions {
    padding: .25rem 0 0 0 !important;
    border: none !important;
    margin-top: .25rem;
    justify-content: flex-end;
  }
  /* Si no hay botones (action row vacío), ocultar la fila por completo */
  .cc-mobile-cards td.cc-mobile-actions:empty { display: none !important; }

  /* En móvil, el card-header de la tabla apila contador + buscador */
  .card-header.d-flex.flex-wrap > .position-relative { width: 100%; max-width: none !important; flex: 1 1 100% !important; }
}

/* Hamburguesa */
.cc-hamburger { color: var(--cc-text); border: none; }
.cc-hamburger:hover { color: var(--cc-primary); }

/* Botones más cómodos en móvil para el dedo */
@media (max-width: 767.98px) {
  .cc-icon-btn { width: 38px; height: 38px; font-size: .95rem; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
}

/* ------------------------------------------------------------
   Ajustes generales para móvil
   ------------------------------------------------------------ */
@media (max-width: 767.98px) {
  /* Reducir padding de topbar y main en móvil */
  .cc-topbar { padding: .5rem .9rem; }
  main.flex-grow-1 { padding: 1rem !important; }

  /* Títulos de página un poco más pequeños */
  .cc-page-title { font-size: 1.25rem; }
  .cc-page-sub   { font-size: .82rem; }

  /* Header de cards (con buscador) — apilar y dar respiro */
  .card-header { padding: .75rem; }

  /* Empty states más compactos */
  .cc-empty { padding: 2rem 1rem; }
  .cc-empty-icon { width: 56px; height: 56px; font-size: 1.6rem; }

  /* Header de página con botón a la derecha — apilar verticalmente */
  .cc-page-header.d-flex.justify-content-between,
  .d-flex.justify-content-between.align-items-end {
    flex-direction: column;
    align-items: stretch !important;
    gap: .75rem !important;
  }
  .cc-page-header.d-flex.justify-content-between > .btn,
  .d-flex.justify-content-between.align-items-end > .btn,
  .d-flex.justify-content-between.align-items-end > a.btn {
    align-self: stretch;
  }

  /* Card-header con buscador a la derecha — usar flex-column */
  .card-header.d-flex.flex-wrap {
    flex-wrap: nowrap !important;
    flex-direction: column;
    align-items: stretch !important;
  }

  /* Forms más cómodos */
  .form-control, .form-select { font-size: 16px; } /* evita zoom en iOS */
}

/* KPI cards más compactas en móvil */
@media (max-width: 767.98px) {
  .cc-kpi-value { font-size: 1.15rem; }
  .cc-kpi-label { font-size: .65rem; letter-spacing: .03em; }
  .cc-kpi-icon { width: 32px; height: 32px; font-size: .95rem; }
  .cc-kpi-icon i { font-size: .95rem; }
  /* Card body con menos padding en móvil para dar más espacio al texto */
  .card-body { padding: .85rem; }
}

/* ------------------------------------------------------------
   Tom Select — cuando hay un item seleccionado (.has-items), el item
   ocupa el espacio disponible y el input queda en 30px para que aún
   se pueda tipear unas letras y filtrar. El truncado con elipsis se
   aplica SIEMPRE (no depende del foco), así no cambia al cambiar
   de campo.
   ------------------------------------------------------------ */
.ts-wrapper.single .ts-control {
  flex-wrap: nowrap !important;
  overflow: hidden !important;
}
.ts-wrapper.single.has-items .ts-control > .item {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}
.ts-wrapper.single.has-items .ts-control > input {
  flex: 0 0 30px !important;
  width: 30px !important;
  min-width: 30px !important;
  max-width: 30px !important;
  padding: 0 !important;
}

/* En móvil: filas de propietarios del bus apilan select arriba,
   y porcentaje + botón eliminar en una segunda fila para que el
   buscador de propietario tenga ancho completo */
@media (max-width: 575.98px) {
  .cc-prop-row {
    flex-wrap: wrap;
  }
  .cc-prop-row > select,
  .cc-prop-row > .ts-wrapper {
    flex: 1 1 100% !important;
    min-width: 0;
  }
  .cc-prop-row > .input-group {
    flex: 1 1 auto !important;
  }
}
