/* ============================================================
   Cotizador Aire Bahía — v1.0
   Sin emojis. Iconos: Tabler Icons via CDN
   Paleta: #25646d | #52bdb0 | #91fff0 | #ffffff
   ============================================================ */

:root {
  --primary:    #25646d;
  --primary-dk: #1a4a52;
  --secondary:  #52bdb0;
  --accent:     #91fff0;
  --accent-dk:  #5ee8d4;
  --light:      #f0fafa;
  --white:      #ffffff;
  --text:       #1e2d2f;
  --muted:      #637e82;
  --border:     #cfe0e2;
  --danger:     #d94f4f;
  --success:    #2eaa71;
  --warning:    #e09a2e;

  --shadow-xs:  0 1px 3px rgba(37,100,109,.1);
  --shadow-sm:  0 2px 8px rgba(37,100,109,.12);
  --shadow-md:  0 4px 20px rgba(37,100,109,.16);
  --shadow-lg:  0 8px 40px rgba(37,100,109,.18);
  --r-sm:       5px;
  --r-md:       9px;
  --r-lg:       14px;
  --t:          .16s ease;
  --font:       'Inter', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body { font-family: var(--font); background: #e8f2f3; color: var(--text); min-height: 100vh; }

/* ---- TOPBAR ---- */
.topbar {
  background: var(--primary);
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow-md);
  gap: 16px;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-logo {
  height: 30px;
  filter: brightness(0) invert(1);
  flex-shrink: 0;
}
.topbar-divider {
  width: 1px;
  height: 28px;
  background: rgba(255,255,255,.2);
}
.topbar-title {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.topbar-title .app-name {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--white);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.topbar-title .app-version {
  font-size: .68rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: .5px;
  margin-top: 2px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  border-radius: var(--r-sm);
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: .84rem;
  font-weight: 600;
  transition: var(--t);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn i { font-size: 1rem; }
.btn-primary   { background: var(--primary);   color: var(--white); }
.btn-primary:hover { background: var(--primary-dk); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-secondary { background: var(--secondary); color: var(--white); }
.btn-secondary:hover { background: var(--primary); transform: translateY(-1px); }
.btn-accent    { background: var(--accent);    color: var(--primary-dk); }
.btn-accent:hover { background: var(--accent-dk); transform: translateY(-1px); }
.btn-ghost     { background: transparent; border: 1.5px solid rgba(255,255,255,.3); color: var(--white); }
.btn-ghost:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.5); }
.btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--primary); }
.btn-outline:hover { border-color: var(--secondary); background: var(--light); }
.btn-danger    { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #b84040; }
.btn-sm  { padding: 5px 11px; font-size: .78rem; }
.btn-lg  { padding: 10px 22px; font-size: .95rem; }
.btn-icon { padding: 7px; width: 34px; height: 34px; justify-content: center; border-radius: var(--r-sm); }

/* ---- LAYOUT ---- */
.page { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; gap: 16px; }

/* ---- CARD ---- */
.card {
  background: var(--white);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  padding: 12px 18px;
  background: var(--light);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.card-header h2 {
  font-size: .88rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 7px;
  letter-spacing: .2px;
}
.card-header h2 i { font-size: 1rem; color: var(--secondary); }
.card-body { padding: 18px; }

/* ---- FORM ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 11px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--font);
  font-size: .875rem;
  color: var(--text);
  outline: none;
  transition: var(--t);
  background: var(--white);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(82,189,176,.14);
}

/* Folio + usuario badges */
.folio-row { display: flex; align-items: center; gap: 10px; }
.folio-prefix-select {
  width: 72px !important;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}
.folio-badge-display {
  background: var(--accent);
  color: var(--primary-dk);
  font-weight: 700;
  font-size: .82rem;
  padding: 4px 11px;
  border-radius: 20px;
  letter-spacing: .5px;
  white-space: nowrap;
}

/* ---- TABLA DE PARTIDAS ---- */
.toolbar-partidas {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--light);
  flex-wrap: wrap;
}
.toolbar-partidas .label-count {
  font-size: .78rem;
  color: var(--muted);
  margin-left: auto;
}

.tabla-wrap { overflow-x: auto; }
.tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: .855rem;
}
.tabla thead tr { background: var(--primary); }
.tabla thead th {
  padding: 9px 11px;
  text-align: left;
  font-size: .74rem;
  font-weight: 700;
  color: rgba(255,255,255,.9);
  letter-spacing: .4px;
  white-space: nowrap;
  border: none;
}
.tabla thead th.col-right { text-align: right; }
.tabla thead th.col-center { text-align: center; }

.tabla tbody tr {
  border-bottom: 1px solid #e8f0f1;
  transition: background var(--t);
  position: relative;
}
.tabla tbody tr:hover { background: rgba(145,255,240,.05); }
.tabla tbody tr.row-dragging { opacity: .45; background: var(--light); }
.tabla tbody tr.row-new { animation: rowIn .25s ease; }
@keyframes rowIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.tabla td {
  padding: 6px 8px;
  vertical-align: top;
  border: none;
}
.col-drag  { width: 22px; text-align: center; cursor: grab; color: #bcd0d3; user-select: none; padding-top: 12px; }
.col-drag:hover { color: var(--muted); }
.col-drag:active { cursor: grabbing; }
.col-num   { width: 30px; text-align: center; color: var(--muted); font-size: .75rem; padding-top: 13px; }
.col-cant  { width: 72px; }
.col-unid  { width: 82px; }
.col-desc  { min-width: 280px; position: relative; }
.col-precio { width: 120px; }
.col-imp   { width: 120px; text-align: right; padding-right: 14px; padding-top: 13px; }
.col-del   { width: 34px; text-align: center; padding-top: 8px; }

/* Inputs en tabla */
.tabla td input[type="number"],
.tabla td input[type="text"],
.tabla td select {
  width: 100%;
  padding: 6px 8px;
  border: 1.5px solid transparent;
  border-radius: var(--r-sm);
  font-family: var(--font);
  font-size: .855rem;
  background: transparent;
  outline: none;
  transition: var(--t);
  color: var(--text);
}
.tabla td input:hover, .tabla td select:hover { border-color: var(--border); background: var(--light); }
.tabla td input:focus, .tabla td select:focus { border-color: var(--secondary); background: var(--white); box-shadow: 0 0 0 3px rgba(82,189,176,.12); }
.tabla td input[type="number"] { text-align: right; }
.tabla td input.input-precio { text-align: right; }

.desc-area {
  width: 100%;
  min-height: 52px;
  max-height: 120px;
  padding: 6px 8px;
  border: 1.5px solid transparent;
  border-radius: var(--r-sm);
  font-family: var(--font);
  font-size: .845rem;
  background: transparent;
  outline: none;
  transition: var(--t);
  resize: none;
  line-height: 1.5;
  color: var(--text);
  overflow-y: hidden;
}
.desc-area:hover { border-color: var(--border); background: var(--light); }
.desc-area:focus { border-color: var(--secondary); background: var(--white); box-shadow: 0 0 0 3px rgba(82,189,176,.12); overflow-y: auto; }

/* Autocomplete dropdown */
.autocomplete-wrapper { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--white);
  border: 1.5px solid var(--secondary);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  z-index: 500;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}
.autocomplete-list.show { display: block; }
.ac-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f5f6;
  transition: background var(--t);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: var(--light); }
