/* ==========================================================================
   Financar — Tarifa de arriendo · estilos
   Edita los colores en :root. Diseño "mobile-first": 1 columna en celular,
   2 columnas (datos | resultado) en pantallas grandes.
   ========================================================================== */

:root {
  --bg: #F2F5FA;
  --surface: #FFFFFF;
  --surface-2: #F7F9FD;
  --border: #E1E8F2;
  --border-strong: #CBD6E6;
  --ink: #0E1B33;
  --muted: #5B6A86;
  --faint: #8E9BB3;

  --accent: #1B4FA0;
  --accent-2: #2D6AD1;
  --accent-hover: #143A78;
  --accent-soft: #E7EFFB;
  --red: #E11D2A;
  --green: #12805C;
  --green-soft: #E3F5EE;
  --wa: #1FA855;
  --wa-hover: #178a44;
  --error: #B42318;

  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(14, 27, 51, .04), 0 8px 24px rgba(14, 27, 51, .06);
  --shadow-sm: 0 1px 2px rgba(14, 27, 51, .05);
  --nav-h: 68px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }

body {
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1000px 500px at 100% -10%, rgba(45, 106, 209, .10), transparent 60%),
    radial-gradient(800px 500px at -10% 110%, rgba(27, 79, 160, .08), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.45;
}

