/* ═══════════════════════════════════════════════════════════════
   LIFE PAGE — life.css
   Depends on global.css design tokens
   NOTE: Many rules are also defined in main.css; a final clean-up
         could consolidate duplicates there.
   ═══════════════════════════════════════════════════════════════ */

/* ── MAIN CONTAINER & GRID ────────────────────────────────────── */
.life-main {
  position: relative;
  z-index: 1;
  padding: 26px 30px;
}

.life-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ── PANELS ──────────────────────────────────────────────────── */
.panel--income,
.panel--expenses {
  display: flex;
  flex-direction: column;
  max-height: 380px;
}

.panel--income .data-table-wrap,
.panel--expenses .data-table-wrap {
  overflow-y: auto;
  flex: 1;
}

/* Wallets panel: now uses a grid inside*/
.panel--wallets {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: 420px;
}

/* Debt panel: fixed height with scroll — matches wallets */
.panel--debt {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: 420px;
  overflow: hidden; /* prevents panel from growing */
}

.panel--debt .data-table-wrap {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* ── WALLET CARDS ────────────────────────────────────────────── */
.panel--wallets .wallets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  padding: 15px 15px 20px;
}

[data-theme="light"] .panel--wallets .wallets-grid {
  background: var(--bg);
}

[data-theme="light"] .wallet-card {
  background: var(--card);
  border-color: var(--border);
}

.wallet-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--r-md);
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition:
    border-color 0.35s ease,
    transform 0.35s var(--ease-spring),
    box-shadow 0.4s ease;
}

.wallet-card:hover {
  border-color: var(--border-2);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(212, 187, 255, 0.1);
}

.wallet-name {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Balance display: originally used display font; later overridden to body font.
   The rule at the bottom of this file forces the body font to maintain consistency. */
.wallet-balance {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent2);
  letter-spacing: -0.02em;
}

.wallet-input {
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.82rem;
  width: 100%;
  font-family: var(--font-body);
  outline: none;
  box-sizing: border-box;
  transition:
    border-color var(--t-fast),
    box-shadow var(--t-fast);
}

.wallet-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 187, 255, 0.12);
}

.btn-save-wallet {
  background: var(--btn-primary);
  color: var(--btn-primary-text);
  border: none;
  border-radius: var(--r-sm);
  padding: 6px;
  font-size: 0.73rem;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 700;
  transition:
    background var(--t-fast),
    transform var(--t-fast) var(--ease-spring);
}

.btn-save-wallet:hover {
  background: var(--btn-primary-hover);
  transform: translateY(-1px);
}

[data-theme="light"] .btn-save-wallet { color: #fff; }

/* ── GOAL ROW & ACTIONS ──────────────────────────────────────── */
.goal-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0 3px;
  user-select: none;
  transition: color var(--t-fast);
  touch-action: none;
  -webkit-touch-callout: none;
}

.drag-handle:hover {
  color: var(--muted-2);
}

.drag-handle:active {
  cursor: grabbing;
}

.goal-row.dragging {
  opacity: 0.35;
}

.goal-row.drag-over {
  border-top: 2px solid var(--accent);
}

.goal-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.goal-actions .goal-checkbox {
  order: 0;
  flex-shrink: 0;
}
.goal-actions .btn-edit {
  order: 1;
  flex-shrink: 0;
}
.goal-actions .btn-del {
  order: 2;
  flex-shrink: 0;
}

/* ── DEBT SUMMARY ROW ─────────────────────────────────────────── */
.debt-summary {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  flex-shrink: 0;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
}

