/* Layout: app de una mano — encabezado fijo, lienzo scrollable, navegación inferior */
:root {
  --bg: #f1f3f6;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --fg: #16202b;
  --muted: #5d6b7a;
  --line: #dce2e9;
  --primary: #17556b;
  --primary-soft: #e3eef3;
  --ok: #2f7a4f;
  --warn: #9e6414;
  --bad: #a93a31;
  --ok-soft: #e4f1ea;
  --warn-soft: #faeedb;
  --bad-soft: #f8e5e3;
  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-body: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10161c; --surface: #18212a; --surface-2: #1e2832;
    --fg: #e6ecf2; --muted: #94a3b2; --line: #2a3542;
    --primary: #6cb6d1; --primary-soft: #1d3440;
    --ok: #63c290; --warn: #dda84f; --bad: #e5796f;
    --ok-soft: #1a3328; --warn-soft: #33280f; --bad-soft: #351f1d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #10161c; --surface: #18212a; --surface-2: #1e2832;
  --fg: #e6ecf2; --muted: #94a3b2; --line: #2a3542;
  --primary: #6cb6d1; --primary-soft: #1d3440;
  --ok: #63c290; --warn: #dda84f; --bad: #e5796f;
  --ok-soft: #1a3328; --warn-soft: #33280f; --bad-soft: #351f1d;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
  margin: 0; -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px); background: var(--surface); z-index: 40;
}
.app {
  max-width: 460px; margin: 0 auto; min-height: 100%;
  display: flex; flex-direction: column; background: var(--bg);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}
@media (max-width: 480px) { .app { border: 0; } }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px; display: flex; align-items: center; gap: 10px; min-height: 56px;
}
.topbar h1 {
  font-family: var(--font-display); font-size: 17px; font-weight: 600;
  letter-spacing: -0.01em; margin: 0; flex: 1; min-width: 0;
}
.topbar .sub { font-size: 12px; color: var(--muted); display: block; font-weight: 400; letter-spacing: 0; }
.backbtn {
  background: none; border: 0; padding: 6px 8px 6px 0; margin: 0;
  color: var(--primary); font: inherit; cursor: pointer; display: flex; align-items: center;
}
.demo-chip {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--warn-soft); color: var(--warn);
  padding: 3px 7px; border-radius: 4px; font-weight: 600; white-space: nowrap;
}

main {
  flex: 1;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 18px 94px; display: flex; flex-direction: column; gap: 18px;
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: max(0px, env(safe-area-inset-left, 0px));
  padding-right: max(0px, env(safe-area-inset-right, 0px));
}
.tabs-inner { max-width: 460px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tab {
  background: none; border: 0; font: inherit; cursor: pointer;
  padding: 9px 2px 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 500; position: relative;
}
.tab[aria-current="true"] { color: var(--primary); }
.tab svg { width: 19px; height: 19px; }
.tab .dot {
  position: absolute; top: 5px; left: 50%; margin-left: 5px;
  min-width: 15px; height: 15px; border-radius: 8px;
  background: var(--bad); color: #fff; font-size: 9.5px; font-weight: 600;
  display: grid; place-items: center; padding: 0 4px;
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.card-pad { padding: 14px 15px; }
.section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600; margin: 0 0 8px;
}

.hero { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px 16px 16px; }
.hero .amount {
  font-family: var(--font-display); font-size: 40px; font-weight: 700;
  letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; display: block;
}
.hero .amount-label { font-size: 13px; color: var(--muted); margin-top: 6px; display: block; }
.hero .aging {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--warn); font-weight: 500;
}

.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 15px;
  border-top: 1px solid var(--line); border-left: 0; border-right: 0; border-bottom: 0;
  background: none; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.row:first-child { border-top: 0; }
button.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; font-size: 14.5px; }
.row-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.row-end { text-align: right; flex-shrink: 0; }
.row-amt { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 15px; }
.row-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.chev { color: var(--muted); flex-shrink: 0; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 20px; white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--primary-soft); color: var(--primary); }

.src {
  font-size: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; white-space: nowrap;
}

.thumb {
  width: 44px; height: 52px; border-radius: 5px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--muted); position: relative; overflow: hidden;
}
.thumb::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 7px, var(--line) 7px 8px); opacity: 0.5;
}
.thumb svg { position: relative; z-index: 1; width: 18px; height: 18px; }
.thumb.hand::after { background: repeating-linear-gradient(-6deg, transparent 0 9px, var(--line) 9px 10px); }

