/* ============================================================================
   Claude-APU · Identidad visual TechGroupOne (TGO)
   Primario TEAL #1F7091 sobre fondo claro. Tipografia Arial/Helvetica.
   ============================================================================ */

:root {
  --teal:        #1F7091;
  --teal-dark:   #185b76;
  --teal-light:  #2c86ab;
  --teal-050:    #eaf2f6;
  --teal-100:    #d6e6ee;
  --total-hl:    #cfe8f7; /* celeste claro: realce de columnas de totales (Total Price/Cost) */
  --uncertain-hl: #fff3b0; /* amarillo suave: marca de INCERTIDUMBRE (flag uncertain) en celdas de precio/cantidad */

  --bg:      #eef1f4;
  --surface: #ffffff;
  --text:    #1f2a30;
  --muted:   #667680;
  --border:  #d7dee3;

  --danger:  #c0392b;
  --danger-050: #fbecea;
  --ok:      #1e7a46;
  --ok-050:  #e8f5ee;

  --shadow: 0 1px 3px rgba(16, 42, 55, .08), 0 1px 2px rgba(16, 42, 55, .06);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: Arial, Helvetica, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------- Topbar ---------------------------------- */
header.topbar {
  background: var(--teal);
  color: #fff;
  padding: 0.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
header.topbar .brand-logo {
  display: flex; align-items: center; gap: .6rem;
  background: #fff;
  border-radius: 8px;
  padding: 4px 10px;
  line-height: 0;
}
header.topbar .brand-logo img { height: 34px; width: auto; display: block; }
header.topbar .brand-fallback {
  font-weight: 700; color: var(--teal); font-size: 1rem; line-height: 1.1; white-space: nowrap;
}
header.topbar .brand-fallback small { display: block; font-weight: 400; color: var(--muted); font-size: .68rem; letter-spacing: .04em; }

header.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; align-items: center; }
header.topbar nav a {
  color: #fff; padding: .4rem .7rem; border-radius: 6px; font-size: .92rem;
  white-space: nowrap; transition: background .15s;
}
header.topbar nav a:hover { background: rgba(255,255,255,.16); text-decoration: none; }
header.topbar nav a.active { background: rgba(255,255,255,.22); }

header.topbar .spacer { flex: 1; }
header.topbar .user-chip { color: #eaf5fa; font-size: .85rem; opacity: .95; }
header.topbar .user-chip strong { color: #fff; font-weight: 600; }
/* Spinner "trabajando" junto al usuario (visible al generar Excel/PDF). */
header.topbar .work-spin {
  display: inline-block; width: 16px; height: 16px; vertical-align: middle;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%;
  animation: tgo-spin .7s linear infinite;
}
header.topbar .work-spin[hidden] { display: none; }
@keyframes tgo-spin { to { transform: rotate(360deg); } }
header.topbar .logout {
  color: #fff; border: 1px solid rgba(255,255,255,.5); padding: .32rem .7rem;
  border-radius: 6px; font-size: .85rem;
}
header.topbar .logout:hover { background: rgba(255,255,255,.16); text-decoration: none; }
header.topbar .env-badge {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: .06em;
  background: rgba(255,255,255,.18); color: #fff; padding: .12rem .5rem; border-radius: 999px;
}

/* -------------------------------- Main ----------------------------------- */
main { max-width: 1160px; margin: 1.6rem auto; padding: 0 1.25rem; }
/* Estimado: usa (casi) todo el ancho de la ventana. */
body.page-estimate main { max-width: none; margin: 1.2rem auto; padding: 0 1rem; }
/* APU: contenido contenido y centrado (no full-width), responsivo en pantallas chicas. */
body.page-apu main { max-width: 1280px; margin: 1.2rem auto; padding: 0 1rem; }

/* APU: barra superior FIJA (nav principal + fila de contexto) al hacer scroll.
   --tgo-topbar-h la fija por JS segun la altura real del nav (que envuelve).
   height:auto permite que el <body> crezca con el contenido para que el sticky
   del topbar (cuyo bloque contenedor es el body) funcione en todo el scroll. */
body.page-apu { height: auto; min-height: 100%; }
body.page-apu header.topbar { position: sticky; top: 0; z-index: 200; }
body.page-apu .apu-topnav {
  position: sticky; top: var(--tgo-topbar-h, 56px); z-index: 150;
  background: var(--bg); padding: .55rem 0; margin-bottom: .6rem;
  box-shadow: 0 6px 10px -8px rgba(0,0,0,.35);
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; color: var(--teal-dark); font-weight: 700; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .7rem; color: var(--teal-dark); font-weight: 700; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

/* ------------------------------ Dashboard -------------------------------- */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}
.grid-cards a.tile {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.15rem; color: var(--text); text-decoration: none;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--teal);
  transition: transform .15s, box-shadow .15s;
}
.grid-cards a.tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16,42,55,.12); text-decoration: none; }
.grid-cards a.tile .count { font-size: 1.9rem; font-weight: 700; color: var(--teal); }
.grid-cards a.tile .name { color: var(--muted); margin-top: .2rem; }

