:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2a37;
  --muted: #64748b;
  --primary: #1b4dff;
  --secondary: #e2e8f0;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #0ea5e9;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

body.sidebar-collapsed .app {
  grid-template-columns: 88px 1fr;
}

.sidebar {
  background: #111827;
  color: #e5e7eb;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  /* La barra como tal no se desborda; el menu interno hace scroll. */
  overflow: hidden;
  transition: width 0.3s ease;
}

.sidebar__brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  border-radius: 12px;
  transition: opacity 0.15s ease;
}

.sidebar__brand:hover {
  opacity: 0.85;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #1b4dff, #22c55e);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.sidebar__brand h1 {
  font-size: 18px;
}

.sidebar__brand span {
  font-size: 12px;
  color: #9ca3af;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Ocupa el espacio disponible y hace scroll si hay muchos modulos
     (brand arriba y footer abajo permanecen visibles). */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* Scrollbar discreta sobre el fondo oscuro. */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.sidebar__nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar__nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.sidebar__nav a {
  text-decoration: none;
  color: inherit;
  padding: 12px 14px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s ease;
}

.sidebar.collapsed {
  width: 88px;
}

.sidebar.collapsed .sidebar__brand h1,
.sidebar.collapsed .sidebar__brand span,
.sidebar.collapsed .sidebar__nav a span,
.sidebar.collapsed .sidebar__footer button {
  display: none;
}

.sidebar__nav a i {
  font-size: 18px;
}

.sidebar__nav a.active,
.sidebar__nav a:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar__footer {
  margin-top: auto;
}

.main {
  padding: 24px 32px 80px;
  /* Evita que un contenido ancho (tablas) expanda la columna del grid y
     desborde la pagina; los .table-card hacen scroll interno en su lugar. */
  min-width: 0;
  overflow-x: hidden;
}

.header {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header__left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header__right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.eyebrow {
  font-size: 12px;
  color: var(--muted);
}

.select {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

select,
input {
  border: 1px solid #e2e8f0;
  padding: 10px 12px;
  border-radius: 12px;
  font-family: inherit;
  background: #fff;
}

.user {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
}

.user span {
  font-weight: 600;
}

.user small {
  font-size: 12px;
  color: var(--muted);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: #1f2937;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 14px;
  flex-shrink: 0;
}

.icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.content {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.actions {
  display: flex;
  gap: 10px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.grid {
  display: grid;
  gap: 20px;
}

.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.chart-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.two-cols {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.kpi {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.kpi h4 {
  font-size: 28px;
}

/* Tarjetas KPI del dashboard que navegan a su modulo. */
.kpi--link {
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.05s ease;
}

.kpi--link:hover {
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.14);
}

.kpi--link:active {
  transform: translateY(1px);
}

.icon-pill {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

/* Evita que un numero largo (p.ej. costos) deforme el icono o desborde el card. */
.kpi > div {
  min-width: 0;
}

.kpi h4 {
  overflow-wrap: anywhere;
}

.icon-pill.success { background: var(--success); }
.icon-pill.warning { background: var(--warning); }
.icon-pill.danger { background: var(--danger); }
.icon-pill.info { background: var(--info); }

.trend {
  font-size: 12px;
}

.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }
.trend.warning { color: var(--warning); }

/* Permite que la tabla haga scroll horizontal dentro del card en vez de
   desbordarse, y que el card pueda encogerse dentro de un grid (min-width:0). */
.table-card {
  overflow-x: auto;
  min-width: 0;
}

/* En planes la tabla (7 columnas) comparte fila con el editor de checklist;
   en escritorio le damos mas ancho para que quepa sin recortarse. */
@media (min-width: 900px) {
  #planes .grid.two-cols {
    grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr);
  }
}

/* En repuestos la tabla tiene 7 columnas + la barra de exportar/buscar de
   DataTables: no cabe bien compartiendo fila con el panel "Kardex visual" (se
   recortaba y aparecia scroll horizontal). Se apila: tabla a todo el ancho y el
   kardex debajo como una tira compacta de 3 estadisticas. */
#repuestos .grid.two-cols {
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  #repuestos .kardex {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.table-card table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table-card th,
.table-card td {
  padding: 12px 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
}

.table-card td.actions {
  display: flex;
  gap: 6px;
}

.table-card td.loading,
.table-card td.empty,
.table-card td.error {
  text-align: center;
  color: var(--muted);
}

.table-card td.error {
  color: var(--danger);
}

/* Filas seleccionables y resaltado de la fila activa (p. ej. el plan cuyo
   checklist se esta editando en /planes). */
.table-card tbody tr.clickable {
  cursor: pointer;
  transition: background 0.12s ease;
}

.table-card tbody tr.clickable:hover td {
  background: #f8fafc;
}

.table-card tbody tr.is-selected td,
.table-card tbody tr.is-selected:hover td {
  background: rgba(27, 77, 255, 0.10);
}

.table-card tbody tr.is-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--primary);
}

/* Nombre del plan activo junto al titulo "Editor de checklist". */
.checklist-plan-label {
  color: var(--primary);
  font-weight: 600;
}

/* Cabecera del editor de checklist con su icono de ayuda. */
.checklist-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.checklist-editor-header h5 {
  margin: 0;
}

.btn-help {
  border: none;
  background: transparent;
  color: var(--muted, #64748b);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.12s ease, color 0.12s ease;
}

.btn-help:hover {
  color: var(--primary);
  background: #eef2ff;
}

/* Contenido del modal de ayuda del checklist. */
.help-steps {
  margin: 6px 0 14px;
  padding-left: 20px;
}

.help-steps li {
  margin: 5px 0;
}

.help-example {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 16px;
}

.help-example ul {
  margin: 0;
  padding-left: 18px;
}

.help-example li {
  margin: 4px 0;
}

.help-tip {
  margin-top: 12px;
}

.card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.badge.success { background: var(--success); }
.badge.warning { background: var(--warning); }
.badge.danger { background: var(--danger); }
.badge.info { background: var(--info); }
.badge.secondary { background: var(--muted); }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.tabs__header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tabs__header button {
  border: 1px solid #e2e8f0;
  background: #fff;
  padding: 10px 16px;
  border-radius: 12px;
}

.tabs__header button.active {
  background: #1b4dff;
  color: #fff;
  border-color: transparent;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline__item {
  padding: 12px;
  border-radius: 12px;
  background: #f8fafc;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.list {
  list-style: none;
  display: grid;
  gap: 12px;
}

.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.checklist {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.detail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.detail__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail__actions {
  display: flex;
  gap: 10px;
}

.kardex {
  display: grid;
  gap: 12px;
}

.kardex div {
  display: flex;
  justify-content: space-between;
  background: #f8fafc;
  padding: 12px;
  border-radius: 12px;
}

/* ===== Detalle de repuesto (#repuesto/<id>) ===== */
/* Sidebar (imagen + stock/costo) con ancho fijo; la columna principal toma el
   resto. En pantallas chicas se apila (hereda el auto-fit de .two-cols). */
@media (min-width: 900px) {
  #repuestoDetail .grid.two-cols {
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: start;
  }
}

.rep-hero__main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.rep-hero__main h3 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rep-hero__icon {
  width: 38px; height: 38px; border-radius: 11px; display: inline-grid; place-items: center;
  background: #eef2ff; color: var(--primary, #1b4dff); font-size: 18px; flex: 0 0 auto;
}
.rep-sku {
  font-size: 12px; font-weight: 700; letter-spacing: .3px; color: var(--primary, #1b4dff);
  background: #eef2ff; padding: 2px 8px; border-radius: 999px;
}
.rep-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rep-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted, #64748b);
  background: #f1f5f9; border-radius: 999px; padding: 3px 10px;
}

.rep-info li { gap: 16px; }
.rep-info li span:last-child { text-align: right; color: var(--text, #0f172a); font-weight: 500; overflow-wrap: anywhere; }
.rep-info__lbl, .rep-extra__lbl {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px; font-weight: 700; color: var(--muted, #64748b);
}

.rep-sidebar { display: flex; flex-direction: column; }
@media (min-width: 900px) { .rep-sidebar { position: sticky; top: 16px; } }

/* Imagen del producto */
.rep-img {
  width: 100%; aspect-ratio: 1 / 1; border-radius: 14px; overflow: hidden;
  display: grid; place-items: center; background: #f8fafc;
  border: 1px dashed var(--border, #e2e8f0); color: #cbd5e1; font-size: 54px;
}
.rep-img.has-img { border-style: solid; }
.rep-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Stock destacado */
.rep-stock-hero {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #f8fafc; border-radius: 12px; padding: 14px; margin-bottom: 14px;
}
.rep-stock-hero__lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted, #64748b); font-weight: 700; }
.rep-stock-hero__num { font-size: 34px; font-weight: 800; line-height: 1.1; color: #0f172a; }
.rep-stock-hero__unit { font-size: 12px; color: var(--muted, #64748b); }

.rep-kpi { gap: 8px; }
.rep-kpi li { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; }
.rep-kpi li span { color: var(--muted, #64748b); }
.rep-kpi li strong { color: #0f172a; }
.rep-kpi__total { border-top: 1px solid var(--border, #e2e8f0); padding-top: 10px; margin-top: 2px; }
.rep-kpi__total span, .rep-kpi__total strong { font-weight: 700; color: var(--primary, #1b4dff); }

/* Tabla de Movimientos / Kardex: tipografia mas compacta y prolija (evita que la
   fecha y la OT se partan en varias lineas y se vean desordenadas). */
#repuestoDetail .detail-table table { font-size: 13px; }
#repuestoDetail .detail-table th,
#repuestoDetail .detail-table td { padding: 9px 12px; vertical-align: middle; line-height: 1.35; }
#repuestoDetail .detail-table td:first-child,   /* Fecha */
#repuestoDetail .detail-table td:nth-child(3) { white-space: nowrap; }  /* Cantidad */
#repuestoDetail .detail-table td a { display: inline-flex; align-items: center; gap: 4px; }
#repuestoDetail .detail-table td a .bi { font-size: 11px; opacity: .8; }

/* ===== Agenda / calendario moderno ===== */
.agenda-toolbar { display: flex; align-items: center; gap: 10px; }
.agenda-bell {
  width: 40px; height: 40px; border-radius: 10px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 18px;
}
.agenda-bell.is-on { color: var(--primary); background: #eef2ff; }
.agenda-lead {
  height: 40px; border-radius: 10px; border: 1px solid var(--border, #e2e8f0);
  padding: 0 10px; background: #fff; font-size: 13px; color: var(--text, #0f172a);
}

.agenda-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 980px) { .agenda-layout { grid-template-columns: 1fr; } }

.calendar__toolbar {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.calendar__nav { display: flex; align-items: center; gap: 8px; }
.calendar__nav strong { font-size: 16px; min-width: 150px; text-align: center; }

.calendar__weekdays {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px;
  text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px;
}

.calendar__grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }

.cal-cell {
  position: relative; min-height: 96px; background: #f8fafc;
  border: 1px solid transparent; border-radius: 10px; padding: 6px 6px 4px;
  display: flex; flex-direction: column; gap: 4px; cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.cal-cell:hover { background: #eef2ff; border-color: #c7d2fe; }
.cal-cell__num { font-size: 12px; font-weight: 600; color: #475569; align-self: flex-end; }
.cal-cell.is-other { background: #fff; opacity: .5; cursor: default; }
.cal-cell.is-other:hover { background: #fff; border-color: transparent; }
.cal-cell.is-today { border-color: var(--primary); background: #fff; }
.cal-cell.is-today .cal-cell__num {
  background: var(--primary); color: #fff; border-radius: 999px;
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center;
}

.cal-cell__events { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.cal-chip {
  display: flex; align-items: center; gap: 5px; width: 100%; text-align: left;
  border: 0; border-left: 3px solid var(--chip, #1b4dff); border-radius: 4px;
  padding: 2px 6px; cursor: pointer; font-size: 11px;
  color: #334155; background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}
.cal-chip:hover { background: #f1f5f9; }
.cal-chip__time { font-weight: 700; color: var(--chip, #1b4dff); flex: 0 0 auto; }
.cal-chip__txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-cell__more { border: 0; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; text-align: left; padding: 0 6px; }
.cal-cell__more:hover { color: var(--primary); }

.calendar__legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.cal-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend__dot { width: 10px; height: 10px; border-radius: 3px; }

/* Panel de proximos eventos */
.agenda-side h5 { margin: 0 0 12px; display: flex; align-items: center; gap: 6px; }
.agenda-upcoming { display: flex; flex-direction: column; gap: 8px; }
.upcoming-item {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; text-align: left;
  border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 10px;
  background: #fff; cursor: pointer; transition: border-color .12s ease, background .12s ease;
}
.upcoming-item:hover { border-color: var(--primary); background: #f8faff; }
.upcoming-item__dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto; }
.upcoming-item__body { display: flex; flex-direction: column; min-width: 0; }
.upcoming-item__title { font-weight: 600; font-size: 13px; color: #0f172a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upcoming-item__when { font-size: 12px; color: var(--muted); }

/* ===== Aviso "Programacion de hoy" (briefing al ingresar) ===== */
.briefing__date { margin: -4px 0 14px; color: var(--muted); font-size: 13px; }
.briefing__empty {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 18px 12px; color: var(--muted); font-size: 14px;
  background: #f0fdf4; border: 1px solid #dcfce7; border-radius: 12px;
}
.briefing__empty i { color: #16a34a; font-size: 18px; }
.briefing__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.briefing__stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px; border-radius: 12px; background: #f8fafc; border: 1px solid #eef2f7;
}
.briefing__stat i { font-size: 18px; }
.briefing__stat-num { font-size: 22px; font-weight: 700; color: #0f172a; line-height: 1; }
.briefing__stat-label { font-size: 11px; color: var(--muted); text-align: center; }
.briefing__stat--primary i { color: var(--primary); }
.briefing__stat--info i { color: #0ea5e9; }
.briefing__stat--danger i { color: var(--danger); }
.briefing__stat--danger .briefing__stat-num { color: var(--danger); }

.briefing__body { display: flex; flex-direction: column; gap: 16px; max-height: 48vh; overflow-y: auto; }
.briefing__section h6 {
  margin: 0 0 8px; font-size: 13px; display: flex; align-items: center; gap: 6px; color: #334155;
}
.briefing__count {
  margin-left: auto; background: #eef2ff; color: var(--primary); border-radius: 999px;
  padding: 1px 8px; font-size: 11px; font-weight: 700;
}
.briefing__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.briefing__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; background: #fff;
}
/* Previsualizacion de fotos en el registro de inspeccion (#registrar). */
.reg-fotos { display: flex; flex-wrap: wrap; gap: 10px; }
.reg-foto { position: relative; width: 96px; height: 96px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border, #e2e8f0); background: #f8fafc; }
.reg-foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.reg-foto__del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%; cursor: pointer;
  background: rgba(15, 23, 42, 0.65); color: #fff; font-size: 11px; line-height: 1;
}
.reg-foto__del:hover { background: var(--danger, #ef4444); }

.briefing__item--link { cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s; }
.briefing__item--link:hover,
.briefing__item--link:focus-visible {
  border-color: var(--primary, #1b4dff); background: #f5f8ff;
  box-shadow: 0 1px 6px rgba(27, 77, 255, 0.12); outline: none;
}
.briefing__dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.briefing__item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.briefing__item-main strong { font-size: 13px; color: #0f172a; }
.briefing__item-main .muted { font-size: 12px; }
.briefing__more { list-style: none; font-size: 12px; color: var(--muted); padding: 2px 4px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.install-summary {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: #1f2937;
  max-height: 320px;
  overflow: auto;
}

.install-hint {
  color: var(--muted);
  font-size: 14px;
  margin: 8px 0 12px;
}

button {
  border: none;
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  color: #fff;
}

button.secondary {
  background: var(--secondary);
  color: #1f2937;
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button.ghost {
  background: transparent;
  color: inherit;
}

button.ghost.danger {
  color: var(--danger);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  padding: 14px 18px;
  border-radius: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.3s ease;
  /* Sobre el modal (1000): las notificaciones deben verse aun con un modal abierto. */
  z-index: 1100;
}

.toast.success {
  background: #16a34a;
}

.toast.error {
  background: #ef4444;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  /* Por encima del header sticky (z-index:10) para que no lo tape. */
  z-index: 1000;
}

.modal.active {
  animation: cmms-fade-in 0.18s ease;
}

.modal__content {
  background: #fff;
  padding: 24px;
  border-radius: 18px;
  max-width: 360px;
  width: 100%;
  /* El formulario puede ser mas alto que la pantalla: scroll interno. */
  max-height: 90vh;
  overflow-y: auto;
  animation: cmms-modal-in 0.22s ease;
}

.modal__content--wide {
  max-width: 600px;
}

.modal__content--detail {
  max-width: 860px;
}

@keyframes cmms-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes cmms-modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Detalle (vista) dentro del modal ===== */
/* Solo se muestra la pestana activa (sin esto se veian todas a la vez). */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ===== Detalle de equipo (modal) — diseno elegante ===== */
/* Tabs estilo "underline" en vez de botones pildora. */
#equipoDetail.tabs .tabs__header {
  gap: 2px;
  border-bottom: 1px solid #e9eef5;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#equipoDetail.tabs .tabs__header button {
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 10px 16px;
  color: var(--muted);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

#equipoDetail.tabs .tabs__header button:hover {
  color: var(--text);
}

#equipoDetail.tabs .tabs__header button.active {
  background: transparent;
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 24px;
  align-items: start;
}

.detail-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 12px;
}

.ficha-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 24px;
}

.ficha-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 0;
  border-bottom: 1px solid #eef2f7;
  min-width: 0;
}

.ficha-item--full {
  grid-column: 1 / -1;
}

.ficha-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.ficha-item > span:last-child {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.detail-aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-card {
  background: #f8fafc;
  border: 1px solid #eef2f7;
  border-radius: 14px;
  padding: 16px;
}

/* Tablas dentro de los tabs del detalle */
.detail-table {
  border: 1px solid #eef2f7;
  border-radius: 14px;
  overflow: auto;
}

.detail-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.detail-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #f8fafc;
  padding: 11px 14px;
  border-bottom: 1px solid #eef2f7;
  white-space: nowrap;
}

.detail-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
}

.detail-table tbody tr:last-child td {
  border-bottom: none;
}

.detail-table tbody tr.clickable {
  cursor: pointer;
  transition: background 0.12s ease;
}

.detail-table tbody tr.clickable:hover {
  background: #f8fafc;
}

.detail-table td.empty,
.detail-table td.loading,
.detail-table td.error {
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

.detail-table td.error {
  color: var(--danger);
}

/* El badge muestra el texto del estado en una sola linea, sin encimarse. */
.detail-table .badge {
  display: inline-block;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .ficha-grid {
    grid-template-columns: 1fr;
  }
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.qr-box img {
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 12px;
  padding: 6px;
  background: #fff;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal__form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

/* Texto del label + asterisco en una sola linea (ahorra alto en el formulario). */
.field-label {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.required {
  color: #ef4444;
  font-weight: 700;
}

.help-text {
  font-size: 11px;
  color: var(--muted);
}

/* ===== Select con buscador (combobox) ===== */
.search-select {
  position: relative;
}

.search-select__caret {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted, #64748b);
  font-size: 12px;
  transition: transform 0.15s ease;
}

.search-select.open .search-select__caret {
  transform: translateY(-50%) rotate(180deg);
}

.search-select__list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
}

.search-select__item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text, #0f172a);
}

.search-select__item:hover {
  background: #f1f5f9;
}

.search-select__item.active {
  background: rgba(27, 77, 255, 0.1);
  font-weight: 600;
}

.modal__form .form-grid {
  gap: 12px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.skeleton {
  width: 140px;
  height: 10px;
  background: linear-gradient(90deg, #e2e8f0, #f8fafc, #e2e8f0);
  border-radius: 999px;
  animation: shimmer 1.6s infinite;
  margin-top: 20px;
}

@keyframes shimmer {
  0% { background-position: -120px; }
  100% { background-position: 120px; }
}

.muted { color: var(--muted); }

@media (max-width: 1024px) {
  /* En tablet/movil el layout es de UNA sola columna siempre, incluso si el
     usuario dejo el sidebar colapsado en escritorio. Sin incluir
     `body.sidebar-collapsed .app` aqui, esa regla (mayor especificidad) seguiria
     forzando `88px 1fr` y, como el sidebar pasa a position:fixed, el .main caia
     en la columna de 88px y todo el contenido quedaba aplastado. */
  .app,
  body.sidebar-collapsed .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 82vw);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 20;
  }

  /* El "colapsado" es un concepto de escritorio. En el drawer movil mostramos
     siempre el ancho y las etiquetas completas para que sea navegable. */
  .sidebar.collapsed {
    width: min(280px, 82vw);
  }

  .sidebar.collapsed .sidebar__brand h1,
  .sidebar.collapsed .sidebar__brand span,
  .sidebar.collapsed .sidebar__nav a span,
  .sidebar.collapsed .sidebar__footer button {
    display: revert;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 720px) {
  .header {
    padding: 12px 14px;
    gap: 12px;
  }

  .header__left {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
  }

  .header__left h2 {
    font-size: 17px;
  }

  .header__left .select {
    width: 100%;
  }

  .header__left .select select {
    width: 100%;
  }

  .header__right {
    width: 100%;
    justify-content: flex-start;
    gap: 10px;
  }

  .header__right .user {
    margin-left: auto;
    text-align: right;
  }

  .section__header {
    flex-direction: column;
    align-items: stretch;
  }

  .section__header button {
    width: 100%;
    justify-content: center;
  }

  /* Aprovechar el ancho de pantalla en móvil: el contenedor principal y las
     tarjetas tenían demasiado padding lateral (32px + 20px) y desperdiciaban
     ~50px por lado en pantallas chicas. */
  .main {
    padding: 16px 12px 72px;
  }

  .content {
    margin-top: 18px;
    gap: 14px;
  }

  .card,
  .table-card,
  .card.filters,
  .kpi {
    padding: 14px;
  }

  /* Las tablas (DataTables) hacen scroll horizontal dentro de su tarjeta: que la
     tarjeta no añada padding lateral para ganar ancho útil. */
  .table-card {
    padding: 12px 10px;
  }
}

/* En teléfonos muy estrechos, pegar aún más el contenido a los bordes. */
@media (max-width: 430px) {
  .main {
    padding: 14px 8px 68px;
  }
  .card,
  .card.filters,
  .kpi {
    padding: 12px;
  }
}

/* ===== Loaders / Spinners ===== */
/* El loader global esta OCULTO por defecto y solo se muestra con .active.
   Sin estas reglas el overlay "Cargando aplicacion..." quedaba visible para siempre. */
.global-loader {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.global-loader.active {
  display: flex;
}

.global-loader .loader-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.global-loader .loader-content {
  position: relative;
  background: #fff;
  padding: 28px 40px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
}

.loader {
  width: 40px;
  height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary, #1b4dff);
  border-radius: 50%;
  animation: cmms-spin 0.8s linear infinite;
}

.spinner,
.spinner-small {
  width: 20px;
  height: 20px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary, #1b4dff);
  border-radius: 50%;
  animation: cmms-spin 0.8s linear infinite;
  display: inline-block;
}

.spinner-small {
  width: 14px;
  height: 14px;
  border-width: 2px;
  vertical-align: middle;
}

@keyframes cmms-spin {
  to { transform: rotate(360deg); }
}

.loader-text {
  color: var(--muted, #64748b);
  font-size: 14px;
  margin: 0;
}

.loader-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  color: var(--muted, #64748b);
}

.loader-inline,
.inline-loader,
.loader-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  color: var(--muted, #64748b);
}

.loader-overlay {
  position: absolute;
  inset: 0;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.7);
}

td.loading,
td.empty,
td.error {
  text-align: center;
  color: var(--muted, #64748b);
  padding: 24px;
}

.empty-state,
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted, #64748b);
  padding: 16px;
}

.empty-state i,
.error-state i {
  font-size: 28px;
  opacity: 0.6;
}

/* ===== Kanban de ordenes ===== */
.kanban {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 16px;
  align-items: start;
  margin-top: 20px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.kanban__col {
  background: #f1f5f9;
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.kanban__col.drag-over {
  background: #e0e7ff;
  box-shadow: inset 0 0 0 2px var(--primary);
}

/* Color por estado para identificar cada columna de un vistazo. Cada columna
   lleva una franja superior, fondo tenue y badge/encabezado en su color. */
.kanban__col {
  border-top: 3px solid transparent;
}
.kanban__col[data-estado="pendiente"]  { border-top-color: #f59e0b; background: #fffbeb; }
.kanban__col[data-estado="en_proceso"] { border-top-color: #0ea5e9; background: #f0f9ff; }
.kanban__col[data-estado="pausada"]    { border-top-color: #94a3b8; background: #f8fafc; }
.kanban__col[data-estado="finalizada"] { border-top-color: #16a34a; background: #f0fdf4; }
.kanban__col[data-estado="cancelada"]  { border-top-color: #ef4444; background: #fef2f2; }

.kanban__col[data-estado="pendiente"]  .kanban__col-header,
.kanban__col[data-estado="pendiente"]  .kanban__col-header i { color: #b45309; }
.kanban__col[data-estado="en_proceso"] .kanban__col-header,
.kanban__col[data-estado="en_proceso"] .kanban__col-header i { color: #0369a1; }
.kanban__col[data-estado="pausada"]    .kanban__col-header,
.kanban__col[data-estado="pausada"]    .kanban__col-header i { color: #475569; }
.kanban__col[data-estado="finalizada"] .kanban__col-header,
.kanban__col[data-estado="finalizada"] .kanban__col-header i { color: #15803d; }
.kanban__col[data-estado="cancelada"]  .kanban__col-header,
.kanban__col[data-estado="cancelada"]  .kanban__col-header i { color: #b91c1c; }

.kanban__col[data-estado="pendiente"]  .kanban__count { background: #f59e0b; color: #fff; }
.kanban__col[data-estado="en_proceso"] .kanban__count { background: #0ea5e9; color: #fff; }
.kanban__col[data-estado="pausada"]    .kanban__count { background: #94a3b8; color: #fff; }
.kanban__col[data-estado="finalizada"] .kanban__count { background: #16a34a; color: #fff; }
.kanban__col[data-estado="cancelada"]  .kanban__count { background: #ef4444; color: #fff; }

.kanban__col-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  padding: 4px 4px 0;
}

.kanban__col-header i {
  color: var(--muted);
  margin-right: 4px;
}

.kanban__count {
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}

.kanban__cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px;
}

.kanban__msg {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 16px 8px;
  margin: 0;
}

.kanban-card {
  background: #fff;
  border: 1px solid #e9eef5;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: box-shadow 0.15s ease, opacity 0.1s ease;
}

.kanban-card:hover {
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.1);
}

.kanban-card.dragging {
  opacity: 0.45;
}

.kanban-card__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.kanban-card__code {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.kanban-card__equipo {
  font-size: 13px;
  color: var(--text);
  margin: 0;
}

.kanban-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--muted);
}

.kanban-card__meta i {
  margin-right: 3px;
}

.kanban-card__assign {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.kanban-card__assign select {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 12px;
  background: #fff;
  cursor: pointer;
}

/* En pantallas estrechas, columnas en carrusel horizontal. */
@media (max-width: 1024px) {
  .kanban {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(240px, 78%);
  }
}

/* ===== Permisos de rol (RBAC) ===== */
.permisos-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: 4px 0 16px;
}

.permisos-toolbar #permisosSearch {
  flex: 1 1 220px;
  min-width: 180px;
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 14px;
}

.permisos-toolbar__actions {
  display: flex;
  gap: 8px;
}

.permisos-toolbar__actions .ghost {
  padding: 7px 12px;
  font-size: 13px;
}

.permisos-count {
  color: var(--muted, #64748b);
  font-size: 13px;
  margin-left: auto;
  white-space: nowrap;
}

.permisos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.permiso-modulo {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #f8fafc;
  overflow: hidden;
}

.permiso-modulo__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}

.permiso-modulo__title {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: #0f172a;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.permiso-modulo__title i {
  color: var(--primary, #1b4dff);
}

.permiso-modulo__all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted, #64748b);
  cursor: pointer;
  white-space: nowrap;
}

.permiso-modulo__items {
  display: flex;
  flex-direction: column;
  padding: 8px 6px;
}

.permiso-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 14px;
  color: #1e293b;
  cursor: pointer;
  transition: background 0.12s ease;
}

.permiso-item:hover {
  background: #eef2ff;
}

.permiso-item input[type="checkbox"],
.permiso-modulo__all input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary, #1b4dff);
  cursor: pointer;
}

/* ===== Detalle de tecnico (KPIs) ===== */
.tecnico-detail { display: flex; flex-direction: column; gap: 16px; }

.tecnico-detail__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.tecnico-detail__id { display: flex; align-items: center; gap: 14px; }

.tecnico-detail__avatar {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1b4dff, #0ea5e9);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.tecnico-detail__id h4 { margin: 0; font-size: 18px; }
.tecnico-detail__id p { margin: 2px 0 0; font-size: 13px; }

.tecnico-detail__periodo {
  font-size: 12px;
  color: var(--muted, #64748b);
  background: #f1f5f9;
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}

.kpi-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.kpi-tile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #fff;
}

.kpi-tile__icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex: 0 0 auto;
  background: #eef2ff;
  color: #1b4dff;
}

.kpi-tile--success .kpi-tile__icon { background: #dcfce7; color: #16a34a; }
.kpi-tile--warning .kpi-tile__icon { background: #fef3c7; color: #b45309; }
.kpi-tile--danger  .kpi-tile__icon { background: #fee2e2; color: #dc2626; }
.kpi-tile--info    .kpi-tile__icon { background: #e0f2fe; color: #0284c7; }
.kpi-tile--neutral .kpi-tile__icon { background: #f1f5f9; color: #475569; }

.kpi-tile__body { display: flex; flex-direction: column; min-width: 0; }
.kpi-tile__value { font-size: 20px; font-weight: 700; color: #0f172a; line-height: 1.1; }
.kpi-tile__label { font-size: 12px; color: #475569; margin-top: 2px; }
.kpi-tile__hint { font-size: 11px; color: #94a3b8; margin-top: 2px; }

/* Lista compacta etiqueta/valor reutilizada en el detalle del tecnico. */
.kpi-mini { display: flex; flex-direction: column; gap: 2px; }
.kpi-mini > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dashed #e2e8f0;
}
.kpi-mini > div:last-child { border-bottom: 0; }
.kpi-mini span { color: var(--muted, #64748b); font-size: 13px; }
.kpi-mini strong { font-size: 15px; color: #0f172a; }

.tecnico-detail .chart canvas { max-height: 240px; }

/* Detalle del tecnico como pagina */
.tecnico-detail__topbar { margin-bottom: 2px; }

.hint-click { font-size: 11px; font-weight: 400; margin-left: 6px; }

/* Filas clicables de carga / tipo / prioridad */
.kpi-mini .kpi-mini__row {
  padding: 8px;
  margin: 0 -8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s ease;
}
.kpi-mini .kpi-mini__row:hover { background: #eff3ff; }
.kpi-mini__row strong i { font-size: 11px; color: #94a3b8; margin-left: 2px; }

/* Detalle de OT por categoria (drill-down) */
.tecnico-drill__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.tecnico-drill__head h5 { margin: 0; }
.tecnico-drill__total { margin: 12px 2px 0; font-size: 13px; color: #475569; }

.table-card th.num, .table-card td.num { text-align: right; }

/* Oculta la columna de costo de M.O. cuando el rol no tiene permiso de costos. */
#tecnicoDrillCard.hide-costo .col-costo { display: none; }

/* Select con creacion de opciones inline (boton "+" en el formulario). */
.select-creatable__row { display: flex; gap: 8px; align-items: center; }
.select-creatable__row select { flex: 1; min-width: 0; }
.select-creatable__add {
  flex: 0 0 auto;
  padding: 8px 11px;
  border: 1px dashed var(--border, #cbd5e1);
  border-radius: 8px;
  cursor: pointer;
}
.select-creatable__add:hover { color: var(--primary); border-color: var(--primary); background: #eef2ff; }

/* Modal de creacion rapida (p. ej. "Nueva categoria"), apilado sobre el modal
   del formulario sin alterar su layout. */
.modal.modal--stack { z-index: 1200; }
.cc-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.cc-field .cc-input { width: 100%; }

/* ===== Header: menus, dropdowns y perfil ===== */
.header-menu { position: relative; }

.icon { position: relative; }

.icon-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.user-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 12px;
  transition: background 0.15s ease;
}
.user-trigger:hover { background: rgba(15, 23, 42, 0.05); }
.user-trigger__caret { color: var(--muted, #64748b); font-size: 12px; }

.dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 260px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16);
  padding: 8px;
  z-index: 50;
  display: none;
  animation: cmms-fade-in 0.12s ease;
}
.dropdown.open { display: block; }
.dropdown--right { right: 0; }

.dropdown__title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted, #64748b);
  padding: 6px 10px;
}

.dropdown__body { max-height: 320px; overflow-y: auto; }

.dropdown__empty {
  color: var(--muted, #64748b);
  font-size: 13px;
  text-align: center;
  padding: 18px 8px;
  margin: 0;
}

.dropdown__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  font-size: 14px;
  color: #1e293b;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease;
}
.dropdown__item:hover { background: #eef2ff; }
.dropdown__item i { color: var(--muted, #64748b); width: 16px; text-align: center; }
.dropdown__item--danger { color: #dc2626; }
.dropdown__item--danger:hover { background: #fef2f2; }
.dropdown__item--danger i { color: #dc2626; }

.dropdown__sep { height: 1px; background: #e2e8f0; margin: 6px 4px; }

.dropdown__user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
}
.dropdown__user strong { display: block; font-size: 14px; }
.dropdown__user .muted { font-size: 12px; }

.dropdown__foot {
  font-size: 11px;
  color: #94a3b8;
  padding: 8px 10px 4px;
  text-align: center;
}

.notif-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: #1e293b;
  text-decoration: none;
  transition: background 0.12s ease;
}
.notif-item:hover { background: #eef2ff; }
.notif-item__icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: #e0f2fe;
  color: #0284c7;
}
.notif-item__icon--danger { background: #fee2e2; color: #dc2626; }
.notif-item__icon--success { background: #dcfce7; color: #16a34a; }
.notif-item__icon--info { background: #e0f2fe; color: #0284c7; }

.perfil-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.perfil-head strong { display: block; font-size: 16px; }
.perfil-head .muted { font-size: 13px; }
.avatar--lg { width: 52px; height: 52px; font-size: 18px; border-radius: 14px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #475569; }
.field input {
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 14px;
}

@media (max-width: 720px) {
  .user-trigger .user { display: none; }

  /* En móvil los botones del header se empacan a la izquierda, así que un menú
     anclado con `right: 0` se desbordaba por el borde izquierdo y cortaba las
     opciones. Se anclan a la IZQUIERDA de su botón (extienden hacia la derecha,
     donde sí hay espacio) y se limitan al ancho de pantalla. */
  .header-menu .dropdown,
  .header-menu .dropdown--right {
    left: 0;
    right: auto;
    min-width: 0;
    width: max-content;
    max-width: calc(100vw - 20px);
  }
}

/* ===== Detalle de OT (pagina) — diseño elegante ===== */
#ordenBody { display: flex; flex-direction: column; gap: 20px; }

.ot-head {
  position: relative; overflow: hidden; padding-left: 28px;
  display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
}
.ot-head::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--primary);
}
.ot-head[data-estado="pendiente"]::before { background: #f59e0b; }
.ot-head[data-estado="en_proceso"]::before { background: #0ea5e9; }
.ot-head[data-estado="pausada"]::before  { background: #94a3b8; }
.ot-head[data-estado="finalizada"]::before { background: #16a34a; }
.ot-head[data-estado="cancelada"]::before { background: #ef4444; }

.ot-head__main { flex: 1 1 340px; min-width: 0; }
.ot-head__title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ot-head__title h3 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.ot-head__actions { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.ot-acciones { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ot-acciones button { padding: 9px 14px; border-radius: 10px; }

.ot-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin: 18px 0 14px;
}
.ot-meta > div {
  display: flex; flex-direction: column; gap: 2px;
  background: #f8fafc; border: 1px solid #eef2f7; border-radius: 12px; padding: 10px 12px;
}
.ot-meta span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #64748b); }
.ot-meta strong { font-size: 14px; color: #0f172a; font-weight: 600; }
.ot-desc { margin: 4px 0 0; color: #334155; background: #f8fafc; border: 1px solid #eef2f7; border-radius: 12px; padding: 12px 14px; }

/* Encabezados de las tarjetas de seccion */
#ordenBody .card > h5 {
  display: flex; align-items: center; gap: 8px; margin: 0 0 14px;
  font-size: 15px; padding-bottom: 10px; border-bottom: 1px solid #eef2f7;
}
#ordenBody .card > h5 i { color: var(--primary); }

.ot-add { display: flex; gap: 8px; margin: 0 0 14px; flex-wrap: wrap; }
.ot-add input, .ot-add select {
  flex: 1 1 140px; padding: 10px 12px; border: 1px solid #e2e8f0; border-radius: 10px; font-size: 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.ot-add input:focus, .ot-add select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,77,255,.12); }
.ot-add--col { flex-direction: column; }
.ot-add--col input, .ot-add--col select { flex: none; width: 100%; }
.ot-add button { white-space: nowrap; }

.ot-list { list-style: none; padding: 0; margin: 0; }
.ot-list li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 8px; border-radius: 8px; font-size: 14px; }
.ot-list li:nth-child(odd) { background: #f8fafc; }
.ot-total { text-align: right; font-weight: 700; margin: 12px 4px 0; color: #0f172a; }

/* Timeline de seguimiento con linea conectora */
.ot-timeline { list-style: none; padding: 0; margin: 0; }
.ot-timeline li { display: flex; gap: 12px; padding: 4px 0 14px; position: relative; }
.ot-timeline li:not(:last-child)::before {
  content: ''; position: absolute; left: 5px; top: 16px; bottom: 0; width: 2px; background: #e2e8f0;
}
.ot-timeline__dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--primary); margin-top: 4px;
  flex: 0 0 auto; box-shadow: 0 0 0 3px rgba(27,77,255,.15); position: relative; z-index: 1;
}
.ot-timeline p { margin: 0; font-size: 14px; }

/* Zona de subida y galeria de adjuntos */
.ot-upload {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
  border: 1.5px dashed #cbd5e1; border-radius: 12px; padding: 14px; background: #f8fafc;
}
.ot-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.ot-thumb {
  position: relative; margin: 0; border-radius: 14px; overflow: hidden; background: #0f172a;
  box-shadow: 0 4px 12px rgba(15,23,42,.08); transition: transform .15s ease, box-shadow .15s ease;
}
.ot-thumb:hover { transform: translateY(-2px); box-shadow: 0 10px 22px rgba(15,23,42,.16); }
.ot-thumb a { display: block; }
.ot-thumb img { width: 100%; height: 120px; object-fit: cover; display: block; transition: transform .25s ease; }
.ot-thumb:hover img { transform: scale(1.05); }
.ot-file { height: 120px; display: flex; align-items: center; justify-content: center; font-size: 40px; color: #fff; background: linear-gradient(135deg,#ef4444,#b91c1c); }
.ot-thumb figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 8px 6px;
  font-size: 11px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(to top, rgba(0,0,0,.72), transparent);
}
.ot-thumb__del {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 8px;
  background: rgba(220,38,38,.92); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s ease;
}
.ot-thumb:hover .ot-thumb__del { opacity: 1; }
.ot-thumb__del:hover { background: #b91c1c; }

/* ===== Formulario de usuario (layout elegante 2 columnas) ===== */
#crudFields.form-usuarios { grid-template-columns: 1fr 1fr; gap: 14px 16px; }
#crudFields.form-usuarios .span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { #crudFields.form-usuarios { grid-template-columns: 1fr; } }

/* Inputs del formulario CRUD: consistencia y foco */
.modal__form input:not([type="checkbox"]),
.modal__form select,
.modal__form textarea {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.modal__form input:focus,
.modal__form select:focus,
.modal__form textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,77,255,.12);
}
.modal__form label { gap: 6px; }
.modal__form .field-label { font-weight: 500; color: #334155; }

/* Campo de contraseña con boton ver/ocultar integrado */
.password-field { position: relative; display: flex; align-items: center; }
.password-field input { padding-right: 42px; }
.password-field .toggle-password {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; padding: 0; border: 0; background: transparent; color: var(--muted, #64748b);
  border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.password-field .toggle-password:hover { background: #f1f5f9; color: var(--text, #0f172a); }

.qr-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

/* ============================================================================
   DataTables — tema acorde al sistema (listas server-side y tabs de detalle)
   ========================================================================== */
.dataTables_wrapper { width: 100%; color: var(--text); }

/* Barra superior: buscador propio + herramientas (exportar/imprimir) */
.dataTables_wrapper .dt-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.dataTables_wrapper .dt-tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* Botones de exportar / imprimir */
.dt-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; font-size: 13px; font-weight: 600;
  color: var(--muted); background: #fff;
  border: 1px solid var(--secondary); border-radius: 10px;
  cursor: pointer; transition: all .15s ease;
}
.dt-btn:hover { color: var(--primary); border-color: var(--primary); background: #eef2ff; }
.dt-btn:active { transform: translateY(1px); }
.dt-btn:disabled { opacity: .55; cursor: default; }
.dt-btn i { font-size: 15px; }

/* Buscador */
.dataTables_wrapper .dataTables_filter { margin: 0; }
.dataTables_wrapper .dataTables_filter label { color: var(--muted); font-size: 0; }
.dataTables_wrapper .dataTables_filter input {
  margin: 0; min-width: 240px; padding: 9px 12px;
  border: 1px solid var(--secondary); border-radius: 10px;
  font-size: 14px; color: var(--text); background: #fff; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.dataTables_wrapper .dataTables_filter input::placeholder { color: #9aa6b2; }
.dataTables_wrapper .dataTables_filter input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27, 77, 255, .12);
}

/* Selector de cantidad por pagina */
.dataTables_wrapper .dataTables_length { color: var(--muted); font-size: 13px; }
.dataTables_wrapper .dataTables_length select {
  margin: 0 6px; padding: 6px 26px 6px 10px; border: 1px solid var(--secondary);
  border-radius: 8px; background: #fff; color: var(--text); cursor: pointer;
}

/* Tabla */
table.dataTable { width: 100% !important; border-collapse: collapse; margin: 0 !important; }
table.dataTable thead th {
  position: relative; text-align: left; padding: 12px 26px 12px 14px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  color: var(--muted); background: #f8fafc;
  border-bottom: 1px solid var(--secondary);
}
table.dataTable thead th:first-child { border-top-left-radius: 10px; }
table.dataTable thead th:last-child  { border-top-right-radius: 10px; }
table.dataTable tbody td {
  padding: 12px 14px; font-size: 14px; color: var(--text);
  border-bottom: 1px solid #eef2f7; vertical-align: middle;
}
table.dataTable tbody tr { background: #fff; transition: background .12s ease; }
table.dataTable tbody tr:hover { background: #f7f9ff; cursor: default; }
table.dataTable tbody tr.is-selected,
table.dataTable tbody tr.selected { background: #eef2ff; }
table.dataTable tbody tr.is-selected td { box-shadow: inset 3px 0 0 var(--primary); }

/* Indicadores de orden: ocultamos el doble icono de la libreria (::before) y
   usamos ::after como unica flecha, al estilo del sistema. */
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc { cursor: pointer; }
table.dataTable thead th.sorting::before,
table.dataTable thead th.sorting_asc::before,
table.dataTable thead th.sorting_desc::before { content: '' !important; display: none !important; }
table.dataTable thead th.sorting::after,
table.dataTable thead th.sorting_asc::after,
table.dataTable thead th.sorting_desc::after {
  position: absolute; right: 10px; top: 50%; left: auto; bottom: auto;
  transform: translateY(-50%); font-size: 11px; line-height: 1; opacity: 1 !important;
}
table.dataTable thead th.sorting::after     { content: '\2195' !important; color: var(--muted); opacity: .4 !important; }
table.dataTable thead th.sorting_asc::after { content: '\2191' !important; color: var(--primary); }
table.dataTable thead th.sorting_desc::after{ content: '\2193' !important; color: var(--primary); }
table.dataTable thead th:hover.sorting::after { opacity: .7 !important; }

/* Celda de acciones dentro de DataTables */
table.dataTable td.actions { white-space: nowrap; text-align: right; width: 1%; }

/* Pie: info + paginacion */
.dataTables_wrapper .dataTables_info {
  color: var(--muted); font-size: 13px; padding-top: 16px;
}
.dataTables_wrapper .dataTables_paginate { float: right; padding-top: 12px; }
.dataTables_wrapper .dataTables_paginate .paginate_button {
  box-sizing: border-box; min-width: 34px; height: 34px; padding: 0 10px !important;
  margin: 0 2px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--secondary) !important; border-radius: 9px !important;
  color: var(--text) !important; background: #fff !important; cursor: pointer;
  font-size: 13px; transition: all .15s ease;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  border-color: var(--primary) !important; color: var(--primary) !important;
  background: #eef2ff !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--primary) !important; border-color: var(--primary) !important;
  color: #fff !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
  opacity: .45; color: var(--muted) !important; background: #fff !important;
  border-color: var(--secondary) !important; cursor: default;
}

/* Overlay de carga */
.dataTables_wrapper .dataTables_processing {
  background: rgba(255, 255, 255, .82); color: var(--muted); font-weight: 600;
  border: 0; box-shadow: none; border-radius: 12px;
}

/* En las tablas del detalle (tabs) el wrapper va dentro de .detail-table */
.detail-table .dataTables_wrapper .dt-head { margin-bottom: 10px; }

/* Responsivo */
@media (max-width: 720px) {
  .dataTables_wrapper .dataTables_filter input { min-width: 0; width: 100%; }
  .dataTables_wrapper .dt-head { flex-direction: column; align-items: stretch; }
  .dataTables_wrapper .dataTables_paginate { float: none; text-align: center; margin-top: 12px; }
}

/* ============================================================================
   Vista de factura (diseño de factura, en el modal de detalle e impresión)
   ========================================================================== */
.modal__header-actions { display: flex; gap: 8px; align-items: center; }

.invoice {
  background: #fff; color: var(--text); padding: 8px 4px;
  font-size: 14px; max-width: 820px; margin: 0 auto;
}
.invoice__head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 24px; border-bottom: 2px solid var(--primary); padding-bottom: 16px;
}
.invoice__brand { display: flex; gap: 12px; align-items: center; }
.invoice__logo {
  width: 48px; height: 48px; border-radius: 12px; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; flex: 0 0 auto;
}
.invoice__brand h2 { margin: 0; font-size: 19px; }
.invoice__brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.invoice__title { text-align: right; }
.invoice__title h1 { margin: 0; font-size: 28px; letter-spacing: 2px; color: var(--primary); }
.invoice__num { margin: 4px 0 8px; color: var(--muted); font-size: 13px; }

.invoice__parties {
  display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin: 22px 0;
}
.invoice__party h4, .invoice__notes h4 {
  margin: 0 0 6px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.invoice__party p { margin: 2px 0; font-size: 13px; }
.invoice__party .strong { font-weight: 700; font-size: 15px; }
.invoice__meta { display: grid; grid-template-columns: auto auto; gap: 8px 20px; align-content: start; }
.invoice__meta div { display: flex; flex-direction: column; }
.invoice__meta span { font-size: 11px; color: var(--muted); }
.invoice__meta b { font-size: 13px; }

table.invoice__items { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.invoice__items th {
  background: #f1f5f9; text-align: left; padding: 10px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .03em; color: #475569;
}
.invoice__items td { padding: 10px; border-bottom: 1px solid #eef2f7; }
.invoice__items .num, .invoice__items th.num { text-align: right; }

.invoice__footer { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-top: 20px; }
.invoice__notes p { font-size: 12px; color: #475569; margin: 0; max-width: 340px; }
.invoice__totals { min-width: 250px; margin-left: auto; }
.invoice__totals div { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.invoice__totals span { color: var(--muted); }
.invoice__grand {
  border-top: 2px solid var(--primary); margin-top: 6px; padding-top: 10px !important;
  font-size: 18px !important; font-weight: 800; color: var(--primary);
}
.invoice__grand span { color: var(--primary) !important; }
