@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');
@import './variables.css';

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---- Typography ---- */
h1,h2,h3,h4,h5 { font-family: var(--font-display); line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.375rem; font-weight: 600; }
h3 { font-size: 1.125rem; font-weight: 600; }
h4 { font-size: 0.9375rem; font-weight: 600; }

p { line-height: 1.6; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---- Utility classes ---- */
.text-muted   { color: var(--fg-muted); }
.text-subtle  { color: var(--fg-subtle); }
.text-green   { color: var(--green); }
.text-red     { color: var(--red); }
.text-yellow  { color: var(--yellow); }
.text-accent  { color: var(--accent); }
.text-sm      { font-size: 0.8125rem; }
.text-xs      { font-size: 0.75rem; }
.font-medium  { font-weight: 500; }
.font-semi    { font-weight: 600; }
.font-bold    { font-weight: 700; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  padding: 1.25rem;
}

.card:hover { box-shadow: var(--card-shadow-hover); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--fg);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }

.btn-danger {
  background: var(--red-soft);
  color: var(--red);
  border-color: transparent;
}
.btn-danger:hover { background: var(--red); color: var(--on-accent); }

.btn-success {
  background: var(--green-soft);
  color: var(--green);
  border-color: transparent;
}
.btn-success:hover { background: var(--green); color: var(--on-accent); }

.btn-sm { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.nav-item:active, .icon-btn:active, .month-chip:active { background: var(--surface-2); }

/* ---- Form controls ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-muted);
}

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  padding: 0.625rem 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 0;
}

html, body { overflow-x: clip; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

input::placeholder, textarea::placeholder { color: var(--fg-subtle); }

select option { background: var(--surface); }

/* ---- Pantalla de carga ---- */
#boot-splash {
  position: fixed; inset: 0; z-index: 5000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
#boot-splash.done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-rings { position: relative; width: 96px; height: 96px; }
.boot-ring, .boot-dot {
  position: absolute; left: 50%; top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.boot-ring {
  width: 96px; height: 96px;
  border: 1.5px solid var(--accent);
  opacity: 0;
  animation: boot-ring 1.8s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.3s);
}
.boot-dot {
  width: 6px; height: 6px;
  background: var(--accent);
  animation: boot-dot 1.8s ease-in-out infinite;
}
@keyframes boot-ring {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
@keyframes boot-dot {
  0%, 100% { transform: translate(-50%, -50%) scale(0.6); opacity: 0.5; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
}

/* ---- Form alert ---- */
.form-alert {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius);
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid var(--red);
  font-size: 0.875rem;
  line-height: 1.5;
  text-align: left;
}

/* ---- Badges / Chips ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.badge-green  { background: var(--green-soft);  color: var(--green); }
.badge-red    { background: var(--red-soft);    color: var(--red); }
.badge-yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge-blue   { background: var(--accent-soft); color: var(--accent); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-cyan   { background: var(--cyan-soft);   color: var(--cyan); }
.badge-gray   { background: var(--surface-2);   color: var(--fg-muted); }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
thead tr { background: var(--surface-2); }
thead th {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--fg-muted);
  padding: 0.75rem 1rem;
  text-align: left;
  white-space: nowrap;
}
tbody tr { border-top: 1px solid var(--border); transition: background 0.1s; }
tbody tr:hover { background: var(--surface-2); }
td { padding: 0.875rem 1rem; font-size: 0.9375rem; vertical-align: middle; }

/* ---- Progress bar ---- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
}

/* ---- Modal overlay ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.75rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

/* ---- Toast notifications ---- */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow-hover);
  padding: 0.875rem 1.25rem;
  font-size: 0.9375rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 260px;
  animation: toast-in 0.3s ease;
}
.toast-success { box-shadow: inset 0 0 0 1px var(--green); }
.toast-error   { box-shadow: inset 0 0 0 1px var(--red); }
.toast-info    { box-shadow: inset 0 0 0 1px var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---- Loading spinner ---- */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ---- Responsive helpers ---- */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .table-wrap.no-scroll-mobile { overflow-x: visible; }
  .table-wrap.no-scroll-mobile table { min-width: 0; }
}
@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}

/* ---- Mobile transaction card list ---- */
.mv-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.mv-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border);
  transition: background 0.1s;
}
.mv-card:first-child { border-top: none; }
.mv-card:hover, .mv-card:active { background: var(--surface-2); }
.bdg-cat-header:active, .bdg-cat-header:hover { background: var(--surface-2); }
.bdg-item:active { background: var(--surface-2); }
.mv-card-left { flex: 1; min-width: 0; }
.mv-card-desc {
  font-weight: 500;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mv-card-meta {
  font-size: 0.75rem;
  color: var(--fg-muted);
  margin-top: 4px;
}
.mv-card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.mv-card-amount {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}
.mv-card-actions {
  display: flex;
  gap: 0;
  margin-top: 2px;
}

/* ---- Tablas que pasan a tarjetas en móvil ---- */
@media (max-width: 768px) {
  .table-wrap.table-cards { overflow: visible; border: none; }
  .card:has(> .table-wrap.table-cards) { background: none; border: none; box-shadow: none; padding: 0; }
  .table-wrap.table-cards table,
  .table-wrap.table-cards tbody { display: block; min-width: 0; width: 100%; }
  .table-wrap.table-cards thead { display: none; }
  .table-wrap.table-cards tbody { display: flex; flex-direction: column; gap: 0.625rem; }
  .table-wrap.table-cards tbody tr {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 0.75rem 1rem;
  }
  .table-wrap.table-cards tbody tr:hover { background: var(--surface); }
.table-wrap.table-cards tbody tr:active { background: var(--surface-2); }
  .table-wrap.table-cards tbody tr:has(> td.td-empty) { background: none; border: none; padding: 0; }
  .table-wrap.table-cards td {
    display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
    padding: 0.2rem 0; border: none; font-size: 0.875rem; text-align: right; white-space: normal;
  }
  .table-wrap.table-cards td[data-label]::before {
    content: attr(data-label); color: var(--fg-muted); font-size: 0.75rem; font-weight: 500; text-align: left;
  }
  .table-wrap.table-cards td.td-title {
    flex: 1 1 100%; display: block; text-align: left; font-size: 0.9375rem; font-weight: 600;
  }
  .table-wrap.table-cards td.td-actions { flex: 1 1 100%; justify-content: flex-end; flex-wrap: wrap; gap: 0.375rem; }
  .table-wrap.table-cards td.td-empty { flex: 1 1 100%; display: block; text-align: center; padding: 1rem 0; }
}

/* ---- Mobile budget card list ---- */
.bdg-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.bdg-cat-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.bdg-cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
  gap: 0.75rem;
}
.bdg-cat-name {
  font-weight: 700;
  font-size: 0.8125rem;
  letter-spacing: 0;
  color: var(--accent);
}
.bdg-item {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}
.bdg-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.bdg-item-desc { font-size: 0.9375rem; font-weight: 500; }
.bdg-item-right { text-align: right; flex-shrink: 0; }
.bdg-item-amount { font-weight: 600; font-size: 0.9375rem; display: block; }
.bdg-item-pct { font-weight: 700; font-size: 0.8125rem; }
.bdg-item-bar { margin: 0.4rem 0 0.3rem; }
.bdg-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--fg-muted);
}
.bdg-item-actions { display: flex; justify-content: flex-end; margin-top: 0.25rem; }
.bdg-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 0.9375rem;
}
