:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #1c2434;
  --muted: #6b7688;
  --line: #e3e8f0;
  --brand: #2b4c7e;
  --brand-2: #3d6fb4;
  --accent: #1f9d76;
  --warn: #d97a1a;
  --danger: #c0392b;
  --sidebar: #16233a;
  --shadow: 0 1px 3px rgba(16, 28, 48, .08), 0 8px 24px rgba(16, 28, 48, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
}

.layout { display: flex; min-height: 100vh; }

/* Sidebar ---------------------------------------------------------- */
.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar);
  color: #dbe4f0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  display: grid; place-items: center;
  font-weight: 700; letter-spacing: .5px; color: #fff;
}
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 15px; color: #fff; }
.brand-text small { color: #8fa2bd; font-size: 11px; }
.sidebar nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  text-align: left;
  background: transparent;
  border: 0;
  color: #c3cfe0;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--brand-2); color: #fff; font-weight: 600; }
.nav-group {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #6f83a3;
  padding: 14px 12px 6px;
  font-weight: 600;
}
.nav-group:first-child { padding-top: 4px; }
.sidebar-foot { margin-top: auto; padding: 14px 18px; font-size: 11px; color: #7d8fac; border-top: 1px solid rgba(255,255,255,.08); }

/* Contenido -------------------------------------------------------- */
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; padding: 22px 26px 14px;
}
.topbar h1 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); margin: 4px 0 0; font-size: 12.5px; }
.view { padding: 8px 26px 40px; }

