:root {
  --blue: #2f6fed;
  --blue-dark: #1e4fb8;
  --orange: #e0913f;
  --green: #3aa876;
  --red: #d9483f;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e2e6ec;
  --text: #1f2937;
  --muted: #6b7280;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; height: 60px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--blue-dark); text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: 14px;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--blue); color: #fff; }
.nav a.nav-leon.active { background: #92d050; color: #1f2937; }
.nav a.nav-mty.active { background: #ffc000; color: #1f2937; }
.nav a.nav-qro.active { background: #00b0f0; color: #1f2937; }
.user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.user-box a { color: var(--blue); text-decoration: none; }

.content { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 32px 0 12px; }
.muted { color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-ok { background: #e6f6ee; color: #1a7a4a; }
.flash-error { background: #fbeaea; color: #a4241c; }

.page-header { margin-bottom: 20px; }
.totales-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.totales-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 20px; min-width: 160px;
}
.totales-card-title { font-size: 13px; color: var(--muted); }
.totales-card-value { font-size: 26px; font-weight: 700; }
.totales-card-sub { font-size: 12px; color: var(--muted); }

.toolbar { display: flex; align-items: center; gap: 16px; margin: 16px 0; flex-wrap: wrap; }
.total-col { font-weight: 700; }

.semanas-dropdown { position: relative; display: inline-block; margin: 16px 0; }
.semanas-dropdown .semanas-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.semanas-toggle .caret { color: var(--muted); font-size: 11px; }
.semanas-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12); padding: 16px; width: 460px; max-width: 90vw;
}
.semanas-panel.hidden { display: none; }
.semanas-panel .hint { margin-bottom: 4px; }
.semanas-checks {
  display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 10px 0 16px;
  max-height: 260px; overflow-y: auto;
}
.semanas-checks .checkbox-label { font-size: 13px !important; width: calc(50% - 9px); }
.semanas-checks .checkbox-label:has(input:disabled) { opacity: 0.4; cursor: not-allowed; }

.data-table th.col-group-header { text-align: center; border-left: 3px solid #8895ab; }
.block-start { border-left: 3px solid #8895ab; }
.data-table th.header-center { text-align: center; }

.val-pos { background: #c9f0d8; color: var(--text); }
.val-neg { background: #f9cfcb; color: var(--text); }

/* Colores tipo Excel por almacén (también usados en Historial semanal y su gráfica). */
.data-table th.hcol-leon { background: #92d050; color: #1f2937; }
.data-table th.hcol-mty { background: #ffc000; color: #1f2937; }
.data-table th.hcol-qro { background: #00b0f0; color: #1f2937; }
.data-table th.hcol-total { background: #d9d9d9; color: #1f2937; }

.almacen-badge {
  display: inline-block; padding: 2px 12px; border-radius: 999px; font-size: 16px; margin-right: 8px;
}
.almacen-badge.hcol-leon { background: #92d050; color: #1f2937; }
.almacen-badge.hcol-mty { background: #ffc000; color: #1f2937; }
.almacen-badge.hcol-qro { background: #00b0f0; color: #1f2937; }
.inicial-input { width: 80px; padding: 4px 6px; text-align: right; }

.group-toggle { font-size: 13px; }
.data-table.hide-detalle .col-detalle { display: none; }
.data-table.hide-prestamos .col-prestamos { display: none; }

.filter-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.filter-form label, .card-form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }

input, select, button {
  font-family: inherit; font-size: 14px;
}
input[type=text], input[type=search], input[type=number], input[type=date], select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
#tableSearch { min-width: 260px; margin-left: auto; }

.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-link { border: none; background: none; color: var(--blue); }
.btn-zoho { background: #d0483f; border-color: #d0483f; color: #fff; margin-top: 20px; }

.card-form {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 12px;
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 14px !important; color: var(--text) !important; }
.hidden { display: none; }
.hint { font-weight: normal; color: var(--muted); }

.table-wrap {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; max-height: 70vh;
}
.table-wrap-wide {
  width: 100vw; margin-left: calc(50% - 50vw); box-sizing: border-box;
  padding: 0 16px; overflow: visible; max-height: none;
}
.table-wrap-wide .data-table thead th { top: 60px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
.data-table th, .data-table td {
  padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap;
}
.data-table th.wrap, .data-table td.wrap { white-space: normal; word-break: break-word; }
.data-table.table-fixed { table-layout: fixed; }
.data-table.table-fixed th, .data-table.table-fixed td {
  overflow: hidden; text-overflow: ellipsis;
}
.data-table.table-fixed th.wrap, .data-table.table-fixed td.wrap {
  white-space: normal; word-break: break-word; text-overflow: clip;
}
.data-table thead th {
  position: sticky; top: 0; background: #fafbfc; font-weight: 600; color: var(--muted);
  cursor: default; user-select: none;
}
.data-table.sortable thead tr:first-child > th { cursor: pointer; }
.data-table.sortable thead tr:first-child > th:hover { color: var(--text); }
.data-table .num { text-align: right; }
.data-table tbody tr:hover { background: #f8fafc; }
.row-low { background: #fff4f2; }

.data-table thead tr.filter-row th {
  top: 37px; padding: 6px 8px; cursor: default;
}
.data-table thead tr.filter-row input {
  width: 100%; box-sizing: border-box; padding: 5px 7px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 6px; font-weight: normal; color: var(--text);
}

.empty { padding: 20px; color: var(--muted); text-align: center; }

.login-box {
  max-width: 420px; margin: 80px auto; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; text-align: center;
}
.login-box h1 { margin-bottom: 8px; }

.tag {
  display: inline-block; font-size: 11px; background: var(--blue); color: #fff; padding: 1px 6px; border-radius: 999px;
}
.tag-warn { background: var(--orange); margin-left: 6px; }

.inline-form { display: inline; }

.row-modificado > td { background: #fff8ec; }
.row-anotacion > td { background: #fafbfc; border-bottom: 2px solid var(--border); padding: 6px 10px; }
.anotacion-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.anotacion-fecha { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.anotacion-input { flex: 1; min-width: 220px; }

.chart-wrap {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; }
  #tableSearch { margin-left: 0; width: 100%; }
}
