:root {
  --navy: #2c4a7c;
  --blue: #3f5ba9;
  --blue-soft: #e8eefb;
  --band: #a6cee0;
  --pink: #f4a79d;
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #1b2333;
  --muted: #5e6a80;
  --line: #d5dbe7;
  --ok: #1d7a46;
  --ok-bg: #e6f5ec;
  --warn: #8a5300;
  --warn-bg: #fff4e0;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 35, 70, .08), 0 4px 14px rgba(20, 35, 70, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
a { color: var(--blue); }
h1, h2, h3 { margin: 0; }

/* ---------- barra superior y pestañas ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--navy); color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-back {
  border: 0; background: rgba(255, 255, 255, .15); color: #fff;
  font-size: 15px; font-weight: 600; padding: 8px 12px; border-radius: 10px; min-height: 40px;
}
.top-logo { display: flex; align-items: center; flex: none; background: #fff; border-radius: 10px; padding: 5px 9px; height: 40px; }
.top-logo img { height: 30px; width: auto; display: block; }
.save-state { font-size: 12px; opacity: .9; white-space: nowrap; }
.save-state.pending { color: #ffe39a; }
.save-state.err { color: #ffb4ab; font-weight: 700; }

.view { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar[hidden] { display: none; }
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 10px; font-size: 11.5px; color: var(--muted); text-decoration: none; min-height: 58px;
}
.tabbar a span { font-size: 20px; line-height: 1.1; }
.tabbar a.active { color: var(--navy); font-weight: 700; }

/* ---------- tarjetas ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 0 0 14px;
}
.card-title { font-size: 17px; font-weight: 700; color: var(--navy); margin-bottom: 12px; }
details.card > summary.card-title { margin: 0; cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; min-height: 28px; }
details.card > summary.card-title::after { content: '＋'; font-weight: 400; color: var(--muted); }
details.card[open] > summary.card-title { margin-bottom: 12px; }
details.card[open] > summary.card-title::after { content: '－'; }
details.card > summary::-webkit-details-marker { display: none; }
details.sub { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
details.sub > summary { font-weight: 600; color: var(--blue); cursor: pointer; padding: 6px 0 10px; }

.card.warn { background: var(--warn-bg); color: #4a3200; box-shadow: none; border: 1px solid #f1d39b; }
.card.ok { background: var(--ok-bg); color: #0f4b2a; box-shadow: none; border: 1px solid #b5e0c5; }
.card.notice { background: var(--blue-soft); box-shadow: none; border: 1px solid #c8d5f3; }
.card.warn p, .card.ok p { margin: 6px 0; }
.card ul { margin: 6px 0 0; padding-left: 20px; }

.section-title { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 10px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.center { text-align: center; }
.hero { padding: 8px 0 6px; }

/* ---------- campos ---------- */
.field { display: block; margin: 0 0 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: #34405a; margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  border: 1.5px solid var(--line); border-radius: 10px; background: #fbfcfe;
  padding: 12px; min-height: 50px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(63, 91, 169, .15); }
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.time-row { display: flex; gap: 8px; }
.time-row input { flex: 1; min-width: 0; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; font-size: 16px; text-decoration: none; text-align: center;
  border: 0; border-radius: 12px; padding: 12px 18px; min-height: 50px; cursor: pointer;
  background: var(--blue-soft); color: var(--navy);
  transition: transform .05s ease, filter .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-secondary { background: var(--blue-soft); color: var(--navy); border: 1.5px solid #c8d5f3; }
.btn-ghost { background: transparent; color: var(--blue); }
.btn-small { min-height: 42px; padding: 8px 12px; font-size: 14.5px; }
.btn-lg { min-height: 56px; font-size: 17px; }
.btn-xl { min-height: 64px; font-size: 19px; width: 100%; border-radius: 16px; }
.btn-block { width: 100%; }
.danger { color: var(--danger) !important; }
.file-btn { position: relative; }
.icon-btn { border: 0; background: #f0f2f7; color: var(--muted); width: 44px; height: 44px; border-radius: 10px; font-size: 17px; flex: none; cursor: pointer; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0; min-width: 96px; min-height: 52px; font: inherit; font-weight: 700; font-size: 15.5px;
  border: 2px solid var(--line); background: #fff; color: #34405a; border-radius: 12px; cursor: pointer; padding: 6px 10px;
}
.seg button.on { border-color: var(--blue); background: var(--blue); color: #fff; }
.seg-small button { min-width: 54px; min-height: 42px; font-size: 14px; flex: 0 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip-btn { font: inherit; font-size: 14px; border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 12px; min-height: 40px; cursor: pointer; color: #34405a; }
.chip-btn.on { border-color: var(--blue); background: var(--blue); color: #fff; font-weight: 700; }

.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 44px; margin-bottom: 8px; }
.switch input { width: 24px; height: 24px; min-height: 0; accent-color: var(--blue); }
.switch.small { font-size: 14px; margin: 0; }
.switch.small input { width: 20px; height: 20px; }

/* ---------- pasos ---------- */
.stepper { display: flex; gap: 4px; margin: -4px -4px 14px; position: sticky; top: calc(env(safe-area-inset-top, 0px) + 60px); z-index: 10; background: var(--bg); padding: 6px 4px; }
.stepper a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 4px 0;
}
.stepper a span {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; border: 2px solid var(--line); font-size: 14px; color: var(--muted);
}
.stepper a.done span { background: var(--blue-soft); border-color: #c8d5f3; color: var(--blue); }
.stepper a.active { color: var(--navy); }
.stepper a.active span { background: var(--blue); border-color: var(--blue); color: #fff; }
.step-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 10px; padding: 10px 16px calc(10px + var(--safe-b));
  background: rgba(255, 255, 255, .97); border-top: 1px solid var(--line);
}
.step-footer .btn { flex: 1; }

.trabajo { border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.trabajo-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; min-height: 32px; }
.mat-row { display: grid; grid-template-columns: 70px 1fr 44px; gap: 8px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); align-items: center; }
.mat-row input[data-k="parte"] { grid-column: 2; }
.mat-row .icon-btn { grid-column: 3; grid-row: 1; }
@media (min-width: 560px) { .mat-row { grid-template-columns: 80px 1fr 140px 44px; } .mat-row input[data-k="parte"] { grid-column: 3; } .mat-row .icon-btn { grid-column: 4; } }
.chk-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.chk-row > span { font-weight: 600; }

/* ---------- fotos ---------- */
.photo-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.photos { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .photos { grid-template-columns: 1fr 1fr; } }
.photo { margin: 0; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.photo img { display: block; width: 100%; height: 220px; object-fit: cover; background: #eef1f6; }
.photo textarea { border: 0; border-top: 1px solid var(--line); border-radius: 0; min-height: 60px; }
.photo-actions { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 8px; border-top: 1px solid var(--line); }
.photo.excluded img { opacity: .35; }

/* ---------- firmas ---------- */
.sig-box {
  height: 150px; border: 2px dashed #b9c4da; border-radius: 12px; display: grid; place-items: center;
  background: #fbfcfe; color: var(--muted); font-weight: 600; cursor: pointer; margin-bottom: 8px; overflow: hidden;
}
.sig-box img { max-width: 92%; max-height: 130px; }
.sig-box.signed { border-style: solid; border-color: #9fd2b3; background: #fff; }
.sig-box.stale { border-color: #f1b25a; }
.sig-box.stale img { opacity: .35; }
.sig-status { font-size: 14px; font-weight: 600; margin-bottom: 10px; color: var(--muted); }
.sig-box.signed + .sig-status { color: var(--ok); }
.sig-box.stale + .sig-status { color: var(--warn); }

.sig-overlay {
  position: fixed; inset: 0; z-index: 100; background: #fff;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.sig-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sig-title { font-size: 18px; font-weight: 700; color: var(--navy); }
.sig-sub { font-size: 13.5px; color: var(--muted); }
.sig-area { position: relative; flex: 1; margin: 12px 16px; border: 2px solid var(--line); border-radius: 14px; background: #fff; overflow: hidden; }
.sig-area canvas { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }
.sig-line { position: absolute; left: 8%; right: 8%; bottom: 28%; border-bottom: 2px solid #c9d1e1; pointer-events: none; }
.sig-hint { position: absolute; left: 0; right: 0; bottom: calc(28% - 26px); text-align: center; color: #9aa6bd; pointer-events: none; font-size: 14px; }
.sig-actions { display: flex; gap: 10px; padding: 0 16px 14px; }
.sig-actions .btn { flex: 1; }

/* ---------- tarjetas de reporte ---------- */
.report-card { padding: 0; overflow: hidden; }
.rc-main { padding: 14px 16px 8px; cursor: pointer; }
.rc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.folio { font-weight: 800; color: var(--navy); font-size: 14.5px; letter-spacing: .02em; }
.rc-title { font-size: 17px; font-weight: 700; margin-top: 2px; }
.rc-meta { font-size: 14px; color: var(--muted); }
.rc-actions { display: flex; gap: 6px; padding: 6px 10px 10px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-draft { background: var(--warn-bg); color: var(--warn); }
.suc-card { display: flex; flex-direction: column; gap: 6px; }
.suc-card .rc-actions { padding: 0; }
.stats { list-style: none; padding: 0 !important; margin: 0; }
.stats li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.logo-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.logo-row img { width: 150px; max-height: 70px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.sticky-save { position: sticky; bottom: calc(66px + var(--safe-b)); padding: 8px 0; }

.done { text-align: center; }
.done-icon { width: 56px; height: 56px; border-radius: 50%; background: var(--ok); color: #fff; font-size: 30px; display: grid; place-items: center; margin: 4px auto 8px; }
.done h2 { color: var(--ok); margin-bottom: 4px; }

/* ---------- vista previa ---------- */
.preview { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; font-size: 14.5px; }
.pv-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.pv-head img { width: 110px; flex: none; }
.pv-company { font-weight: 800; color: var(--blue); font-size: 14px; line-height: 1.2; }
.pv-band { background: var(--navy); color: #fff; font-size: 10.5px; font-weight: 700; padding: 3px 6px; margin-top: 4px; text-align: center; }
.pv-title { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 800; color: var(--navy); border-bottom: 2px solid var(--navy); padding-bottom: 6px; margin-bottom: 8px; }
.preview h3 { background: var(--band); font-size: 13px; text-transform: uppercase; padding: 4px 8px; margin: 12px 0 6px; }
.pv-table { width: 100%; border-collapse: collapse; }
.pv-table th { text-align: left; vertical-align: top; width: 38%; font-size: 12.5px; text-transform: uppercase; color: var(--muted); padding: 6px 8px 6px 0; border-bottom: 1px solid #eef1f6; }
.pv-table td { padding: 6px 0; border-bottom: 1px solid #eef1f6; word-break: break-word; }
.pv-mat { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.pv-mat th, .pv-mat td { border: 1px solid var(--line); padding: 5px 6px; text-align: left; }
.preview ol { margin: 0; padding-left: 22px; }
.pv-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pv-photos img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #1b2333; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 15px;
  max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 200; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 900px) {
  .tabbar { top: 0; bottom: auto; left: auto; right: 16px; width: auto; background: transparent; border: 0; z-index: 30; }
  .tabbar a { color: rgba(255, 255, 255, .8); padding: 6px 10px; min-height: 0; flex-direction: row; gap: 6px; white-space: nowrap; font-size: 14px; margin-top: env(safe-area-inset-top, 0px); }
  .tabbar a span { font-size: 16px; }
  .tabbar a.active { color: #fff; }
  .topbar { padding-right: 520px; }
  .view { padding-bottom: 110px; }
  .sticky-save { bottom: 0; }
}