.ac-item-name { font-size: .82rem; font-weight: 600; color: var(--text); }
.ac-item-meta { font-size: .73rem; color: var(--muted); margin-top: 1px; display: flex; gap: 8px; }
.ac-item-price { color: var(--secondary); font-weight: 600; }
.ac-item-folio { background: var(--light); border-radius: 3px; padding: 0 4px; }
mark { background: rgba(145,255,240,.5); border-radius: 2px; padding: 0 1px; }

.importe-val { font-weight: 700; color: var(--primary); font-size: .88rem; }
.importe-zero { color: var(--border); font-weight: 400; }

.del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #c5d5d8;
  font-size: .95rem;
  padding: 5px;
  border-radius: var(--r-sm);
  transition: var(--t);
  display: flex;
  align-items: center;
  justify-content: center;
}
.del-btn:hover { color: var(--danger); background: rgba(217,79,79,.08); }

/* Fila vacía */
.row-empty td { padding: 36px; text-align: center; color: var(--muted); font-size: .84rem; }
.empty-hint { margin-top: 6px; font-size: .78rem; }

/* ---- TOTALES ---- */
.bottom-grid { display: grid; grid-template-columns: 1fr 290px; gap: 16px; align-items: start; }

/* Notas */
.notas-wrap { display: flex; flex-direction: column; gap: 6px; }
.nota-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--light);
  border-left: 3px solid var(--secondary);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 8px 10px;
}
.nota-num { font-size: .72rem; font-weight: 700; color: var(--secondary); min-width: 16px; padding-top: 2px; }
.nota-input {
  flex: 1;
  font-size: .79rem;
  color: var(--muted);
  border: none;
  background: transparent;
  font-family: var(--font);
  resize: none;
  outline: none;
  min-height: 34px;
  line-height: 1.5;
}
.nota-input:focus { color: var(--text); }

