:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #0f766e;
  --primary-dark: #0d5f5a;
  --accent: #b45309;
  --danger: #b91c1c;
  --success: #15803d;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }

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

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-shrink: 0;
}
.brand h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand .tagline {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

nav {
  display: flex;
  gap: 4px;
  flex: 1;
}
nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.12s;
}
nav a:hover {
  background: #f3f4f6;
  color: var(--text);
}
nav a.active {
  background: var(--primary);
  color: white;
}

.actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.1s;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: #f3f4f6;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger-text {
  background: transparent;
  color: var(--danger);
}
.btn-danger-text:hover { background: #fee2e2; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); background: #f3f4f6; }

main {
  padding: 24px 28px 80px;
  max-width: 1400px;
  margin: 0 auto;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.section-header {
  margin-bottom: 20px;
}
.section-header h2 {
  font-size: 22px;
  margin: 0 0 4px 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.section-header .muted {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

/* ---- KPIs ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.kpi-card .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.kpi-card .value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.kpi-card .delta {
  font-size: 12px;
  margin-top: 4px;
}
.kpi-card .delta.up { color: var(--success); }
.kpi-card .delta.down { color: var(--danger); }

/* ---- Charts ---- */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.chart-section h3 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
}
.chart-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.chart-header-row h3 {
  margin: 0;
  flex: 1;
}
.chart-filter {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  cursor: pointer;
}
.chart-filter:hover { border-color: #9ca3af; }
.chart-wrap {
  position: relative;
  height: 280px;
}
.chart-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) {
  .chart-grid-2 { grid-template-columns: 1fr; }
}

/* ---- Tables ---- */
.data-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) {
  .data-grid-2 { grid-template-columns: 1fr; }
}
.basket-locales-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 900px) {
  .basket-locales-grid { grid-template-columns: 1fr; }
}
.data-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.data-section h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  font-weight: 600;
}
.table-wrap {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
thead th {
  background: #f9fafb;
  font-weight: 600;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid #f3f4f6;
}
tbody tr:hover { background: #fafafa; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #f3f4f6;
  color: var(--muted);
}
.up-tag { color: var(--success); }
.down-tag { color: var(--danger); }

/* ---- Section divider ---- */
.section-divider {
  margin: 32px 0 14px 0;
  padding-top: 12px;
  border-top: 2px solid var(--border);
}
.section-divider h2 {
  font-size: 17px;
  margin: 0 0 4px 0;
  color: var(--primary);
  font-weight: 600;
}

/* ---- Material matrix (heatmap-style table) ---- */
.material-matrix-table {
  border-collapse: collapse;
  font-size: 11px;
  min-width: 100%;
}
.material-matrix-table th,
.material-matrix-table td {
  padding: 7px 9px;
  text-align: right;
  border: 1px solid #f3f4f6;
  font-variant-numeric: tabular-nums;
}
.material-matrix-table thead th {
  background: #f9fafb;
  font-weight: 600;
  position: sticky;
  top: 0;
}
.material-matrix-table tbody th {
  text-align: left;
  background: #f9fafb;
  font-weight: 500;
  white-space: nowrap;
}
.matrix-cell { font-weight: 500; }

/* ---- Heatmap ---- */
#heatmap-container {
  display: grid;
  grid-template-columns: 80px repeat(24, 1fr);
  gap: 2px;
  font-size: 10px;
}
.heatmap-label {
  padding: 4px 6px;
  color: var(--muted);
  font-weight: 500;
  text-align: right;
}
.heatmap-hour {
  text-align: center;
  color: var(--muted);
  font-size: 9px;
}
.heatmap-cell {
  height: 26px;
  border-radius: 3px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: rgba(255,255,255,0.85);
}

/* ---- Iniciativas ---- */
.initiatives-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.filters-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.filters-bar label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.filters-bar select {
  font-family: inherit;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
}
.filters-bar button { margin-left: auto; }

.workstream-group {
  margin-bottom: 24px;
}
.workstream-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--ws-color, var(--primary));
}
.workstream-badge {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--ws-color, var(--primary));
}
.workstream-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.workstream-header .count {
  color: var(--muted);
  font-size: 12px;
  font-weight: normal;
}
.workstream-header .category {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 4px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.initiative-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ws-color, var(--primary));
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
}
.initiative-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.06);
}
.initiative-card.status-completed { opacity: 0.55; }
.initiative-card.status-completed .ic-title { text-decoration: line-through; }
.initiative-card .ic-header {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}
.initiative-card .ic-title {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.35;
  flex: 1;
}
.initiative-card .priority-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.priority-dot.alta { background: var(--danger); }
.priority-dot.media { background: #f59e0b; }
.priority-dot.baja { background: var(--muted); }

.initiative-card .ic-desc {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.initiative-card .ic-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}
.initiative-card .ic-meta span {
  background: #f9fafb;
  padding: 2px 6px;
  border-radius: 4px;
}
.status-pill {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.status-pill.todo { background: #f3f4f6; color: var(--muted); }
.status-pill.in_progress { background: #dbeafe; color: #1e40af; }
.status-pill.completed { background: #dcfce7; color: var(--success); }
.status-pill.blocked { background: #fee2e2; color: var(--danger); }

/* ---- Tabla iniciativas ---- */
.initiatives-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 12px;
}
.initiatives-table th {
  background: #f9fafb;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.initiatives-table th:hover { background: #f3f4f6; }
.initiatives-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f3f4f6;
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
}
.modal h2 {
  margin: 0 0 16px 0;
  font-size: 18px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: span 2; }
.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-field label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-field input,
.form-field select,
.form-field textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
}
.form-field textarea {
  resize: vertical;
  min-height: 60px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ---- GEO ---- */
.geo-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.horizon-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.horizon-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--h-color, var(--primary));
}
.horizon-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.horizon-header .progress {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}
.geo-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}
.geo-item {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  cursor: pointer;
  transition: all 0.12s;
}
.geo-item:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.geo-item.completed { opacity: 0.55; }
.geo-item.completed .gi-title { text-decoration: line-through; }
.geo-checkbox {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid var(--border);
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
}
.geo-item.completed .geo-checkbox {
  background: var(--success);
  border-color: var(--success);
  color: white;
  font-weight: bold;
}
.gi-body { flex: 1; }
.gi-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.35;
}
.gi-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 6px;
}
.gi-meta {
  display: flex;
  gap: 6px;
  font-size: 10px;
  flex-wrap: wrap;
}
.gi-meta .pill {
  background: white;
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 10px;
}
.gi-meta .pill.impact-muy { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.gi-meta .pill.impact-alto { background: #fef9c3; border-color: #fde047; color: #854d0e; }
.gi-meta .pill.impact-medio { background: #f0fdf4; border-color: #86efac; color: #166534; }

/* ---- Diagnostico ---- */
.diagnostico-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 900px) {
  .diagnostico-grid { grid-template-columns: 1fr; }
}
.diag-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.diag-card h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  color: var(--primary);
  font-weight: 600;
}
.diag-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
}

footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
