/* ===========================================================================
   MEDGLOBAL ERP — estilos
   =========================================================================== */
:root {
  --mg-brand: #0f766e;
  --mg-brand-2: #14b8a6;
  --mg-brand-dark: #115e59;
  --mg-ink: #0b1f2a;
  --mg-side: #0b1f2a;
  --mg-side-2: #123241;
  --mg-bg: #f3f6f8;
  --mg-card: #ffffff;
  --mg-border: #e4eaee;
  --mg-radius: 14px;
  --mg-shadow: 0 1px 2px rgba(11, 31, 42, .05), 0 6px 24px rgba(11, 31, 42, .06);
  --bs-primary: #0f766e;
  --bs-primary-rgb: 15, 118, 110;
  --bs-link-color: #0f766e;
  --bs-link-color-rgb: 15, 118, 110;
  --bs-link-hover-color: #115e59;
  --bs-body-font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-font-size: .875rem;
  --sidebar-w: 252px;
}
[data-bs-theme="dark"] {
  --mg-bg: #0d161c;
  --mg-card: #14212a;
  --mg-border: #223540;
  --mg-shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
  --bs-link-color: #2dd4bf;
  --bs-link-color-rgb: 45, 212, 191;
  --bs-body-bg: #0d161c;
  --bs-body-color: #d5e0e6;
  --bs-secondary-bg: #14212a;
  --bs-tertiary-bg: #101c24;
  --bs-border-color: #223540;
}