/* Totales box */
.totales-box {
  background: var(--light);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.totales-box .t-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: .87rem;
}
.totales-box .t-row:last-child { border-bottom: none; }
.totales-box .t-label { color: var(--muted); font-weight: 500; }
.totales-box .t-val { font-weight: 700; color: var(--text); }
.totales-box .t-row.row-total {
  background: var(--primary);
  padding: 11px 14px;
}
.totales-box .t-row.row-total .t-label { color: rgba(255,255,255,.8); font-size: .9rem; font-weight: 700; }
.totales-box .t-row.row-total .t-val { color: var(--accent); font-size: 1.15rem; font-weight: 800; }

/* IVA toggle */
.iva-label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.sw { position: relative; width: 34px; height: 18px; flex-shrink: 0; }
.sw input { display: none; }
.sw-track {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 18px;
  transition: var(--t);
}
.sw-thumb {
  position: absolute;
  width: 12px; height: 12px;
  top: 3px; left: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: var(--t);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.sw input:checked ~ .sw-track { background: var(--secondary); }
.sw input:checked ~ .sw-thumb { transform: translateX(16px); }

/* Anticipo */
.anticipo-section { padding: 10px 14px; border-top: 1px dashed var(--border); }
.ant-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: .84rem; }
.ant-row .t-label { color: var(--muted); }
.ant-input-wrap { display: flex; align-items: center; gap: 5px; }
.ant-input-wrap input {
  width: 56px;
  padding: 4px 7px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--font);
  font-size: .82rem;
  text-align: right;
  outline: none;
  transition: var(--t);
}
.ant-input-wrap input:focus { border-color: var(--secondary); }
.ant-input-wrap span { font-size: .75rem; color: var(--muted); }
.ant-row .t-val { font-weight: 700; color: var(--primary); font-size: .87rem; min-width: 100px; text-align: right; }

