:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 20px; height: 58px;
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 34px; width: auto; display: block; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active { background: var(--accent); color: #08131f; font-weight: 600; }

.cart-btn {
  margin-left: auto; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px;
  cursor: pointer; font-size: 14px; font-weight: 600; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.cart-btn:hover { border-color: var(--accent); }
.cart-badge {
  background: var(--accent); color: #08131f; border-radius: 999px;
  padding: 1px 8px; font-size: 12px; font-weight: 700; min-width: 20px; text-align: center;
}
.cart-badge.empty { background: var(--border); color: var(--muted); }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }

/* Botón agregar al carrito en la tabla de productos */
.btn.add { background: var(--green); color: #052e16; }
.btn.add:hover { background: #16a34a; }

/* Cards / KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.kpi .n { font-size: 28px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 13px; margin-top: 4px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 12px; }

/* Botones */
.btn {
  background: var(--accent); color: #08131f; border: none;
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { background: var(--red); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

/* Tabla */
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
th { background: var(--panel-2); color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty { text-align: center; color: var(--muted); padding: 40px; background: var(--panel); border-radius: var(--radius); border: 1px dashed var(--border); }

/* Badges de estado */
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; display: inline-block; }
.badge.borrador { background: #475569; color: #e2e8f0; }
.badge.enviado { background: #1e3a5f; color: var(--accent); }
.badge.aceptado { background: #14432a; color: var(--green); }
.badge.rechazado { background: #4c1d1d; color: #fca5a5; }

/* Formularios */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
.field { margin-bottom: 14px; }
.filtros { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; margin-bottom: 10px; }
@media (max-width: 640px) { .filtros { grid-template-columns: 1fr; } }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 720px; }
.modal.wide { max-width: 920px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.hidden { display: none !important; }

/* Ítems de presupuesto */
.items-table input, .items-table select { padding: 6px 8px; }
.items-table td { padding: 6px; }
.link { color: var(--accent); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* Totales */
.totales { margin-top: 16px; margin-left: auto; max-width: 320px; }
.totales .row { display: flex; justify-content: space-between; padding: 5px 0; }
.totales .row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: 19px; font-weight: 700; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); padding: 12px 20px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.usd { color: var(--amber); }
.mini { font-size: 12px; color: var(--muted); }

/* Impresión de presupuesto */

/* =========================================================
   COTIZACIÓN STYLES
   ========================================================= */
.cotizacion-print {
  font-family: Arial, sans-serif;
  font-size: 12px;
  color: #1a1a1a;
  max-width: 760px;
  margin: 0 auto;
}

.cot-banner {
  background: #BDD7EE;
  color: #1F4E79;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
  padding: 10px 0;
  margin-bottom: 16px;
  border-radius: 2px;
}

.cot-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.cot-logo {
  max-height: 70px;
  max-width: 180px;
  display: block;
  margin-bottom: 6px;
}

.cot-empresa-nombre {
  font-size: 15px;
  font-weight: bold;
  color: #1F4E79;
}

.cot-empresa-datos {
  font-size: 11px;
  color: #444;
  margin-top: 4px;
}

.cot-meta {
  border-collapse: collapse;
  min-width: 220px;
}
.cot-meta th {
  background: #2E74B5;
  color: #fff;
  padding: 5px 10px;
  font-size: 10px;
  text-align: left;
  border: 1px solid #2060a0;
}
.cot-meta td {
  background: #fff;
  padding: 5px 10px;
  font-size: 11px;
  border: 1px solid #cdd8e6;
}

.cot-section-title {
  background: #2E74B5;
  color: #fff;
  font-weight: bold;
  font-size: 11px;
  padding: 5px 10px;
  margin: 14px 0 0 0;
  border-radius: 2px 2px 0 0;
}

.cot-cliente {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 16px;
}
.cot-cliente td {
  border: 1px solid #cdd8e6;
  padding: 4px 8px;
  font-size: 11px;
}
.cot-cliente .cot-lbl {
  background: #EBF3FB;
  font-weight: bold;
  width: 110px;
  color: #1F4E79;
}

.cot-items {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 14px;
}
.cot-items thead th {
  background: #2E74B5;
  color: #fff;
  padding: 6px 8px;
  font-size: 11px;
  text-align: left;
  border: 1px solid #2060a0;
}
.cot-items thead th.num {
  text-align: right;
}
.cot-items tbody td {
  border: 1px solid #cdd8e6;
  padding: 5px 8px;
  font-size: 11px;
  vertical-align: top;
}
.cot-items tbody td.num {
  text-align: right;
}
.cot-items tbody tr:nth-child(even) td {
  background: #F2F8FD;
}
.cot-subtotal-row td {
  background: #EBF3FB;
  border: 1px solid #cdd8e6;
  padding: 4px 8px;
  font-size: 11px;
  text-align: right;
  color: #333;
}
.cot-subtotal-row td:first-child {
  text-align: left;
  font-style: italic;
}
.cot-total-row td {
  background: #2E74B5;
  color: #fff;
  font-weight: bold;
  font-size: 13px;
  padding: 7px 8px;
  border: 1px solid #1F4E79;
  text-align: right;
}
.cot-total-row td:first-child {
  text-align: left;
}

.cot-notas-box {
  border: 1px solid #2E74B5;
  border-radius: 3px;
  margin-top: 14px;
}
.cot-notas-lbl {
  background: #EBF3FB;
  color: #1F4E79;
  font-weight: bold;
  font-size: 11px;
  padding: 4px 10px;
  border-bottom: 1px solid #2E74B5;
}
.cot-notas-txt {
  padding: 8px 10px;
  font-size: 11px;
  min-height: 40px;
  color: #333;
}

@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea {
    position: absolute;
    left: 0; top: 0;
    width: 100%;
    margin: 0;
    padding: 16px;
  }
  .no-print { display: none !important; }
  .modal-overlay, .modal { box-shadow: none !important; border: none !important; }
}

/* ===== RESPONSIVE MOBILE ===== */
@media (max-width: 768px) {
  /* Topbar: fila 1 = marca+carrito, fila 2 = tabs scrolleables */
  .topbar {
    padding: 8px 12px 0;
    height: auto;
    flex-wrap: wrap;
    gap: 0;
    align-items: center;
  }
  .brand {
    flex: 1;
    font-size: 15px;
  }
  .brand-logo { height: 26px; }
  .cart-btn {
    padding: 6px 10px;
    font-size: 13px;
    flex-shrink: 0;
  }
  /* Tabs: fila separada debajo, scroll horizontal */
  .tabs {
    order: 10;
    width: calc(100% + 24px);
    margin: 6px -12px 0;
    padding: 4px 12px 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 2px;
    border-top: 1px solid var(--border);
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 8px 14px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Contenido principal */
  main { padding: 12px; }
  h1 { font-size: 18px; }
  h2 { font-size: 16px; }

  /* KPIs: 2 columnas en mobile */
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi .n { font-size: 22px; }

  /* Section head: botón debajo del título */
  .section-head { flex-direction: column; align-items: flex-start; }
  .section-head .btn { width: 100%; text-align: center; }

  /* Tablas: scroll horizontal */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 500px; }
  th, td { font-size: 13px; padding: 8px 10px; }

  /* Formularios: ancho completo */
  .form-row { flex-direction: column; }
  .form-row > * { width: 100% !important; }
  input, select, textarea {
    font-size: 16px; /* evita zoom automático en Safari */
  }

  /* Modal: pantalla completa en mobile */
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 88vh !important;
    margin: 0 !important;
    border-radius: 12px 12px 0 0 !important;
    overflow-y: auto;
  }
  .modal-bg {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  /* Botones en filas de tabla */
  .btn-row { flex-direction: column; gap: 6px; }
  .btn-row .btn { width: 100%; }
}
