/* =============================================================
   Mis Finanzas — identidad visual
   Violeta/lavanda (referencia cromática: billete de 500€, solo color)
   + Anton para títulos y cifras + Inter para lectura e interacción.
   Mobile-first, tarjetas limpias, sombras muy discretas.
   ============================================================= */

:root {
  /* ---- Marca ---- */
  --primary: #6f4a8e;
  --primary-dark: #56366f;
  --primary-soft: #8a6ba8;

  --lavender: #b7a0ce;
  --lavender-light: #ded3ea;
  --lavender-ultralight: #f6f2f8;

  --surface: #ffffff;
  --surface-secondary: #f3eef6;

  --text-primary: #29242d;
  --text-secondary: #6d6571;

  --border: #e5dceb;

  --positive: #2f7d5b;
  --positive-soft: #e6f2ec;
  --negative: #b44a5a;
  --negative-soft: #f7e7ea;
  --negative-soft-hover: #f0d2d8;

  /* ---- Alias: nombres usados en todo el CSS existente ----
     Centraliza el color aquí; el resto de reglas nunca usa hex directo. */
  --color-bg: var(--lavender-ultralight);
  --color-surface: var(--surface);
  --color-border: var(--border);
  --color-text: var(--text-primary);
  --color-text-muted: var(--text-secondary);
  --color-primary: var(--primary);
  --color-primary-dark: var(--primary-dark);
  --color-primary-light: var(--lavender-light);
  --color-income: var(--positive);
  --color-expense: var(--negative);
  --color-danger: var(--negative);
  --color-danger-dark: #8f3a47;

  /* ---- Sidebar: violeta oscuro, subpaleta propia ---- */
  --sidebar-bg: var(--primary-dark);
  --sidebar-bg-hover: rgba(255, 255, 255, 0.07);
  --sidebar-bg-active: rgba(255, 255, 255, 0.14);
  --sidebar-text: rgba(255, 255, 255, 0.72);
  --sidebar-text-active: #ffffff;
  --sidebar-accent: var(--lavender);

  /* ---- Tipografía ---- */
  --font-display: 'Anton', 'Arial Narrow Bold', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(41, 20, 54, 0.05), 0 6px 16px -12px rgba(41, 20, 54, 0.16);
  --sidebar-width: 240px;
  --bottom-nav-height: 68px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

h1,
h2 {
  margin: 0 0 0.5rem 0;
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.15;
}
h3 {
  margin: 0 0 0.5rem 0;
}
h2 {
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

p {
  margin: 0;
}

/* Foco visible y coherente con la marca (teclado) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.sidebar :focus-visible {
  outline-color: var(--lavender);
}

/* ---------------- Botones ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease, border-color 150ms ease;
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn-block {
  width: 100%;
}
.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover {
  background: var(--color-primary-dark);
}
.btn-secondary {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}
.btn-secondary:hover {
  background: var(--lavender);
  color: white;
}
.btn-danger {
  background: var(--negative-soft);
  color: var(--color-danger-dark);
}
.btn-danger:hover {
  background: var(--negative-soft-hover);
}
.btn-icon {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 6px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--color-primary);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
}

/* ---------------- Campos de formulario ---------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-weight: 600;
}
.field input,
.field textarea,
.select-input {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  font-family: inherit;
  resize: vertical;
  transition: border-color 150ms ease;
}
.field input:focus,
.field textarea:focus,
.select-input:focus {
  border-color: var(--color-primary);
}
.field-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.field-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
}
.hint-text {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  margin-bottom: 12px;
}
.auth-error {
  color: var(--color-danger);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 10px;
}

/* ---------------- Toasts ---------------- */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 0 16px;
  pointer-events: none;
}
.toast {
  background: var(--text-primary);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  box-shadow: var(--shadow-card);
  max-width: 90vw;
}
.toast-visible {
  opacity: 1;
  transform: translateY(0);
}
.toast-success {
  background: var(--color-primary-dark);
}
.toast-error {
  background: var(--color-danger-dark);
}

/* ---------------- Vista de autenticación ---------------- */
.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--color-bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 36px 28px;
}
.auth-title {
  font-size: clamp(1.7rem, 6vw, 2.2rem);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--primary-dark);
}
.auth-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}
.auth-form {
  margin-top: 8px;
}
.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 0.88rem;
  color: var(--color-text-muted);
}