.debt-net-sep {
  color: var(--border);
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ── ACTION BUTTONS (debt) ───────────────────────────────────── */
.btn-add-debt {
  background: rgba(74, 222, 128, 0.07);
  color: var(--green);
  border: 1px solid rgba(74, 222, 128, 0.22);
  border-radius: var(--r-sm);
  padding: 4px 9px;
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 600;
  font-family: var(--font-body);
  line-height: 1.4;
  transition: all var(--t-fast);
  flex-shrink: 0;
}

.btn-add-debt:hover {
  background: rgba(74, 222, 128, 0.16);
  border-color: rgba(74, 222, 128, 0.4);
}

/* ── SUMMARY BAR (life override) ──────────────────────────────── */
.summary-bar {
  grid-template-columns: repeat(6, 1fr);
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — SMALL TABLET (≤ 900px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .life-grid {
    grid-template-columns: 1fr;
  }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — PHONE (≤ 700px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 700px) {
  .life-main {
    padding: 14px 14px 90px;
  }

  .summary-bar {
    grid-template-columns: repeat(3, 1fr) !important;
    overflow-x: hidden !important;
  }

  /* Wallets: 2 columns, smaller cards */
  .panel--wallets .wallets-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .wallet-card {
    min-height: auto;
    padding: 8px 10px;
    gap: 3px;
  }

  .wallet-card:last-child {
    margin-bottom: 0;
  }

  .wallet-name {
    font-size: 0.58rem;
    margin-bottom: 0;
  }

  .wallet-balance {
    font-size: 1rem;
    margin: 0;
  }

  .wallet-input {
    font-size: 0.75rem;
    padding: 5px 8px;
    margin: 0;
  }

  .btn-save-wallet {
    font-size: 0.65rem;
    padding: 5px;
    margin-top: 2px;
  }

  /* Remove forced min-height so panel shrinks to cards */
  .panel--wallets {
    min-height: auto;
    max-height: none;
  }

  .panel--wallets .wallets-grid {
    padding-bottom: 10px;
  }

  /* Tables: strict single-row, no horizontal scroll */
  .data-table-wrap {
    overflow-x: hidden !important;
    width: 100%;
  }

  .data-table {
    table-layout: fixed;
    width: 100%;
  }

  .data-table th,
  .data-table td {
    font-size: 0.68rem;
    padding: 7px 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
  }

  .data-table td:nth-child(4) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .data-table td:last-child {
    white-space: nowrap;
    text-align: right;
    padding: 8px 14px 8px 5px;
    overflow: hidden;
    vertical-align: middle;
  }
  .data-table td:last-child > * {
    vertical-align: middle;
  }

  /* Fix empty-state cells (colspan) so they display normally */
  .panel--income .data-table td[colspan],
  .panel--expenses .data-table td[colspan],
  .panel--debt .data-table td[colspan],
  .panel--todos .data-table td[colspan] {
    display: table-cell !important;
    white-space: normal !important;
    overflow: visible !important;
    text-align: center !important;
    padding: 16px 8px !important;
  }

  /* Goals table: checkbox is the true last-child; reset it to table-cell */
  .panel--goals .data-table td:last-child {
    display: table-cell;
    padding: 7px 5px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    overflow: visible;
  }

  /* Keep the goal-actions cell as flex */
  .panel--goals .data-table td:nth-child(5) {
    display: flex;
    flex-wrap: nowrap;
    gap: 3px;
    align-items: center;
    white-space: nowrap;
    padding: 4px 5px;
    overflow: hidden;
  }

  .btn-edit,
  .btn-del,
  .btn-add-debt {
    padding: 3px 6px;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
  }
  .btn-add-debt { font-size: 0.68rem; }
  .btn-edit::before, .btn-del::before { width: 12px; height: 12px; }

  .goal-actions {
    flex-wrap: nowrap;
    gap: 3px;
  }

  .goal-actions .goal-checkbox {
    width: 14px;
    height: 14px;
  }

  /* Debt panel: auto height, scroll when needed */
  .panel--debt {
    min-height: 0;
    max-height: calc(34px + 5 * 40px + 40px); /* header + 5 rows + summary */
  }

  .panel--debt .data-table-wrap {
    max-height: 180px; /* ~4 rows */
    overflow-y: auto;
    overflow-x: hidden !important;
    flex: 1;
    min-height: 0;
  }

  /* Income/expense panels: fixed height with scroll */
  .panel--income,
  .panel--expenses {
    max-height: calc(34px + 4 * 40px);
  }

  .panel--income .data-table-wrap,
  .panel--expenses .data-table-wrap {
    max-height: calc(4 * 40px);
    overflow-y: auto;
    overflow-x: hidden !important;
    flex: 1;
    min-height: 0;
  }

  /* Debt summary stays single row */
  .debt-summary {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 4px 10px;
    font-size: 0.63rem;
    padding: 7px 10px;
    overflow: hidden;
    white-space: nowrap;
  }

  .debt-net-sep {
    display: inline;
    flex-shrink: 0;
  }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — SMALL PHONE (≤ 480px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .life-main {
    padding: 12px 11px 90px;
  }

  .summary-bar {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 7px;
  }

  .debt-summary {
    font-size: 0.58rem;
    gap: 3px 7px;
    padding: 6px 8px;
  }
}

/* ── FINAL OVERRIDE: wallet-balance uses body font (kept at end
   so it overrides previous declaration without `!important`) ──── */
.wallet-balance {
  font-family: var(--font-body) !important;
}

/* ── TO-DO LIST PANEL ─────────────────────────────────────────── */
.panel--todos {
  display: flex;
  flex-direction: column;
  max-height: 400px;
}

.panel--todos .data-table-wrap {
  overflow-y: auto;
  flex: 1;
}

.panel--todos .data-table td:first-child {
  width: 36px;
  text-align: center;
}
