:root {
  --navy: #062d4e;
  --navy-deep: #041f37;
  --ink: #0d2238;
  --gold: #c9972b;
  --gold-deep: #a97a17;
  --gold-soft: #f6dc8a;
  --paper: #f5f2eb;
  --card: #ffffff;
  --line: #ddd6c8;
  --muted: #5d6b7a;
  --danger: #b3261e;
  --gold-grad: linear-gradient(90deg, #d9a93c 0%, #c58f22 22%, #e9c25a 45%, #fbdc7c 62%, #e6bb4e 80%, #c9972b 100%);
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Montserrat', system-ui, 'Segoe UI', sans-serif;
  font-size: 18px;
  line-height: 1.45;
}

button, input, textarea { font: inherit; color: inherit; }

#app.loading { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid var(--line); border-top-color: var(--gold);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Barra superior ---------- */
.topbar {
  background: var(--navy);
  border-bottom: 4px solid var(--gold);
  color: #fff;
}
.topbar-in {
  max-width: 1280px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 16px;
}
.topbar img { height: 54px; width: auto; display: block; }
.topbar .spacer { flex: 1; }
.topbar .link {
  background: transparent; border: 2px solid rgba(255,255,255,.35); color: #fff;
  border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: 16px; cursor: pointer;
}
.topbar .link:hover { border-color: var(--gold-soft); color: var(--gold-soft); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px 20px 120px; }

h1 { font-size: 30px; margin: 0 0 4px; color: var(--navy); letter-spacing: -.01em; }
h2 { font-size: 22px; margin: 0 0 14px; color: var(--navy); }
.sub { color: var(--muted); margin: 0 0 22px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 56px; padding: 12px 24px;
  border-radius: 12px; border: 2px solid var(--navy);
  background: #fff; color: var(--navy);
  font-weight: 700; font-size: 18px; cursor: pointer; text-decoration: none;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { background: #eef3f8; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-deep); }
.btn.gold {
  background: var(--gold-grad); border-color: var(--gold-deep); color: var(--navy-deep);
  box-shadow: 0 4px 14px rgba(169, 122, 23, .35);
}
.btn.gold:hover { filter: brightness(1.04); background: var(--gold-grad); }
.btn.big { min-height: 68px; font-size: 21px; padding: 14px 30px; }
.btn.small { min-height: 46px; padding: 8px 16px; font-size: 16px; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #fdeceb; }
.btn.ghost { border-color: var(--line); }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Campos ---------- */
.field { display: block; margin-bottom: 18px; }
.field > span, .label {
  display: block; font-weight: 700; font-size: 17px; margin-bottom: 7px; color: var(--navy);
}
.input, textarea.input {
  width: 100%; min-height: 56px; padding: 13px 16px;
  background: #fff; border: 2px solid #b9c2cc; border-radius: 12px;
  font-size: 19px; font-weight: 500;
}
textarea.input { min-height: 150px; resize: vertical; line-height: 1.4; }
.input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 4px rgba(201, 151, 43, .35); }
.input::placeholder { color: #98a2ad; font-weight: 400; }
.hint { font-size: 15px; color: var(--muted); margin-top: 6px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: 0 2px 10px rgba(6, 45, 78, .06);
}

/* ---------- Entrada (clave) ---------- */
.gate {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #0d4270 0%, var(--navy) 45%, var(--navy-deep) 100%);
}
.gate-card {
  width: 100%; max-width: 440px; background: #fff; border-radius: 20px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .4);
}
.gate-head { background: var(--navy); padding: 26px 20px 20px; text-align: center; border-bottom: 5px solid transparent; border-image: var(--gold-grad) 1; }
.gate-head img { height: 96px; max-width: 100%; }
.gate-body { padding: 28px 26px 30px; }
.gate-body h1 { text-align: center; font-size: 26px; }
.gate-body .sub { text-align: center; }
.gate-body .btn { width: 100%; }
.error { color: var(--danger); font-weight: 600; min-height: 26px; margin: 4px 0 10px; }

/* ---------- Lista ---------- */
.list-head { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px; margin-bottom: 22px; }
.list-head .titles { flex: 1; min-width: 240px; }
.list-head .sub { margin: 0; }
.search { margin-bottom: 18px; }

.rows { display: grid; gap: 12px; }
.row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px;
  background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--gold);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: 0 2px 8px rgba(6, 45, 78, .05);
}
.row-main { flex: 1; min-width: 220px; cursor: pointer; }
.row-name { font-size: 21px; font-weight: 700; color: var(--navy); word-break: break-word; }
.row-meta { color: var(--muted); font-size: 16px; }
.row-total { font-size: 22px; font-weight: 700; color: var(--navy); white-space: nowrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.empty {
  text-align: center; padding: 50px 20px; color: var(--muted);
  border: 2px dashed var(--line); border-radius: var(--radius); background: rgba(255,255,255,.6);
}
.empty b { display: block; font-size: 22px; color: var(--navy); margin-bottom: 6px; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 28px; align-items: start; }
.editor-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.editor-head h1 { margin: 0; flex: 1; min-width: 200px; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.item {
  border: 2px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  background: #fbfaf6;
}
.item-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.item-top b { color: var(--navy); font-size: 17px; }
.item .two { grid-template-columns: 110px 1fr; }
.item .field { margin-bottom: 12px; }
.money { position: relative; }
.money::before {
  content: '$'; position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  font-weight: 700; font-size: 20px; color: var(--navy);
}
.money .input { padding-left: 36px; font-weight: 700; }

.total-box {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--gold-grad); color: var(--navy-deep);
  border-radius: 12px; padding: 14px 20px; font-size: 24px; font-weight: 700; margin: 18px 0;
}

.check { display: flex; align-items: center; gap: 12px; font-weight: 600; cursor: pointer; padding: 6px 0; }
.check input { width: 26px; height: 26px; accent-color: var(--navy); flex: none; }

.preview-col { position: sticky; top: 16px; }
.preview-label { font-weight: 700; color: var(--muted); font-size: 15px; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 8px; }
.preview-box {
  position: relative; width: 100%; max-width: 700px; overflow: hidden; background: #fff;
  border-radius: 6px; box-shadow: 0 12px 40px rgba(6, 45, 78, .22), 0 0 0 1px var(--line);
}
.preview-box .sheet { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); box-shadow: 0 -6px 24px rgba(6, 45, 78, .1);
}
.actionbar-in { max-width: 1280px; margin: 0 auto; padding: 12px 20px; display: flex; gap: 12px; flex-wrap: wrap; }
.actionbar .btn { flex: 1; min-width: 150px; }

/* ---------- Ajustes ---------- */
.settings { display: grid; gap: 22px; max-width: 640px; }
.sig-preview {
  border: 2px dashed var(--line); border-radius: 12px; min-height: 130px; background: #fff;
  display: grid; place-items: center; padding: 14px; margin-bottom: 14px; color: var(--muted);
}
.sig-preview img { max-width: 100%; max-height: 140px; }
.sig-inline { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.sig-thumb { border: 2px dashed var(--line); border-radius: 12px; background: #fff; padding: 8px 14px; }
.sig-thumb img { display: block; max-height: 64px; max-width: 200px; }
.topbar a.link { text-decoration: none; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Aviso ---------- */
#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 20px);
  background: var(--navy-deep); color: #fff; padding: 14px 24px; border-radius: 999px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center; border: 2px solid var(--gold);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); border-color: #fff; }

#stage { position: fixed; left: -10000px; top: 0; width: 816px; height: 1056px; overflow: hidden; }

/* =====================================================
   LA HOJA DEL PRESUPUESTO (tamaño carta, 816 x 1056 px)
   ===================================================== */
.sheet {
  --k: 1;
  width: 816px; height: 1056px; background: #fff; color: #0b2340;
  font-family: 'Montserrat', Arial, sans-serif; line-height: 1.2;
  display: flex; flex-direction: column; overflow: hidden;
}
.sh-head { background: #062d4e; height: 130px; flex: none; display: flex; align-items: center; justify-content: center; }
.sh-head img { height: 96px; width: auto; display: block; }
.sh-body { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: 0 60px; }
.sh-title {
  font-family: 'Tinos', 'Times New Roman', Times, serif; font-style: italic; font-weight: 700;
  font-size: 70px; line-height: 1; color: #0b2340; margin: 44px 0 34px;
  text-shadow: 0 5px 9px rgba(11, 35, 64, .32);
}
.sh-date { font-size: 15px; font-weight: 500; }
.sh-client { font-size: 22px; font-weight: 600; margin-top: 3px; text-align: center; }
.sh-rule { width: 466px; height: 4px; background: #000; margin: 13px 0 15px; flex: none; }
.sh-intro { width: 600px; text-align: center; font-size: 17px; font-weight: 500; line-height: 1.22; margin-bottom: 18px; }

.sh-table { width: 650px; border-collapse: collapse; table-layout: fixed; flex: none; }
.sh-table th, .sh-table td { border: 2px solid #000; }
.sh-table th {
  font-size: calc(22px * var(--k)); font-weight: 700; text-align: center; vertical-align: bottom;
  padding: calc(22px * var(--k)) 4px calc(8px * var(--k));
}
.sh-table td { vertical-align: top; padding: calc(12px * var(--k)) 8px calc(34px * var(--k)); }
.sh-table .c-qty, .sh-table .c-amt { text-align: center; font-size: calc(30px * var(--k)); font-weight: 700; padding-top: calc(16px * var(--k)); }
.sh-table .c-con { font-size: calc(15px * var(--k)); font-weight: 500; line-height: 1.27; padding-left: calc(17px * var(--k)); white-space: pre-line; word-break: break-word; }
.sh-total {
  width: 650px; flex: none; display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(90deg, #d7a436 0%, #c48d20 20%, #e3b94c 40%, #fbdc7c 60%, #f0cb62 75%, #d2a033 90%, #c9972b 100%);
  font-size: calc(30px * var(--k)); font-weight: 700;
  padding: calc(8px * var(--k)) 30px calc(8px * var(--k)) 14px; margin-top: -1px;
}

.sh-sign { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; align-items: center; flex: none; }
.sh-sign-img { height: 84px; display: flex; align-items: flex-end; justify-content: center; }
.sh-sign-img img { max-height: 84px; max-width: 250px; display: block; margin-bottom: -6px; }
.sh-sign-line { width: 257px; height: 4px; background: #000; }
.sh-sign-text { font-size: 19px; font-weight: 500; margin: 7px 0 22px; }

.sh-foot { flex: none; border-top: 3px solid #000; text-align: center; font-size: 15px; font-weight: 500; padding: 18px 40px 30px; }
.sh-foot p { margin: 0 0 7px; }
.sh-foot p:last-child { margin: 0; line-height: 1.1; }

/* ---------- Teléfono ---------- */
@media (max-width: 900px) {
  body { font-size: 17px; }
  .editor { grid-template-columns: 1fr; }
  .preview-col { position: static; }
  .preview-box { max-width: none; }
  .wrap { padding: 18px 16px 190px; }
  .topbar img { height: 44px; }
  .topbar-in { padding: 8px 16px; }
  h1 { font-size: 25px; }
  .list-head .btn { width: 100%; }
  .row-actions { width: 100%; }
  .row-actions .btn { flex: 1; }
  .actionbar-in { padding: 10px 12px; gap: 8px; }
  .actionbar .btn { min-width: 120px; padding: 10px 12px; font-size: 16px; }
  .card { padding: 16px; }
}
@media (max-width: 420px) {
  .two { grid-template-columns: 1fr; }
  .item .two { grid-template-columns: 90px 1fr; }
}