/* ---------------- Estructura general de la app ---------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  display: none;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 16px 16px calc(var(--bottom-nav-height) + 24px) 16px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px 4px;
}
.topbar-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.period-label {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--primary-dark);
}

/* ---------------- Tarjetas resumen dashboard ---------------- */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.summary-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.summary-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  text-transform: uppercase;
}
.summary-value {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.5rem, 4.5vw, 1.9rem);
  line-height: 1.1;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}
.summary-value.income {
  color: var(--color-income);
}
.summary-value.expense {
  color: var(--color-expense);
}
.summary-value.savings {
  color: var(--color-primary-dark);
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
}
.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.card-header-row h2 {
  margin-bottom: 0;
}

.year-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.year-summary > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.mini-label {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.mini-value {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(0.95rem, 3vw, 1.15rem);
  letter-spacing: 0.005em;
  overflow-wrap: anywhere;
}
.mini-value.income {
  color: var(--color-income);
}
.mini-value.expense {
  color: var(--color-expense);
}
.mini-value.savings {
  color: var(--color-primary-dark);
}
.mini-value.invested {
  color: var(--color-primary-dark);
}

/* ---------------- Objetivo de ahorro ---------------- */
.goal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.goal-empty {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}
.goal-empty p {
  color: var(--color-text-muted);
  font-size: 0.88rem;
}
.goal-text {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}
.progress-bar {
  background: var(--surface-secondary);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.goal-footnote {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ---------------- Listado de movimientos ---------------- */
.movement-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.movement-list-full {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 8px 12px;
}
.movement-group-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 14px 6px 6px 6px;
}
.movement-group-label:first-child {
  margin-top: 6px;
}
.movement-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 150ms ease;
}
.movement-row:hover {
  background: var(--color-bg);
}
.movement-icon {
  font-size: 1.2rem;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-secondary);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  filter: grayscale(0.5);
}
.movement-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.movement-description {
  font-weight: 700;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.movement-category {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
.movement-amount {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.05rem;
  letter-spacing: 0.005em;
  white-space: nowrap;
}
.movement-amount.income {
  color: var(--color-income);
}
.movement-amount.expense {
  color: var(--color-expense);
}
.gain-positive {
  color: var(--color-income);
}
.gain-negative {
  color: var(--color-expense);
}

/* ---------------- Gastos fijos ---------------- */
.recurring-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.recurring-row-inactive {
  opacity: 0.5;
}
.recurring-row-main {
  flex: 1;
  min-width: 0;
}
.toggle-switch {
  flex-shrink: 0;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  border: none;
  background: var(--color-border);
  position: relative;
  cursor: pointer;
  padding: 0;
  transition: background 150ms ease;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  transition: transform 150ms ease;
  box-shadow: 0 1px 2px rgba(41, 20, 54, 0.25);
}
.toggle-switch.on {
  background: var(--color-primary);
}
.toggle-switch.on::after {
  transform: translateX(18px);
}

/* ---------------- Inversiones ---------------- */
.platform-row-amount {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  white-space: nowrap;
}
.platform-row-value {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.05rem;
  color: var(--color-text);
}
.back-link {
  display: inline-block;
  margin-bottom: 4px;
}
.empty-state-block {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 36px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.empty-state-block h3 {
  font-size: 1.05rem;
  color: var(--text-primary);
}
.empty-state-block p {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  max-width: 320px;
}

/* ---------------- Menú "Más" (móvil) ---------------- */
.more-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.more-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  text-align: left;
  padding: 14px 10px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}
.more-menu-item:hover {
  background: var(--color-bg);
}

.empty-state {
  padding: 24px 8px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---------------- Filtros ---------------- */
.filters-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chip-group {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}
.chip {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}
.chip.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}
.select-group {
  display: flex;
  gap: 8px;
}
.select-group .select-input {
  flex: 1;
}

/* ---------------- Estadísticas / gráficos ---------------- */
.chart-wrap {
  position: relative;
  height: 260px;
}
.chart-wrap-tall {
  height: 300px;
}

/* ---------------- Navegación inferior (móvil) ---------------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}
.bottom-nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.66rem;
  color: var(--color-text-muted);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 10px;
  filter: grayscale(0.6);
  transition: filter 150ms ease, color 150ms ease;
}
.bottom-nav-item.active {
  color: var(--color-primary-dark);
  filter: grayscale(0);
}
.bn-icon {
  font-size: 1.2rem;
}
.bottom-nav-add {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  font-size: 1.8rem;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px -4px rgba(86, 54, 111, 0.5);
  margin-top: -26px;
  line-height: 0;
  padding-bottom: 4px;
  transition: background 150ms ease;
}
.bottom-nav-add:hover {
  background: var(--color-primary-dark);
}

/* ---------------- Modales ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(41, 20, 54, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--color-surface);
  width: 100%;
  max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom)) 20px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-small {
  border-radius: var(--radius-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-header h2 {
  margin-bottom: 0;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
}

.type-picker {
  display: flex;
  gap: 12px;
}
.type-btn {
  flex: 1;
  padding: 28px 12px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.type-btn-expense {
  color: var(--color-expense);
}
.type-btn-expense:hover {
  border-color: var(--color-expense);
  background: var(--negative-soft);
}
.type-btn-income {
  color: var(--color-income);
}
.type-btn-income:hover {
  border-color: var(--color-income);
  background: var(--positive-soft);
}

.movement-form .form-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.movement-form .form-actions .btn {
  flex: 1;
}
.form-actions-edit .btn-danger {
  flex: 0 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* =============================================================
   Tablet / Escritorio
   ============================================================= */
@media (min-width: 900px) {
  .bottom-nav {
    display: none;
  }
  .sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    padding: 28px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    box-shadow: 2px 0 16px -8px rgba(41, 20, 54, 0.4);
  }
  .sidebar-brand {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1.5rem;
    line-height: 1.05;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #ffffff;
    margin-bottom: 32px;
    padding: 0 10px;
  }
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    text-align: left;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--sidebar-text);
    cursor: pointer;
    filter: grayscale(0.55);
    transition: background 150ms ease, color 150ms ease, filter 150ms ease;
  }
  .nav-item:hover {
    background: var(--sidebar-bg-hover);
    color: var(--sidebar-text-active);
    filter: grayscale(0.15);
  }
  .nav-item.active {
    background: var(--sidebar-bg-active);
    color: var(--sidebar-text-active);
    filter: grayscale(0);
  }
  .nav-item.active::before {
    content: '';
    position: absolute;
    left: -16px;
    top: 6px;
    bottom: 6px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--sidebar-accent);
  }
  .sidebar-add {
    margin-top: 20px;
  }
  .sidebar .sidebar-add {
    background: var(--lavender);
    color: var(--primary-dark);
    font-weight: 700;
  }
  .sidebar .sidebar-add:hover {
    background: #ffffff;
  }
  .sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 10px;
  }
  .sidebar .user-email {
    font-size: 0.8rem;
    color: var(--sidebar-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .sidebar .link-btn {
    color: var(--lavender-light);
  }
  .sidebar .link-btn:hover {
    color: #ffffff;
  }

  .content {
    padding: 28px 32px 32px 32px;
    max-width: 900px;
  }
  .topbar {
    display: none;
  }
  .btn-logout-mobile-wrap {
    display: none;
  }

  .summary-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .modal-overlay {
    align-items: center;
  }
  .modal {
    border-radius: var(--radius-lg);
  }
}

#btn-logout-mobile {
  display: inline-flex;
}
@media (min-width: 900px) {
  #btn-logout-mobile {
    display: none;
  }
}
