/* ============================================================
   Finanzas — style.css
   All styles for the entire app live here. No inline styles
   anywhere else. If you want to change a color, spacing, or
   layout rule, this is the only file you edit.
   ============================================================ */

/* ------------------------------------------------------------
   1. Design tokens (CSS custom properties)
   ------------------------------------------------------------ */
:root {
  /* Color palette */
  --teal-50:   #E1F5EE;
  --teal-400:  #1D9E75;
  --teal-800:  #085041;

  --blue-50:   #E6F1FB;
  --blue-400:  #378ADD;
  --blue-800:  #0C447C;

  --amber-50:  #FAEEDA;
  --amber-400: #EF9F27;
  --amber-800: #633806;

  --coral-50:  #FAECE7;
  --coral-400: #D85A30;
  --coral-800: #712B13;

  --green-50:  #EAF3DE;
  --green-400: #639922;
  --green-800: #27500A;

  --purple-50: #EEEDFE;
  --purple-400:#7F77DD;
  --purple-800:#3C3489;

  --gray-50:   #F1EFE8;
  --gray-200:  #B4B2A9;
  --gray-600:  #5F5E5A;

  /* Semantic aliases */
  --bg:           #FFFFFF;
  --bg-subtle:    var(--gray-50);
  --text:         #1A1A1A;
  --text-muted:   var(--gray-600);
  --border:       var(--gray-200);
  --accent:       var(--teal-400);
  --accent-bg:    var(--teal-50);
  --accent-dark:  var(--teal-800);
  --warning:      var(--amber-400);
  --warning-bg:   var(--amber-50);
  --danger:       var(--coral-400);
  --danger-bg:    var(--coral-50);
  --success:      var(--green-400);
  --success-bg:   var(--green-50);

  /* Sizes */
  --radius-sm:    8px;
  --radius-md:    12px;
  --tap-target:   44px;
  --nav-height:   64px;

  /* Spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Type */
  --font:        system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs:       11px;
  --fs-sm:       12px;
  --fs-md:       13px;
  --fs-lg:       15px;
  --fs-xl:       18px;
  --fs-xxl:      24px;
}

/* ------------------------------------------------------------
   2. Reset & base
   ------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-sm);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

button {
  cursor: pointer;
  background: none;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  min-height: var(--tap-target);
}

input,
select,
textarea {
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-3);
  background: var(--bg);
  width: 100%;
  min-height: var(--tap-target);
}

textarea {
  resize: vertical;
  min-height: 60px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%235F5E5A' stroke-width='1' fill='none'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
}

h1 { font-size: var(--fs-xxl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }

/* ------------------------------------------------------------
   3. App shell
   ------------------------------------------------------------ */
#app {
  min-height: 100vh;
  padding-bottom: var(--nav-height);
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  padding: var(--sp-4);
  overflow-y: auto;
}

.screen.active {
  display: block;
}

/* ------------------------------------------------------------
   4. Bottom navigation
   ------------------------------------------------------------ */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--nav-height);
  background: var(--bg);
  border-top: 0.5px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  min-height: var(--nav-height);
  padding: 0;
  border-radius: 0;
}

.nav-tab .nav-icon {
  font-size: 18px;
  line-height: 1;
}

.nav-tab.active {
  color: var(--accent);
}

.nav-tab.active .nav-icon {
  color: var(--accent);
}

/* ------------------------------------------------------------
   5. Cards & sections
   ------------------------------------------------------------ */
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.section-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin: 0 0 var(--sp-3) 0;
}

.section-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin: 0 0 var(--sp-3) 0;
}

/* ------------------------------------------------------------
   6. Buttons
   ------------------------------------------------------------ */
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  font-weight: 600;
}

.btn-primary:disabled {
  background: var(--gray-200);
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg);
  border: 0.5px solid var(--border);
  color: var(--text);
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--accent);
  min-height: auto;
  padding: var(--sp-2) var(--sp-3);
}

.btn-danger {
  background: var(--danger);
  color: white;
  border: none;
}

.btn-pill {
  border-radius: 999px;
  padding: var(--sp-2) var(--sp-4);
  min-height: 36px;
  font-size: var(--fs-sm);
}