/* avisos */
.alert {
  display: flex; gap: 11px; padding: 13px 15px; border-top: 1px solid var(--line); align-items: flex-start;
}
.alert:first-child { border-top: 0; }
.alert .bar { width: 3px; align-self: stretch; border-radius: 2px; flex-shrink: 0; }
.alert.bad .bar { background: var(--bad); }
.alert.warn .bar { background: var(--warn); }
.alert.neutral .bar { background: var(--primary); }
.alert.ok .bar { background: var(--ok); }
.alert-main { flex: 1; min-width: 0; }
.alert-t { font-weight: 600; font-size: 14px; }
.alert-s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.alert-acts { display: flex; gap: 7px; margin-top: 9px; flex-wrap: wrap; align-items: center; }
.mini {
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  border-radius: 6px; padding: 6px 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--fg);
}
.mini.go { background: var(--primary); border-color: var(--primary); color: #fff; }
:root[data-theme="dark"] .mini.go { color: #10161c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mini.go { color: #10161c; } }
.inline-amt {
  font: inherit; font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums;
  width: 74px; padding: 5px 8px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--fg);
}

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }
.kv.total { font-weight: 600; font-size: 16px; padding-top: 11px; margin-top: 4px; border-top: 2px solid var(--line); }

.approval {
  background: var(--ok-soft); border-radius: 8px; padding: 11px 13px;
  font-size: 13px; display: flex; gap: 9px; align-items: flex-start;
}
.approval svg { width: 16px; height: 16px; color: var(--ok); flex-shrink: 0; margin-top: 1px; }
.approval .t { font-weight: 600; color: var(--ok); }
.approval .d { color: var(--muted); margin-top: 1px; }