body { background: var(--mg-bg); }
.btn-primary {
  --bs-btn-bg: var(--mg-brand); --bs-btn-border-color: var(--mg-brand);
  --bs-btn-hover-bg: var(--mg-brand-dark); --bs-btn-hover-border-color: var(--mg-brand-dark);
  --bs-btn-active-bg: var(--mg-brand-dark); --bs-btn-active-border-color: var(--mg-brand-dark);
  --bs-btn-disabled-bg: var(--mg-brand); --bs-btn-disabled-border-color: var(--mg-brand);
}
.btn-outline-primary {
  --bs-btn-color: var(--mg-brand); --bs-btn-border-color: var(--mg-brand);
  --bs-btn-hover-bg: var(--mg-brand); --bs-btn-hover-border-color: var(--mg-brand);
  --bs-btn-active-bg: var(--mg-brand); --bs-btn-active-border-color: var(--mg-brand);
}
.text-primary { color: var(--mg-brand) !important; }
.bg-primary { background-color: var(--mg-brand) !important; }
.form-control:focus, .form-select:focus { border-color: var(--mg-brand-2); box-shadow: 0 0 0 .2rem rgba(20,184,166,.18); }
.form-check-input:checked { background-color: var(--mg-brand); border-color: var(--mg-brand); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); position: fixed; inset: 0 auto 0 0; z-index: 1040;
  background: linear-gradient(185deg, var(--mg-side) 0%, var(--mg-side-2) 100%);
  color: #b8cbd6; display: flex; flex-direction: column; transition: transform .25s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.25rem; color: #fff; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--mg-brand-2), var(--mg-brand)); box-shadow: 0 6px 16px rgba(20,184,166,.35);
}
.brand-name { font-weight: 800; letter-spacing: .02em; line-height: 1.05; }
.brand-name small { display: block; font-weight: 500; font-size: .68rem; color: #7ea0b2; letter-spacing: .12em; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: .25rem .75rem 1rem; scrollbar-width: thin; scrollbar-color: #2a4756 transparent; }
.nav-group-title {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; border-radius: 10px; color: #b8cbd6;
  text-decoration: none; font-weight: 600; cursor: pointer; user-select: none;
}
.nav-group-title:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-group-title .bi:first-child { font-size: 1.1rem; color: #7ea0b2; }
.nav-group-title .chev { margin-left: auto; font-size: .75rem; transition: transform .2s; }
.nav-group-title[aria-expanded="true"] .chev { transform: rotate(90deg); }
.nav-group-title.active { color: #fff; background: rgba(20,184,166,.14); }
.nav-group-title.active .bi:first-child { color: var(--mg-brand-2); }
.nav-sub { list-style: none; margin: .1rem 0 .4rem; padding: 0 0 0 1.35rem; border-left: 1px solid rgba(255,255,255,.08); margin-left: 1.15rem; }
.nav-sub a {
  display: flex; align-items: center; gap: .55rem; padding: .38rem .7rem; border-radius: 8px; color: #9db5c2;
  text-decoration: none; font-size: .86rem;
}
.nav-sub a:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-sub a.active { color: #fff; background: rgba(20,184,166,.2); font-weight: 600; }
.nav-sub a .bi { font-size: .95rem; opacity: .8; }
.sidebar-foot { padding: .9rem 1.1rem; border-top: 1px solid rgba(255,255,255,.07); font-size: .78rem; color: #7ea0b2; }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1030; display: flex; align-items: center; gap: 1rem; padding: .7rem 1.5rem;
  background: color-mix(in srgb, var(--mg-card) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--mg-border);
}
.topbar .empresa-chip { font-weight: 600; }
.content { padding: 1.25rem 1.25rem 1rem; flex: 1; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1.1rem; }
.page-head h1 { font-size: 1.45rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--bs-secondary-color); font-size: .85rem; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .5rem; }
.sidebar-backdrop { display: none; }
@media (min-width: 992px) {
  body.nav-oculto .sidebar { transform: translateX(-100%); }
  body.nav-oculto .main { margin-left: 0; }
}
.sidebar, .main { transition: margin-left .2s ease, transform .25s ease; }
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.5); }
  .main { margin-left: 0; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1035; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
}

/* ---------- Tarjetas ---------- */
.card { background: var(--mg-card); border: 1px solid var(--mg-border); border-radius: var(--mg-radius); box-shadow: var(--mg-shadow); }
.card-header { background: transparent; border-bottom: 1px solid var(--mg-border); font-weight: 600; padding: .85rem 1.1rem; display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.card-header .bi { color: var(--mg-brand); }
.card-body { padding: 1.1rem; }
.kpi { display: flex; flex-direction: row; gap: .9rem; align-items: center; padding: 1rem 1.1rem; height: 100%; }
.kpi .ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; font-size: 1.35rem; flex: 0 0 46px; }
.kpi > div:last-child { min-width: 0; }
.kpi .lbl { overflow-wrap: anywhere; }
.kpi .val { white-space: nowrap; }
@media (max-width: 575.98px) { .kpi { padding: .8rem .85rem; gap: .65rem; } .kpi .val { font-size: 1.15rem; } .kpi .ico { width: 38px; height: 38px; flex-basis: 38px; font-size: 1.1rem; } }
.kpi .lbl { font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--bs-secondary-color); font-weight: 600; }
.kpi .val { font-size: 1.45rem; font-weight: 800; line-height: 1.15; letter-spacing: -.02em; }
.kpi .sub { font-size: .78rem; color: var(--bs-secondary-color); }
.ico-teal { background: rgba(20,184,166,.14); color: #0f766e; }
.ico-blue { background: rgba(59,130,246,.14); color: #2563eb; }
.ico-amber { background: rgba(245,158,11,.16); color: #b45309; }
.ico-rose { background: rgba(244,63,94,.14); color: #be123c; }
.ico-violet { background: rgba(139,92,246,.15); color: #6d28d9; }
.ico-slate { background: rgba(100,116,139,.16); color: #475569; }
.ico-green { background: rgba(34,197,94,.15); color: #15803d; }
[data-bs-theme="dark"] .ico-teal { color: #5eead4; } [data-bs-theme="dark"] .ico-blue { color: #93c5fd; }
[data-bs-theme="dark"] .ico-amber { color: #fcd34d; } [data-bs-theme="dark"] .ico-rose { color: #fda4af; }
[data-bs-theme="dark"] .ico-violet { color: #c4b5fd; } [data-bs-theme="dark"] .ico-slate { color: #cbd5e1; }
[data-bs-theme="dark"] .ico-green { color: #86efac; }
.chart-box { position: relative; height: 290px; }
.chart-box.sm { height: 230px; }

/* ---------- Tablas (celdas de dos líneas: principal + secundaria) ---------- */
.table-erp { margin: 0; --bs-table-bg: transparent; font-size: .875rem; line-height: 1.35; }
.table-erp thead th {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); font-weight: 700;
  border-bottom: 1px solid var(--mg-border); background: color-mix(in srgb, var(--mg-card) 70%, var(--mg-bg));
  white-space: nowrap; padding: .75rem .7rem;
}
.table-erp td { padding: .6rem .7rem; vertical-align: middle; border-color: var(--mg-border); }
.table-erp td.text-nowrap, .table-erp td.text-end, .table-erp td.text-center { white-space: nowrap; }
.table-erp td:not(.text-nowrap):not(.text-end):not(.text-center) { min-width: 120px; }
.table-erp tbody tr:hover { background: color-mix(in srgb, var(--mg-brand-2) 6%, transparent); }
.table-erp tfoot td { font-weight: 700; border-top: 2px solid var(--mg-border); background: color-mix(in srgb, var(--mg-card) 70%, var(--mg-bg)); }
.table-erp td a.fw-semibold { color: var(--bs-body-color); }
.table-erp td a.fw-semibold:hover { color: var(--mg-brand); }
.celda-main { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; max-width: 230px; }
.celda-sub {
  font-size: .78rem; font-weight: 400; color: var(--bs-secondary-color); line-height: 1.3; margin-top: .1rem;
  max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.table-erp td.text-end .celda-sub, .table-erp td.text-center .celda-sub { margin-left: auto; margin-right: auto; }
.table-erp td.text-end .celda-sub { margin-right: 0; }
.table-erp.table-sm td, .table-erp.table-sm th { padding: .35rem .5rem; }
.table-reporte { font-size: .7rem; }
.table-reporte td:not(.text-end):not(.text-center) { min-width: 0 !important; }
.table-reporte thead th { white-space: normal; font-size: .62rem; vertical-align: bottom; line-height: 1.15; }
.table-reporte td, .table-reporte th { padding: .28rem .35rem !important; }
.table-erp .col-oculta { display: none !important; }
.table-erp.tabla-compacta td, .table-erp.tabla-compacta thead th { padding-left: .4rem; padding-right: .4rem; }
.table-erp.tabla-compacta .acciones { gap: .15rem; }
.autofit-nota { font-size: .75rem; color: var(--bs-secondary-color); padding: .4rem .9rem; border-top: 1px dashed var(--mg-border); }
.autofit-nota .bi { margin-right: .3rem; }
.table-responsive { border-radius: var(--mg-radius); }
.badge-soft { font-weight: 600; padding: .34em .65em; border-radius: 999px; font-size: .74rem; white-space: nowrap; }
.badge-soft .bi { font-size: .7rem; margin-right: .3rem !important; }

/* Botones de acción: cuadros con borde, como en una barra de herramientas */
.acciones { display: inline-flex; align-items: center; gap: .25rem; white-space: nowrap; }
.btn-icon {
  width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; border-radius: 9px;
  border: 1px solid var(--mg-border); background: var(--mg-card); color: var(--bs-secondary-color);
  font-size: .95rem; transition: all .15s; text-decoration: none; cursor: pointer;
}
.acciones .btn-icon:hover { border-color: color-mix(in srgb, var(--mg-brand) 45%, var(--mg-border)); background: color-mix(in srgb, var(--mg-brand-2) 12%, var(--mg-card)); color: var(--mg-brand); }
.btn-icon.danger:hover { border-color: #fda4af !important; background: rgba(244,63,94,.1) !important; color: #e11d48 !important; }
.btn-icon.pdf:hover { border-color: #fca5a5 !important; background: rgba(239,68,68,.1) !important; color: #dc2626 !important; }
.btn-icon.warn:hover { border-color: #fcd34d !important; background: rgba(245,158,11,.14) !important; color: #b45309 !important; }
.btn-icon.disabled { opacity: .38; cursor: not-allowed; background: transparent; pointer-events: auto; }
.btn-icon.disabled:hover { border-color: var(--mg-border) !important; background: transparent !important; color: var(--bs-secondary-color) !important; }
.btn-icon.es-menu { border-style: dashed; }
.acciones-mas .dropdown-menu { min-width: 190px; font-size: .86rem; border-radius: 12px; border-color: var(--mg-border); padding: .35rem; }
.acciones-mas .dropdown-item { border-radius: 8px; padding: .45rem .7rem; }
.acciones-mas form { margin: 0; }
.topbar .btn-icon { border-color: transparent; background: transparent; }
.topbar .btn-icon:hover { background: color-mix(in srgb, var(--mg-brand-2) 14%, transparent); color: var(--mg-brand); }
.filtros .form-label { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); margin-bottom: .25rem; }
.dl-erp dt { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); font-weight: 600; }
.dl-erp dd { margin-bottom: .8rem; font-weight: 500; }
.total-box { background: color-mix(in srgb, var(--mg-brand) 8%, var(--mg-card)); border: 1px solid color-mix(in srgb, var(--mg-brand) 25%, var(--mg-border)); border-radius: var(--mg-radius); padding: 1rem 1.2rem; }
.total-box .row-t { display: flex; justify-content: space-between; padding: .18rem 0; }
.total-box .row-t.grand { border-top: 1px solid var(--mg-border); margin-top: .4rem; padding-top: .55rem; font-size: 1.2rem; font-weight: 800; color: var(--mg-brand); }
[data-bs-theme="dark"] .total-box .row-t.grand { color: #5eead4; }
.lineas-table input, .lineas-table select { min-width: 70px; }
.lineas-table .col-desc { min-width: 240px; } .lineas-table .col-prod { min-width: 220px; }
.lineas-table td { padding: .35rem .3rem; vertical-align: top; }
.required-mark::after { content: " *"; color: #e11d48; }
.form-label { font-weight: 600; font-size: .82rem; margin-bottom: .25rem; }
.help-text, .form-text { font-size: .76rem; }
.errorlist { list-style: none; padding: 0; margin: .25rem 0 0; color: #dc2626; font-size: .8rem; }
.ts-wrapper.form-select, .ts-wrapper.form-control { padding: 0; border: 0; }
.ts-control { border-radius: var(--bs-border-radius) !important; min-height: 38px; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--bs-secondary-color); }
.empty-state .bi { font-size: 2.4rem; opacity: .5; }
.pagination .page-link { border-radius: 8px; margin: 0 2px; color: var(--mg-brand); }
.pagination .active .page-link { background: var(--mg-brand); border-color: var(--mg-brand); color: #fff; }
.timeline { list-style: none; padding-left: 0; margin: 0; }
.timeline li { padding: .4rem 0 .4rem 1.4rem; position: relative; border-left: 2px solid var(--mg-border); margin-left: .4rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .85rem; width: 10px; height: 10px; border-radius: 50%; background: var(--mg-brand-2); }
pre.xml { max-height: 420px; overflow: auto; background: #0b1f2a; color: #b8e6df; padding: 1rem; border-radius: 10px; font-size: .78rem; }
.step-ok { color: #16a34a; } .step-fail { color: #dc2626; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--mg-bg); }
.login-hero {
  background: radial-gradient(1200px 600px at 10% 0%, rgba(20,184,166,.35), transparent 60%),
              linear-gradient(160deg, #0b1f2a, #0f3a44 60%, #0f766e);
  color: #e6f4f1; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
}
.login-hero h1 { font-weight: 800; font-size: 2.3rem; letter-spacing: -.02em; }
.login-hero .feature { display: flex; gap: .8rem; align-items: flex-start; margin-bottom: 1rem; }
.login-hero .feature .bi { font-size: 1.3rem; color: var(--mg-brand-2); }
.login-card { max-width: 400px; width: 100%; }
@media (max-width: 900px) { .login-wrap { grid-template-columns: 1fr; } .login-hero { display: none; } }

/* ---------- Impresión ---------- */
@media print {
  .sidebar, .topbar, .no-print, .page-head .actions { display: none !important; }
  .main { margin: 0; } .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