/* ------------------------------------------------------------
   7. Pills, badges, dots
   ------------------------------------------------------------ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--gray-50);
  color: var(--gray-600);
  border: 0.5px solid var(--border);
}

.pill-teal   { background: var(--teal-50);   color: var(--teal-800);   border-color: var(--teal-400); }
.pill-blue   { background: var(--blue-50);   color: var(--blue-800);   border-color: var(--blue-400); }
.pill-amber  { background: var(--amber-50);  color: var(--amber-800);  border-color: var(--amber-400); }
.pill-coral  { background: var(--coral-50);  color: var(--coral-800);  border-color: var(--coral-400); }
.pill-green  { background: var(--green-50);  color: var(--green-800);  border-color: var(--green-400); }
.pill-purple { background: var(--purple-50); color: var(--purple-800); border-color: var(--purple-400); }
.pill-gray   { background: var(--gray-50);   color: var(--gray-600);   border-color: var(--gray-200); }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-teal   { background: var(--teal-400); }
.dot-blue   { background: var(--blue-400); }
.dot-amber  { background: var(--amber-400); }
.dot-coral  { background: var(--coral-400); }
.dot-green  { background: var(--green-400); }
.dot-purple { background: var(--purple-400); }
.dot-gray   { background: var(--gray-200); }

/* Category color swatches (icon squares) */
.cat-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.cat-teal   { background: var(--teal-50);   color: var(--teal-800); }
.cat-blue   { background: var(--blue-50);   color: var(--blue-800); }
.cat-amber  { background: var(--amber-50);  color: var(--amber-800); }
.cat-coral  { background: var(--coral-50);  color: var(--coral-800); }
.cat-green  { background: var(--green-50);  color: var(--green-800); }
.cat-purple { background: var(--purple-50); color: var(--purple-800); }
.cat-gray   { background: var(--gray-50);   color: var(--gray-600); }

/* ------------------------------------------------------------
   8. Entry screen — date bar
   ------------------------------------------------------------ */
.date-bar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  margin-bottom: var(--sp-4);
}

.date-bar .today-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  padding: var(--sp-2) var(--sp-4);
  min-height: 40px;
  font-weight: 600;
  font-size: var(--fs-sm);
}

.date-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: 999px;
  padding: var(--sp-2) var(--sp-4);
  min-height: 40px;
  font-size: var(--fs-sm);
  font-weight: 500;
}

.date-pill.past {
  background: var(--amber-50);
  border-color: var(--amber-400);
  color: var(--amber-800);
}

.past-badge {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Calendar dropdown */
.calendar-dropdown {
  position: absolute;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  z-index: 50;
  width: 280px;
  margin-top: var(--sp-2);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
  font-weight: 600;
}

.calendar-header button {
  border: none;
  background: none;
  min-height: auto;
  padding: var(--sp-2);
  font-size: 18px;
}

.calendar-header button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--sp-1);
}

.calendar-day-name {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
  padding: var(--sp-1);
  font-weight: 500;
}

.calendar-day {
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  min-height: 36px;
  font-size: var(--fs-sm);
  padding: 0;
}

.calendar-day:hover:not(:disabled) {
  background: var(--gray-50);
}