/* ---- ACTIONS BAR ---- */
.actions-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 4px 0;
  flex-wrap: wrap;
}

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px);
  animation: mIn .18s ease;
}
@keyframes mIn { from { opacity:0 } to { opacity:1 } }
.modal {
  background: var(--white);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 820px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  animation: mSlide .2s ease;
}
@keyframes mSlide { from { transform: translateY(20px); opacity:0 } to { transform:none; opacity:1 } }
.modal-hd {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.modal-hd h3 { font-size: .92rem; color: var(--primary); font-weight: 700; }
.modal-bd { padding: 22px; overflow-y: auto; flex: 1; }
.modal-ft {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--light);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ---- PREVIEW PDF ---- */
.preview-doc { font-family: 'Inter', sans-serif; max-width: 760px; margin: 0 auto; }
.preview-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 3px solid var(--primary);
}
.preview-logo { height: 46px; }
.preview-company { text-align: center; }
.preview-company h1 { font-size: 1.2rem; color: var(--primary); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.preview-company p { font-size: .73rem; color: var(--muted); }
.preview-folio { text-align: right; }
.preview-folio .folio-num { font-size: 1.4rem; font-weight: 800; color: var(--primary); }
.preview-folio .folio-meta { font-size: .75rem; color: var(--muted); }

.preview-client {
  background: var(--light);
  border-left: 4px solid var(--secondary);
  padding: 10px 14px;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin-bottom: 16px;
  font-size: .85rem;
}
.preview-client strong { color: var(--primary); }

.ptable { width: 100%; border-collapse: collapse; font-size: .82rem; margin-bottom: 16px; }
.ptable thead tr { background: var(--primary); }
.ptable thead th { padding: 8px 10px; color: rgba(255,255,255,.9); text-align: left; font-size: .74rem; font-weight: 700; letter-spacing: .3px; }
.ptable thead th.tr { text-align: right; }
.ptable tbody tr:nth-child(even) { background: var(--light); }
.ptable tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ptable tbody td.tr { text-align: right; font-weight: 700; color: var(--primary); }
.ptable tfoot td { padding: 7px 10px; }
.ptable tfoot .fl { text-align: right; color: var(--muted); }
.ptable tfoot .fv { text-align: right; font-weight: 700; color: var(--primary); }
.ptable tfoot tr.row-grand { background: var(--primary); }
.ptable tfoot tr.row-grand td { color: var(--white); font-weight: 800; font-size: .95rem; }

.preview-notas h4 { font-size: .8rem; color: var(--primary); margin-bottom: 5px; font-weight: 700; }
.preview-notas ol { padding-left: 16px; }
.preview-notas li { font-size: .75rem; color: var(--muted); line-height: 1.7; }

.preview-anticipo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.ant-box { background: var(--light); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px 14px; text-align: center; }
.ant-box .alabel { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.ant-box .aval { font-size: 1.05rem; font-weight: 800; color: var(--primary); margin-top: 3px; }

/* ---- FOLIOS MODAL ---- */
.folio-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.folio-table th { padding: 8px 12px; background: var(--light); text-align: left; font-size: .76rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); }
.folio-table td { padding: 8px 12px; border-bottom: 1px solid #f0f5f6; }
.folio-table tr:hover td { background: var(--light); }
.folio-status { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: .72rem; font-weight: 700; }
.status-used { background: rgba(82,189,176,.15); color: var(--secondary); }
.status-draft { background: rgba(224,154,46,.15); color: var(--warning); }

/* ---- TOAST ---- */
.toast-wrap { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 7px; z-index: 9999; }
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-size: .85rem;
  font-weight: 500;
  min-width: 230px;
  animation: tIn .22s ease;
}
.toast i { font-size: 1.05rem; }
.toast.ok   { background: var(--success); color: var(--white); }
.toast.err  { background: var(--danger);  color: var(--white); }
.toast.info { background: var(--primary); color: var(--white); }
@keyframes tIn  { from { transform: translateX(110%); opacity:0 } to { transform:none; opacity:1 } }
@keyframes tOut { to   { transform: translateX(110%); opacity:0 } }
.toast.out { animation: tOut .22s ease forwards; }

/* ---- RESPONSIVE ---- */
@media (max-width: 860px) {
  .bottom-grid { grid-template-columns: 1fr; }
  .topbar-title .app-name { font-size: .95rem; }
}
@media (max-width: 580px) {
  .page { padding: 12px 10px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .actions-bar .btn { flex: 1; justify-content: center; }
}
@media print {
  .topbar, .toolbar-partidas, .actions-bar, .card-header .btn,
  .toast-wrap, .modal-overlay, .del-btn, .col-drag, .col-del { display: none !important; }
  body { background: white; }
  .card { box-shadow: none; border: none; }
}
