/* ============================================================
   Control Financiero — Adrián
   Paleta moderna: degradé índigo → fucsia, fondo frío claro.
   Tipografía: Plus Jakarta Sans en todo (números tabulares).
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f6f5fb;
  --surface: #ffffff;
  --surface-alt: #eeecf9;
  --ink: #1e1b2e;
  --ink-soft: #6b6580;
  --ink-faint: #a39ec2;
  --line: #e3e0f0;

  --wine: #4f46e5;         /* azul índigo — primario */
  --wine-deep: #3730a3;
  --wine-tint: #eef0ff;
  --fuchsia: #ec4899;       /* fucsia — segundo color del degradé */
  --gradient: linear-gradient(135deg, var(--wine) 0%, var(--fuchsia) 100%);

  --olive: #0d9488;         /* positivo (teal) */
  --olive-tint: #e6f8f6;
  --rust: #e11d48;          /* negativo (rosa-rojo) */
  --rust-tint: #fde3ea;
  --gold: var(--fuchsia);

  --radius: 10px;
  --shadow: 0 1px 0 rgba(30, 27, 46, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  font-feature-settings: 'tnum' 1;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1, h2, h3, .num-display {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, button {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.95rem;
}

a { color: var(--wine); }

/* ---------- Login ---------- */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--gradient);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(30, 27, 46, 0.25);
}

.login-card h1 {
  font-size: 1.6rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 4px;
}

.login-card .subtitle {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 500;
}

.field input, .field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.field input:focus, .field select:focus, button:focus-visible {
  outline: 2px solid var(--wine);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  transition: filter 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn-primary {
  background: var(--gradient);
  color: #fff;
  width: 100%;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn-secondary:hover { border-color: var(--ink-faint); }

.btn-text {
  background: transparent;
  color: var(--wine);
  padding: 6px 8px;
}

#login-error {
  color: var(--rust);
  font-size: 0.85rem;
  margin-top: 12px;
  min-height: 1em;
}

/* ---------- App shell ---------- */

#app { display: none; min-height: 100vh; }
#app.visible { display: flex; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--gradient);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  padding: 0 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  margin-bottom: 12px;
}

.sidebar .brand .name {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
}

.sidebar .brand .tag,
.sidebar .brand .brand-tag {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
  font-weight: 500;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 24px;
  color: rgba(255, 255, 255, 0.8);
  border-left: 3px solid transparent;
  font-size: 0.92rem;
  font-weight: 500;
  background: none;
  border-top: none;
  border-right: none;
  border-bottom: none;
  text-align: left;
  width: 100%;
}

.nav-item:hover { color: #fff; }

.nav-item.active {
  color: #fff;
  border-left-color: #fff;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 24px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.sidebar-footer .who {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 8px;
  word-break: break-word;
}

.sidebar-footer button {
  color: rgba(255, 255, 255, 0.9);
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 0.82rem;
  width: 100%;
  font-weight: 500;
}

main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 60px;
  max-width: 1100px;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.view-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
}

.view-header .desc {
  color: var(--ink-soft);
  font-size: 0.88rem;
  margin-top: 2px;
}

/* ---------- Dashboard ---------- */

.hero-balance {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px 32px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.hero-asof {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 500;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.hero-asof input[type="date"] {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.hero-asof-note {
  color: var(--fuchsia);
  font-weight: 600;
}

.hero-totals {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
  padding-bottom: 22px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.hero-amount .label {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 500;
}

.hero-amount .amount {
  font-size: 2.1rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
}

.hero-final {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 18px;
}

.hero-final .label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
}

.hero-final-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hero-final-row .amount {
  font-size: 2.4rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
}

.hero-final-row select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 500;
}

.exchange-rows {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.exchange-edit {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.exchange-edit input {
  width: 90px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.panel h3 {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 14px;
}

.panel .empty {
  color: var(--ink-faint);
  font-size: 0.88rem;
  padding: 8px 0;
}

.account-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.account-row:last-child { border-bottom: none; }
.account-row .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.account-row .amt.neg { color: var(--rust); }

.alert-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
}
.alert-row:last-child { border-bottom: none; }
.alert-row .due-soon { color: var(--rust); font-size: 0.78rem; font-weight: 600; }

.progress-track {
  height: 6px;
  background: var(--surface-alt);
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0 4px;
}
.progress-fill {
  height: 100%;
  background: var(--gradient);
}

/* ---------- Tables ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 560px;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: 0.78rem;
}

th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover { color: var(--wine); }
th.sortable .arrow {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.35;
  font-size: 0.7rem;
}
th.sortable.active .arrow { opacity: 1; color: var(--wine); }

tbody td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--wine-tint); }

.amt-pos { color: var(--olive); font-weight: 600; }
.amt-neg { color: var(--rust); font-weight: 600; }

.row-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 9px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 500;
}
.icon-btn:hover { border-color: var(--wine); color: var(--wine); }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 0.74rem;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--ink-soft);
}
.tag.due { background: var(--rust-tint); color: var(--rust); }
.tag.ok { background: var(--olive-tint); color: var(--olive); }
.tag.done { background: var(--surface-alt); color: var(--ink-faint); }

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
  gap: 10px;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 46, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
}

.modal h3 {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.sign-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.sign-toggle button {
  flex: 1;
  padding: 9px;
  background: var(--surface);
  border: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
}
.sign-toggle button.active-pos { background: var(--olive-tint); color: var(--olive); }
.sign-toggle button.active-neg { background: var(--rust-tint); color: var(--rust); }

/* ---------- Mobile ---------- */

.mobile-topbar { display: none; }
.mobile-nav { display: none; }

@media (max-width: 860px) {
  #app.visible { flex-direction: column; }
  .sidebar { display: none; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    background: var(--gradient);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .mobile-topbar .name { font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 800; font-size: 1.05rem; }
  .mobile-topbar button {
    background: none;
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    border-radius: var(--radius);
    padding: 5px 10px;
    font-size: 0.78rem;
    font-weight: 500;
  }

  main { padding: 16px 16px 40px; max-width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .hero-balance .amount { font-size: 2rem; }

  .mobile-nav {
    display: flex;
    position: sticky;
    top: calc(53px + env(safe-area-inset-top, 0px));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 19;
    overflow-x: auto;
    box-shadow: var(--shadow);
  }
  .mobile-nav button {
    flex: 1;
    min-width: 64px;
    background: none;
    border: none;
    padding: 12px 4px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--ink-soft);
    border-bottom: 2px solid transparent;
  }
  .mobile-nav button.active {
    color: var(--wine);
    border-bottom-color: var(--fuchsia);
  }
}