.calendar-day.selected {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.calendar-day.today {
  border: 0.5px solid var(--accent);
}

.calendar-day:disabled {
  color: var(--gray-200);
  cursor: not-allowed;
}

.calendar-day.empty {
  visibility: hidden;
}

/* ------------------------------------------------------------
   9. Entry screen — merchant field & autocomplete
   ------------------------------------------------------------ */
.merchant-wrap {
  position: relative;
  margin-bottom: var(--sp-3);
}

.merchant-input {
  font-size: var(--fs-lg);
  font-weight: 500;
  padding: var(--sp-3) var(--sp-4);
}

.autocomplete {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  margin-top: var(--sp-1);
  z-index: 40;
  max-height: 280px;
  overflow-y: auto;
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  min-height: var(--tap-target);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.highlighted {
  background: var(--gray-50);
}

.autocomplete-name {
  font-weight: 500;
  flex: 1;
}

.autocomplete-count {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.autocomplete-meta {
  display: flex;
  gap: var(--sp-1);
  flex-wrap: wrap;
  margin-top: var(--sp-1);
}

/* ------------------------------------------------------------
   10. Entry screen — form fields
   ------------------------------------------------------------ */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.field-row.single {
  grid-template-columns: 1fr;
}

.field-label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Toggles */
.toggle-row {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.toggle-group {
  display: flex;
  flex: 1;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle-btn {
  flex: 1;
  border: none;
  border-radius: 0;
  background: var(--bg);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  min-height: var(--tap-target);
  padding: var(--sp-2);
}

.toggle-btn.active {
  background: var(--accent-bg);
  color: var(--accent-dark);
  font-weight: 600;
}

/* ------------------------------------------------------------
   11. Entry screen — amount display & numpad
   ------------------------------------------------------------ */
.amount-display {
  font-size: 36px;
  font-weight: 700;
  text-align: right;
  padding: var(--sp-3) var(--sp-4);
  background: var(--gray-50);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-3);
  font-variant-numeric: tabular-nums;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transition: background 200ms ease;
}

.amount-display.flash {
  background: var(--success-bg);
}

.amount-currency {
  font-size: 18px;
  color: var(--text-muted);
  margin-right: var(--sp-2);
  font-weight: 500;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.numpad-key {
  border: 0.5px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  min-height: 56px;
  font-size: var(--fs-xl);
  font-weight: 500;
}

.numpad-key:active {
  background: var(--gray-50);
}

.numpad-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: var(--sp-2);
}

.numpad-actions .clear-btn {
  background: var(--bg);
  border: 0.5px solid var(--border);
  color: var(--text-muted);
  min-height: 56px;
  font-weight: 500;
}

.numpad-actions .save-btn {
  background: var(--accent);
  color: white;
  border: none;
  min-height: 56px;
  font-weight: 600;
  font-size: var(--fs-lg);
}

.numpad-actions .save-btn:disabled {
  background: var(--gray-200);
  cursor: not-allowed;
}

/* ------------------------------------------------------------
   12. Today strip
   ------------------------------------------------------------ */
.today-strip {
  margin-top: var(--sp-4);
}

.today-strip-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.today-strip-total {
  font-size: var(--fs-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.txn-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-bottom: 0.5px solid var(--border);
  min-height: var(--tap-target);
  cursor: pointer;
}

.txn-row:last-child {
  border-bottom: none;
}

.txn-row:hover {
  background: var(--gray-50);
}

.txn-info {
  flex: 1;
  min-width: 0;
}

.txn-merchant {
  font-weight: 500;
  font-size: var(--fs-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.txn-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.txn-amount {
  font-weight: 600;
  font-size: var(--fs-md);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.txn-amount.income {
  color: var(--success);
}

.empty-state {
  text-align: center;
  padding: var(--sp-6);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* ------------------------------------------------------------
   13. History screen
   ------------------------------------------------------------ */
.search-bar {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 0 0 var(--sp-3) 0;
  z-index: 10;
  margin-bottom: var(--sp-3);
}

.date-group {
  margin-bottom: var(--sp-4);
}

.date-group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: var(--sp-2) 0;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: var(--sp-2);
}

.date-group-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
}

.date-group-total {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------
   14. Modal
   ------------------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 0;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--sp-5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}

.modal-title {
  font-size: var(--fs-xl);
  font-weight: 600;
}

.modal-close {
  border: none;
  background: none;
  font-size: 24px;
  min-height: auto;
  padding: var(--sp-2);
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary,
.modal-actions .btn-danger {
  flex: 1;
}

/* ------------------------------------------------------------
   15. Fixed expenses screen
   ------------------------------------------------------------ */
.fixed-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-bottom: 0.5px solid var(--border);
  min-height: var(--tap-target);
  cursor: pointer;
}

.fixed-item:last-child {
  border-bottom: none;
}

.fixed-item-info {
  flex: 1;
  min-width: 0;
}

.fixed-item-name {
  font-weight: 500;
  font-size: var(--fs-md);
}

.fixed-item-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.fixed-item-amount {
  font-weight: 600;
  font-size: var(--fs-md);
  font-variant-numeric: tabular-nums;
}

.due-badge {
  font-size: var(--fs-xs);
  font-weight: 600;
  padding: 2px var(--sp-2);
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.due-badge.posted {
  background: var(--green-50);
  color: var(--green-800);
}

.due-badge.pending {
  background: var(--amber-50);
  color: var(--amber-800);
}

.add-btn-large {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  padding: var(--sp-3);
  border: 0.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--accent);
  font-weight: 500;
  margin-top: var(--sp-3);
}

/* ------------------------------------------------------------
   16. Analysis screen
   ------------------------------------------------------------ */
.month-selector {
  margin-bottom: var(--sp-4);
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.stat-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
}

.stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: var(--sp-1);
}

.stat-value {
  font-size: var(--fs-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-container {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.chart-title {
  font-size: var(--fs-md);
  font-weight: 600;
  margin-bottom: var(--sp-3);
}

.chart-canvas-wrap {
  position: relative;
  height: 240px;
}

.debt-row {
  margin-bottom: var(--sp-3);
}

.debt-row:last-child {
  margin-bottom: 0;
}

.debt-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-1);
}

.debt-progress {
  height: 8px;
  background: var(--gray-50);
  border-radius: 999px;
  overflow: hidden;
}

.debt-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 300ms ease;
}

/* ------------------------------------------------------------
   17. Settings screen
   ------------------------------------------------------------ */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-bottom: 0.5px solid var(--border);
  min-height: var(--tap-target);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row-info {
  flex: 1;
  min-width: 0;
}

.settings-row-label {
  font-weight: 500;
  font-size: var(--fs-md);
}

.settings-row-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.settings-row-actions {
  display: flex;
  gap: var(--sp-1);
}

.icon-btn {
  border: none;
  background: none;
  min-height: 36px;
  min-width: 36px;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.icon-btn:hover {
  background: var(--gray-50);
}

.icon-btn.danger {
  color: var(--danger);
}

.subcategory-list {
  margin-left: var(--sp-5);
  padding-left: var(--sp-3);
  border-left: 0.5px solid var(--border);
}

.export-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.export-actions button {
  width: 100%;
}

.file-input-wrap {
  position: relative;
}

.file-input-wrap input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ------------------------------------------------------------
   18. Utility
   ------------------------------------------------------------ */
.hidden { display: none !important; }
.row    { display: flex; align-items: center; gap: var(--sp-2); }
.spacer { flex: 1; }
.muted  { color: var(--text-muted); }
.tabular { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
