/* =========================================================================
   INTERPLAST · Sistema Predictivo de Calidad — Estilos globales
   ========================================================================= */

:root {
  --ip-navy-900: #0b1f33;
  --ip-navy-800: #0f2a45;
  --ip-navy-700: #16395a;
  --ip-blue-600: #1b6fb8;
  --ip-blue-500: #2688d6;
  --ip-blue-100: #e6f1fb;
  --ip-teal-500: #12897a;
  --ip-teal-100: #e2f4f1;
  --ip-gray-900: #1a2330;
  --ip-gray-700: #3d4a5c;
  --ip-gray-500: #6b7a8d;
  --ip-gray-300: #c9d3dd;
  --ip-gray-200: #dfe6ed;
  --ip-gray-100: #eef2f6;
  --ip-gray-50: #f6f8fa;
  --ip-white: #ffffff;

  --ip-green: #1f9d55;
  --ip-green-bg: #e8f7ee;
  --ip-amber: #c9820a;
  --ip-amber-bg: #fbf1e0;
  --ip-red: #c0392b;
  --ip-red-bg: #fbe9e7;
  --ip-blue-badge-bg: #e6f1fb;

  --ip-radius: 10px;
  --ip-radius-lg: 14px;
  --ip-shadow: 0 1px 3px rgba(15, 42, 69, 0.08), 0 1px 2px rgba(15,42,69,0.06);
  --ip-shadow-md: 0 4px 14px rgba(15, 42, 69, 0.10);
  --sidebar-w: 250px;
  --header-h: 64px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--ip-gray-50);
  color: var(--ip-gray-900);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; color: var(--ip-navy-900); }
p { margin: 0; }
a { color: var(--ip-blue-600); text-decoration: none; }
ul { margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--ip-navy-900), var(--ip-navy-800));
  color: #cfe0ee;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .logo-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--ip-blue-500), var(--ip-teal-500));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 15px;
  flex-shrink: 0;
}
.sidebar-brand .brand-text { line-height: 1.15; }
.sidebar-brand .brand-name { font-weight: 800; font-size: 15px; color: #fff; letter-spacing: 0.5px; }
.sidebar-brand .brand-sub { font-size: 10.5px; color: #8fa8bf; }

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.sidebar-nav .nav-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em;
  color: #6f8aa2; margin: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; margin-bottom: 2px;
  color: #b9cddf; font-size: 13.5px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; color: #7fa0bd; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(38,136,214,0.22); color: #fff; }
.nav-item.active i { color: #5cb2f2; }

.sidebar-footer {
  padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 10.5px; color: #6f8aa2;
}
.sidebar-footer strong { color: #a9c2d8; }

.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--header-h);
  background: var(--ip-white);
  border-bottom: 1px solid var(--ip-gray-200);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px;
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { display: flex; flex-direction: column; }
.topbar-title .t-main { font-size: 15.5px; font-weight: 800; color: var(--ip-navy-900); letter-spacing: 0.3px; }
.topbar-title .t-sub { font-size: 11px; color: var(--ip-gray-500); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--ip-green);
  background: var(--ip-green-bg); padding: 5px 10px; border-radius: 20px;
}
.topbar-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ip-green); }
.topbar-user {
  display: flex; align-items: center; gap: 8px;
}
.topbar-user .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ip-blue-100); color: var(--ip-blue-600);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.topbar-user .u-name { font-size: 12.5px; font-weight: 600; color: var(--ip-gray-900); }
.topbar-user .u-role { font-size: 10.5px; color: var(--ip-gray-500); }

.page-content { padding: 24px 28px 60px; flex: 1; }

.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 21px; }
.page-header .page-desc { font-size: 13px; color: var(--ip-gray-500); margin-top: 4px; }

.breadcrumb { font-size: 12px; color: var(--ip-gray-500); margin-bottom: 8px; }
.breadcrumb a { color: var(--ip-gray-500); }
.breadcrumb .sep { margin: 0 6px; }
.breadcrumb .current { color: var(--ip-gray-900); font-weight: 600; }

/* ---------- Cards ---------- */
.card {
  background: var(--ip-white);
  border: 1px solid var(--ip-gray-200);
  border-radius: var(--ip-radius-lg);
  box-shadow: var(--ip-shadow);
}
.card-pad { padding: 20px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--ip-gray-100);
}
.card-header h3 { font-size: 14.5px; }
.card-header .card-sub { font-size: 11.5px; color: var(--ip-gray-500); margin-top: 2px; }

