/* ────────────────────────────────────────────────────────────────────────────
   Aisprotek ERP — hoja de estilo única, sin build.
   La paleta viene del presupuestador que ya usaba el equipo, para que la
   herramienta les resulte reconocible desde el primer día.
   ──────────────────────────────────────────────────────────────────────────── */

:root {
  --navy: #1C4F6B;
  --navy-dark: #143a50;
  --navy-light: #e8f2f7;
  --steel: #6B7B8A;
  --steel-light: #f0f3f5;
  --accent: #2E8B6E;
  --accent-light: #e6f5f1;
  --text: #1a2a35;
  --text-muted: #5a6e7a;
  --border: #d0dce4;
  --white: #ffffff;
  --bg: #f2f6f9;
  --danger: #c0392b;
  --danger-light: #fdecea;
  --warning: #e67e22;
  --warning-light: #fdf1e5;
  --success: #27ae60;
  --success-light: #e8f8ef;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(28, 79, 107, 0.10);
  --shadow-lg: 0 8px 32px rgba(28, 79, 107, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Cabecera y navegación ────────────────────────────────────────────────── */

.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
.topbar-inner { display: flex; align-items: center; gap: 14px; padding: 10px 20px; max-width: 1400px; margin: 0 auto; }
.topbar-logo { height: 30px; filter: brightness(0) invert(1); }
.topbar-brand { font-size: 15px; font-weight: 700; letter-spacing: 0.4px; flex: 1; color: #fff; }
.topbar-brand:hover { text-decoration: none; }
.topbar-user { font-size: 13px; opacity: 0.85; }
.topbar-user form { display: inline; }
.topbar-logout { background: rgba(255,255,255,0.15); border: none; color: #fff; font-size: 12px; padding: 5px 11px; border-radius: 20px; cursor: pointer; font-family: inherit; margin-left: 8px; }
.topbar-logout:hover { background: rgba(255,255,255,0.28); }

.nav { background: var(--navy-dark); }
.nav-inner { display: flex; max-width: 1400px; margin: 0 auto; overflow-x: auto; }
.nav a {
  padding: 12px 18px; font-size: 13px; font-weight: 600; color: rgba(255,255,255,0.65);
  text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap; border-bottom: 3px solid transparent;
}
.nav a:hover { color: #fff; text-decoration: none; }
.nav a.active { color: #fff; border-bottom-color: #fff; }

/* ── Contenedor ───────────────────────────────────────────────────────────── */

.page { max-width: 1400px; margin: 0 auto; padding: 22px 20px 60px; }
.page-narrow { max-width: 820px; }
.page-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--navy); flex: 1; }
.page-subtitle { font-size: 13px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }

/* ── Tarjetas ─────────────────────────────────────────────────────────────── */

.card { background: var(--white); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); border: 1px solid rgba(28,79,107,0.07); }
.card-title { font-size: 11px; font-weight: 700; color: var(--navy); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.card-title::before { content: ''; width: 3px; height: 14px; background: var(--navy); border-radius: 2px; }
.card-title .spacer { flex: 1; }
.card--flush { padding: 0; overflow: hidden; }
.card--flush .card-title { padding: 18px 18px 0; margin-bottom: 10px; }

/* ── Formularios ──────────────────────────────────────────────────────────── */

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11px; font-weight: 700; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.05em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; color: var(--text); background: var(--white); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(28,79,107,0.12);
}
.field textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field .error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.field input.invalid, .field select.invalid { border-color: var(--danger); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 6px 12px; border-radius: 20px; font-size: 13px; font-weight: 500; cursor: pointer; border: 1.5px solid var(--border); background: #fff; color: var(--text-muted); user-select: none; }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ── Botones ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-block; padding: 10px 18px; border-radius: var(--radius-sm); font-size: 14px;
  font-weight: 700; cursor: pointer; border: 1.5px solid transparent; font-family: inherit;
  text-align: center; line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); color: #fff; }
.btn-secondary { background: #fff; color: var(--navy); border-color: var(--navy); }
.btn-secondary:hover { background: var(--navy-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--steel-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a5322a; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { display: block; width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Tablas ───────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  background: var(--steel-light); color: var(--text-muted); text-align: left; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 10px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid #eef2f5; vertical-align: middle; }
table.data tbody tr:hover { background: #fafcfd; }
table.data .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data .acciones { text-align: right; white-space: nowrap; }
table.data tr.grupo td { background: var(--navy-light); font-weight: 700; color: var(--navy); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border); background: #fafcfd; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty p { margin-bottom: 14px; }

/* ── Distintivos de estado ────────────────────────────────────────────────── */

.badge { display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.badge-gris { background: var(--steel-light); color: var(--text-muted); }
.badge-azul { background: var(--navy-light); color: var(--navy); }
.badge-verde { background: var(--success-light); color: #1a6b50; }
.badge-ambar { background: var(--warning-light); color: #a15c12; }
.badge-rojo { background: var(--danger-light); color: var(--danger); }

/* ── Avisos ───────────────────────────────────────────────────────────────── */

.alerta { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; border-left: 4px solid; }
.alerta-ok { background: var(--success-light); border-color: var(--success); color: #17603f; }
.alerta-error { background: var(--danger-light); border-color: var(--danger); color: #8e2820; }
.alerta-aviso { background: var(--warning-light); border-color: var(--warning); color: #8a4d0d; }
.alerta-info { background: var(--navy-light); border-color: var(--navy); color: var(--navy); }
.alerta ul { margin: 6px 0 0 18px; }

/* ── Panel de indicadores ─────────────────────────────────────────────────── */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: #fff; border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-left: 4px solid var(--navy); }
.kpi-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-valor { font-size: 26px; font-weight: 700; color: var(--navy); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-nota { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi--verde { border-left-color: var(--success); }
.kpi--verde .kpi-valor { color: #1a6b50; }
.kpi--ambar { border-left-color: var(--warning); }
.kpi--ambar .kpi-valor { color: #a15c12; }
.kpi--rojo { border-left-color: var(--danger); }
.kpi--rojo .kpi-valor { color: var(--danger); }

/* ── Resumen de totales ───────────────────────────────────────────────────── */

.totales { background: var(--navy); color: #fff; border-radius: var(--radius); padding: 16px 20px; }
.totales-fila { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; opacity: 0.85; }
.totales-total { display: flex; justify-content: space-between; padding: 10px 0 2px; border-top: 1px solid rgba(255,255,255,0.25); margin-top: 6px; font-size: 22px; font-weight: 700; }

/* ── Editor de líneas ─────────────────────────────────────────────────────── */

.lineas-cab, .linea {
  display: grid;
  grid-template-columns: 110px 130px 80px 1fr 90px 105px 110px 38px;
  gap: 8px; align-items: center;
}
.lineas-cab { padding-bottom: 8px; border-bottom: 1px solid var(--border); font-size: 10px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.linea { padding: 7px 0; border-bottom: 1px solid #f0f3f5; }
.linea select, .linea input { width: 100%; font-size: 14px; padding: 7px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; background: #fff; }
.linea input[readonly] { background: var(--steel-light); color: var(--text-muted); }
.linea .importe { text-align: right; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; padding-right: 4px; }
.linea-quitar { width: 32px; height: 32px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; color: #aaa; font-size: 18px; cursor: pointer; line-height: 1; }
.linea-quitar:hover { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }
.linea.es-libre .solo-pieza { visibility: hidden; }
.anadir-linea { width: 100%; margin-top: 10px; padding: 10px; border: 1.5px dashed var(--border); border-radius: var(--radius-sm); background: none; color: var(--navy); font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit; }
.anadir-linea:hover { background: var(--navy-light); }
.aviso-tarifa { font-size: 12px; color: var(--warning); }

/* ── Filtros ──────────────────────────────────────────────────────────────── */

.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filtros .field { margin-bottom: 0; }
.filtros input, .filtros select { min-width: 180px; }

/* ── Autenticación ────────────────────────────────────────────────────────── */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--navy); }
.login-card { background: #fff; border-radius: var(--radius); padding: 32px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { display: block; height: 44px; margin: 0 auto 8px; }
.login-titulo { text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 24px; letter-spacing: 0.05em; text-transform: uppercase; font-weight: 700; }

/* ── Utilidades ───────────────────────────────────────────────────────────── */

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-family: 'Consolas', 'Menlo', monospace; font-size: 12px; word-break: break-all; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.negativo { color: var(--danger); }
.positivo { color: #1a6b50; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.spacer { flex: 1; }
.oculto { display: none !important; }

/* ── Móvil ────────────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  .lineas-cab { display: none; }
  .linea {
    grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  .linea > * { min-width: 0; }
  .linea .importe { text-align: left; }
}

@media (max-width: 640px) {
  .page { padding: 16px 12px 50px; }
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .page-title { font-size: 19px; }
  .card { padding: 14px; }
  .filtros input, .filtros select { min-width: 0; width: 100%; }
  .filtros .field { width: 100%; }
}

/* ── Panel: calendario de obras ─────────────────────────────────────────── */
.cal-mes { min-width: 130px; text-align: center; font-size: 13px; text-transform: none; letter-spacing: 0; }
.cal { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--white); }
.cal-cabecera { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--steel-light); font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.cal-cabecera div { padding: 4px 5px; font-size: 10px; }
.cal-semana { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: auto; border-top: 1px solid var(--border); }
.cal-semana > .cal-dia { min-height: 40px; padding: 2px 5px; border-left: 1px solid var(--border); font-size: 11px; color: var(--text-muted); }
.cal-semana > .cal-dia:first-child { border-left: 0; }
.cal-dia--finde { background: #fafbfc; }
.cal-dia--fuera { color: #aab7c0; background: var(--steel-light); }
.cal-dia--hoy span { display: inline-block; min-width: 22px; text-align: center; background: var(--navy); color: #fff; border-radius: 11px; font-weight: 700; }
.cal-obra { display: block; z-index: 1; margin: 17px 2px 1px; padding: 0 5px; font-size: 10px; line-height: 1.5; background: var(--navy-light); color: var(--navy); border-left: 4px solid var(--navy); border-radius: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-decoration: none; }
.cal-obra:hover { background: #d6e8f1; }
.cal-obra--ejecucion { background: var(--success-light); color: #1a6b50; border-left-color: var(--success); }
.cal-obra--retraso { background: var(--danger-light); color: var(--danger); border-left-color: var(--danger); }
.cal-obra--desde-antes { margin-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.cal-obra--sigue { margin-right: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.cal-leyenda { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin: 0 4px 0 12px; }
.cal-leyenda--abierto { background: var(--navy-light); border-left: 3px solid var(--navy); }
.cal-leyenda--ejecucion { background: var(--success-light); border-left: 3px solid var(--success); }
.cal-leyenda--retraso { background: var(--danger-light); border-left: 3px solid var(--danger); }

/* ── Panel: gráficos de facturación ─────────────────────────────────────── */
.grafico-barras { display: flex; align-items: stretch; gap: 6px; height: 220px; }
.barra { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.barra-valor { font-size: 10px; color: var(--text-muted); height: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.barra-relleno { display: block; width: 100%; background: var(--navy); border-radius: 4px 4px 0 0; flex: 0 0 auto; max-height: calc(100% - 38px); }
.barra:hover .barra-relleno { background: var(--accent); }
.barra--fuera { opacity: 0.35; }
.barra-etiqueta { font-size: 11px; color: var(--text-muted); height: 22px; line-height: 22px; border-top: 1px solid var(--border); width: 100%; text-align: center; }
.grafico-hbarras { display: flex; flex-direction: column; gap: 9px; }
.hbarra { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbarra-nombre { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hbarra-pista { background: var(--steel-light); border-radius: 4px; height: 14px; overflow: hidden; }
.hbarra-relleno { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.hbarra-valor { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--navy); }
@media (max-width: 720px) {
  .hbarra { grid-template-columns: 1fr auto; }
  .hbarra-pista { grid-column: 1 / -1; order: 3; }
}

/* ── Panel: gráficos a la izquierda, calendario (compacto) a la derecha ──── */
.panel-doble { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.panel-izq, .panel-der { min-width: 0; }
.graficos-pila { display: flex; flex-direction: column; }
.panel-doble .grafico-barras { height: 170px; }
@media (max-width: 1000px) { .panel-doble { grid-template-columns: 1fr; } }
