:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5b6470;
  --line: #d9dde3;
  --brand: #1f4e79;
  --brand-2: #2e75b6;
  --ok: #2e7d32;
  --warn: #b26a00;
  --bad: #c62828;
  --ok-bg: #e6f4ea;
  --warn-bg: #fff4e0;
  --bad-bg: #fdecea;
  --radius: 6px;
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; }
a { color: var(--brand-2); }

/* barra superior */
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 52px; background: var(--brand); color: #fff; }
.topbar .brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.topbar .brand small { font-weight: 400; opacity: .8; margin-left: 6px; }
.topbar select { background: #fff; color: var(--text); border: 0; border-radius: 4px; padding: 5px 8px; }
.topbar .spacer { flex: 1; }
.topbar .user { font-size: 13px; opacity: .9; }
.topbar button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); border-radius: 4px; padding: 4px 10px; cursor: pointer; }
.topbar button:hover { background: rgba(255,255,255,.12); }

/* pestañas tipo Excel */
.tabs { display: flex; gap: 2px; padding: 6px 12px 0; background: #e8eaed; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 1px solid var(--line); border-bottom: 0; background: #f6f7f8; padding: 6px 12px; border-radius: 6px 6px 0 0; cursor: pointer; white-space: nowrap; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand-2); }
.tabs button.special { color: var(--brand); }

main { padding: 12px 16px 24px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.toolbar h2 { margin: 0 12px 0 0; font-size: 17px; }
.toolbar input[type=search] { padding: 6px 10px; border: 1px solid var(--line); border-radius: 4px; min-width: 240px; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 4px; cursor: pointer; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.hint { color: var(--muted); font-size: 12.5px; }

.grid-wrap { height: calc(100vh - 170px); min-height: 380px; }
.ag-theme-balham { --ag-font-family: Calibri, "Segoe UI", Arial, sans-serif; --ag-font-size: 12.5px; --ag-header-background-color: #1f4e79; --ag-header-foreground-color: #fff; --ag-header-cell-hover-background-color: #1f4e79; --ag-header-cell-moving-background-color: #1f4e79; --ag-header-column-separator-display: block; --ag-header-column-separator-color: rgba(255,255,255,.3); --ag-header-column-resize-handle-color: rgba(255,255,255,.55); --ag-borders: solid 1px; --ag-border-color: #c8c8c8; --ag-row-border-color: #dcdcdc; --ag-cell-horizontal-padding: 6px; }
.ag-theme-balham .ag-header-cell-label { white-space: normal; line-height: 1.15; }
.ag-theme-balham .ag-header-cell-text { white-space: normal; }
.ag-theme-balham .ag-header-group-cell { font-weight: 700; justify-content: center; }
.ag-theme-balham .ag-header-group-cell-label { justify-content: center; }
/* encabezado completo (grupos, etapas y columnas) en azul con letra blanca, también al seleccionar o arrastrar */
.ag-theme-balham .ag-header-group-cell,
.ag-theme-balham .ag-header-group-cell:hover,
.ag-theme-balham .ag-header-group-cell.ag-header-cell-moving { background: #1f4e79 !important; color: #fff !important; border-left: 1px solid rgba(255,255,255,.3); }
.ag-theme-balham .ag-header .ag-icon { color: inherit; }
.ag-theme-balham .ag-header-cell:focus-visible, .ag-theme-balham .ag-header-group-cell:focus-visible { outline: 2px solid #9ec5ef; outline-offset: -2px; }
.ag-theme-balham .ag-cell.calc { font-style: italic; }
.ag-theme-balham .ag-cell.dirty { outline: 2px solid #f0b400; outline-offset: -2px; }

/* hoja estática (réplica de celdas Excel) */
.sheet-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); max-height: calc(100vh - 150px); }
table.xl { border-collapse: collapse; table-layout: fixed; font-size: 13px; }
table.xl td { border: 1px solid transparent; padding: 2px 5px; height: 20px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; vertical-align: middle; }
table.xl td.gridline { border-color: #eceff2; }
table.xl td.wrap { white-space: normal; }
table.xl td.edit { cursor: text; box-shadow: inset 0 0 0 1px #9ec5ef; }
table.xl td.edit:hover { background-image: linear-gradient(rgba(46,117,182,.08), rgba(46,117,182,.08)); }
table.xl td.calcv { color: #0b3d6b; }
table.xl td input { width: 100%; border: 0; padding: 0; font: inherit; background: #fffbe6; }

/* tarjetas y tablas de reportes */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.card h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.card .big { font-size: 20px; font-weight: 700; }
.card .row { display: flex; justify-content: space-between; font-size: 13px; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 13px; }
table.list th, table.list td { border: 1px solid var(--line); padding: 4px 7px; text-align: left; }
table.list th { background: #f2f4f7; position: sticky; top: 0; z-index: 1; }
table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.diferencia { background: var(--bad-bg); color: var(--bad); }
.pill.sin_softland { background: var(--warn-bg); color: var(--warn); }
td.ok { background: var(--ok-bg); }
td.diferencia { background: var(--bad-bg); }
td.sin_softland { background: var(--warn-bg); }
.scroll { max-height: calc(100vh - 330px); overflow: auto; border: 1px solid var(--line); }
section.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
section.panel h3 { margin: 0 0 10px; font-size: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 14px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
.form-grid input, .form-grid select, textarea { border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; color: var(--text); }
textarea { width: 100%; font-family: Consolas, monospace; font-size: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.checks label { flex-direction: row; align-items: center; gap: 5px; color: var(--text); }

/* login */
.login { max-width: 360px; margin: 12vh auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px; }
.login h1 { font-size: 20px; margin: 0 0 4px; color: var(--brand); }
.login p { margin: 0 0 18px; color: var(--muted); }
.login label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.login input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; margin-top: 4px; }
.login .btn { width: 100%; padding: 9px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* gráfico */
.bars { display: grid; grid-template-columns: max-content 1fr max-content; gap: 6px 10px; align-items: center; max-width: 900px; }
.bars .bar { height: 18px; background: var(--brand-2); border-radius: 3px; }

/* editor de fecha con calendario */
.date-editor { display: flex; height: 100%; background: #fff; }
.date-editor input { flex: 1; min-width: 0; border: 0; padding: 0 4px; font: inherit; }
.date-editor button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 6px; }
.date-editor button:hover { color: var(--bad); }

/* diálogos */
dialog.modal { border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; width: min(560px, 92vw); color: var(--text); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .35); }
dialog.modal h3 { margin: 0 0 4px; font-size: 16px; color: var(--brand); }
dialog.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.form-grid label[hidden] { display: none; }

#toast { position: fixed; right: 16px; bottom: 16px; max-width: 420px; padding: 10px 14px; border-radius: 6px; background: #263238; color: #fff; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 50; }
#toast.show { opacity: 1; transform: none; }
#toast.error { background: var(--bad); }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px; }
  .topbar .brand small { display: none; }
  main { padding: 10px 16px; }
  .toolbar input[type=search] { min-width: 0; width: 100%; }
}