/* garantía */
.deposit {
  background: var(--primary-soft); border-radius: 9px; padding: 14px 15px;
}
.deposit .big {
  font-family: var(--font-display); font-size: 27px; font-weight: 700;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums; color: var(--primary); line-height: 1.1;
}
.deposit .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.deposit ul { margin: 11px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.deposit li { font-size: 13px; display: flex; justify-content: space-between; gap: 10px; }
.deposit li span:last-child { font-variant-numeric: tabular-nums; font-weight: 500; }

/* recorrido del trabajo */
.steps { display: flex; gap: 0; padding: 2px 0 4px; overflow-x: auto; }
.step { flex: 1; min-width: 62px; text-align: center; position: relative; padding-top: 16px; }
.step::before {
  content: ""; position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  width: 9px; height: 9px; border-radius: 50%; background: var(--line); z-index: 1;
}
.step::after {
  content: ""; position: absolute; top: 8px; left: 50%; width: 100%; height: 1px; background: var(--line);
}
.step:last-child::after { display: none; }
.step.done::before { background: var(--ok); }
.step.done::after { background: var(--ok); }
.step.now::before { background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.step .lb { font-size: 10px; color: var(--muted); line-height: 1.25; display: block; }
.step.now .lb { color: var(--primary); font-weight: 600; }
.step.done .lb { color: var(--fg); }

.photos { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.photo {
  width: 72px; height: 72px; border-radius: 7px; flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--muted); position: relative;
}
.photo span { position: absolute; bottom: 3px; font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.btn {
  font: inherit; font-weight: 600; font-size: 14.5px; border-radius: 8px;
  padding: 12px 16px; cursor: pointer; border: 1px solid transparent; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.btn-primary { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #10161c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #10161c; } }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--fg); }
.btn-row { display: flex; gap: 9px; }

.sheet-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 18, 26, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 460px;
  border-radius: 14px 14px 0 0; max-height: 90%; overflow-y: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 16px calc(20px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
}
.sheet h2 { font-family: var(--font-display); font-size: 17px; margin: 0; font-weight: 600; }
.sheet-head { display: flex; align-items: center; gap: 12px; }
.bigthumb {
  width: 100%; height: 118px; border-radius: 8px; background: var(--surface-2);
  border: 1px dashed var(--line); display: grid; place-items: center; gap: 6px;
  color: var(--muted); font-size: 12px; text-align: center; padding: 10px;
}
.field label { font-size: 12px; color: var(--muted); font-weight: 500; display: block; margin-bottom: 4px; }
.field input, .field select {
  width: 100%; font: inherit; font-size: 16px; font-variant-numeric: tabular-nums;
  padding: 10px 12px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--fg);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }
.joblist { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.jobopt {
  padding: 11px 13px; border-top: 1px solid var(--line); cursor: pointer;
  background: var(--surface); font: inherit; color: inherit; text-align: left; width: 100%;
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.jobopt:first-child { border-top: 0; }
.jobopt:hover { background: var(--primary-soft); }
.jobopt .jt { font-weight: 500; font-size: 14px; }
.jobopt .js { font-size: 12px; color: var(--muted); margin-top: 1px; }

.extra-line { display: flex; gap: 8px; align-items: center; }
.extra-line input:first-child { flex: 1; min-width: 0; }
.extra-line input:last-of-type { width: 92px; flex-shrink: 0; }
.xbtn {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 6px; width: 34px; height: 38px; flex-shrink: 0; cursor: pointer; font: inherit; font-size: 16px;
}

.invoice { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.invoice-head { border-bottom: 2px solid var(--fg); padding-bottom: 10px; margin-bottom: 12px; }
.invoice-head .co { font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.invoice-head .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.invoice-line { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.invoice-line .d { flex: 1; min-width: 0; }
.invoice-line .d .sm { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.invoice-line .a { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 30px 16px; font-size: 14px; }
.empty strong { display: block; color: var(--fg); font-size: 15px; margin-bottom: 4px; font-weight: 600; }
.note {
  font-size: 12.5px; color: var(--muted); line-height: 1.5; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500; max-width: 90%; text-align: center;
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 0.18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }
}
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* ================================================================
   Agregados de la app real (no estaban en el prototipo)
   ================================================================ */

/* ---- Pantalla de entrada -------------------------------------- */
.login-wrap {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px max(20px, env(safe-area-inset-left, 0px))
           calc(24px + env(safe-area-inset-bottom, 0px));
  gap: 22px; background: var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 22px; display: flex; flex-direction: column; gap: 16px;
}
.brand { text-align: center; }
.brand .mark {
  font-family: var(--font-display); font-size: 27px; font-weight: 700;
  letter-spacing: -0.03em; color: var(--primary);
}
.brand .tag { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.login-card h2 { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0; }
.err {
  background: var(--bad-soft); color: var(--bad); border-radius: 7px;
  padding: 10px 12px; font-size: 13px; font-weight: 500;
}

/* ---- Estados de carga ----------------------------------------- */
.loading { display: flex; justify-content: center; padding: 42px 0; }
.spin {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--primary);
}
@media (prefers-reduced-motion: no-preference) {
  .spin { animation: giro 0.7s linear infinite; }
  @keyframes giro { to { transform: rotate(360deg); } }
}
.skeleton {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; height: 68px; opacity: 0.55;
}

/* ---- Barra superior con acción -------------------------------- */
.topbar .act {
  background: none; border: 0; padding: 6px; margin: 0; cursor: pointer;
  color: var(--primary); display: flex; align-items: center;
}
.topbar .act svg { width: 21px; height: 21px; }

/* ---- Filtros --------------------------------------------------- */
.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
  white-space: nowrap; padding: 6px 12px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
}
.chip[aria-pressed="true"] {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
:root[data-theme="dark"] .chip[aria-pressed="true"] { color: #10161c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chip[aria-pressed="true"] { color: #10161c; }
}

/* ---- Formularios en hoja -------------------------------------- */
.field textarea {
  width: 100%; font: inherit; font-size: 16px; min-height: 76px; resize: vertical;
  padding: 10px 12px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--fg);
}
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.field.bad input, .field.bad select, .field.bad textarea { border-color: var(--bad); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button {
  flex: 1; font: inherit; font-size: 13.5px; font-weight: 500; padding: 9px 6px;
  background: var(--surface-2); border: 0; cursor: pointer; color: var(--muted);
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; font-weight: 600; }
:root[data-theme="dark"] .seg button[aria-pressed="true"] { color: #10161c; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .seg button[aria-pressed="true"] { color: #10161c; }
}

.btn[disabled] { opacity: 0.55; cursor: default; }
.btn-danger { background: var(--surface); border-color: var(--bad); color: var(--bad); }
.linkbtn {
  background: none; border: 0; padding: 0; font: inherit; font-size: 13px;
  color: var(--primary); cursor: pointer; text-decoration: underline;
}
.toast.bad { background: var(--bad); color: #fff; }
