:root {
  --brand: #4CB99A; --brand-dark: #3aa085; --brand-soft: #e8f6f1; --orange: #C97130; --ink: #1f2937;
  --side: #111827; --side-2: #1f2937; --muted: #6b7280; --bg: #f4f6f8; --line: #e5e7eb;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
}
* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--ink); font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; font-size: 14px; }
a { color: var(--brand-dark); }
.demo-strip { background: #fff7ed; color: #9a3412; font-size: 12px; text-align: center; padding: 4px 10px; border-bottom: 1px solid #fed7aa; position: sticky; top: 0; z-index: 1031; }
.demo-strip a { color: #9a3412; font-weight: 600; }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 25px; z-index: 1030; height: 58px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; white-space: nowrap; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; line-height: 1; }
.brand-logo { width: 34px; height: 34px; }
.sap-ind { display: inline-flex; align-items: center; gap: 8px; border: 1px solid #bbe5d7; background: var(--brand-soft); color: #145c47; border-radius: 999px; padding: 6px 14px; font-size: 12.5px; font-weight: 600; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.sap-ind:hover { background: #d8f0e7; }
.sap-ind .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; animation: pulse 2s infinite; }
.sap-ind.relogin .dot { background: var(--warn); }
.sap-ind .sep { opacity: .4; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(22,163,74,.55); } 70% { box-shadow: 0 0 0 8px rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.role-select { width: auto; font-size: 13px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--orange); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-outline-brand { border-color: var(--brand); color: var(--brand-dark); }
.btn-outline-brand:hover { background: var(--brand); color: #fff; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 83px); }
.sidebar { width: 262px; flex: none; background: var(--side); color: #d1d5db; position: sticky; top: 83px; height: calc(100vh - 83px); overflow-y: auto; padding: 14px 10px 90px; }
.side-area { margin-bottom: 4px; }
.side-head { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: #e5e7eb; font-weight: 600; font-size: 13px; user-select: none; }
.side-head:hover { background: var(--side-2); }
.side-head .chev { margin-left: auto; font-size: 10px; transition: transform .2s; }
.side-area.open .chev { transform: rotate(180deg); }
.side-items { display: none; padding: 2px 0 6px; }
.side-area.open .side-items { display: block; }
.side-items a { display: flex; align-items: center; gap: 6px; padding: 6px 10px 6px 36px; color: #9ca3af; text-decoration: none; font-size: 13px; border-radius: 6px; }
.side-items a:hover { color: #fff; background: var(--side-2); }
.side-items a.active { color: #fff; background: rgba(76,185,154,.22); box-shadow: inset 3px 0 0 var(--brand); }
.side-items a .star { color: #fbbf24; font-size: 10px; }
.side-foot { font-size: 11px; color: #6b7280; padding: 14px 10px; border-top: 1px solid #1f2937; margin-top: 10px; }
.side-foot img { height: 22px; filter: brightness(1.6); }
.main { flex: 1; min-width: 0; padding: 22px 24px 120px; }
.side-backdrop { display: none; }

/* ---------- Componentes ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; font-weight: 700; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.sync-box { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.card { border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.03); }
.card-header { background: #fff; border-bottom: 1px solid var(--line); font-weight: 600; border-radius: 12px 12px 0 0 !important; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; height: 100%; }
.kpi .lbl { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpi .val { font-size: 21px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.kpi .hint { font-size: 12px; color: var(--muted); }
.tech-note { font-size: 12px; color: #475569; background: #f1f5f9; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px; }
.tech-note code { color: #0f766e; }
.table { font-size: 13px; }
.table thead th { background: #f9fafb; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: #4b5563; white-space: nowrap; }
.table td { vertical-align: middle; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.link-doc { cursor: pointer; color: var(--brand-dark); font-weight: 600; text-decoration: underline dotted; }
.sem { display: inline-block; min-width: 62px; text-align: center; border-radius: 6px; padding: 2px 6px; font-weight: 700; font-size: 12px; }
.sem-ok { background: #dcfce7; color: #166534; } .sem-warn { background: #fef3c7; color: #92400e; } .sem-bad { background: #fee2e2; color: #991b1b; } .sem-na { background: #f3f4f6; color: #6b7280; }
.row-bad td { background: #fef2f2 !important; }
.row-total td { font-weight: 700; background: #f3f4f6 !important; }
.row-div td { font-weight: 700; background: #f9fafb !important; }

/* Dashboard de ventas */
.cia-table td, .cia-table th { text-align: right; } .cia-table td:first-child, .cia-table th:first-child { text-align: left; }
.vend-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; transition: .15s; height: 100%; }
.vend-card:hover { border-color: var(--brand); box-shadow: 0 4px 14px rgba(0,0,0,.06); transform: translateY(-1px); }
.vend-card .name { font-weight: 700; font-size: 13px; }
.vend-card .pct { font-weight: 800; font-size: 18px; }
.vend-card .progress { height: 7px; border-radius: 99px; }
.vend-card .expected { position: relative; }
.bar-ok { background: var(--ok); } .bar-warn { background: #f59e0b; } .bar-bad { background: var(--bad); }
.text-ok { color: var(--ok); } .text-warn { color: var(--warn); } .text-bad { color: var(--bad); }

/* Estanques */
.tank-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; gap: 12px; height: 100%; }
.tank-svg { width: 58px; flex: none; }
.tank-card .code { font-weight: 800; font-size: 14px; }
.tank-card .prod { font-size: 12px; color: var(--muted); }
.tank-card .kg { font-variant-numeric: tabular-nums; font-size: 13px; }
.muestreo { font-size: 11.5px; border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 6px; }
.muestreo .anulado { color: var(--bad); font-weight: 700; }
.accordion-button { font-weight: 600; }
.accordion-button:not(.collapsed) { background: var(--brand-soft); color: #145c47; }

/* Portal */
.hero { background: linear-gradient(120deg, #111827 0%, #1f2937 55%, #134e4a 100%); color: #fff; border-radius: 16px; padding: 22px 24px; }
.hero .clock { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.ind-chip { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); border-radius: 10px; padding: 8px 12px; min-width: 110px; }
.ind-chip .l { font-size: 11px; opacity: .7; } .ind-chip .v { font-weight: 700; font-size: 15px; }
.alert-card { border-radius: 12px; padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; cursor: pointer; border: 1px solid; height: 100%; transition: .15s; }
.alert-card:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.alert-card .n { font-size: 26px; font-weight: 800; line-height: 1; }
.alert-red { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-amber { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-blue { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.cal { width: 100%; table-layout: fixed; text-align: center; font-size: 12px; }
.cal th { color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal td { padding: 5px 0; border-radius: 6px; }
.cal .today { background: var(--brand); color: #fff; font-weight: 700; }
.cal .fer { background: #fee2e2; color: #991b1b; font-weight: 700; }
.cal .we { color: #9ca3af; }
.shortcut { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); font-size: 12.5px; font-weight: 600; text-align: center; height: 100%; }
.shortcut i { font-size: 22px; color: var(--brand-dark); }
.shortcut:hover { border-color: var(--brand); color: var(--ink); }

/* Catálogo */
.mod-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; height: 100%; display: flex; flex-direction: column; gap: 6px; }
.mod-card h6 { font-weight: 700; margin: 0; font-size: 14px; }
.mod-card .sap { font-size: 11.5px; color: #475569; font-family: ui-monospace, Consolas, monospace; }
.tag { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .03em; }
.tag-prod { background: #dcfce7; color: #166534; } .tag-disp { background: #e0e7ff; color: #3730a3; } .tag-demo { background: #fef3c7; color: #92400e; }
.tag-r { background: #f1f5f9; color: #334155; } .tag-w { background: #fde7d6; color: #9a3412; }

/* Mapa */
.chile { display: flex; flex-direction: column; gap: 3px; max-width: 360px; }
.chile .reg { display: flex; align-items: center; gap: 8px; font-size: 12px; cursor: default; }
.chile .reg .bar { height: 18px; border-radius: 4px; background: var(--brand); min-width: 3px; }
.chile .reg .lbl { width: 128px; text-align: right; color: #374151; flex: none; }

/* Cómo se conecta */
.flow { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; }
.flow .node { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; text-align: center; min-width: 140px; font-weight: 600; font-size: 13px; }
.flow .node small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; }
.flow .arrow { color: var(--brand); font-size: 22px; }
.lanes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lane { border-radius: 12px; padding: 12px; font-size: 13px; }
.lane-r { background: #eff6ff; border: 1px solid #bfdbfe; } .lane-w { background: #fff7ed; border: 1px solid #fed7aa; }

/* Drop zone */
.drop { border: 2px dashed #cbd5e1; border-radius: 12px; padding: 26px; text-align: center; color: var(--muted); background: #fff; cursor: pointer; transition: .15s; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); color: #145c47; }

/* ---------- Consola Service Layer ---------- */
.console-tab { position: fixed; right: 16px; bottom: 16px; z-index: 1040; background: #0b1220; color: #d1fae5; border: 1px solid #1f2a3d; border-radius: 999px; padding: 9px 16px; font-size: 12.5px; font-weight: 600; font-family: ui-monospace, Consolas, monospace; box-shadow: 0 8px 24px rgba(0,0,0,.25); cursor: pointer; }
.console-tab .cnt { background: var(--brand); color: #04221a; border-radius: 99px; padding: 0 7px; margin-left: 6px; }
.console-tab.flash { animation: flash .6s; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(76,185,154,.9); } 100% { box-shadow: 0 0 0 14px rgba(76,185,154,0); } }
.console { position: fixed; left: 0; right: 0; bottom: 0; height: 46vh; min-height: 260px; z-index: 1050; background: #0b1220; color: #cbd5e1; font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12px; display: none; flex-direction: column; border-top: 2px solid var(--brand); box-shadow: 0 -10px 30px rgba(0,0,0,.3); }
.console.open { display: flex; }
.console-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #0f1a2e; border-bottom: 1px solid #1f2a3d; flex-wrap: wrap; }
.console-head .t { color: #e2e8f0; font-weight: 700; }
.console-head .btn { font-size: 11.5px; padding: 2px 9px; }
.console-body { overflow-y: auto; flex: 1; }
.c-row { display: grid; grid-template-columns: 70px 56px 1fr 108px 44px 60px; gap: 8px; padding: 5px 12px; border-bottom: 1px solid #141e31; cursor: pointer; align-items: start; }
.c-row:hover { background: #111c30; }
.c-row .p { word-break: break-all; color: #e2e8f0; }
.c-row .lane { font-size: 10.5px; padding: 1px 6px; border-radius: 4px; text-align: center; white-space: nowrap; }
.lane-sl { background: #064e3b; color: #a7f3d0; } .lane-staging { background: #1e3a8a; color: #bfdbfe; } .lane-intranet { background: #4c1d95; color: #ddd6fe; }
.m-GET { color: #93c5fd; } .m-POST { color: #86efac; } .m-PATCH { color: #fcd34d; } .m-DELETE { color: #fca5a5; }
.s-2 { color: #86efac; } .s-4, .s-5 { color: #fca5a5; }
.c-detail { background: #070d18; padding: 10px 12px 12px; border-bottom: 1px solid #1f2a3d; }
.c-detail pre { background: #0b1220; border: 1px solid #1f2a3d; border-radius: 8px; padding: 10px; color: #e2e8f0; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 11.5px; margin: 4px 0 8px; }
.c-detail .lbl { color: #94a3b8; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.c-empty { padding: 30px; text-align: center; color: #64748b; }
@media (max-width: 700px) {
  .c-row { grid-template-columns: 56px 44px 1fr 38px; }
  .c-row .lane, .c-row .ms { display: none; }
}

/* ---------- Tour ---------- */
.tour-box { position: fixed; z-index: 1060; right: 18px; bottom: 70px; width: 340px; max-width: calc(100vw - 32px); background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3); border: 1px solid var(--line); padding: 16px 18px; }
.tour-box .step { font-size: 11px; font-weight: 700; color: var(--brand-dark); text-transform: uppercase; letter-spacing: .05em; }
.tour-box h6 { font-weight: 700; margin: 4px 0 6px; }
.tour-box p { font-size: 13px; color: #374151; margin-bottom: 12px; }
.tour-hl { outline: 3px solid var(--orange) !important; outline-offset: 3px; border-radius: 10px; transition: outline .2s; }

/* ---------- Modal documento SAP ---------- */
.sapdoc-head { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 13px; }
.sapdoc-head .k { color: var(--muted); font-size: 11px; text-transform: uppercase; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: -280px; top: 83px; z-index: 1045; transition: left .25s; width: 270px; }
  .sidebar.open { left: 0; }
  .side-backdrop.open { display: block; position: fixed; inset: 83px 0 0 0; background: rgba(0,0,0,.45); z-index: 1044; }
  .main { padding: 16px 14px 120px; }
  .brand .txt small { display: none; }
}
@media (max-width: 767.98px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .brand .txt { display: none; }
  .sap-ind .long { display: none; }
  .top-actions .btn-label { display: none; }
  .lanes { grid-template-columns: 1fr; }
  .kpi .val { font-size: 18px; }
  .page-head h1 { font-size: 19px; }
}
@media (max-width: 420px) { .role-select { max-width: 110px; } }
@media print { .sidebar, .topbar, .demo-strip, .console, .console-tab { display: none !important; } }
