:root {
  --bg: #f5f5f5;
  --surface: #fff;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #e0e0e0;
  --primary: #c0392b;
  --primary-dark: #a93226;
  --ok: #27ae60;
  --parcial: #e67e22;
  --error: #c0392b;
  --nav-bg: #1a1a1a;
  --nav-text: #f0f0f0;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

nav {
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 1rem;
  height: 48px;
}
nav .brand { font-weight: 700; font-size: 1rem; margin-right: 1.5rem; }
nav a { color: var(--nav-text); text-decoration: none; padding: 0.75rem 0.75rem; opacity: 0.75; font-size: 0.875rem; }
nav a:hover, nav a.active { opacity: 1; }
nav .logout { margin-left: auto; }

main {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

h2 { font-size: 1.5rem; margin: 0 0 1.5rem; }
h3 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }

.flash { padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; font-size: 0.9rem; }
.flash-success { background: #d5f5e3; border-left: 4px solid var(--ok); }
.flash-error { background: #fde8e8; border-left: 4px solid var(--error); }

/* Login */
.login-box {
  max-width: 380px;
  margin: 5rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2.5rem;
  text-align: center;
}
.login-box h1 { font-size: 1.75rem; margin: 0 0 0.5rem; }
.login-box p { color: var(--text-muted); margin: 0 0 1.5rem; }
.login-box label { display: none; }
.login-box input { width: 100%; padding: 0.6rem 0.75rem; margin-bottom: 1rem; border: 1px solid var(--border); border-radius: 4px; font-size: 1rem; }
.login-box button { width: 100%; background: var(--primary); color: #fff; border: none; border-radius: 4px; padding: 0.65rem; font-size: 1rem; cursor: pointer; }
.login-box button:hover { background: var(--primary-dark); }
.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 1rem; }

/* Cards dashboard */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1rem; }
.card-fecha { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.5rem; }
.local-row { display: flex; justify-content: space-between; align-items: center; padding: 0.25rem 0; gap: 0.5rem; font-size: 0.875rem; }
.local-row.ok { opacity: 1; }
.local-row.parcial { opacity: 0.75; }
.card-total { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px solid var(--border); font-size: 0.9rem; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 3px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: #d5f5e3; color: #1d8348; }
.badge-parcial { background: #fdebd0; color: #784212; }
.badge-error { background: #fde8e8; color: #922b21; }
.badge-agora_api { background: #d6eaf8; color: #1a5276; }
.badge-myagora_directo { background: #e8daef; color: #4a235a; }
.badge-myagora_historico { background: #fef9e7; color: #784212; }
.badge-manual { background: #fdfefe; color: #515a5a; border: 1px solid #aab7b8; }

/* Tables */
.runs-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.runs-table th { background: #f0f0f0; text-align: left; padding: 0.6rem 0.75rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.runs-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.runs-table tr:last-child td { border-bottom: none; }
.runs-table .mensaje { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.runs-table a { color: var(--primary); text-decoration: none; }

.estado-error td { background: #fef5f5; }
.estado-parcial td { background: #fffbf5; }

/* Forms */
.config-form section { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; }
.config-form label { display: block; font-weight: 600; font-size: 0.85rem; margin: 0.75rem 0 0.3rem; color: var(--text-muted); }
.config-form label:first-child { margin-top: 0; }
.config-form input, .config-form select, .config-form textarea {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border);
  border-radius: 4px; font-size: 0.9rem; font-family: inherit;
  background: var(--surface); color: var(--text);
}
.config-form input:focus, .config-form select:focus, .config-form textarea:focus {
  outline: none; border-color: var(--primary);
}
.config-form textarea { resize: vertical; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.set-indicator { font-weight: 400; color: var(--ok); font-size: 0.8rem; margin-left: 0.5rem; }

/* Filter form */
.filter-form { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-form label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; }
.filter-form select { padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; }

/* Buttons */
.btn { display: inline-block; padding: 0.5rem 1.25rem; border: 1px solid var(--border); border-radius: 4px; text-decoration: none; color: var(--text); background: var(--surface); cursor: pointer; font-size: 0.875rem; font-family: inherit; }
.btn:hover { background: #f0f0f0; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.actions { margin-top: 1.5rem; }

/* Facturación */
.tabla-scroll { width: 100%; overflow-x: auto; margin-bottom: 1rem; }
.fact-table th.num, .fact-table td.num, .em-table th.num { text-align: right; }
.fact-table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.fact-table tr.fila-activa td { background: #fdf2f0; }
.fact-table tfoot td { font-weight: 700; border-top: 2px solid var(--text); background: #fafafa; }
.fact-table td.dia { white-space: nowrap; }
.muted { color: var(--text-muted); font-size: 0.8rem; }
.info-btn { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 6px; padding: 0; border: 1.5px solid #9a9a9a; border-radius: 50%; background: transparent; color: #7a7a7a; font: italic 700 10px/1 Georgia, "Times New Roman", serif; cursor: pointer; vertical-align: 1px; }
.info-btn:hover, .info-btn:focus-visible { border-color: var(--text); color: var(--text); outline: none; }
.info-btn.info-aviso { border-color: var(--parcial); color: var(--parcial); }
.info-btn.info-demo { cursor: default; margin: 0 2px; }
.info-pop { position: fixed; z-index: 50; max-width: 280px; padding: 0.5rem 0.7rem; background: #1a1a1a; color: #fff; border-radius: 6px; font-size: 0.8rem; line-height: 1.4; white-space: pre-line; box-shadow: 0 4px 14px rgba(0,0,0,0.18); pointer-events: none; }
.input-celda { width: 7.5rem; padding: 0.3rem 0.4rem; border: 1px solid var(--border); border-radius: 4px; text-align: right; font: inherit; }
.input-celda:focus { outline: none; border-color: var(--primary); }
.input-celda.input-error { border-color: var(--error); background: #fde8e8; }

/* Cabecera, columna del día y total del mes fijos al hacer scroll dentro de la tabla */
.tabla-fija { max-height: 70vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.tabla-fija .fact-table { overflow: visible; border: none; border-radius: 0; border-collapse: separate; border-spacing: 0; }
.tabla-fija .fact-table thead th { position: sticky; top: 0; z-index: 2; background: #f0f0f0; box-shadow: inset 0 -1px 0 var(--border); }
.tabla-fija .fact-table tfoot td { position: sticky; bottom: 0; z-index: 2; border-top: none; box-shadow: inset 0 2px 0 var(--text); }
.tabla-fija .fact-table td:first-child, .tabla-fija .fact-table th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: inset -1px 0 0 var(--border); }
.tabla-fija .fact-table thead th:first-child, .tabla-fija .fact-table tfoot td:first-child { z-index: 3; }
.tabla-fija .fact-table thead th:first-child { background: #f0f0f0; }
.tabla-fija .fact-table tfoot td:first-child { background: #fafafa; }
.detalle-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1.5rem; }
.detalle-head h3 { margin: 0; }
.detalle-acciones { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.75rem 0; }
.mes-form input { padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font: inherit; }

/* Entrada manual múltiple */
.em-table input, .em-table select { width: 100%; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font: inherit; background: var(--surface); }
.em-table .em-ventas { text-align: right; min-width: 7rem; }
.em-table .em-fecha { min-width: 9rem; }
.em-table .em-acciones { white-space: nowrap; width: 1%; }
.em-table tr.fila-error td { background: #fde8e8; }
.btn:disabled { opacity: 0.6; cursor: wait; }

@media (max-width: 600px) {
  nav { padding: 0 0.5rem; overflow-x: auto; }
  nav .brand { display: none; }
  main { padding: 0 1rem; }
  .card-grid { grid-template-columns: 1fr; }
}
