@font-face { font-family: 'Montserrat'; src: url('fonts/montserrat.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Playfair Display'; src: url('fonts/playfair-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }

:root {
  --forest: #173A2E; --forest-2: #24503F; --oliva: #7C8560; --amarillo: #F1E4A8; --crema: #F5EFE4;
  --blanco: #FFFDF9; --tinta: #1D2622; --gris: #6B716C; --linea: #E3DACA; --rojo: #B3412E; --rojo-bg: #F8E3DD;
  --ok: #2F6B4F; --ok-bg: #E2EFE6; --radio: 14px; --sombra: 0 1px 2px rgba(23,58,46,.06), 0 4px 14px rgba(23,58,46,.06);
  --top: env(safe-area-inset-top, 0px); --bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--crema); color: var(--tinta); font: 15px/1.45 'Montserrat', system-ui, sans-serif; }
body { min-height: 100dvh; }
h1, h2, h3 { font-family: 'Playfair Display', Georgia, serif; font-weight: 600; color: var(--forest); margin: 0; letter-spacing: .1px; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
a { color: var(--forest); }
button, input, select, textarea { font: inherit; color: inherit; }
.oculto { display: none !important; }
.muted { color: var(--gris); }
.peq { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }

/* ----- Estructura ----- */
.top { position: sticky; top: 0; z-index: 20; background: var(--forest); color: #fff; padding: calc(10px + var(--top)) 16px 10px; display: flex; align-items: center; gap: 12px; }
.top img { height: 26px; display: block; }
.top .quien { margin-left: auto; font-size: 12px; opacity: .85; text-align: right; }
.vista { max-width: 860px; margin: 0 auto; padding: 16px 14px calc(110px + var(--bot)); }
.cab { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; flex-wrap: wrap; }
.cab h1 { flex: 1; min-width: 0; }
.volver { border: 0; background: none; padding: 6px 8px 6px 0; color: var(--forest); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }

.nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; background: var(--blanco); border-top: 1px solid var(--linea); display: flex; padding-bottom: var(--bot); }
.nav a { flex: 1; text-align: center; text-decoration: none; color: var(--gris); font-size: 11.5px; font-weight: 600; padding: 9px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.nav a svg { width: 22px; height: 22px; }
.nav a.activo { color: var(--forest); }
.nav a.activo svg { stroke-width: 2.4; }
.fab { position: fixed; z-index: 31; right: 16px; bottom: calc(76px + var(--bot)); width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--amarillo); color: var(--forest); box-shadow: 0 6px 18px rgba(23,58,46,.28); cursor: pointer; display: grid; place-items: center; }
.fab svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  .nav { top: 0; bottom: 0; right: auto; width: 92px; flex-direction: column; border-top: 0; border-right: 1px solid var(--linea); padding-top: 70px; }
  .nav a { flex: 0; padding: 14px 0; }
  .top { padding-left: 108px; }
  .vista { padding-left: 108px; max-width: 980px; padding-bottom: 60px; }
  .fab { bottom: 28px; right: 28px; }
}

/* ----- Tarjetas y listas ----- */
.card { background: var(--blanco); border: 1px solid var(--linea); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px; margin-bottom: 12px; }
.card h3 { margin-bottom: 8px; }
.lista { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--blanco); border: 1px solid var(--linea); border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; cursor: pointer; }
.item:active { background: #F9F4EA; }
.item .cuerpo { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t2 { font-size: 13px; color: var(--gris); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .der { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cod { font-weight: 700; color: var(--oliva); font-variant-numeric: tabular-nums; }
.vacio { text-align: center; color: var(--gris); padding: 26px 10px; font-size: 14px; }
.seccion { margin: 20px 0 8px; display: flex; align-items: baseline; gap: 8px; }
.seccion h2 { font-size: 17px; }
.seccion .n { color: var(--gris); font-size: 13px; }

.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #ECE6D8; color: var(--forest); white-space: nowrap; }
.e-Cotizado { background: #EEE9DC; color: #5D5A4C; }
.e-Pagado { background: var(--amarillo); color: #5B4D10; }
.e-Modelado, .e-Aprobación, .e-Por-grabar, .e-Grabado { background: #E3E7D6; color: #4C5537; }
.e-Por-enviar, .e-Enviado { background: #DCE8E2; color: var(--forest); }
.e-Entregado { background: var(--forest); color: #fff; }
.e-Perdido { background: var(--rojo-bg); color: var(--rojo); }
.alerta { color: var(--rojo); font-weight: 600; }
.chip-saldo { font-size: 11.5px; font-weight: 700; color: var(--rojo); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; border: 1px solid var(--linea); background: var(--blanco); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--forest); }
.chip.activo { background: var(--forest); border-color: var(--forest); color: #fff; }
.chip .n { opacity: .7; margin-left: 4px; font-weight: 500; }

.buscar { position: relative; margin-bottom: 12px; }
.buscar input[type=search] { width: 100%; padding: 12px 14px 12px 40px; border-radius: 12px; border: 1px solid var(--linea); background: var(--blanco); font-size: 16px; }
.buscar svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--gris); }

.datos { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.datos dt { color: var(--gris); }
.datos dd { margin: 0; font-weight: 500; word-break: break-word; }

.acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { border: 1px solid var(--forest); background: var(--forest); color: #fff; border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; font-size: 14.5px; min-height: 44px; }
.btn.sec { background: var(--blanco); color: var(--forest); border-color: var(--linea); }
.btn.amarillo { background: var(--amarillo); border-color: var(--amarillo); color: var(--forest); }
.btn.peligro { background: var(--blanco); color: var(--rojo); border-color: #E6C2B8; }
.btn.chico { padding: 7px 12px; min-height: 36px; font-size: 13px; border-radius: 10px; }
.btn.ancho { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .55; cursor: default; }

.estado-caja { display: flex; flex-direction: column; gap: 10px; }
.pasos { display: flex; gap: 3px; }
.pasos span { flex: 1; height: 5px; border-radius: 3px; background: #E7E0D0; }
.pasos span.si { background: var(--oliva); }

.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla td { padding: 7px 0; border-bottom: 1px solid var(--linea); vertical-align: top; }
.tabla td:last-child { text-align: right; white-space: nowrap; padding-left: 10px; }
.tabla tr:last-child td { border-bottom: 0; }
.totales { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; margin-top: 8px; }
.totales .fuerte { font-weight: 700; }

.notas { display: flex; flex-direction: column; gap: 8px; }
.nota { background: #FBF7EE; border-radius: 10px; padding: 9px 11px; font-size: 14px; }
.nota .meta { font-size: 11.5px; color: var(--gris); margin-bottom: 2px; }
.nota-nueva { display: flex; gap: 8px; margin-top: 10px; }
.nota-nueva textarea { flex: 1; min-height: 44px; }
.hist { font-size: 13px; color: var(--gris); display: flex; flex-direction: column; gap: 5px; }
.hist b { color: var(--tinta); font-weight: 600; }

/* ----- Formularios ----- */
.campo { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.campo > label, .lbl { font-size: 13px; font-weight: 600; color: var(--forest); }
.campo .req::after { content: ' *'; color: var(--rojo); }
.campo .ayuda { font-size: 12px; color: var(--gris); }
.campo .error { font-size: 12.5px; color: var(--rojo); font-weight: 600; }
input[type=text], input[type=tel], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid #D6CCB8; border-radius: 10px; background: #fff; font-size: 16px; min-height: 46px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--oliva); outline-offset: 0; border-color: var(--oliva); }
.invalido { border-color: var(--rojo) !important; background: #FFF8F6 !important; }
.fila { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fila > .campo { min-width: 0; }
.fecha { display: flex; gap: 6px; position: relative; }
.fecha input[type=text] { flex: 1; min-width: 0; }
.fecha .cal { flex-shrink: 0; width: 46px; border: 1px solid #D6CCB8; border-radius: 10px; background: #fff; display: grid; place-items: center; cursor: pointer; color: var(--forest); }
.fecha .cal svg { width: 20px; height: 20px; }
.fecha input[type=date] { position: absolute; right: 0; bottom: 0; width: 46px; height: 46px; opacity: 0; pointer-events: none; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--forest); font-size: 14px; padding: 6px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--forest); }
.grupo { border: 1px solid var(--linea); border-radius: 12px; padding: 12px; margin-bottom: 14px; background: #FFFCF6; }
.grupo > .lbl { display: block; margin-bottom: 10px; font-family: 'Playfair Display', Georgia, serif; font-size: 16px; }
.pieza { border: 1px dashed #D6CCB8; border-radius: 10px; padding: 10px; margin-bottom: 10px; background: #fff; }
.pieza .ph { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 700; color: var(--oliva); font-size: 13px; }
.x { border: 0; background: none; color: var(--rojo); font-weight: 600; cursor: pointer; padding: 4px; font-size: 13px; }
.selector-cliente .resultados { max-height: 230px; overflow: auto; margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.selector-cliente .resultados button { text-align: left; border: 1px solid var(--linea); background: #fff; border-radius: 10px; padding: 9px 11px; cursor: pointer; }
.elegido { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--oliva); border-radius: 10px; padding: 10px 12px; }
.elegido .cuerpo { flex: 1; min-width: 0; }

/* ----- Modales ----- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,30,24,.45); display: flex; align-items: flex-end; justify-content: center; }
.modal .hoja { background: var(--crema); width: 100%; max-width: 640px; max-height: 100dvh; height: 100dvh; display: flex; flex-direction: column; }
.modal .mcab { background: var(--blanco); border-bottom: 1px solid var(--linea); padding: calc(10px + var(--top)) 12px 10px 16px; display: flex; align-items: center; gap: 8px; }
.modal .mcab h2 { flex: 1; font-size: 18px; }
.modal .cerrar { border: 0; background: none; width: 42px; height: 42px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; color: var(--forest); }
.modal .cerrar svg { width: 22px; height: 22px; }
.modal .mcuerpo { flex: 1; overflow: auto; padding: 16px 14px 24px; -webkit-overflow-scrolling: touch; }
.modal .mpie { background: var(--blanco); border-top: 1px solid var(--linea); padding: 10px 14px calc(10px + var(--bot)); display: flex; gap: 8px; }
.modal .mpie .btn { flex: 1; }
.modal.chico { align-items: center; padding: 16px; }
.modal.chico .hoja { height: auto; max-height: 90dvh; border-radius: 16px; overflow: hidden; max-width: 460px; }
@media (min-width: 700px) {
  .modal { align-items: center; padding: 24px; }
  .modal .hoja { height: auto; max-height: calc(100dvh - 48px); border-radius: 18px; overflow: hidden; }
  .modal .mcab { padding-top: 12px; }
}
.borrador { background: var(--amarillo); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 13.5px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.borrador span { flex: 1 1 180px; }
.aviso { background: var(--rojo-bg); color: var(--rojo); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; font-weight: 600; margin-bottom: 12px; }

#toast { position: fixed; z-index: 80; left: 50%; bottom: calc(150px + var(--bot)); transform: translateX(-50%) translateY(20px); background: var(--tinta); color: #fff; padding: 11px 18px; border-radius: 12px; font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); text-align: center; }
#toast.ver { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--rojo); }

/* ----- Login ----- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 22px; }
.login img { display: block; width: 210px; margin: 0 auto 6px; }
.login p { text-align: center; margin: 0 0 22px; color: var(--gris); font-size: 13px; letter-spacing: .4px; text-transform: uppercase; }

.cargando { display: grid; place-items: center; min-height: 60dvh; color: var(--gris); }
.wa { color: #1F7A4D; }
