*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --border-hover: #c8ccd5;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-hint: #9ca3af;
  --primary: #185FA5;
  --primary-light: #E6F1FB;
  --primary-dark: #0C447C;
  --success: #3B6D11;
  --success-light: #EAF3DE;
  --warning: #854F0B;
  --warning-light: #FAEEDA;
  --danger: #A32D2D;
  --danger-light: #FCEBEB;
  --info: #185FA5;
  --info-light: #E6F1FB;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --sidebar-w: 220px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto; z-index: 100; }
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; height: 56px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; }
.page-body { padding: 24px; flex: 1; }

/* ── Sidebar ── */
.sidebar-logo { padding: 20px 16px 12px; border-bottom: 1px solid var(--border); }
.sidebar-logo h2 { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; }
.sidebar-logo p { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.nav-section { font-size: 10px; font-weight: 600; letter-spacing: .08em; color: var(--text-hint); text-transform: uppercase; padding: 12px 16px 4px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 8px 16px; font-size: 13px; color: var(--text-muted); cursor: pointer; border-radius: 0; text-decoration: none; transition: all .12s; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 500; border-right: 2px solid var(--primary); }
.nav-item svg, .nav-item i { font-size: 16px; flex-shrink: 0; }
.sidebar-footer { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.user-name { font-size: 12px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--text-muted); }

/* ── Topbar ── */
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 20px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 14px; display: flex; align-items: center; gap: 7px; }

/* ── KPI grid ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card { background: var(--bg); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 11px; color: var(--text-muted); margin-bottom: 5px; }
.kpi-value { font-size: 24px; font-weight: 600; color: var(--text); line-height: 1; }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.kpi-card.primary .kpi-value { color: var(--primary); }
.kpi-card.success .kpi-value { color: var(--success); }
.kpi-card.danger .kpi-value { color: var(--danger); }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { background: var(--bg); color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg); }
tfoot td { padding: 9px 12px; font-weight: 600; border-top: 1px solid var(--border); background: var(--bg); }

/* ── Badges ── */
.badge { display: inline-block; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge-green { background: var(--success-light); color: var(--success); }
.badge-amber { background: var(--warning-light); color: var(--warning); }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-gray { background: #F1EFE8; color: #5F5E5A; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; transition: all .12s; white-space: nowrap; }
.btn:hover { border-color: var(--border-hover); background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { font-size: 12px; padding: 5px 10px; }
.btn-danger { background: var(--danger-light); color: var(--danger); border-color: #f0b0b0; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  font-size: 13px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-family: inherit; outline: none; transition: border .12s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Alerts ── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; display: flex; align-items: flex-start; gap: 8px; }
.alert-info { background: var(--primary-light); color: var(--primary-dark); border-left: 3px solid var(--primary); }
.alert-success { background: var(--success-light); color: var(--success); border-left: 3px solid var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger); border-left: 3px solid var(--danger); }
.alert-warning { background: var(--warning-light); color: var(--warning); border-left: 3px solid var(--warning); }

/* ── Sections ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title { font-size: 14px; font-weight: 600; }

/* ── Winner banner ── */
.winner-banner { background: var(--primary-light); border: 1px solid #B5D4F4; border-radius: var(--radius-lg); padding: 16px 20px; margin-bottom: 18px; }
.winner-banner-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.winner-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.winner-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.wchip { background: var(--surface); border: 1px solid #B5D4F4; border-radius: var(--radius-lg); padding: 8px 14px; flex: 1; min-width: 120px; }
.wchip-label { font-size: 10px; font-weight: 600; color: var(--primary); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px; }
.wchip-val { font-size: 15px; font-weight: 600; color: var(--primary-dark); }
.wchip-sub { font-size: 11px; color: var(--primary); }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 36px 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.login-logo p { font-size: 13px; color: var(--text-muted); }

/* ── Bar charts ── */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-lbl { font-size: 12px; color: var(--text-muted); width: 90px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; transition: width .4s; }
.bar-val { font-size: 12px; font-weight: 500; width: 70px; text-align: right; flex-shrink: 0; }

/* ── Upload area ── */
.upload-area { border: 2px dashed var(--border-hover); border-radius: var(--radius-lg); padding: 36px; text-align: center; cursor: pointer; transition: all .15s; }
.upload-area:hover, .upload-area.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-area p { font-size: 13px; color: var(--text-muted); margin-top: 8px; }

/* ── Modal ── */
.modal-overlay, .modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 1000; opacity: 0; pointer-events: none; transition: opacity .15s; }
.modal-overlay.open, .modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 24px 28px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.14); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--text-muted); padding: 2px 6px; border-radius: var(--radius); }
.modal-close:hover { background: var(--bg); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── Misc ── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.spacer { flex: 1; }
.cell-best { background: var(--success-light) !important; color: var(--success); font-weight: 600; }
.cell-high { background: var(--danger-light) !important; color: var(--danger); }
.oferta-pick { all: unset; cursor: pointer; display: block; width: 100%; padding: 4px 6px; border-radius: 6px; border: 1px solid transparent; box-sizing: border-box; }
.oferta-pick:hover { background: var(--primary-light); }
.oferta-pick.picked { background: var(--primary-light); border-color: var(--primary); }
.oferta-pick .picked-tag { display: block; font-size: 9px; font-weight: 700; color: var(--primary-dark); margin-top: 2px; }
.cell-iva { background: #EEF6FF; color: var(--primary); }
.cell-total { background: var(--success-light); color: var(--success); font-weight: 600; }
.input-price { width: 100%; font-size: 13px; text-align: right; padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }
.input-price:focus { border-color: var(--primary); outline: none; }
.comment-input { width: 100%; font-size: 12px; padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }
.comment-input:focus { border-color: var(--primary); outline: none; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .winner-chips { flex-direction: column; }
}