input, button { font-family: inherit; font-size: 16px; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
svg { flex-shrink: 0; }

.num, .row-value, .card-total-amount, .money-field input, .hist-right .amount, .mini-row {
  font-variant-numeric: tabular-nums;
}

/* ---------- Shell ---------- */
.app-shell { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.app-header-inner {
  max-width: 1120px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand-logo {
  width: 44px; height: 44px; object-fit: contain; flex-shrink: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 4px;
}
.brand-text { min-width: 0; }
.brand-title {
  font-size: 19px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1;
  margin: 2px 0 0; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-title .dot { color: var(--red); }
.date-chip {
  margin: 0; font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}

/* ---------- Typography ---------- */
.eyebrow {
  font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 700; color: var(--muted); margin: 0;
}
.muted-sm { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.page-head { margin-bottom: 20px; }
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -.025em; margin: 4px 0 0; line-height: 1.15; }

/* ---------- Main ---------- */
.app-main { max-width: 1120px; margin: 0 auto; padding: 20px 16px 8px; }
.page { display: block; }

/* ---------- Layout calculadora ---------- */
.calc-grid { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }
.calc-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 18px; display: flex; flex-direction: column; gap: 18px;
}
.panel-head { display: flex; align-items: center; gap: 12px; }
.step {
  width: 30px; height: 30px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
  color: var(--accent); background: var(--accent-soft);
}
.panel-title { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: -.01em; }
.panel-sub { margin: 1px 0 0; font-size: 13px; color: var(--muted); }
.optional {
  font-size: 11px; font-weight: 700; color: var(--faint); letter-spacing: .04em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px;
}

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field-label { margin: 0; font-size: 13px; font-weight: 700; color: var(--ink); }
.fields-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }

.money-field {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface-2); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 16px; height: 62px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.money-field:focus-within {
  border-color: var(--accent); background: #fff;
  box-shadow: 0 0 0 4px rgba(27, 79, 160, .12);
}
.money-field .currency { font-size: 22px; font-weight: 700; color: var(--faint); }
.money-field input {
  flex: 1; min-width: 0; width: 100%; border: none; outline: none; background: transparent;
  font-size: 28px; font-weight: 800; letter-spacing: -.02em; padding: 0 0 0 4px; height: 100%;
}
.money-field input::placeholder { color: #B7C1D3; }

.text-field {
  width: 100%; height: 50px; padding: 0 14px; font-size: 16px; font-weight: 500;
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.text-field:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px rgba(27, 79, 160, .12); }
.text-field::placeholder { color: #B7C1D3; font-weight: 400; }

/* ---------- Segmented toggle ---------- */
.toggle-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 4px; border-radius: 14px;
}
.toggle-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 10px; border: none; border-radius: 10px;
  background: transparent; color: var(--muted); font-size: 14px; font-weight: 700;
  transition: background .15s, color .15s, box-shadow .15s;
}
.toggle-btn:hover { color: var(--ink); }
.toggle-btn.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 4px 12px rgba(27, 79, 160, .28);
}
.toggle-help {
  margin: 0; font-size: 13px; color: var(--accent); background: var(--accent-soft);
  padding: 10px 12px; border-radius: 10px; line-height: 1.4;
}

/* ---------- Resultados ---------- */
.results-head { margin-bottom: 14px; }
.cards { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.card-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head-title { margin: 0; font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
.card-head-badge {
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.card-body { padding: 4px 18px 6px; }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }
.row-label { display: flex; flex-direction: column; min-width: 0; }
.row-label .lbl { font-size: 14px; font-weight: 600; color: var(--ink); }
.row-label .sub { font-size: 12px; color: var(--faint); margin-top: 1px; }
.row-value { font-size: 15px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.row-value.neg { color: var(--muted); font-weight: 600; }
.row-value.pos { color: var(--green); }
.card-total {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 18px; color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
}
.card-total-label { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .9; }
.card-total-amount { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }

/* ---------- Botones ---------- */
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.actions-row { flex-direction: row; flex-wrap: wrap; margin-top: 0; }
.actions-row .btn { flex: 1 1 180px; }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1.5px solid transparent; font-size: 15px; font-weight: 700;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 6px 16px rgba(27, 79, 160, .28);
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--accent-hover), var(--accent)); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--border-strong); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-wa { background: var(--wa); color: #fff; }
.btn-wa:hover { background: var(--wa-hover); }
.btn-link {
  background: none; border: none; color: var(--muted); font-size: 13px; font-weight: 700;
  padding: 8px; text-decoration: underline; text-underline-offset: 3px;
}
.btn-link:hover { color: var(--ink); }

/* ---------- Navegación ---------- */
.top-nav { display: none; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); padding: 4px; border-radius: 14px; }
.nav-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: none; border: none; color: var(--muted); font-weight: 700; transition: color .15s, background .15s;
}
.nav-btn.is-active { color: var(--accent); }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .nav-btn { flex: 1; flex-direction: column; gap: 3px; height: var(--nav-h); font-size: 11px; position: relative; }
.bottom-nav .nav-btn.is-active::before {
  content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px;
  border-radius: 0 0 4px 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ---------- Historial ---------- */
.history-list { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: start; }
.history-empty {
  text-align: center; padding: 56px 16px; color: var(--muted); font-size: 15px;
  background: var(--surface); border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
}
.hist-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.hist-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; width: 100%;
  background: none; border: none; text-align: left; transition: background .15s;
}
.hist-head:hover { background: var(--surface-2); }
.hist-info { flex: 1; min-width: 0; }
.hist-info .name { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-info .sub { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-info .advisor { font-size: 12px; color: var(--faint); margin-top: 1px; }
.hist-right { text-align: right; }
.hist-right .tag { font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.hist-right .amount { font-size: 15px; font-weight: 800; color: var(--accent); }
.hist-caret { color: var(--faint); transition: transform .2s; }
.hist-item.is-open .hist-caret { transform: rotate(180deg); }
.hist-detail { display: none; border-top: 1px solid var(--border); background: var(--surface-2); }
.hist-item.is-open .hist-detail { display: block; }
.hist-detail-section { padding: 14px 16px 4px; }
.hist-detail-section .ttl { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 800; color: var(--muted); margin: 0 0 8px; }
.hist-detail-section .mini-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 4px 0; }
.hist-detail-section .mini-row.total { font-weight: 800; border-top: 1px solid var(--border-strong); padding-top: 8px; margin-top: 6px; }
.hist-detail-section .mini-row.total span:last-child { color: var(--accent); }
.hist-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 10px 16px 16px; }
.hist-actions .btn { min-height: 42px; font-size: 14px; }
.hist-actions .btn.danger:hover { border-color: var(--error); color: var(--error); }

/* ---------- Ajustes ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
.settings-side { display: flex; flex-direction: column; gap: 16px; }
.rates-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.setting-field { display: flex; flex-direction: column; gap: 6px; }
.setting-field .eyebrow { font-size: 13px; letter-spacing: 0; text-transform: none; color: var(--ink); font-weight: 700; }
.setting-field .input-row {
  display: flex; align-items: center; gap: 8px; height: 52px; padding: 0 14px;
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.setting-field .input-row:focus-within { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 4px rgba(27, 79, 160, .12); }
.ledger-input {
  flex: 1; min-width: 0; width: 100%; border: none; outline: none; background: transparent;
  font-size: 22px; font-weight: 800; height: 100%; font-variant-numeric: tabular-nums;
}
.ledger-input::-webkit-outer-spin-button, .ledger-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ledger-input[type=number] { -moz-appearance: textfield; }
.setting-field .pct { font-size: 18px; font-weight: 800; color: var(--faint); }
.setting-field .help { font-size: 12px; color: var(--muted); margin: 0; }
.backup-note { margin-bottom: 0; }

.formula-box {
  font-size: 13px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; line-height: 1.7;
}
.formula-box p { margin: 0; }
.formula-box .ttl { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 800; margin-bottom: 6px; color: var(--ink); }
.formula-box .total-line { color: var(--accent); font-weight: 800; margin-top: 6px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  max-width: calc(100vw - 32px); background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 12px 32px rgba(14, 27, 51, .3); z-index: 2000; animation: toastIn .2s ease-out;
}
.toast.error { background: var(--error); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

.fade-in { animation: fadeIn .25s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Tablet (≥ 640px)
   ========================================================================== */
@media (min-width: 640px) {
  .app-header-inner, .app-main { padding-left: 24px; padding-right: 24px; }
  .app-main { padding-top: 28px; }
  .fields-grid { grid-template-columns: 1fr 1fr; }
  .field-wide { grid-column: 1 / -1; }
  .rates-grid { grid-template-columns: 1fr 1fr; }
  .history-list { grid-template-columns: 1fr 1fr; }
}

/* ==========================================================================
   Escritorio (≥ 960px): navegación arriba, 2 columnas
   ========================================================================== */
@media (min-width: 960px) {
  .app-shell { padding-bottom: 40px; }
  .bottom-nav { display: none; }
  .top-nav { display: flex; }
  .top-nav .nav-btn { height: 40px; padding: 0 16px; border-radius: 10px; font-size: 14px; }
  .top-nav .nav-btn:hover { color: var(--ink); }
  .top-nav .nav-btn.is-active { background: #fff; color: var(--accent); box-shadow: var(--shadow-sm); }
  .brand { flex: 0 1 auto; margin-right: auto; }

  .calc-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; }
  .page-title { font-size: 30px; }
  .settings-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; }
  .rates-grid { grid-template-columns: 1fr 1fr; }
  .history-list { grid-template-columns: 1fr 1fr 1fr; }
}

/* Pantallas muy angostas */
@media (max-width: 380px) {
  .money-field input { font-size: 24px; }
  .card-total-amount { font-size: 22px; }
  .toggle-btn { font-size: 13px; gap: 6px; }
  .date-chip { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
