:root {
  --ink: #1d1b2e;
  --ink-2: #4a4763;
  --mute: #7c7993;
  --line: #dcdaea;
  --bg: #f5f4fa;
  --card: #ffffff;
  --lav: #8f8ad0;
  --lav-2: #e9e7f7;
  --lav-3: #f3f2fb;
  --ok: #2f8f5b;
  --warn: #b7791f;
  --bad: #c0392b;
  --r: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.4; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.cargando { padding: 40px; text-align: center; color: var(--mute); }

/* barra superior */
.top { position: sticky; top: 0; z-index: 10; background: var(--ink); color: #fff; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); display: flex; align-items: center; gap: 14px; }
.top .marca { font-weight: 800; letter-spacing: .03em; font-size: 15px; text-decoration: none; white-space: nowrap; }
.top .marca small { font-weight: 500; opacity: .6; margin-left: 6px; letter-spacing: 0; }
.top nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.top nav a, .top nav button { color: #e7e5f7; text-decoration: none; white-space: nowrap; padding: 7px 11px; border-radius: 8px; background: none; border: 0; cursor: pointer; font-size: 14px; }
.top nav a.on, .top nav a:hover, .top nav button:hover { background: rgba(255,255,255,.12); color: #fff; }
.top nav .nueva { background: var(--lav); color: #fff; font-weight: 600; }
.top nav .nueva:hover { background: #a29ee0; }
.quien { font-size: 12px; opacity: .65; margin-left: 6px; white-space: nowrap; }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin: 0 0 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 14px; }
.card.lav { background: var(--lav-3); border-color: var(--lav-2); }

/* formularios */
.grid { display: grid; gap: 10px 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.g2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
label.f > span em { font-style: normal; color: var(--bad); }
input:not([type]), input[type=text], input[type=tel], input[type=email], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; font-size: 15px; font-weight: 400; color: var(--ink);
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--lav); outline-offset: 0; border-color: var(--lav); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 9px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--lav); }
.btn.pri { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.pri:hover { background: #2e2b47; }
.btn.lav { background: var(--lav); color: #fff; border-color: var(--lav); }
.btn.peq { padding: 6px 10px; font-size: 13px; }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; }

/* chips de fallas y toggles */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; cursor: pointer; font-size: 14px; user-select: none; }
.chip.on { border-color: var(--lav); background: var(--lav-2); color: var(--ink); font-weight: 600; }
.chip input { display: none; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-weight: 600; }
.toggle.on { border-color: var(--lav); background: var(--lav-2); }
.toggle input { width: 18px; height: 18px; accent-color: var(--ink); }

.aviso { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 10px 0 0; }
.aviso.info { background: var(--lav-2); }
.aviso.warn { background: #fdf2dd; color: #6b4a0f; }
.aviso.ok { background: #e3f4ea; color: #1d5b39; }
.aviso a { font-weight: 700; }

/* fotos */
.fotos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.fotos .ft { width: 92px; height: 92px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); position: relative; background: var(--lav-3); }
.fotos .ft img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.fotos .ft button { position: absolute; top: 3px; right: 3px; border: 0; background: rgba(0,0,0,.6); color: #fff; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; line-height: 1; }
.subir { width: 92px; height: 92px; border: 1.5px dashed var(--lav); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink-2); font-size: 12px; cursor: pointer; background: var(--lav-3); text-align: center; }
.subir input { display: none; }
.subir b { font-size: 24px; line-height: 1; }

/* firma */
.firma-box { border: 1.5px dashed var(--lav); border-radius: 10px; background: #fff; position: relative; touch-action: none; }
.firma-box canvas { width: 100%; height: 170px; display: block; }
.firma-box .lin { position: absolute; left: 20px; right: 20px; bottom: 38px; border-bottom: 1px solid var(--line); pointer-events: none; }
.firma-box .hint { position: absolute; left: 22px; bottom: 16px; color: var(--mute); font-size: 12px; pointer-events: none; }

/* bandeja */
.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filtros input[type=search] { flex: 1 1 260px; }
.estados { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: thin; }
.estados button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.estados button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.estados button .n { display: inline-block; min-width: 20px; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--lav-2); color: var(--ink); font-size: 12px; font-weight: 700; }
.estados button.on .n { background: rgba(255,255,255,.2); color: #fff; }
.lista { display: flex; flex-direction: column; gap: 8px; }
.fila { display: grid; grid-template-columns: 74px 1fr auto; gap: 4px 14px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; text-decoration: none; }
.fila:hover { border-color: var(--lav); }
.fila .nro { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.fila .nro small { display: block; font-size: 11px; font-weight: 500; color: var(--mute); }
.fila .cli { font-weight: 600; }
.fila .eq { color: var(--ink-2); font-size: 14px; }
.fila .der { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.fila .dias { font-size: 12px; color: var(--mute); }
.fila .dias.tarde { color: var(--bad); font-weight: 700; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--lav-2); color: var(--ink); white-space: nowrap; }
.badge.e-ingresada { background: #e7f0fb; color: #1f4f86; }
.badge.e-con_tecnico, .badge.e-en_reparacion { background: #fdf2dd; color: #7a5310; }
.badge.e-cotizada, .badge.e-presupuestada { background: #f1e6fb; color: #6a2e93; }
.badge.e-aprobada { background: #e3f4ea; color: #1d5b39; }
.badge.e-lista { background: #d8f3e4; color: #13573a; }
.badge.e-para_devolucion { background: #fbe3e1; color: #8c2a20; }
.badge.e-entregada, .badge.e-devuelta, .badge.e-repuestos { background: #eceaf2; color: #5b5873; }
.badge.gar { background: var(--ink); color: #fff; }
.vacio { text-align: center; color: var(--mute); padding: 40px 10px; }

/* ficha */
.ficha-head { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 14px; }
.ficha-head .nro { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ficha-head .sub { color: var(--mute); font-size: 13px; }
.ficha-cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; align-items: start; }
dl.datos { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
dl.datos dt { color: var(--mute); }
dl.datos dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.historial { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.historial li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.historial li:last-child { border: 0; }
.historial .q { color: var(--mute); font-size: 12px; }
.firma-img { max-width: 100%; max-height: 110px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20,18,35,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal .caja { background: #fff; border-radius: 14px; padding: 18px; width: min(460px, 100%); max-height: 90vh; overflow: auto; }
.modal img.grande { max-width: 100%; max-height: 85vh; border-radius: 10px; display: block; }
.modal.img .caja { width: auto; padding: 8px; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--ink); }
.login .caja { background: #fff; border-radius: 16px; padding: 28px 24px; width: min(360px, 100%); }
.login .logo { font-weight: 800; font-size: 22px; letter-spacing: .02em; margin-bottom: 2px; }
.login p { color: var(--mute); margin: 0 0 18px; font-size: 14px; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.err { color: var(--bad); font-size: 14px; min-height: 18px; }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(30px); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px); font-size: 14px; }
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.mal { background: var(--bad); }

.barra-guardar { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 max(10px, env(safe-area-inset-bottom)); display: flex; gap: 10px; justify-content: flex-end; }
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th, .tabla td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.tabla th { font-size: 12px; color: var(--mute); font-weight: 600; }
.muted { color: var(--mute); }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 6px; }
  .top nav { width: 100%; margin: 0; overflow-x: auto; }
  .quien { display: none; }
  .ficha-cols { grid-template-columns: 1fr; }
  .fila { grid-template-columns: 58px 1fr; }
  .fila .der { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  dl.datos { grid-template-columns: 100px 1fr; }
  h1 { font-size: 20px; }
}
@media print { .top, .acciones, .barra-guardar { display: none !important; } }