/* Tarjetas --------------------------------------------------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow);
}
.card .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.card .value { font-size: 22px; font-weight: 700; margin-top: 8px; }
.card .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.value.pos { color: var(--accent); }
.value.neg { color: var(--danger); }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-body { padding: 16px; }
.panel-body.pad0 { padding: 0; }

/* Formularios y controles ----------------------------------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
input, select, textarea, button { font-family: inherit; font-size: 13.5px; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  background: #fff; color: var(--ink); min-width: 120px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(61,111,180,.25); border-color: var(--brand-2); }
button.btn {
  border: 1px solid var(--brand-2); background: var(--brand-2); color: #fff;
  border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 600;
}
button.btn:hover { background: var(--brand); border-color: var(--brand); }
button.btn.ghost { background: #fff; color: var(--brand); }
button.btn.ghost:hover { background: #eef3fb; }
button.btn.small { padding: 6px 10px; font-size: 12.5px; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Tablas ----------------------------------------------------------- */
.table-wrap { overflow: auto; max-height: 68vh; }
table { border-collapse: collapse; width: 100%; min-width: max-content; font-size: 13px; }
thead th {
  position: sticky; top: 0; background: #f7f9fc; z-index: 1;
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted);
  white-space: nowrap;
}
tbody td { padding: 9px 12px; border-bottom: 1px solid #cfd8e5; white-space: nowrap; }
thead th, tbody td { border-right: 1px solid #eef1f7; }
thead th:last-child, tbody td:last-child { border-right: 0; }
tbody tr:hover { background: #f7faff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }
tr.click { cursor: pointer; }

/* Primera columna fija (tabla de Obras) ---------------------------- */
table.sticky-first td:first-child,
table.sticky-first th:first-child {
  position: sticky; left: 0; z-index: 2;
  background: var(--manual);
  box-shadow: 1px 0 0 var(--line), 6px 0 8px -8px rgba(16,28,48,.45);
}
table.sticky-first thead th:first-child { z-index: 4; background: #f7f9fc; }
table.sticky-first tbody tr:hover td:first-child { background: var(--manual-hover); }

/* Libro diario: columna Concepto fija + columnas compactas --------- */
table.freeze-concepto th, table.freeze-concepto td { padding: 8px 9px; }
table.freeze-concepto td:nth-child(2),
table.freeze-concepto th:nth-child(2) {
  position: sticky; left: 0; z-index: 2;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line), 6px 0 8px -8px rgba(16,28,48,.45);
}
table.freeze-concepto thead th:nth-child(2) { z-index: 4; background: #f7f9fc; }
table.freeze-concepto tbody tr:hover td:nth-child(2) { background: #f7faff; }
.c-clip { display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; max-width: 100%; }
.c-fecha { min-width: 74px; }
.c-concepto { max-width: 240px; }
.c-ref { max-width: 120px; }
.c-obra { max-width: 150px; }
.c-terc { max-width: 120px; }
.c-cuenta { max-width: 110px; }
.c-nota { max-width: 150px; }
.t-num { color: var(--danger); }
.t-pos { color: var(--accent); }
.table-foot { padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); }
td.acciones { white-space: nowrap; }
td.acciones .btn { margin-right: 6px; }
td.acciones .btn:last-child { margin-right: 0; }
button.btn.ghost.danger { color: var(--danger); border-color: #e6b3ab; }
button.btn.ghost.danger:hover { background: #fdeeea; border-color: var(--danger); }

/* Pivote ----------------------------------------------------------- */
.pivot td:first-child, .pivot th:first-child {
  position: sticky; left: 0; background: #f7f9fc; z-index: 2; font-weight: 600;
}
.pivot thead th:first-child { z-index: 3; }

/* Modal ------------------------------------------------------------ */
.overlay {
  position: fixed; inset: 0; background: rgba(16,28,48,.45);
  display: grid; place-items: center; padding: 24px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 14px; box-shadow: 0 24px 60px rgba(0,0,0,.3);
  width: min(900px, 100%); max-height: 90vh; display: flex; flex-direction: column;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-grid .span2 { grid-column: span 2; }
.error-text { color: var(--danger); font-size: 12.5px; }

/* Sub-tabs (detalle obra) ------------------------------------------ */
.subtabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.subtab {
  border: 1px solid var(--line); background: #fff; border-radius: 20px;
  padding: 6px 14px; cursor: pointer; font-size: 12.5px;
}
.subtab.active { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: #16233a; color: #fff;
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: all .2s; pointer-events: none; z-index: 90;
  max-width: 380px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.ok { background: #137a5a; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; background: #eef3fb; color: var(--brand); font-size: 11px; }

/* ================================================================= */
/* Convencion de colores: manual (celeste) vs calculado (naranja)    */
/* ================================================================= */
:root {
  --manual: #e6f0ff;
  --manual-hover: #d5e6ff;
  --calc: #ffe7c9;
  --calc-hover: #ffd9a8;
  --calc-line: #e8890c;
  --manual-line: #3d6fb4;
}

.cell-manual { background: var(--manual); }
.cell-calc { background: var(--calc); }
tbody tr:hover .cell-manual { background: var(--manual-hover); }
tbody tr:hover .cell-calc { background: var(--calc-hover); }

/* Inputs = carga manual */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  background: var(--manual);
}
input[readonly]:not([type="checkbox"]):not([type="radio"]), select[disabled], input[disabled] {
  background: var(--calc);
}

/* Tarjetas: borde segun tipo */
.card.manual { border-left: 4px solid var(--manual-line); }
.card.calc { border-left: 4px solid var(--calc-line); }

/* Chip para valores calculados en formularios */
.calc-chip {
  display: inline-block;
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--calc);
  border: 1px solid var(--calc-line);
  font-weight: 600;
}

/* Leyenda */
.legend {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  padding: 0 26px 12px;
  font-size: 12px;
  color: var(--muted);
}
.legend span { display: inline-flex; gap: 7px; align-items: center; }
.legend i {
  width: 15px; height: 15px; border-radius: 4px;
  display: inline-block; border: 1px solid rgba(0,0,0,.12);
}
.legend i.sw-manual { background: var(--manual); }
.legend i.sw-calc { background: var(--calc); border-color: var(--calc-line); }

/* Balance mensual: ingreso (verde) vs egreso (rojo) ----------------- */
.cell-ing { background: #e6f7ee; }
.cell-egr { background: #fdeaea; }
thead th.th-ing { color: #16603c; }
thead th.th-egr { color: #9b2c2c; }
.cell-tot-ing { background: #bfe9d0; font-weight: 600; }
.cell-tot-egr { background: #f6c6c6; font-weight: 600; }
tbody tr:hover .cell-ing { background: #d6f0e2; }
tbody tr:hover .cell-egr { background: #f8dada; }
tbody tr:hover .cell-tot-ing { background: #a9e0c0; }
tbody tr:hover .cell-tot-egr { background: #f0b3b3; }
tr.tot-row td { border-top: 2px solid var(--line); font-weight: 700; }
.mini-legend { display:flex; gap:14px; align-items:center; flex-wrap:wrap; font-size:12px; color:var(--muted); }
.mini-legend i { width:14px; height:14px; border-radius:4px; display:inline-block; border:1px solid rgba(0,0,0,.12); vertical-align:-2px; margin-right:5px; }

/* Balance para contador: headers largos en varias lineas ------------- */
table.balance-contador thead th {
  white-space: normal;
  vertical-align: bottom;
  min-width: 105px;
  max-width: 190px;
}
table.balance-contador thead th:first-child { min-width: 90px; }

/* Encabezado compacto (IVA / AFIP) --------------------------------- */
body.compact-head .topbar { padding: 10px 26px 6px; align-items: center; }
body.compact-head .topbar h1 { font-size: 18px; }
body.compact-head .topbar .muted { display: none; }
body.compact-head .legend { padding-bottom: 6px; }
body.compact-head .view { padding-bottom: 8px; }
body.compact-head .table-foot { padding: 6px 16px; }
.iva-panel { margin-bottom: 0; }
.panel-head.compact { padding: 8px 12px; flex-wrap: wrap; }
.panel-head.compact input, .panel-head.compact select { padding: 5px 8px; }
.mini-stats { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mini-stat {
  display: flex; flex-direction: column; padding: 4px 10px;
  border: 1px solid var(--line); border-left: 4px solid var(--calc-line);
  border-radius: 8px; background: var(--panel); line-height: 1.25;
}
.mini-stat span { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.mini-stat strong { font-size: 15px; }
.info-tip {
  width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center;
  background: #eef3fb; color: var(--brand); font-size: 12px; font-weight: 700; cursor: help;
}

/* Login ------------------------------------------------------------- */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--sidebar); }
.login-card {
  background: #fff; padding: 30px 28px; border-radius: 14px;
  width: min(360px, 92vw); box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.login-card .brand-logo { margin: 0 auto 12px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-card .field { margin-top: 14px; }
.login-card .field input { width: 100%; }
.login-card .btn { width: 100%; margin-top: 18px; }

/* Usuario en la barra lateral --------------------------------------- */
.user-box { display: flex; flex-direction: column; gap: 6px; }
.user-name { color: #fff; font-weight: 600; font-size: 13px; }
.user-actions { display: flex; gap: 12px; }
.link-btn {
  background: transparent; border: 0; padding: 0; cursor: pointer;
  color: #9db0cc; font-size: 11.5px; text-decoration: underline;
}
.link-btn:hover { color: #fff; }

/* Mostrar / ocultar contrasena ------------------------------------- */
.pass-wrap { position: relative; display: block; }
.pass-wrap input { width: 100%; padding-right: 40px; }
.pass-eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; cursor: pointer; padding: 4px;
  color: var(--muted); line-height: 0; border-radius: 6px;
}
.pass-eye:hover { color: var(--ink); background: rgba(0,0,0,.05); }
.pass-eye svg { width: 18px; height: 18px; display: block; }
.pass-eye .ic-off { display: none; }
.pass-eye.activo .ic-on { display: none; }
.pass-eye.activo .ic-off { display: block; }
.pill { display:inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; background:#eef7f1; color:#1f7a56; }
.pill.off { background:#fdeeea; color:#b8452f; }
.pill.gray { background:#eef0f4; color:#68738a; }
.stack { display:flex; flex-direction:column; gap:2px; }
.stack small { color: var(--muted); }
.actions { display:flex; gap:6px; justify-content:flex-end; }

/* Combobox con busqueda ------------------------------------------- */
.combo { position: relative; }
.combo-input { width: 100%; min-width: 160px; }
.combo-list {
  position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 4px);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  max-height: 240px; overflow: auto; box-shadow: 0 10px 30px rgba(16,28,48,.18);
}
.combo-list div { padding: 7px 10px; cursor: pointer; font-size: 13px; }
.combo-list div:hover { background: #eef3fb; }
.combo-list .empty { padding: 8px 10px; color: var(--muted); text-align: left; }
.combo-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
