/* Linaje Data · tablero de inteligencia comercial (assets/js/linaje-data.js) */
.ld {
  --ld-ink: #2f3d2e;
  --ld-green: #374836;
  --ld-copper: #b0703c;
  --ld-line: rgba(55, 72, 54, 0.12);
  --ld-muted: rgba(55, 72, 54, 0.62);
  --ld-bg: #ffffff;
  --ld-soft: #f4f6f2;
  --ld-r: 12px;
}

/* Encabezado: selector de archivo */
.ld_file { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ld_file_sel {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 12px; border: 1px solid var(--ld-line, rgba(55,72,54,.12)); border-radius: 10px; background: #fff;
  color: #2f3d2e; font-size: 14px;
}
.ld_file_sel i { color: #1d6f42; }
.ld_file_sel select { border: 0; background: transparent; outline: none; max-width: 280px; font-weight: 600; color: inherit; }
.ld_upload { cursor: pointer; }
.ld_upload.is_busy { opacity: .6; pointer-events: none; }
.ld_icon_btn {
  width: 42px; height: 42px; border-radius: 10px; border: 1px solid rgba(55,72,54,.15); background: #fff; color: #374836; cursor: pointer;
}
.ld_icon_btn:hover { background: #374836; color: #fff; }

/* Pestañas */
.ld_tabs {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  margin: 4px 0 14px; padding: 4px; background: #fff; border: 1px solid var(--ld-line); border-radius: 12px;
}
.ld_tabs::-webkit-scrollbar { display: none; }
.ld_tab {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border: 0; border-radius: 9px; background: transparent;
  color: var(--ld-muted); font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.ld_tab i { font-size: 13px; }
.ld_tab:hover { background: var(--ld-soft); color: var(--ld-ink); }
.ld_tab[aria-selected="true"] { background: var(--ld-green); color: #fff; }

/* Barra de filtros */
.ld_filters {
  position: sticky; top: 76px; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 16px; padding: 10px; background: rgba(249, 251, 243, 0.96); backdrop-filter: blur(4px);
  border: 1px solid var(--ld-line); border-radius: 12px;
}
.ld_seg { display: inline-flex; padding: 3px; background: #fff; border: 1px solid var(--ld-line); border-radius: 10px; }
.ld_seg button {
  padding: 7px 12px; border: 0; border-radius: 7px; background: transparent; font-size: 13px; font-weight: 600; color: var(--ld-muted); cursor: pointer;
}
.ld_seg button[aria-pressed="true"] { background: var(--ld-green); color: #fff; }
.ld_seg_inline { margin-bottom: 12px; flex-wrap: wrap; }
.ld_slicer {
  display: inline-flex; align-items: center; gap: 8px; max-width: 230px;
  padding: 6px 10px; border: 1px solid var(--ld-line); border-radius: 10px; background: #fff; cursor: pointer; text-align: left;
}
.ld_slicer small { display: block; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--ld-muted); line-height: 1.1; }
.ld_slicer span { display: block; font-size: 13px; font-weight: 600; color: var(--ld-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.ld_slicer > i { font-size: 10px; color: var(--ld-muted); }
.ld_slicer.is_on { border-color: var(--ld-copper); background: #fbf4ee; }
.ld_search { position: relative; display: inline-flex; align-items: center; }
.ld_search i { position: absolute; left: 11px; font-size: 12px; color: var(--ld-muted); }
.ld_search input {
  height: 38px; width: 220px; padding: 0 12px 0 32px; border: 1px solid var(--ld-line); border-radius: 10px; background: #fff; font-size: 13px; outline: none;
}
.ld_search input:focus { border-color: var(--ld-green); }
.ld_search_sm input { width: 210px; }
.ld_clear { border: 0; background: none; color: #a2382a; font-size: 13px; font-weight: 600; cursor: pointer; }
.ld_chips { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.ld_chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 20px; background: #374836; color: #fff; font-size: 12px; }
.ld_chip b { font-weight: 600; }
.ld_chip button { width: 20px; height: 20px; border: 0; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; line-height: 1; cursor: pointer; }

/* Popover del segmentador */
.ld_pop {
  position: absolute; z-index: 3000; width: 320px; max-width: calc(100vw - 32px);
  padding: 12px; background: #fff; border: 1px solid rgba(55,72,54,.15); border-radius: 12px; box-shadow: 0 18px 40px rgba(34,45,33,.18);
}
.ld_pop_head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; color: #2f3d2e; }
.ld_pop_head button { border: 0; background: none; color: #a2382a; font-size: 12px; font-weight: 600; cursor: pointer; }
.ld_pop .ld_search, .ld_pop .ld_search input { width: 100%; }
.ld_pop_list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow-y: auto; }
.ld_pop_list label { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.ld_pop_list label:hover { background: #f4f6f2; }
.ld_pop_list input { accent-color: #374836; }
.ld_pop_name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #2f3d2e; }
.ld_pop_val { font-size: 12px; color: rgba(55,72,54,.6); font-variant-numeric: tabular-nums; }

/* KPIs */
.ld_kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.ld_kpis_4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ld_kpi {
  position: relative; padding: 16px 18px; background: #fff; border: 1px solid var(--ld-line, rgba(55,72,54,.12)); border-radius: 12px; overflow: hidden;
}
.ld_kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: #c9d1c5; }
.ld_kpi.is_green::before { background: #374836; }
.ld_kpi.is_copper::before { background: #b0703c; }
.ld_kpi span { display: block; font-size: 12px; font-weight: 600; color: rgba(55,72,54,.62); }
.ld_kpi strong { display: block; margin: 4px 0 2px; font-family: var(--heading-font); font-size: 24px; font-weight: 700; color: #2f3d2e; line-height: 1.15; font-variant-numeric: tabular-nums; }
.ld_kpi small { display: block; font-size: 12px; color: rgba(55,72,54,.6); }

/* Rejilla de tarjetas */
.ld_grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.ld_card { grid-column: span 12; background: #fff; border: 1px solid var(--ld-line, rgba(55,72,54,.12)); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.ld_page > .ld_card + .ld_card, .ld_page > #ldProfile + .ld_card { margin-top: 16px; }
.ld_card > header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; margin-bottom: 10px; }
.ld_card > header h3 { margin: 0; font-size: 16px; font-weight: 700; color: #2f3d2e; }
.ld_card > header h3 i { color: #b0703c; margin-right: 4px; }
.ld_card > header span { font-size: 12px; color: rgba(55,72,54,.6); }
.span4 { grid-column: span 4; } .span5 { grid-column: span 5; } .span6 { grid-column: span 6; }
.span7 { grid-column: span 7; } .span8 { grid-column: span 8; } .span12 { grid-column: span 12; }
.ld_chart { width: 100%; }
.ld_section_t { margin: 24px 0 12px; font-size: 18px; }
.ld_muted { color: rgba(55,72,54,.6); margin: 0; }

/* Mapa mundial */
.ld_map_tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 10px; }
.ld_toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: #2f3d2e; cursor: pointer; }
.ld_toggle input { accent-color: #374836; width: 16px; height: 16px; }
.ld_map_hint { margin-left: auto; font-size: 12px; color: rgba(55,72,54,.55); }
.ld_map { background: linear-gradient(180deg, #f7faf9 0%, #eef4f6 100%); border-radius: 10px; }
.ld_map_legend { margin: 0 0 8px; font-size: 12px; color: rgba(55,72,54,.6); }
.ld_map_legend b { color: #2f3d2e; }
.ld_map_note { margin: 6px 0 0; font-size: 12px; color: rgba(55,72,54,.55); }
.ld_map_note:empty { display: none; }
@media (max-width: 767px) { .ld_map { height: 380px !important; } .ld_map_hint { display: none; } }

/* Tablas */
.ld_tbl_tools { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.ld_tbl_right { display: flex; align-items: center; gap: 10px; }
.ld_tbl_count { font-size: 12px; color: rgba(55,72,54,.6); }
.ld_btn_ghost {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid rgba(55,72,54,.2); border-radius: 8px;
  background: #fff; color: #374836; font-size: 13px; font-weight: 600; cursor: pointer;
}
.ld_btn_ghost:hover { background: #374836; color: #fff; }
.ld_tbl_wrap { overflow-x: auto; border: 1px solid rgba(55,72,54,.1); border-radius: 10px; }
.ld_tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.ld_tbl_wrap .ld_tbl { min-width: 960px; }
.ld_tbl th {
  position: sticky; top: 0; background: #f4f6f2; text-align: left; padding: 9px 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: rgba(55,72,54,.7);
  border-bottom: 1px solid rgba(55,72,54,.12); white-space: nowrap; cursor: pointer; user-select: none;
}
.ld_tbl th i { margin-left: 6px; font-size: 10px; opacity: .35; }
.ld_tbl th.is_sorted { color: #2f3d2e; }
.ld_tbl th.is_sorted i { opacity: 1; color: #b0703c; }
.ld_tbl td {
  padding: 8px 10px; border-bottom: 1px solid rgba(55,72,54,.07); color: #2f3d2e; vertical-align: top;
  max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ld_tbl td:hover { white-space: normal; overflow: visible; }
.ld_tbl th.num, .ld_tbl td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ld_tbl tbody tr:nth-child(even) td { background: #fbfcfa; }
.ld_tbl tr.is_link { cursor: pointer; }
.ld_tbl tr.is_link:hover td { background: #f1f4ee; }
.ld_tbl tr.is_current td { background: #fbf4ee !important; font-weight: 600; }
.ld_tbl_empty { text-align: center; padding: 26px !important; color: rgba(55,72,54,.6); }
.ld_tbl_sm { font-size: 12px; margin-bottom: 14px; border: 1px solid rgba(55,72,54,.1); }
.ld_pager { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; color: rgba(55,72,54,.7); }
.ld_pager button { width: 32px; height: 32px; border: 1px solid rgba(55,72,54,.2); border-radius: 8px; background: #fff; cursor: pointer; font-size: 16px; }
.ld_pager button:disabled { opacity: .35; cursor: default; }
.ld_pill { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.ld_pill.is_exp { background: #e4ece2; color: #2f4b2e; }
.ld_pill.is_imp { background: #f6e6d8; color: #8a5428; }
.ld_flag { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; background: #a2382a; color: #fff; font-size: 10px; font-weight: 700; margin-left: 3px; }
.ld_alert { display: inline-block; padding: 2px 6px; border-radius: 6px; background: #fdf1df; color: #8a5428; font-size: 11px; line-height: 1.3; }
.ld_up { color: #2f6b3f; font-weight: 600; }
.ld_down { color: #a2382a; font-weight: 600; }
.ld_badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.ld_badge.is_ok { background: #e1eedf; color: #2f6b3f; }
.ld_badge.is_warn { background: #f8ead9; color: #9a5a1c; }
.ld_badge.is_bad { background: #f7e0dc; color: #a2382a; }
.ld_badge.is_muted { background: #eef0ec; color: #5b6758; }

/* Ficha de empresa / declaración */
.ld_profile_kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.ld_decl .ld_profile_kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ld_route {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 14px; padding: 12px 14px;
  background: #f4f6f2; border-radius: 10px; font-size: 13px; color: #2f3d2e; line-height: 1.5;
}
.ld_route i { color: #b0703c; font-size: 11px; }
.ld_route_big { font-size: 14px; }
.ld_profile_cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-bottom: 10px; }
.ld_profile_cols h4, .ld_decl h4 { margin: 0 0 8px; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: rgba(55,72,54,.6); }
.ld_list { list-style: none; margin: 0 0 14px; padding: 0; }
.ld_list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed rgba(55,72,54,.12); font-size: 13px; }
.ld_list li > span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; color: rgba(55,72,54,.7); }
.ld_list button { border: 0; background: none; padding: 0; text-align: left; color: #374836; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(55,72,54,.3); }
.ld_dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.ld_dl dt { color: rgba(55,72,54,.6); font-weight: 500; }
.ld_dl dd { margin: 0; color: #2f3d2e; word-break: break-word; }
.ld_dl_full { padding: 12px; background: #fbfcfa; border: 1px solid rgba(55,72,54,.08); border-radius: 10px; }
.ld_dl_cols { grid-template-columns: repeat(4, max-content 1fr); }

/* Visor de hojas */
.ld_sheets { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.ld_sheet_list { position: sticky; top: 76px; background: #fff; border: 1px solid rgba(55,72,54,.12); border-radius: 12px; padding: 12px; max-height: calc(100vh - 110px); overflow-y: auto; }
.ld_sheet_list h4 { margin: 0 0 8px 6px; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: rgba(55,72,54,.6); }
.ld_sheet_list ul { list-style: none; margin: 0; padding: 0; }
.ld_sheet_list button {
  width: 100%; display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 0; border-radius: 8px; background: none;
  text-align: left; font-size: 13px; color: #2f3d2e; cursor: pointer;
}
.ld_sheet_list button small { color: rgba(55,72,54,.5); font-variant-numeric: tabular-nums; }
.ld_sheet_list button:hover { background: #f4f6f2; }
.ld_sheet_list button[aria-current="true"] { background: #374836; color: #fff; }
.ld_sheet_list button[aria-current="true"] small { color: rgba(255,255,255,.7); }
.ld_sheet_view { background: #fff; border: 1px solid rgba(55,72,54,.12); border-radius: 12px; padding: 16px 18px; min-width: 0; }
.ld_sheet_head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.ld_sheet_head h3 { margin: 0; font-size: 20px; }
.ld_block { margin-bottom: 22px; }
.ld_block h4 { margin: 0 0 8px; font-size: 14px; color: #374836; }

/* Insights */
.ld_insights { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.ld_insight { padding: 16px 18px; background: #fff; border: 1px solid rgba(55,72,54,.12); border-left: 4px solid #4f6d7a; border-radius: 12px; }
.ld_insight.is_bad { border-left-color: #a2382a; }
.ld_insight.is_ok { border-left-color: #2f6b3f; }
.ld_insight h4 { margin: 8px 0 10px; font-size: 16px; line-height: 1.3; color: #2f3d2e; }
.ld_insight dl { margin: 0; font-size: 13px; }
.ld_insight dt { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: rgba(55,72,54,.55); margin-top: 8px; }
.ld_insight dd { margin: 2px 0 0; color: #2f3d2e; line-height: 1.5; }
.ld_faq details { border-bottom: 1px solid rgba(55,72,54,.1); padding: 10px 0; }
.ld_faq summary { cursor: pointer; font-weight: 600; color: #2f3d2e; }
.ld_faq p { margin: 8px 0 0; font-size: 14px; line-height: 1.6; color: #3e4c3d; }

/* Estados */
.ld_loading { display: grid; place-items: center; gap: 14px; min-height: 360px; color: rgba(55,72,54,.7); }
.ld_spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid #e1e8de; border-top-color: #374836; animation: ldSpin .8s linear infinite; }
@keyframes ldSpin { to { transform: rotate(360deg); } }
.ld_empty_big { text-align: center; padding: 50px 20px; color: rgba(55,72,54,.7); }
.ld_empty_big i { font-size: 40px; color: #b0703c; margin-bottom: 12px; }
.ld_empty_big h3 { margin-bottom: 6px; }
#ldManual .lp_head { margin-top: 0; }

@media (max-width: 1199px) {
  .ld_kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span4, .span5, .span6, .span7, .span8 { grid-column: span 12; }
  .ld_profile_cols { grid-template-columns: 1fr 1fr; }
  .ld_dl_cols { grid-template-columns: max-content 1fr; }
}
@media (max-width: 767px) {
  .ld_kpis, .ld_kpis_4, .ld_profile_kpis { grid-template-columns: 1fr 1fr; }
  .ld_kpi strong { font-size: 19px; }
  .ld_sheets { grid-template-columns: 1fr; }
  .ld_sheet_list { position: static; max-height: 240px; }
  .ld_insights, .ld_profile_cols { grid-template-columns: 1fr; }
  .ld_filters { position: static; }
  .ld_search input, .ld_search_sm input { width: 100%; }
  .ld_search_sm { flex: 1 1 100%; }
}
