/* Partes de trabajo — estilos. Pensado para usarse a pleno sol: alto contraste y botones grandes. */
:root {
  --accent: #e8590c;
  --accent-ink: #b8460a;
  --accent-soft: #fdeee4;
  --ink: #1d1f22;
  --ink-2: #464a4f;
  --muted: #6b7076;
  --line: #e3e0db;
  --line-2: #cfcbc5;
  --bg: #f4f2ee;
  --card: #ffffff;
  --ok: #1f7a3d;
  --ok-soft: #e5f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --err: #b42318;
  --err-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent-ink); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 24px; letter-spacing: -.01em; }
h2 { font-size: 17px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------- Barra superior ---------- */
.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(--ink); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 17px; min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); flex: none; position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 7px; top: 5px; width: 7px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(40deg); }
.sync-pill {
  margin-left: auto; border: 0; border-radius: 999px; padding: 6px 12px; font: 600 13px/1 var(--font);
  background: rgba(255,255,255,.12); color: #fff; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; white-space: nowrap;
}
.sync-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #5ad17a; }
.sync-pill.offline::before { background: #9aa0a6; }
.sync-pill.pending::before { background: #ffb347; }
.sync-pill.syncing::before { background: #ffb347; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.top-actions { display: flex; gap: 4px; margin-left: 4px; }
.sync-pill[hidden] + .top-actions { margin-left: auto; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 40px; height: 40px; padding: 0 10px; border-radius: 10px; border: 0;
  background: transparent; color: #fff; font: 600 14px/1 var(--font); text-decoration: none; cursor: pointer;
}
.icon-btn:hover, .icon-btn.active { background: rgba(255,255,255,.12); }
.icon-btn svg { width: 22px; height: 22px; }
@media (max-width: 520px) { .icon-btn .lbl { display: none; } }

/* ---------- Estructura ---------- */
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(32px + var(--safe-b)); outline: none; }
main.wide { max-width: 1180px; }
.loading { padding: 60px 0; text-align: center; color: var(--muted); }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card > h2 { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card > h2 .count { font-size: 13px; font-weight: 600; color: var(--muted); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 22px 2px 8px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); font: 600 16px/1.1 var(--font); text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { color: var(--err); border-color: #f1b8b2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 18px; border-radius: 16px; }
.link-btn { background: none; border: 0; padding: 4px; color: var(--accent-ink); font: 600 14px/1 var(--font); cursor: pointer; }

.new-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.new-actions .btn { flex-direction: column; gap: 6px; min-height: 104px; text-align: center; }
.new-actions .btn svg { width: 30px; height: 30px; }
.new-actions .btn small { font-weight: 500; font-size: 13px; opacity: .85; }
@media (max-width: 360px) { .new-actions { grid-template-columns: 1fr; } }

/* ---------- Formularios ---------- */
label.field { display: block; }
.field + .field, .grid-2 + .field, .field + .grid-2 { margin-top: 12px; }
.field > span, .lbl-text { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 0 0 5px 2px; }
.field > span em { font-style: normal; color: var(--accent-ink); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=time],
input[type=number], input[type=tel], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px;
  background: #fff; color: var(--ink); font: 16px/1.35 var(--font); appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(232, 89, 12, .25); border-color: var(--accent); }
input[type=date], input[type=time] { min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid-2.collapse { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #ebe8e3; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { min-height: 42px; border: 0; border-radius: 9px; background: transparent; font: 600 15px/1 var(--font); color: var(--ink-2); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.errors { background: var(--err-soft); color: var(--err); border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.errors ul { margin: 6px 0 0; padding-left: 20px; font-weight: 500; }
.has-error { border-color: var(--err) !important; }

/* Buscador desplegable (cliente / obra) */
.picker { position: relative; }
.picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 15; margin: 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--line-2); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.14);
  max-height: 300px; overflow: auto;
}
.picker-list li { padding: 11px 12px; border-radius: 8px; cursor: pointer; }
.picker-list li:hover, .picker-list li.hl { background: var(--accent-soft); }
.picker-list li small { display: block; color: var(--muted); font-size: 13px; }
.picker-list li.create { color: var(--accent-ink); font-weight: 700; }
.picker-list li.empty { color: var(--muted); cursor: default; background: none; }
.picked { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 8px 8px 14px; border: 1px solid var(--line-2); border-radius: 10px; background: #fbfaf8; }
.picked .txt { flex: 1; min-width: 0; }
.picked .txt b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picked .tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-ink); background: var(--accent-soft); border-radius: 6px; padding: 2px 6px; margin-left: 6px; vertical-align: 2px; }
.sub-fields { margin-top: 10px; padding: 12px; border-radius: 10px; background: #faf8f5; border: 1px dashed var(--line-2); }

/* Filas repetibles (horas, materiales) */
.lines { display: flex; flex-direction: column; gap: 10px; }
.line { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fcfbf9; position: relative; }
.line.hours { grid-template-columns: 1fr 1fr 74px; }
.line.hours .w { grid-column: 1 / -1; padding-right: 44px; }
.line.mat { grid-template-columns: 1fr 96px 96px; }
.line.mat .d { grid-column: 1 / -1; padding-right: 44px; }
@media (min-width: 640px) {
  .line.hours { grid-template-columns: 1.6fr 1fr 1fr 80px 40px; align-items: end; }
  .line.hours .w { grid-column: auto; padding-right: 0; }
  .line.mat { grid-template-columns: 1fr 110px 110px 40px; align-items: end; }
  .line.mat .d { grid-column: auto; padding-right: 0; }
  .line .rm { position: static; }
}
.line > *, .line input { min-width: 0; }
.line label > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 3px 2px; }
.line .hours-out { min-height: 48px; display: flex; align-items: center; justify-content: flex-end; font-weight: 800; font-size: 17px; padding-right: 4px; }
.line .rm { position: absolute; top: 8px; right: 8px; width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.line .rm:hover { background: var(--err-soft); color: var(--err); }
.line .rm svg { width: 20px; height: 20px; }
.total-line { display: flex; justify-content: flex-end; gap: 10px; font-weight: 800; margin-top: 10px; font-size: 17px; }

/* Fotos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #ddd; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo button { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; }
.photo-add { aspect-ratio: 1; border: 2px dashed var(--line-2); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--ink-2); font-weight: 700; font-size: 13px; cursor: pointer; background: #fff; text-align: center; padding: 6px; }
.photo-add svg { width: 28px; height: 28px; }
.photo-add input { display: none; }
.photo-busy { aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; background: #eee; color: var(--muted); font-size: 13px; }
a.photo { display: block; }

/* Firma */
.sig-wrap { position: relative; border: 2px solid var(--line-2); border-radius: 12px; background: #fff; overflow: hidden; }
.sig-wrap.has-error { border-color: var(--err); }
.sig-wrap canvas { display: block; width: 100%; height: 210px; touch-action: none; cursor: crosshair; }
.sig-hint { position: absolute; left: 0; right: 0; bottom: 44px; text-align: center; color: #b5b1ab; pointer-events: none; font-weight: 600; }
.sig-line { position: absolute; left: 24px; right: 24px; bottom: 40px; border-top: 1px solid #d9d5cf; pointer-events: none; }
.sig-actions { position: absolute; top: 6px; right: 6px; }
.sig-img { max-width: 320px; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

.save-bar { position: sticky; bottom: 0; z-index: 10; margin: 18px -16px 0; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(to top, var(--bg) 70%, rgba(244,242,238,0)); }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 64px; }
.item:first-child { border-top: 0; }
button.item { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; font: inherit; text-align: left; cursor: pointer; }
.item .main { flex: 1; min-width: 0; }
.item .main b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .main span { display: block; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .side { text-align: right; font-size: 13px; color: var(--muted); flex: none; }
.chev { width: 18px; height: 18px; color: var(--line-2); flex: none; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.grey { background: #ecebe8; color: var(--ink-2); }
.badge.type { background: var(--ink); color: #fff; }
.badge.type.alb { background: #3d5a80; }
.empty { padding: 26px 8px; text-align: center; color: var(--muted); }

/* Banners */
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; font-weight: 600; font-size: 15px; flex-wrap: wrap; }
.banner .btn { min-height: 38px; }
.banner.info { background: #e8eef7; color: #23395b; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.err { background: var(--err-soft); color: var(--err); }
.notice { border-radius: 12px; padding: 12px 14px; font-weight: 600; font-size: 15px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.err { background: var(--err-soft); color: var(--err); }
.notice.info { background: #e8eef7; color: #23395b; }

/* Detalle */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px 18px; }
.kv div span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.kv div b { font-weight: 600; word-break: break-word; }
.pre { white-space: pre-wrap; margin: 0; }
table.simple { width: 100%; border-collapse: collapse; font-size: 15px; }
table.simple th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.simple td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.simple .r { text-align: right; }
table.simple tfoot td { font-weight: 800; border-bottom: 0; }

/* ---------- Administración ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin: 0 0 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 10px 16px; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--ink-2); font-weight: 700; text-decoration: none; font-size: 15px; }
.tabs a.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.filters label > span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 3px 2px; }
.summary { display: flex; gap: 18px; flex-wrap: wrap; font-size: 15px; color: var(--ink-2); }
.summary b { color: var(--ink); }

.dtable { width: 100%; border-collapse: collapse; }
.dtable th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.dtable td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dtable tbody tr { cursor: pointer; }
.dtable tbody tr:hover td { background: #faf8f5; }
.dtable .r { text-align: right; }
.dtable tr.off td { color: var(--muted); }
.dtable tr.void td:not(:last-child) { text-decoration: line-through; color: var(--muted); }
@media (max-width: 760px) {
  .dtable thead { display: none; }
  .dtable, .dtable tbody, .dtable tr, .dtable td { display: block; width: 100%; }
  .dtable tr { padding: 10px 2px; border-bottom: 1px solid var(--line); }
  .dtable td { border: 0; padding: 2px 4px; }
  .dtable td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: 13px; }
  .dtable td.lead { font-weight: 700; font-size: 16px; }
  .dtable .r { text-align: left; }
}
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 14px; }

/* ---------- Login ---------- */
.login { max-width: 400px; margin: 7vh auto 0; }
.login .logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); position: relative; margin-bottom: 18px; }
.login .logo::after { content: ""; position: absolute; left: 18px; top: 12px; width: 14px; height: 24px; border: solid #fff; border-width: 0 5px 5px 0; transform: rotate(40deg); }

/* ---------- Diálogo y avisos ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--ink); }
dialog::backdrop { background: rgba(20, 22, 25, .55); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 40px); }
.dlg-head { padding: 18px 20px 6px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dlg-body { padding: 10px 20px; overflow: auto; }
.dlg-foot { padding: 14px 20px calc(16px + var(--safe-b)); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line); }
.dlg-foot .btn { flex: 1 1 140px; }
@media (max-width: 560px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; }
}

#toasts { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 13px 16px; border-radius: 12px; font-weight: 600; font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: tin .2s ease-out; pointer-events: auto; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }
.toast.warn { background: #8a5300; }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

@media print { .topbar, #banner, .save-bar, .btn { display: none !important; } }

/* Campos de hora compactos en móviles estrechos */
.line input[type=time] { padding: 10px 6px 10px 10px; }
.line input[type=time]::-webkit-calendar-picker-indicator { margin-left: 2px; padding: 0; }
@media (max-width: 400px) { .line.hours { grid-template-columns: 1fr 1fr 56px; gap: 6px; } }