/* ------------------------------- Tables ---------------------------------- */
table {
  width: 100%; border-collapse: collapse; margin-top: .5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th {
  background: var(--teal); color: #fff; font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .03em; border-bottom: none;
}
tbody tr:nth-child(even) td { background: var(--teal-050); }
tbody tr:hover td { background: var(--teal-100); }
tbody tr:last-child td { border-bottom: none; }

/* ------------------------------- Forms ----------------------------------- */
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], textarea, select {
  width: 100%; padding: .55rem .7rem; background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 7px; font-size: .95rem; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(31,112,145,.15);
}
input[readonly] { background: #f3f5f7; color: var(--muted); }
input.is-dim { background: #f3f5f7; color: var(--muted); opacity: .75; }
textarea { min-height: 74px; resize: vertical; }
label { display: block; margin: .8rem 0 .25rem; color: var(--muted); font-size: .85rem; font-weight: 600; }

/* ------------------------------ Buttons ---------------------------------- */
/* Sistema de botones reutilizable con dimensiones consistentes.
   Todos usan inline-flex + box-sizing:border-box para igualar alturas entre
   <a> y <button>, con relleno/borde identicos. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  cursor: pointer; box-sizing: border-box;
  border: 1px solid var(--teal); background: var(--teal); color: #fff;
  font-weight: 600; font-family: inherit; line-height: 1.1;
  padding: .5rem .95rem; border-radius: 7px; font-size: .9rem; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap; vertical-align: middle;
}
.btn:hover { text-decoration: none; }

/* Variantes de color */
.btn-primary, .btn { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover, .btn:hover { background: var(--teal-dark); border-color: var(--teal-dark); color: #fff; }

.btn.secondary, .btn-outline, .btn-edit {
  background: #fff; color: var(--teal); border-color: var(--teal);
}
.btn.secondary:hover, .btn-outline:hover, .btn-edit:hover {
  background: var(--teal-050); color: var(--teal-dark); border-color: var(--teal);
}

.btn.danger, .btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover, .btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* Tamanos */
.btn.small, .btn-sm { padding: .34rem .6rem; font-size: .8rem; min-width: 90px; }
/* Botones de barra (Buscar / Agregar / New): mismo tamano entre si */
.btn-toolbar { min-width: 120px; }
/* Activar / Desactivar: mismo ancho para alinear la columna sin importar estado */
.btn-toggle { min-width: 108px; }

/* ------------------------------ Toolbar ---------------------------------- */
.toolbar { display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar form.search { display: flex; gap: .5rem; flex: 1; min-width: 240px; align-items: center; }
.toolbar form.search { flex: 0 0 auto; }
.toolbar form.search .search-box { flex: 0 0 320px; width: 320px; max-width: 100%; }
.toolbar .btn-newbid { margin-left: auto; white-space: nowrap; }
/* Reserva ancho fijo al label del filtro para que la barra no salte al cambiar de estado. */
#triLbl { display: inline-block; min-width: 112px; }

/* ------------------------------- Flash ----------------------------------- */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok  { background: var(--ok-050); border-color: var(--ok); color: #14532d; }
.flash.err { background: var(--danger-050); border-color: var(--danger); color: #7f1d1d; }

/* ------------------------------ Utilities -------------------------------- */
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
/* Celdas numericas/monetarias alineadas a la derecha (cabecera y cuerpo) */
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: .4rem; justify-content: flex-end; }

/* Acciones apiladas en vertical (Editar arriba, Eliminar abajo), mismo ancho */
.actions-stack { flex-direction: column; align-items: stretch; gap: .35rem; }
.actions-stack form { display: block; margin: 0; }
.actions-stack .btn { width: 100%; min-width: 0; }

/* Fecha/hora apiladas: fecha (MM/DD/YY) arriba, hora (12h AM/PM) debajo */
td.dt { line-height: 1.25; white-space: nowrap; }
.dt-date { display: block; }
.dt-time { display: block; font-size: .78rem; color: var(--muted); }

/* Columnas compactas: User (iniciales) y Fecha ocupan el minimo ancho posible */
th.col-user, td.col-user { width: 1%; white-space: nowrap; text-align: center; font-weight: 600; }
th.col-dt, td.col-dt { width: 1%; white-space: nowrap; }
/* Columna elastica: Descripcion (o Email en Usuarios) toma el ancho sobrante */
th.col-grow, td.col-grow { width: 100%; min-width: 260px; }

/* Encabezados ordenables (click para ordenar filas visibles) */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: var(--teal-dark); }
th.sortable::after { content: '\2195'; opacity: .35; margin-left: .3rem; font-size: .75em; }
th.sort-asc::after { content: '\25B2'; opacity: 1; }
th.sort-desc::after { content: '\25BC'; opacity: 1; }
code { background: var(--teal-050); padding: .1rem .35rem; border-radius: 5px; border: 1px solid var(--border); color: var(--teal-dark); }

/* Iconos editar/borrar (SVG inline heredan currentColor) */
.icon { width: 15px; height: 15px; vertical-align: -2px; }

/* ============================================================================
   AUTENTICACION (login / forgot / reset) — landing branded TGO
   ============================================================================ */
.auth-body {
  min-height: 100vh;
  margin: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  position: relative; overflow: hidden;
  /* Fondo: foto de obra opcional (assets/login-bg.jpg) sobre degradado teal. */
  background:
    linear-gradient(135deg, rgba(24,91,118,.92), rgba(31,112,145,.82)),
    url('login-bg.jpg') center/cover no-repeat, var(--teal-dark);
}
/* Arcos translucidos concentricos caracteristicos de TGO */
.auth-body::before, .auth-body::after {
  content: ""; position: absolute; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.10);
  box-shadow: 0 0 0 40px rgba(255,255,255,.05), 0 0 0 120px rgba(255,255,255,.04);
  pointer-events: none;
}
.auth-body::before { width: 620px; height: 620px; left: -220px; top: -180px; }
.auth-body::after  { width: 780px; height: 780px; right: -300px; bottom: -320px;
  border-color: rgba(255,255,255,.12); }

.auth-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,.28);
  padding: 2rem 1.9rem;
}
.auth-logo { text-align: center; margin-bottom: 1.1rem; }
.auth-logo img { height: 64px; width: auto; }
.auth-logo .brand-fallback { font-size: 1.25rem; font-weight: 700; color: var(--teal); }
.auth-logo .brand-fallback small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; letter-spacing: .04em; }
.auth-card h1 { text-align: center; font-size: 1.25rem; margin: .2rem 0 .3rem; color: var(--teal-dark); }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 1.2rem; font-size: .9rem; }
.auth-card .btn { width: 100%; text-align: center; padding: .6rem; font-size: 1rem; }
.auth-links { margin-top: 1rem; text-align: center; font-size: .88rem; }
.auth-footer { position: relative; z-index: 1; }

