.margen-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.margen-toolbar h2 { margin: 3px 0 4px; color: #0c2136; font-size: 23px; }
.margen-toolbar p { margin: 0; }
.margen-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.margen-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.margen-kpis article {
  position: relative;
  min-height: 118px;
  padding: 18px;
  overflow: hidden;
  background: #fff;
  border: 1px solid #dce6ed;
  border-radius: 14px;
  box-shadow: 0 7px 20px rgba(19, 52, 78, .05);
}

.margen-kpis article::after {
  content: '';
  position: absolute;
  right: -26px;
  bottom: -31px;
  width: 96px;
  height: 96px;
  background: rgba(18, 141, 203, .08);
  border-radius: 50%;
}

.margen-kpis article.fit::after { background: rgba(25, 156, 111, .09); }
.margen-kpis article.review::after { background: rgba(219, 145, 32, .11); }
.margen-kpis article.go::after { background: rgba(19, 161, 108, .11); }
.margen-kpis article.danger::after { background: rgba(204, 68, 68, .1); }
.margen-kpis span { display: block; color: #687c8c; font-size: 11px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.margen-kpis strong { display: block; margin: 9px 0 5px; color: #0b2135; font-size: 24px; line-height: 1; }
.margen-kpis small { position: relative; z-index: 1; display: block; color: #728594; font-size: 11px; }

.margen-filters {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) repeat(4, minmax(150px, .8fr)) auto;
  gap: 9px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fff;
  border: 1px solid #dce6ed;
  border-radius: 12px;
}

.margen-filters input,
.margen-filters select { width: 100%; }

.marketplace-search-panel {
  position: relative;
  padding: 20px;
  margin-bottom: 16px;
  color: #fff;
  background: linear-gradient(125deg, #075d91, #087db8 62%, #0794c9);
  border: 1px solid #056b9f;
  border-radius: 14px;
  box-shadow: 0 12px 28px rgba(5, 93, 145, .18);
}

.marketplace-search-title { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 9px; }
.marketplace-search-title span { font-size: 14px; font-weight: 800; }
.marketplace-search-title small { color: #d9f1fb; font-size: 11px; }
.marketplace-search-line { display: grid; grid-template-columns: minmax(280px, 1fr) auto auto; gap: 9px; }
.marketplace-search-line input { min-height: 45px; border: 1px solid rgba(255,255,255,.65); background: #fff; }
.marketplace-search-line button { min-height: 45px; }
.marketplace-update { padding: 0 18px; color: #07527b; background: #fff; border: 1px solid #fff; border-radius: 9px; font-weight: 800; }
.marketplace-update:hover { background: #eef9fd; }
.marketplace-update:disabled { opacity: .65; }
.marketplace-filter-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 10px; margin-top: 15px; }
.marketplace-filter-grid label { color: #e5f5fb; font-size: 10.5px; font-weight: 750; }
.marketplace-filter-grid select { width: 100%; margin-top: 5px; color: #18354a; background: #fff; }
.marketplace-clear { margin-top: 11px; padding: 0; color: #fff; background: transparent; border: 0; text-decoration: underline; text-underline-offset: 3px; font-size: 11px; cursor: pointer; }
.marketplace-results-head { display: flex; align-items: center; justify-content: space-between; margin: 17px 2px 10px; }
.marketplace-results-head strong, .marketplace-results-head span { display: block; }
.marketplace-results-head strong { color: #123149; font-size: 15px; }
.marketplace-results-head span { margin-top: 2px; color: #718694; font-size: 11px; }

.opportunity-list { display: grid; gap: 9px; }

.opportunity-row {
  display: grid;
  grid-template-columns: minmax(250px, 1.7fr) minmax(230px, 1.4fr) minmax(115px, .7fr) minmax(145px, .9fr) minmax(135px, .8fr) minmax(112px, auto);
  align-items: center;
  gap: 14px;
  padding: 15px 16px;
  background: #fff;
  border: 1px solid #dce6ed;
  border-left: 4px solid #1694cf;
  border-radius: 12px;
  box-shadow: 0 5px 17px rgba(19, 52, 78, .04);
}

.opportunity-row > div:not(.opportunity-main):not(.opportunity-actions) > span,
.opportunity-row > div:not(.opportunity-main):not(.opportunity-actions) > small {
  display: block;
  color: #788a98;
  font-size: 10.5px;
}

.opportunity-row > div:not(.opportunity-main):not(.opportunity-actions) > strong { display: block; margin: 3px 0; color: #18344b; font-size: 12.5px; }
.opportunity-main > strong { display: block; margin: 5px 0 3px; color: #102a40; font-size: 13.5px; }
.opportunity-main > small { display: block; color: #6d8191; font-size: 11px; }
.opportunity-tags { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.profile-score { color: #46657b; font-size: 10px; font-weight: 800; }
.opportunity-official-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 12px; }
.opportunity-official-facts span { min-width: 0; overflow: hidden; color: #29465b; font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.opportunity-official-facts b { display: block; margin-bottom: 2px; color: #7a8d9a; font-size: 9px; letter-spacing: .035em; text-transform: uppercase; }
.opportunity-official-facts.incomplete span { color: #a36919; }

.source-code,
.profile-match,
.decision {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 4px 7px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .055em;
}

.source-code { color: #1b638c; background: #eaf5fb; border: 1px solid #cee8f5; }
.profile-match.fit { color: #137552; background: #e7f8f0; border: 1px solid #c5ebda; }
.profile-match.review { color: #926019; background: #fff5df; border: 1px solid #f3dfad; }
.profile-match.outside { color: #6a7480; background: #f1f3f5; border: 1px solid #dde2e6; }
.decision.go { color: #087048; background: #dff7ed; }
.decision.review { color: #966014; background: #fff1d2; }
.decision.no-go { color: #a03737; background: #fde7e7; }
.deadline { color: #b94747 !important; }
.opportunity-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.margen-source { margin: 13px 2px 0; color: #788a98; font-size: 10.5px; }

.margin-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 17px;
  margin-bottom: 14px;
  color: #e7f6ff;
  background: linear-gradient(125deg, #071d33, #0b3b5d 65%, #0a75a8);
  border: 1px solid rgba(24, 150, 205, .3);
  border-radius: 14px;
  box-shadow: 0 10px 26px rgba(7, 29, 51, .16);
}

.margin-summary p { margin: 3px 0 0; color: #c3d9e6; line-height: 1.45; }
.margin-ai-mark { display: grid; place-items: center; width: 46px; height: 46px; flex: 0 0 46px; color: #fff; background: linear-gradient(145deg, #1ba2dc, #0b6c9c); border: 1px solid rgba(255,255,255,.25); border-radius: 13px; font-size: 23px; font-weight: 850; }

.margin-profile-strip {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  margin-bottom: 14px;
  background: #dce6ed;
  border: 1px solid #dce6ed;
  border-radius: 12px;
}

.margin-profile-strip > div { padding: 14px; background: #fff; }
.margin-profile-strip span { display: block; margin-bottom: 5px; color: #748896; font-size: 10px; text-transform: uppercase; }
.margin-profile-strip strong { color: #16354d; font-size: 12.5px; }

.margin-table-wrap { overflow-x: auto; background: #fff; border: 1px solid #dce6ed; border-radius: 12px; }
.margin-table { min-width: 1080px; margin: 0; }
.margin-table td strong,
.margin-table td small { display: block; }
.margin-table td small { margin-top: 3px; color: #7b8d9a; font-size: 10px; }
.margin-value { display: inline-block; padding: 4px 7px; border-radius: 7px; font-weight: 800; }
.margin-value.healthy { color: #08734c; background: #e3f8ef; }
.margin-value.warning { color: #8d5d17; background: #fff2d7; }
.margin-value.critical { color: #a03535; background: #fde5e5; }
.data-warning { color: #a76b1d; font-size: 11px; font-weight: 750; }

.connector-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 13px 14px;
  margin-bottom: 15px;
  color: #7e5621;
  background: #fff4dd;
  border: 1px solid #f1d9a6;
  border-radius: 10px;
}

.connector-status.configured { color: #176d50; background: #e8f8f1; border-color: #c5eadb; }
.connector-status span { font-size: 11px; }
.form-section-title { margin: 5px 0 -3px; color: #17364d; font-size: 13px; }
.form-help { margin: 0; padding: 10px 12px; color: #667c8d; background: #f5f8fa; border-radius: 8px; font-size: 11px; line-height: 1.45; }
.check-field { display: flex !important; align-items: center; gap: 9px; padding: 10px 12px; background: #f5f8fa; border: 1px solid #e1e9ee; border-radius: 9px; }
.check-field input { width: auto !important; }

#margen-dialog { width: min(920px, calc(100vw - 40px)); max-height: 88vh; padding: 0; border: 0; border-radius: 15px; box-shadow: 0 24px 70px rgba(7, 29, 51, .3); }
#margen-dialog::backdrop { background: rgba(4, 19, 33, .64); backdrop-filter: blur(2px); }
#margen-dialog form { max-height: 88vh; overflow-y: auto; }
#margen-dialog .modal-head { position: sticky; top: 0; z-index: 2; padding: 18px 20px; background: #fff; border-bottom: 1px solid #dce6ed; }
#margen-form-fields { padding: 20px; }
#margen-dialog .modal-actions { position: sticky; bottom: 0; padding: 14px 20px; background: #fff; border-top: 1px solid #dce6ed; }

@media (max-width: 1280px) {
  .margen-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .marketplace-filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .opportunity-row { grid-template-columns: minmax(260px, 1.4fr) minmax(230px, 1.2fr) minmax(130px, .8fr) minmax(145px, .9fr); }
  .opportunity-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 1050px) {
  .margen-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .margen-filters { grid-template-columns: 1fr 1fr; }
  .marketplace-filter-grid { grid-template-columns: 1fr 1fr; }
  .marketplace-search-line { grid-template-columns: 1fr 1fr; }
  .marketplace-search-line input { grid-column: 1 / -1; }
  .opportunity-row { grid-template-columns: 1fr 1fr; }
  .opportunity-main { grid-column: 1 / -1; }
  .margin-profile-strip { grid-template-columns: 1fr 1fr; }
}
.margen-detail-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 14px;
  padding: 12px 16px;
  border: 1px solid #f0ce82;
  border-radius: 12px;
  background: #fff7e5;
  color: #76501b;
  font-size: 13px;
}

.margen-detail-notice strong { white-space: nowrap; }
.margen-detail-notice > div span { display: block; margin-top: 3px; }

@media (max-width: 800px) {
  .margen-detail-notice { align-items: flex-start; flex-direction: column; gap: 4px; }
  .marketplace-filter-grid, .marketplace-search-line { grid-template-columns: 1fr; }
  .marketplace-search-title { align-items: flex-start; flex-direction: column; gap: 3px; }
  .opportunity-official-facts { grid-column: 1 / -1; }
}
