:root {
  --navy: #0e2240;
  --blue: #1a7fc9;
  --blue-soft: #e8f2fb;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1c2533;
  --muted: #5d6b7e;
  --line: #dfe4eb;
  --ok: #1d8a4e;
  --ok-soft: #e4f5ea;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --info: #1a6fb0;
  --info-soft: #e5f0fa;
  --danger: #b3261e;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; font-size: 15px; color: var(--text); background: var(--bg); line-height: 1.45; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Cabecera */
.topbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-in { display: flex; align-items: center; gap: 18px; min-height: 64px; flex-wrap: wrap; }
.logo { height: 40px; width: auto; }
.app-title { display: flex; flex-direction: column; border-left: 1px solid var(--line); padding-left: 16px; }
.app-title strong { color: var(--navy); font-size: 16px; }
.app-title span { color: var(--muted); font-size: 13px; }
.tabs { margin-left: auto; display: flex; gap: 4px; }
.tab { border: 0; background: none; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); border-radius: 8px; cursor: pointer; }
.tab:hover { background: var(--bg); color: var(--navy); }
.tab.active { background: var(--navy); color: #fff; }
.demo-banner { background: var(--warn-soft); color: #7a4a00; text-align: center; font-size: 13px; padding: 6px 16px; border-bottom: 1px solid #f1dfb8; }

main { padding-top: 20px; padding-bottom: 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Tarjetas */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(14,34,64,.04); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card h2 { margin: 0; font-size: 18px; color: var(--navy); display: flex; align-items: center; gap: 10px; }
.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 14px; }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; color: var(--navy); margin-bottom: 12px; }
.field small { font-weight: 400; color: var(--muted); }
.field.grow { flex: 1; }
input[type=text], input[type=number], input[type=search], select, textarea {
  font: inherit; font-weight: 400; color: var(--text); border: 1px solid #c9d1dc; border-radius: 8px; padding: 9px 11px; background: #fff; width: 100%;
}
textarea { resize: vertical; min-height: 140px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 16px; cursor: pointer; border: 1px solid transparent; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: #156aa8; }
.btn.ghost { background: #fff; color: var(--navy); border-color: #c9d1dc; }
.btn.ghost:hover { border-color: var(--navy); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.search { max-width: 260px; }
.sel-ejemplo { width: 100%; max-width: 420px; font-weight: 600; color: var(--navy); }
.card-head .btn-group { max-width: 100%; min-width: 0; }

/* Partidas */
.partida { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.partida-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.partida-head h3 { margin: 0 0 6px; font-size: 15px; color: var(--navy); }
.partida-texto { background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 14px; color: #34404f; margin: 4px 0 12px; }
.partida-texto mark { background: #cfe6fa; color: inherit; border-radius: 3px; padding: 0 2px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.form-grid .field { margin-bottom: 0; font-size: 13px; }
.field-head { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.sis-desc { margin: 12px 0 4px; font-weight: 600; color: var(--navy); }
.partida .sis-desc::before { content: "Sistema: "; color: var(--muted); font-weight: 400; }
.partida.excluida { background: #fafbfc; }
.partida.excluida .sis-desc { color: var(--warn); }
.field.warn select, .field.warn input { border-color: #e2b25e; background: #fffaf0; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.legend { display: flex; gap: 6px; flex-wrap: wrap; }

/* Tablas */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--navy); color: #fff; font-weight: 600; font-size: 13px; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfe; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.fam td { background: var(--blue-soft) !important; font-weight: 700; color: var(--navy); font-size: 13px; }
tfoot td { font-weight: 700; background: var(--bg); }
.compare td.best { background: var(--ok-soft) !important; color: var(--ok); font-weight: 700; }
.compare td.second { box-shadow: inset 0 0 0 2px #9fd3b5; }
.compare td.na { color: #9aa5b4; font-style: italic; }
.compare .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.compare td.best .sub { color: var(--ok); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 13px; color: var(--muted); }
.kpi .value { font-size: 24px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi .note { font-size: 12px; color: var(--muted); }
.kpi.highlight { background: var(--ok-soft); border-color: #b9e2c9; }
.kpi.highlight .value { color: var(--ok); }

/* Pedidos */
.pedidos { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.pedido { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.pedido h3 { margin: 0; padding: 12px 14px; background: var(--blue-soft); color: var(--navy); font-size: 15px; display: flex; justify-content: space-between; }
.pedido table { font-size: 13px; }
.pedido td:first-child { white-space: nowrap; }
.pedido th { position: static; background: #fff; color: var(--muted); border-bottom: 1px solid var(--line); }

/* Tarifas */
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pill { border: 1px solid #c9d1dc; background: #fff; border-radius: 99px; padding: 7px 14px; font: inherit; font-weight: 600; color: var(--navy); cursor: pointer; }
.pill.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.prov-info { align-items: flex-end; }
.prov-info .field { margin: 0; max-width: 220px; }
.prov-info .stat { padding: 8px 0; color: var(--muted); font-size: 14px; }
.upload { display: grid; grid-template-columns: minmax(240px, 1fr) 1.4fr; gap: 18px; }
.upload-box { border: 2px dashed #b9c4d2; border-radius: var(--radius); padding: 24px; text-align: center; background: #fafbfd; }
.upload-box.drag { border-color: var(--blue); background: var(--blue-soft); }
.upload-box p { margin: 6px 0; }
.upload-help p { margin: 0 0 10px; }
.review { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.review h3 { margin: 18px 0 8px; font-size: 15px; color: var(--navy); }
.up { color: var(--danger); font-weight: 700; }
.down { color: var(--ok); font-weight: 700; }
.notice { border-radius: 8px; padding: 12px 14px; margin-top: 14px; }
.notice.info { background: var(--info-soft); color: #134a75; }
.notice.ok { background: var(--ok-soft); color: #155c36; }
.notice.warn { background: var(--warn-soft); color: #6d4300; }
.hist-item { display: flex; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.hist-item:last-child { border-bottom: 0; }
.hist-item .fecha { color: var(--muted); min-width: 100px; }

.footer { color: var(--muted); font-size: 12px; padding-bottom: 30px; text-align: center; }

@media (max-width: 720px) {
  .topbar { position: static; }
  .tabs { margin-left: 0; width: 100%; }
  .tab { flex: 1; padding: 8px 6px; }
  .app-title { border-left: 0; padding-left: 0; }
  .upload { grid-template-columns: 1fr; }
  .pedidos { grid-template-columns: 1fr; }
  .card { padding: 14px; }
}

/* Impresión: solo resultados */
@media print {
  body { background: #fff; font-size: 12px; }
  .tabs, .demo-banner, #tab-calcular > .card, .btn, .footer, .search { display: none !important; }
  .topbar { position: static; border: 0; }
  #resultados { display: block !important; }
  .card { border: 0; box-shadow: none; padding: 0; margin-bottom: 18px; break-inside: avoid; }
  th { background: #0e2240 !important; color: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .compare td.best, .kpi.highlight, tr.fam td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pedido { break-inside: avoid; }
}