/* =================== Motor de estimacion (Bids/APU) ===================== */
.small { font-size: .8rem; }
.inline { display: inline; margin: 0; }
.grow { flex: 1; }
.disabled { opacity: .45; pointer-events: none; }
input.in-sm, select.in-sm { width: 90px; }
input.in-xs { width: 70px; }

.apu-topnav { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.apu-topnav .spacer { flex: 1; }
.apu-topnav select { min-width: 220px; }

.apu-head { padding: .8rem 1rem; }
.apu-head-grid { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-end; }
.apu-head-grid label { display: flex; flex-direction: column; font-size: .78rem; color: var(--muted); gap: .2rem; }
.apu-head-grid label.grow { flex: 1; min-width: 200px; }
.apu-head-grid input, .apu-head-grid select { font-size: .9rem; }

.apu-layout { display: flex; gap: 1rem; align-items: flex-start; }
.apu-sections { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1rem; }
.apu-side { width: 320px; flex: none; display: flex; flex-direction: column; gap: 1rem; }

.apu-sec-head { display: flex; align-items: center; gap: .6rem; border-bottom: 2px solid var(--teal); padding-bottom: .3rem; margin-bottom: .6rem; }
.apu-sec-head h3 { margin: 0; color: var(--teal-dark); }
.apu-sec-title { cursor: pointer; }
.apu-add-btn { margin-left: auto; white-space: nowrap; }
.apu-sec-hint { color: var(--teal); font-size: .78rem; }
.apu-empty { padding: .6rem !important; text-align: center; }
.apu-empty .btn { margin-left: .6rem; }

.apu-search { background: var(--teal-050); border: 1px solid var(--teal-100); border-radius: 8px; padding: .6rem; margin-bottom: .7rem; }
.apu-search input[type=search] { width: 100%; margin-bottom: .4rem; }
.apu-results { max-height: 260px; overflow-y: auto; margin-bottom: .4rem; }
.apu-result { padding: .35rem .5rem; border-radius: 6px; cursor: pointer; font-size: .85rem; }
.apu-result:hover { background: var(--teal-100); }

/* Dropdown de search como tabla con cabeceras ORDENABLES (referencia Azure). */
table.apu-res-tbl { width: 100%; border-collapse: collapse; font-size: .82rem; margin: 0; }
table.apu-res-tbl thead th {
    position: sticky; top: 0; z-index: 1;
    background: var(--teal); color: #fff; font-size: .72rem; font-weight: 700;
    padding: .3rem .45rem; text-align: left; white-space: nowrap; cursor: pointer; user-select: none;
}
table.apu-res-tbl thead th.num { text-align: right; }
table.apu-res-tbl thead th.grow { width: 100%; }
table.apu-res-tbl thead th:hover { background: var(--teal-dark); }
table.apu-res-tbl thead th.sorted { background: var(--teal-dark); }
.apu-sort-ar { font-size: .8em; }
table.apu-res-tbl tbody td { padding: .3rem .45rem; border-bottom: 1px solid var(--teal-050); white-space: nowrap; }
table.apu-res-tbl tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.apu-res-tbl tbody td.grow { white-space: normal; }
table.apu-res-tbl tbody tr.apu-res-row { cursor: pointer; }
table.apu-res-tbl tbody tr.apu-res-row:hover td { background: var(--teal-100); }

table.apu-rows { font-size: .82rem; }
table.apu-rows th { font-size: .72rem; }
table.apu-rows td { padding: .25rem .35rem; }
table.apu-rows td.num input:not([type=text]) { text-align: right; }
table.apu-rows td.num select { text-align: left; }
table.apu-rows input, table.apu-rows select { padding: .28rem .4rem; font-size: .82rem; }
table.apu-rows input[type=number] { text-align: right; }
.apu-notes { display: flex; flex-direction: column; font-size: .78rem; color: var(--muted); gap: .2rem; margin: .5rem 0; }
.apu-notes textarea { font-size: .85rem; }

/* Cascada de subtotales del APU: filas DENTRO de apu-rows (alineadas a Costo U./Ext.) */
table.apu-rows tr.casc td { border-top: 1px solid #eef2f5; padding: .22rem .45rem; }
table.apu-rows td.casc-lbl { text-align: right; color: #333; font-size: .82rem; }
table.apu-rows tr.casc-sub td { background: var(--teal-050); font-weight: 700; }
table.apu-rows tr.casc-margin td { background: #fffdf0; }
table.apu-rows tr.casc-total td { background: var(--teal-100); font-weight: 700; color: var(--teal-dark); }
input.pct-in { width: 66px; text-align: right; padding: .18rem .35rem; font-size: .8rem; }

/* Panel de Totales del APU (abajo de las 5 secciones) */
/* Iconos SVG dentro de botones/enlaces de accion */
.btn .ic { vertical-align: -2px; pointer-events: none; }
.actions-stack .btn-square, .actions .btn-square { margin: 1px; }

.apu-totals-wrap { margin-top: 1rem; }
/* E) Totales alineados a la DERECHA, bajo Costo U. / Costo Ext. (misma vertical y ancho
   que las sub-tablas: Costo Ext. pegado al borde derecho, sin columna sobrante). */
.apu-totals-bottom table.apu-totals-tbl { width: 100%; max-width: none; table-layout: fixed; }
.apu-totals-tbl .lbl { text-align: right; padding-right: .6rem; color: #333; }
.apu-totals-tbl td.num, .apu-totals-tbl th.num { width: 92px; text-align: right; }
.apu-totals-tbl .casc-margin .lbl { text-align: right; }
.apu-totals-tbl .casc-margin form.inline { display: inline; }

/* Valor de catalogo (no editable inline) + input numerico formateado a la derecha */
.apu-rows .cat-static { display: inline-block; min-width: 60px; text-align: right; font-variant-numeric: tabular-nums; color: #333; }
.apu-rows .cat-static.cat-desc { text-align: left; min-width: 0; }
/* Boton de link por fila (material/equipment/contract): activo abre el link;
   gris/deshabilitado si el producto no tiene link. Mismo ancho de icono. */
.apu-rows .apu-link { margin-left: .35rem; vertical-align: middle; }
.apu-rows .apu-link.is-disabled { opacity: .35; cursor: default; pointer-events: none; }
/* Boton deshabilitado generico (ej. link "Calculations" arriba del APU sin URL). */
.btn.is-disabled { opacity: .4; cursor: default; pointer-events: none; }
.apu-calc-link { display: inline-flex; align-items: center; gap: .3rem; }
/* Columna de acciones del APU: AHORA a la IZQUIERDA (primera columna), consistente con
   la hoja de Estimado. Ancho fijo e igual en las 5 sub-tablas para que el grid quede
   parejo. Lapiz (editar), papelera (borrar) y el spacer del mismo ancho alinean los
   botones verticalmente entre filas. */
.apu-rows th.apu-act-col, .apu-rows td.apu-act-col,
.apu-rows td.apu-actions { width: 72px; white-space: nowrap; text-align: left; }
.apu-rows td.apu-actions .btn-square,
.apu-rows td.apu-actions .apu-act-spacer {
    display: inline-block; width: 30px; box-sizing: border-box;
    padding-left: 0; padding-right: 0; margin-right: 3px; margin-left: 0; vertical-align: middle; text-align: center;
}
.apu-rows td.apu-actions .apu-act-spacer { visibility: hidden; }
/* Columnas Costo U. / Costo Ext.: ancho fijo e igual para que las 4 sub-tablas con costo
   (labor, materials, equipments, contracts) y sus filas de subtotal/total caigan en la
   MISMA vertical. Descripcion (col-grow) absorbe el sobrante, dejando Costo Ext. pegado
   al borde derecho en todas. */
.apu-rows th.rc-col, .apu-rows td.rc-u, .apu-rows td.rc-x,
.apu-rows td.casc-u, .apu-rows td.casc-x { width: 92px; }
table.apu-rows input.num-fmt { text-align: right; }
/* Selector de modo de labor (Hours/Perf): ancho suficiente para leer las dos opciones. */
table.apu-rows select.labor-mode { width: auto; min-width: 76px; }

/* Campos del modal de formulario (TGO.form) */
.modal-field { display: flex; flex-direction: column; gap: .2rem; margin: .5rem 0; font-size: .85rem; }
.modal-field-lbl { color: var(--muted); font-size: .78rem; }
/* Campo checkbox: casilla + texto en linea */
.modal-field-check { flex-direction: row; align-items: center; gap: .5rem; }
.modal-field-check .modal-check { width: 16px; height: 16px; flex: 0 0 auto; margin: 0; }
.modal-field-check .modal-field-lbl { color: #223; font-size: .9rem; }

/* Indicador de autoguardado */
.autosave-indicator { position: fixed; right: 18px; bottom: 18px; z-index: 50; padding: .45rem .8rem; border-radius: 20px; font-size: .82rem; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.16); background: #e8f3ee; color: #14562a; border: 1px solid #8fd6a1; }
.autosave-indicator.saving { background: #eef3f7; color: #47606e; border-color: #cfd8dd; }
.autosave-indicator.error { background: #fdeaea; color: #8a1f1f; border-color: #e6a3a3; }

/* Status del line item / APU (3 estados) */
.st-badge { display: inline-block; padding: .1rem .5rem; border-radius: 10px; font-size: .74rem; font-weight: 700; border: 1px solid #cfd8dd; }
.st-select { font-weight: 700; border: 1px solid #cfd8dd; border-radius: 6px; padding: .32rem .4rem; }
.st-progress { background: #ffffff; color: #243; border-color: #cfd8dd; }
.st-review   { background: #ffe08a; color: #5a4600; border-color: #e6c34d; }
.st-ready    { background: #bfe9c6; color: #14562a; border-color: #8fd6a1; }

/* Lista de Bids (Fase 3) */
table.bids-list { width: 100%; font-size: .85rem; }
table.bids-list td, table.bids-list th { padding: .35rem .5rem; }
table.bids-list tr.bid-blocked td { background: #fff6f0; }
table.bids-list tr.bid-edit > td { background: #f7fafc; }
.tristate { display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap; }
.tristate input[type="checkbox"] { width: 22px; height: 22px; cursor: pointer; accent-color: var(--teal, #1F7091); }
.est-views { display: inline-flex; align-items: center; gap: .35rem; }
.grp-special { font-size: .85rem; }
.grp-num { color: var(--teal, #1F7091); }
.grp-name { cursor: text; }
.grp-actions { display: inline-flex; gap: .3rem; align-items: center; margin-left: .5rem; vertical-align: middle; }
.grp-actions .inline { display: inline-flex; }
tr.grp-row .grp-name:hover { text-decoration: underline dotted; }
tr.addline-row td { background: #f7fafc; }
.apu-newline.addline-form { display: flex; gap: .4rem; align-items: center; flex-wrap: nowrap; max-width: 900px; margin-top: .5rem; }
/* El display:flex de arriba pisa el atributo [hidden]; forzamos el cierre para que
   el boton Cancelar (que pone hidden) realmente oculte la fila de alta. */
.apu-newline.addline-form[hidden] { display: none; }
.apu-newline.addline-form .grow { flex: 0 1 300px; min-width: 160px; width: auto; }
.apu-newline.addline-form .in-xs { flex: 0 0 70px; }
.apu-newline.addline-form .in-sm { flex: 0 0 90px; }
.apu-newline.addline-form .btn { flex: 0 0 auto; }
.col-dropdown { position: relative; }
.col-menu { position: absolute; right: 0; top: 115%; z-index: 40; min-width: 170px; background: #fff; border: 1px solid #d9e1e6; border-radius: 8px; box-shadow: 0 8px 22px rgba(0,0,0,.14); padding: .5rem .7rem; }
.col-menu label { display: flex; align-items: center; gap: .45rem; padding: .22rem 0; font-size: .85rem; white-space: nowrap; cursor: pointer; }
.col-menu input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--teal, #1F7091); }
.col-menu hr { border: 0; border-top: 1px solid #eee; margin: .4rem 0; }
/* Panel Columns por columna: 4 grupos en fila (Common/Prices/Cost/Pro-Rate) */
.col-menu-grid { display: flex; gap: 1.2rem; min-width: auto; width: max-content; }
/* El display:flex de arriba pisaba el atributo [hidden]; forzamos el cierre. */
.col-menu[hidden] { display: none; }
/* Grupos de items cortos con ancho UNIFORME (Common/Prices/Pro-Rate/Cost). */
.col-menu .col-grp { flex: 0 0 160px; min-width: 160px; }
/* Totales toma el ancho que necesita (etiquetas largas). */
.col-menu .col-grp-totales { flex: 0 0 auto; min-width: 220px; }
.col-menu .col-grp > strong { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-bottom: .35rem; border-bottom: 1px solid #eef2f5; padding-bottom: .2rem; }
.col-menu .col-grp label { font-size: .82rem; }

/* Combo con buscador (mejora un <select>) */
.combo { position: relative; display: inline-block; min-width: 260px; }
.combo.combo-wide { min-width: 340px; }
.combo.combo-wide .combo-input { min-width: 340px; }
.combo .combo-native { display: none; }
.combo-input { width: 100%; min-width: 260px; }
.combo-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 60; margin: .15rem 0 0; padding: .25rem; list-style: none; max-height: 320px; overflow: auto; background: #fff; border: 1px solid #d9e1e6; border-radius: 8px; box-shadow: 0 8px 22px rgba(0,0,0,.14); }
.combo-item { padding: .4rem .55rem; border-radius: 6px; cursor: pointer; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-item.active, .combo-item:hover { background: var(--teal-050, #eef6f9); }
.combo-item[aria-selected="true"] { font-weight: 700; }

/* ===================== Modal propio (branding TGO) ===================== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(15, 32, 39, .55);
    display: flex; align-items: center; justify-content: center;
    padding: 1rem; opacity: 0; transition: opacity .13s ease;
}
.modal-overlay.show { opacity: 1; }
.modal-card {
    background: #fff; border-radius: 10px; width: 100%; max-width: 460px;
    max-height: calc(100vh - 2rem); display: flex; flex-direction: column;
    box-shadow: 0 14px 44px rgba(0, 0, 0, .28); overflow: hidden;
    transform: translateY(8px) scale(.99); transition: transform .13s ease;
}
.modal-overlay.show .modal-card { transform: none; }
.modal-head {
    background: var(--teal); color: #fff; font-weight: 700;
    font-size: 1rem; padding: .8rem 1.15rem; flex: 0 0 auto;
}
.modal-body { padding: 1.15rem; color: #223; font-size: .93rem; line-height: 1.5; overflow: auto; flex: 1 1 auto; }
.modal-input {
    width: 100%; margin-top: .7rem; padding: .5rem .6rem;
    border: 1px solid #cfd8dd; border-radius: 6px; font-size: .95rem;
}
.modal-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(31, 112, 145, .15); }
.modal-actions {
    display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap;
    padding: .8rem 1.15rem; border-top: 1px solid #eef2f5; background: #fafcfd;
    flex: 0 0 auto;
}

.apu-settings { display: flex; flex-direction: column; gap: .4rem; }
.apu-settings label { display: flex; justify-content: space-between; align-items: center; font-size: .82rem; gap: .5rem; }
.apu-settings input { width: 90px; text-align: right; }

.apu-totals table { font-size: .82rem; margin-bottom: .6rem; }
.apu-totals .apu-grand td { background: var(--teal-050); font-weight: 700; }
.apu-costbreak td { padding: .2rem .4rem; }

.apu-newline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .6rem; }
.apu-newline .grow { min-width: 200px; }

/* Aviso de tiempo real */
.rt-banner {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  background: var(--teal-dark); color: #fff; padding: .7rem 1rem; border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: .85rem; display: flex; align-items: center; gap: .6rem;
}
.rt-banner .btn { background: #fff; color: var(--teal-dark); border-color: #fff; }

/* Hoja de estimado */
.est-toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.est-toolbar select { min-width: 240px; }
.est-toolbar .spacer { flex: 1; }
/* Anchos FIJOS para que TODAS las filas (encabezado, line items, subtotales,
   totales y la fila de alta) queden alineadas verticalmente en las mismas columnas. */
table.est-sheet { font-size: .8rem; table-layout: fixed; width: auto; min-width: 0; margin: 0 auto; }

/* Drag & drop: handle + indicadores de destino */
.drag-h { cursor: grab; color: #9aa7ad; user-select: none; font-weight: 700; letter-spacing: -1px; padding: 0 .15rem; }
.drag-h:active { cursor: grabbing; }
.drag-h:hover { color: #4b5a61; }
tr.drag-src { opacity: .45; }
tr.li-row.drag-over > td { box-shadow: inset 0 2px 0 0 #2f6fed; }
tr.grp-row.drag-over-grp > td { outline: 2px dashed #2f6fed; outline-offset: -2px; }
.st-select.st-inline { padding: .18rem .3rem; font-size: .76rem; }
table.est-sheet th { font-size: .68rem; position: sticky; top: 0; }
table.est-sheet td, table.est-sheet th { padding: .3rem .45rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.est-sheet td.num, table.est-sheet th.num { width: 94px; }
table.est-sheet .col-description { width: 240px; white-space: normal; }
table.est-sheet .col-item_no { width: 64px; min-width: 64px; text-align: center; }
/* Numero grupo-linea en la columna ITEM = link al APU (teal). tabular-nums para que
   1-1 y 1000-1 queden alineados sin descuadrar aunque cambie la cantidad de digitos. */
.item-apu-link { color: var(--teal); cursor: pointer; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-apu-link:hover { color: var(--teal-dark); text-decoration: underline; }
table.est-sheet .col-status { width: 90px; }
table.est-sheet .col-unit { width: 56px; }
table.est-sheet .col-quantity { width: 62px; }
table.est-sheet .col-gross_pct { width: 64px; }
table.est-sheet .col-updated_at { width: 88px; }
table.est-sheet .col-updated_by { width: 58px; }
/* Columna de acciones ajustada al contenido: sin franja blanca a la derecha. */
table.est-sheet .col-actions { width: 86px; }
/* Columna de acciones FIJA a la izquierda (handle + editar + borrar), siempre visible */
table.est-sheet .col-rowact { width: 96px; }
table.est-sheet td.rowact { overflow: visible; white-space: nowrap; padding: .2rem .3rem; }
.rowact-cluster { display: inline-flex; align-items: center; gap: .2rem; }
.rowact-cluster .inline { display: inline-flex; }
.rowact-cluster .drag-h-off { color: #d7dee1; cursor: default; }
.rowact-cluster .drag-h-off:hover { color: #d7dee1; }
/* Filas que ocupan todo el ancho (cabecera de grupo, alta de line item): permiten flujo normal. */
table.est-sheet .grp-row td, table.est-sheet .addline-row td { white-space: normal; overflow: visible; }
table.est-sheet .grp-row td { background: var(--teal-100); font-weight: 700; color: var(--teal-dark); }
table.est-sheet .sub-row td { background: var(--teal-050); font-weight: 700; }
table.est-sheet .special-row td { background: #fff7e6; font-weight: 700; }
table.est-sheet .tot-row td { background: var(--teal); color: #fff; font-weight: 700; }
/* Jerarquia de las tres lineas de cierre: base (teal) -> bond (tinte suave) -> total final (teal fuerte). */
table.est-sheet .tot-bond td { background: var(--teal-100); color: var(--teal-dark); font-weight: 600; }
table.est-sheet .tot-bondtotal td { background: var(--teal-dark); color: #fff; font-weight: 800; border-top: 2px solid var(--teal-light); }
.est-cols { display: flex; gap: 1rem; flex-wrap: wrap; padding: .6rem; }
.est-cols fieldset { border: 1px solid var(--teal-100); border-radius: 8px; padding: .4rem .7rem; }
.est-cols legend { color: var(--teal-dark); font-weight: 700; font-size: .78rem; padding: 0 .3rem; }
.est-cols label { display: block; font-size: .8rem; }
.col-hidden { display: none; }
.btn-square { min-width: 0; padding: .3rem .5rem; }
table.est-sheet.hide-common .c-common { display: none; }
table.est-sheet.hide-prices .c-prices { display: none; }
table.est-sheet.hide-cost .c-cost { display: none; }
table.est-sheet.hide-prorate .c-prorate { display: none; }

/* Realce de las columnas de TOTALES (referencia Azure): banda vertical celeste claro en
   Total Price y Total Cost para ubicarlas de un vistazo. Aplica a las filas de datos
   (line items, subtotales de grupo, Subtotal del proyecto/con Allowance) y a la fila CLARA
   del monto "Payment & Performance Bond" (.tot-bond). Se EXCLUYEN las dos barras teal oscuro
   solido (TOTAL GENERAL = .tot-row, y Total with P&P Bond = .tot-bondtotal), para no romper
   la barra: ahi mandan sus reglas de fila (teal/teal-dark, texto blanco). Va despues de los
   fondos de fila para ganar por orden de fuente. Respeta el toggle (columna oculta => no se ve). */
table.est-sheet tr:not(.tot-row) td.col-total_price,
table.est-sheet tr:not(.tot-row) td.col-cost_total_ext,
table.est-sheet tr:not(.tot-row) td.col-total_pro,
table.est-sheet tr.tot-bond td.col-total_price,
table.est-sheet tr.tot-bond td.col-cost_total_ext,
table.est-sheet tr.tot-bond td.col-total_pro { background: var(--total-hl); color: var(--teal-dark); }

@media (max-width: 960px) {
  .apu-layout { flex-direction: column; }
  .apu-side { width: 100%; }
}

/* ------------------------------ Responsive ------------------------------- */
@media (max-width: 720px) {
  header.topbar { gap: .6rem; }
  header.topbar .user-chip { display: none; }
  main { margin: 1rem auto; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ================= INCERTIDUMBRE (Fase 0) — amarillo ==================== */
/* El amarillo (--uncertain-hl) se dispara EXCLUSIVAMENTE por el flag uncertain
   (ver .unc-cell agregada en el render). Marca SOLO celdas de PRECIO y CANTIDAD:
   - APU (apu.php): salary/price y qty de la fila con uncertain=1.
   - Estimado (estimate.php): Price unitario (estado efectivo) y Qty (flag propio).
   Va al FINAL para tener prioridad sobre otros fondos en las celdas que le tocan
   (precio/cantidad no llevan el celeste de totales, asi que no hay conflicto real).
   !important asegura la prioridad del amarillo en su celda por sobre fondos de fila. */
td.unc-cell { background: var(--uncertain-hl) !important; color: var(--text); }
/* En el APU las celdas contienen inputs/valores de catalogo: que el amarillo del td
   se vea a traves (input transparente) manteniendo el texto legible. */
.apu-rows td.unc-cell input,
.apu-rows td.unc-cell .cat-static { background: transparent; }

/* Celdas gesto-habilitadas (precio/cantidad): relativas para anclar el indicador. */
td.unc-target { position: relative; }
/* INDICADOR estilo Excel: triangulito rojo en la esquina superior derecha cuando
   la celda tiene nota (has-note), TENGA O NO amarillo (nota y color son independientes). */
td.unc-target.has-note::after {
  content: ""; position: absolute; top: 0; right: 0; width: 0; height: 0;
  border-top: 7px solid #c0392b; border-left: 7px solid transparent; pointer-events: none;
}

/* Popover flotante para editar la nota (clic derecho). */
.unc-pop {
  position: absolute; z-index: 1200; background: var(--surface); color: var(--text);
  border: 1px solid var(--teal); border-radius: 6px; padding: .5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.20); display: flex; flex-direction: column; gap: .45rem;
  min-width: 250px;
}
.unc-pop-in { width: 100%; box-sizing: border-box; padding: .35rem .5rem; border: 1px solid var(--border, #cbd5db); border-radius: 4px; font: inherit; }
.unc-pop-bar { display: flex; gap: .4rem; justify-content: flex-end; }

/* Tooltip propio de la nota (al hover de una celda con nota). */
.unc-tip {
  position: absolute; z-index: 1300; max-width: 280px; background: #1f2a30; color: #fff;
  padding: .35rem .55rem; border-radius: 4px; font-size: .82rem; line-height: 1.3;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); pointer-events: none; display: none; white-space: normal;
}