/* ---------- Grid helpers ---------- */
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-6 { grid-template-columns: repeat(6, 1fr); }
.grid-12 { grid-template-columns: repeat(12, 1fr); }
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- KPI cards ---------- */
.kpi-card {
  background: var(--ip-white);
  border: 1px solid var(--ip-gray-200);
  border-radius: var(--ip-radius-lg);
  padding: 18px 20px;
  box-shadow: var(--ip-shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { font-size: 12px; color: var(--ip-gray-500); font-weight: 600; }
.kpi-icon {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.kpi-icon.blue { background: var(--ip-blue-100); color: var(--ip-blue-600); }
.kpi-icon.teal { background: var(--ip-teal-100); color: var(--ip-teal-500); }
.kpi-icon.amber { background: var(--ip-amber-bg); color: var(--ip-amber); }
.kpi-icon.red { background: var(--ip-red-bg); color: var(--ip-red); }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--ip-navy-900); }
.kpi-trend { font-size: 11.5px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.kpi-trend.up { color: var(--ip-green); }
.kpi-trend.down { color: var(--ip-red); }
.kpi-trend.flat { color: var(--ip-gray-500); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: 1px solid transparent; transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--ip-blue-600); color: #fff; box-shadow: 0 2px 6px rgba(27,111,184,0.3); }
.btn-primary:hover { background: #1660a3; }
.btn-secondary { background: var(--ip-white); color: var(--ip-gray-700); border-color: var(--ip-gray-300); }
.btn-secondary:hover { background: var(--ip-gray-50); }
.btn-ghost { background: transparent; color: var(--ip-blue-600); border-color: transparent; }
.btn-ghost:hover { background: var(--ip-blue-100); }
.btn-danger-ghost { background: transparent; color: var(--ip-red); }
.btn-danger-ghost:hover { background: var(--ip-red-bg); }
.btn-lg { padding: 13px 26px; font-size: 14.5px; border-radius: 10px; }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.ip-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ip-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ip-gray-500); font-weight: 700;
  padding: 10px 14px; border-bottom: 1px solid var(--ip-gray-200);
  background: var(--ip-gray-50);
  white-space: nowrap;
}
table.ip-table td {
  padding: 11px 14px; border-bottom: 1px solid var(--ip-gray-100);
  color: var(--ip-gray-900); vertical-align: middle;
}
table.ip-table tbody tr:hover { background: var(--ip-blue-100); cursor: default; }
table.ip-table tbody tr.clickable:hover { cursor: pointer; }

/* ---------- Badges / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700;
}
.badge-optima { background: var(--ip-blue-badge-bg); color: var(--ip-blue-600); }
.badge-correcta { background: var(--ip-green-bg); color: var(--ip-green); }
.badge-riesgo { background: var(--ip-amber-bg); color: var(--ip-amber); }
.badge-fuera { background: var(--ip-red-bg); color: var(--ip-red); }
.badge-gray { background: var(--ip-gray-100); color: var(--ip-gray-700); }

.dot-status { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-optima { background: var(--ip-blue-600); }
.dot-correcta { background: var(--ip-green); }
.dot-riesgo { background: var(--ip-amber); }
.dot-fuera { background: var(--ip-red); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 700; color: var(--ip-gray-700); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 9px 11px; border: 1px solid var(--ip-gray-300); border-radius: 8px;
  font-size: 13px; color: var(--ip-gray-900); background: var(--ip-white);
}
.form-control:focus { outline: none; border-color: var(--ip-blue-500); box-shadow: 0 0 0 3px rgba(38,136,214,0.15); }
.form-row { display: flex; gap: 14px; }
.form-row > * { flex: 1; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M0 0l5 6 5-6z' fill='%236b7a8d'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

.slider-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.slider-row .slider-top { display: flex; justify-content: space-between; align-items: baseline; }
.slider-row .slider-label { font-size: 12px; font-weight: 700; color: var(--ip-gray-700); }
.slider-row .slider-value { font-size: 13px; font-weight: 800; color: var(--ip-blue-600); }
.slider-row input[type=range] {
  width: 100%; height: 5px; border-radius: 4px; background: var(--ip-gray-200);
  outline: none; -webkit-appearance: none;
}
.slider-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 17px; height: 17px; border-radius: 50%;
  background: var(--ip-blue-600); border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(27,111,184,0.4); cursor: pointer;
}
.slider-row .slider-range { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ip-gray-500); }
.slider-row.warn .slider-value { color: var(--ip-amber); }
.slider-row.danger .slider-value { color: var(--ip-red); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--ip-gray-200); margin-bottom: 18px; }
.tab-item {
  padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--ip-gray-500);
  border-bottom: 2px solid transparent; cursor: pointer;
}
.tab-item.active { color: var(--ip-blue-600); border-color: var(--ip-blue-600); }

/* ---------- Gauge / progress ---------- */
.gauge-wrap { position: relative; width: 220px; height: 130px; margin: 0 auto; }
.gauge-score { position: absolute; bottom: 6px; left: 0; right: 0; text-align: center; }
.gauge-score .val { font-size: 42px; font-weight: 800; color: var(--ip-navy-900); line-height: 1; }
.gauge-score .max { font-size: 13px; color: var(--ip-gray-500); font-weight: 600; }

.progress-bar-track { width: 100%; height: 9px; background: var(--ip-gray-200); border-radius: 20px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 20px; transition: width 0.6s ease; }

.metric-mini { text-align: center; }
.metric-mini .m-val { font-size: 24px; font-weight: 800; color: var(--ip-navy-900); }
.metric-mini .m-label { font-size: 11.5px; color: var(--ip-gray-500); font-weight: 600; margin-top: 3px; }

/* ---------- Factor bars (explicabilidad) ---------- */
.factor-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.factor-label { flex: 0 0 300px; font-size: 12.5px; color: var(--ip-gray-900); }
.factor-track { flex: 1; height: 16px; background: var(--ip-gray-100); border-radius: 4px; position: relative; overflow: hidden; }
.factor-fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.factor-fill.pos { background: linear-gradient(90deg, #2fb872, #1f9d55); left: 50%; }
.factor-fill.neg { background: linear-gradient(90deg, #c0392b, #e05c4c); right: 50%; }
.factor-val { flex: 0 0 56px; text-align: right; font-size: 12.5px; font-weight: 800; }
.factor-val.pos { color: var(--ip-green); }
.factor-val.neg { color: var(--ip-red); }

/* ---------- Explicabilidad factor list ---------- */
.factor-list-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--ip-gray-100); font-size: 13px;
}
.factor-list-item:last-child { border-bottom: none; }
.factor-list-item .fi-icon { font-size: 13px; margin-top: 2px; }
.factor-list-item.positive .fi-icon { color: var(--ip-green); }
.factor-list-item.negative .fi-icon { color: var(--ip-red); }
.factor-list-item .fi-text { flex: 1; color: var(--ip-gray-900); }
.factor-list-item .fi-val { font-weight: 800; white-space: nowrap; }
.factor-list-item.positive .fi-val { color: var(--ip-green); }
.factor-list-item.negative .fi-val { color: var(--ip-red); }

/* ---------- Recommendation cards ---------- */
.reco-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border: 1px solid var(--ip-gray-200); border-radius: 10px; margin-bottom: 10px;
  background: var(--ip-gray-50);
}
.reco-item .reco-icon {
  width: 34px; height: 34px; border-radius: 8px; background: var(--ip-blue-100); color: var(--ip-blue-600);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.reco-item .reco-text { flex: 1; font-size: 13px; color: var(--ip-gray-900); }

/* ---------- Loading overlay (motor de predicción) ---------- */
.predict-overlay {
  position: fixed; inset: 0; background: rgba(11,31,51,0.88); z-index: 200;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  color: #fff;
}
.predict-overlay .po-spinner {
  width: 64px; height: 64px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.18); border-top-color: #5cb2f2;
  animation: ip-spin 0.9s linear infinite; margin-bottom: 26px;
}
@keyframes ip-spin { to { transform: rotate(360deg); } }
.predict-overlay .po-step {
  font-size: 15px; font-weight: 600; color: #cfe0ee; min-height: 22px; letter-spacing: 0.2px;
}
.predict-overlay .po-sub { font-size: 12px; color: #6f8aa2; margin-top: 8px; }

/* ---------- Chip / pill selects for formulation table ---------- */
.formulation-table td select, .formulation-table td input {
  font-size: 12.5px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--ip-gray-300);
  width: 100%; min-width: 90px;
}
.formulation-table .col-pct { font-weight: 700; color: var(--ip-blue-600); }
.formulation-table .qty-input { width: 78px; text-align: right; }
.formulation-table .row-remove { color: var(--ip-red); background: none; border: none; font-size: 15px; padding: 4px; }
.formulation-table .row-remove:hover { color: #8e2317; }
.formulation-table td { white-space: nowrap; }

.formulation-total-bar {
  display: flex; justify-content: flex-end; gap: 28px; padding: 14px 20px;
  border-top: 1px solid var(--ip-gray-200); background: var(--ip-gray-50);
  border-radius: 0 0 var(--ip-radius-lg) var(--ip-radius-lg);
}
.formulation-total-bar .tb-item { text-align: right; }
.formulation-total-bar .tb-label { font-size: 11px; color: var(--ip-gray-500); font-weight: 600; }
.formulation-total-bar .tb-value { font-size: 17px; font-weight: 800; color: var(--ip-navy-900); }
.formulation-total-bar .tb-value.warn { color: var(--ip-amber); }
.formulation-total-bar .tb-value.ok { color: var(--ip-green); }

/* ---------- Batch quality pill ---------- */
.quality-pill {
  display: inline-flex; align-items: center; gap: 5px; font-weight: 700; font-size: 12px;
  padding: 2px 8px; border-radius: 20px;
}
.quality-pill.q-high { color: var(--ip-green); background: var(--ip-green-bg); }
.quality-pill.q-mid { color: var(--ip-amber); background: var(--ip-amber-bg); }
.quality-pill.q-low { color: var(--ip-red); background: var(--ip-red-bg); }

/* ---------- Disclaimer ---------- */
.disclaimer-bar {
  font-size: 11px; color: var(--ip-gray-500); background: var(--ip-gray-100);
  border: 1px solid var(--ip-gray-200); border-radius: 8px; padding: 10px 14px;
  margin-top: 26px; display: flex; gap: 8px; align-items: flex-start;
}
.disclaimer-bar i { margin-top: 1px; color: var(--ip-gray-500); }

/* ---------- Empty / helper states ---------- */
.helper-text { font-size: 12px; color: var(--ip-gray-500); }
.section-title { font-size: 15px; font-weight: 800; color: var(--ip-navy-900); margin-bottom: 4px; }
.section-desc { font-size: 12.5px; color: var(--ip-gray-500); margin-bottom: 16px; }

.divider { height: 1px; background: var(--ip-gray-200); margin: 22px 0; }

/* ---------- What-if comparison panel ---------- */
.whatif-compare { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; }
.whatif-col { text-align: center; padding: 18px; border-radius: 12px; }
.whatif-col.before { background: var(--ip-gray-50); border: 1px solid var(--ip-gray-200); }
.whatif-col.after { background: var(--ip-teal-100); border: 1px solid #b7e2da; }
.whatif-col .wc-label { font-size: 11.5px; font-weight: 700; color: var(--ip-gray-500); text-transform: uppercase; letter-spacing: 0.04em; }
.whatif-col .wc-score { font-size: 40px; font-weight: 800; color: var(--ip-navy-900); margin: 6px 0; }
.whatif-arrow { font-size: 22px; color: var(--ip-gray-400); }
.improve-badge {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 15px;
  padding: 6px 14px; border-radius: 20px;
}
.improve-badge.up { background: var(--ip-green-bg); color: var(--ip-green); }
.improve-badge.down { background: var(--ip-red-bg); color: var(--ip-red); }
.improve-badge.flat { background: var(--ip-gray-100); color: var(--ip-gray-700); }

/* ---------- Filters bar ---------- */
.filters-bar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 18px; }
.filters-bar .fb-item { min-width: 160px; }
.filters-bar .fb-item label { display: block; font-size: 11px; font-weight: 700; color: var(--ip-gray-500); margin-bottom: 5px; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ip-gray-300); border-radius: 10px; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-20 { margin-top: 20px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--ip-gray-500); }
.text-sm { font-size: 12px; }
.fw-700 { font-weight: 700; }
.w-100 { width: 100%; }
