:root {
  --navy: #0b1f3a; --navy2: #16345c; --blue: #1e5a9c; --teal: #1c9aae; --green: #2e9e6b; --lime: #7fa800;
  --amber: #e0a100; --red: #d64545; --bg: #f3f6fa; --card: #fff; --line: #e2e8f0; --text: #1f2937; --muted: #6b7280;
  --radius: 12px; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", Calibri, Carlito, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; }
button { font-family: inherit; cursor: pointer; }
h1, h3, h4 { margin: 0; }

/* ---------- Menú lateral ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 240px; background: var(--navy); color: #cbd5e1; display: flex; flex-direction: column; z-index: 30; transition: transform .25s; }
.brand { background: #fff; padding: 12px 18px; height: 84px; display: flex; align-items: center; justify-content: center; }
.brand img { max-width: 100%; max-height: 62px; object-fit: contain; }
.sidebar nav { padding: 14px 12px; flex: 1; }
.sidebar nav button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: 0; color: #c2cfe3; padding: 11px 14px; border-radius: 9px; font-size: 14.5px; margin-bottom: 4px; position: relative; }
.sidebar nav button:hover { background: rgba(255, 255, 255, .07); }
.sidebar nav button.active { background: var(--blue); color: #fff; font-weight: 600; }
.sidebar nav button.active::before { content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 4px; background: var(--lime); border-radius: 0 3px 3px 0; }
.ic { width: 22px; text-align: center; }
.pill { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 10px; }
.side-foot { padding: 14px 16px 18px; display: grid; gap: 8px; }
.side-foot small { color: #7c8da6; text-align: center; margin-top: 4px; }
.ghost { background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .15); color: #dbe5f3; border-radius: 8px; padding: 8px; font-size: 13px; }
.ghost:hover { background: rgba(255, 255, 255, .15); }
.ghost.danger { color: #ffb4b4; }

/* ---------- Estructura principal ---------- */
.main { margin-left: 240px; padding: 0 28px 40px; min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 22px 0 18px; }
.topbar h1 { font-size: 26px; color: var(--text); }
.crumb { color: var(--muted); font-size: 12.5px; }
.top-right { margin-left: auto; color: var(--muted); font-weight: 600; }
.burger { display: none; background: var(--navy); color: #fff; border: 0; border-radius: 8px; font-size: 20px; width: 40px; height: 40px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card h3 { font-size: 16.5px; color: var(--navy); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.card-head h3 { margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.empty { text-align: center; color: var(--muted); padding: 18px; }
.muted { color: var(--muted); } .small { font-size: 12px; }

/* ---------- Indicadores ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; gap: 14px; align-items: center; }
.k-ic { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none; }
.k-ic.blue { background: #e2ecf8; } .k-ic.teal { background: #dff3f6; } .k-ic.amber { background: #fcf1d3; } .k-ic.green { background: #def3e9; }
.kpi label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi b { font-size: 26px; line-height: 1.2; display: block; }
.kpi small { color: var(--muted); font-size: 12px; }
.count { background: var(--red); color: #fff; border-radius: 11px; font-size: 12px; padding: 1px 9px; }
.count.zero { background: var(--green); }

/* ---------- Tablas ---------- */
.tscroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: #f1f5f9; padding: 10px 12px; white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover { background: #fafcff; }
.r { text-align: right !important; }
.bar { height: 9px; background: #e5eaf1; border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--teal)); border-radius: 6px; }

/* ---------- Etiquetas y estados ---------- */
.badge { display: inline-block; padding: 3px 11px; border-radius: 12px; font-size: 12px; font-weight: 700; background: #e5eaf1; color: #475569; white-space: nowrap; }
.badge.in { background: #def3e9; color: #1c7a50; } .badge.out { background: #fcf1d3; color: #9a6f00; }
.badge.ship { background: #dff3f6; color: #15788a; } .badge.deliv { background: #e2ecf8; color: var(--blue); }
.badge.ret { background: #ece6f8; color: #5b3fa6; } .badge.warnb { background: #fde4d3; color: #b45309; }
.stock { display: inline-block; min-width: 38px; text-align: center; padding: 2px 8px; border-radius: 8px; font-weight: 700; }
.stock.good { background: #def3e9; color: #1c7a50; } .stock.warn { background: #fcf1d3; color: #9a6f00; } .stock.bad { background: #fbe0e0; color: var(--red); }
.alert { border-left: 5px solid var(--amber); background: #fdf7e4; border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; display: grid; gap: 2px; }
.alert.crit { border-color: var(--red); background: #fbeaea; }
.alert span { color: var(--muted); font-size: 12.5px; }
.link { background: none; border: 0; color: var(--blue); font-weight: 700; text-align: left; padding: 0; margin-top: 4px; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 16px; align-items: end; }
.span2 { grid-column: span 2; } .span-all { grid-column: 1 / -1; }
.f { display: grid; gap: 5px; font-size: 12.5px; font-weight: 700; color: #475569; }
.f input, .f select, .filters input, .filters select { font-family: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--text); width: 100%; min-height: 40px; }
.f input:focus, .f select:focus, .filters input:focus, .filters select:focus { outline: 2px solid rgba(30, 90, 156, .25); border-color: var(--blue); }
.actions { display: flex; justify-content: flex-end; }
.avail { background: #f1f5f9; border-radius: 10px; padding: 8px 14px; font-weight: 600; color: var(--muted); }
.avail b { display: block; font-size: 22px; color: var(--navy); line-height: 1.1; }
.avail small { font-weight: 500; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input { width: 240px; } .filters select { width: 210px; }

.btn { background: #fff; border: 1px solid #cbd5e1; color: var(--text); border-radius: 8px; padding: 9px 16px; font-weight: 700; font-size: 14px; min-height: 40px; }
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; } .btn.primary:hover { background: #174a82; }
.btn.warn { background: var(--amber); border-color: var(--amber); color: #3b2c00; } .btn.warn:hover { background: #c99200; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }

.seg { display: inline-flex; border: 1px solid #cbd5e1; border-radius: 10px; overflow: hidden; margin-bottom: 12px; flex-wrap: wrap; }
.seg button { background: #fff; border: 0; padding: 10px 20px; font-weight: 700; color: var(--muted); font-size: 14px; }
.seg button + button { border-left: 1px solid #cbd5e1; }
.seg button.on { background: var(--navy); color: #fff; }

.acts { white-space: nowrap; }
.mini { border: 0; border-radius: 6px; padding: 5px 9px; font-size: 12px; font-weight: 700; margin-right: 4px; }
.mini.in { background: #def3e9; color: #1c7a50; } .mini.out { background: #fcf1d3; color: #9a6f00; }
.mini.ship { background: #dff3f6; color: #15788a; } .mini.del { background: #fbe0e0; color: var(--red); }
.mini:hover { filter: brightness(.95); }

/* ---------- Envíos ---------- */
.shipcard { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 12px 0; background: #fcfdff; }
.ship-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sid { font-size: 16px; margin-right: 8px; color: var(--navy); }
.ship-body { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.ship-body label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.ship-body b { display: block; } .ship-body small { color: var(--muted); }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); margin: 16px 0 12px; }
.step { position: relative; text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; }
.step i { display: grid; place-items: center; width: 28px; height: 28px; margin: 0 auto 4px; border-radius: 50%; background: #e2e8f0; color: #64748b; font-style: normal; font-weight: 700; position: relative; z-index: 1; }
.step::before { content: ""; position: absolute; top: 13px; left: -50%; width: 100%; height: 3px; background: #e2e8f0; }
.step:first-child::before { display: none; }
.step.done i { background: var(--green); color: #fff; } .step.done::before { background: var(--green); } .step.done { color: var(--text); }
.ship-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Ventanas modales ---------- */
.overlay { position: fixed; inset: 0; background: rgba(11, 31, 58, .55); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal h3 { color: var(--navy); font-size: 18px; margin-bottom: 6px; } .modal h4 { margin: 14px 0 8px; color: var(--navy); }
.stack { display: grid; gap: 14px; } .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 14px 0; }
.dl dt { color: var(--muted); font-weight: 700; font-size: 12.5px; } .dl dd { margin: 0; }
.ret-item { background: #f1f5f9; border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; display: grid; gap: 2px; }

/* ---------- Avisos ---------- */
.toast { position: fixed; top: 18px; right: 18px; z-index: 80; max-width: 380px; padding: 13px 18px; border-radius: 10px; color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); background: var(--green); }
.toast.err { background: var(--red); }

/* ---------- Adaptable a móvil ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); } .grid2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, 1fr); } .ship-body { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); } .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  .main { margin-left: 0; padding: 0 14px 30px; } .burger { display: block; }
  .filters input, .filters select { width: 100%; } .filters { width: 100%; }
}
@media (max-width: 560px) {
  .kpis, .form-grid, .ship-body, .row2 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .steps { grid-template-columns: repeat(2, 1fr); row-gap: 14px; } .step:nth-child(3)::before { display: none; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
}
