:root {
  --primary: #0091ea;
  --primary-light: #7bbde6;
  --primary-dark: #006bb3;
  --accent: #546e7a;
  --grey: #445;
  --error: #f52;
  --success: #2e7d32;
  --background: #f5f5f6;
  --background-accent: #cfe5f2;
  --white: #fff;
  --border: #dde;
  --radius: 10px;
  --radius-sm: 6px;
  --space-xs: 5px;
  --space-sm: 10px;
  --space-md: 20px;
  --space-xl: 40px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; padding: 0; height: 100%; }
body { font-family: Arial, Helvetica, sans-serif; font-size: 16px; background: var(--background); }

/* ------------------------------------------------------------------ */
/* Typography & base elements */
/* ------------------------------------------------------------------ */

h2 {
  color: var(--primary);
  text-transform: uppercase;
  font-weight: bold;
  font-size: 1.3rem;
  margin: var(--space-md) 0 var(--space-sm);
}

form { display: flex; flex-direction: column; margin: var(--space-sm) var(--space-md); }

label { color: var(--grey); text-transform: uppercase; font-size: 80%; margin-top: var(--space-xs); }

input, select {
  margin-top: 3px;
  margin-bottom: var(--space-sm);
  height: 42px;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--white);
}
input:focus, select:focus { border-color: var(--primary); outline: 0; }

button {
  font-weight: bold;
  background-color: var(--primary);
  color: var(--white);
  height: 40px;
  padding: var(--space-xs) var(--space-md);
  border: 0;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  min-width: 90px;
  margin: var(--space-sm) 0;
  cursor: pointer;
  font-size: .9rem;
}
button:hover { filter: brightness(110%); }
button:focus { outline: none; box-shadow: 0 0 0 3px rgba(0,145,234,.3); }
button:disabled { opacity: .4; cursor: not-allowed; filter: none; }

.button-alt { background-color: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline { background: transparent; color: var(--white); border: 1px solid var(--white); font-size: .85rem; height: 34px; min-width: 70px; }
.btn-back { background: transparent; color: var(--white); border: none; font-size: 1rem; font-weight: bold; min-width: 0; padding: 0 var(--space-sm); }
.btn-icon-sm { background: transparent; color: var(--white); border: none; font-size: 1.1rem; min-width: 0; height: 34px; padding: 0 var(--space-xs); }
.btn-icon-sm.btn-danger:hover { color: #ff8a80; }
.btn-icon { background: transparent; color: var(--error); border: none; min-width: 0; height: 28px; padding: 0 6px; font-size: .85rem; }

.error { color: var(--error); font-size: .9rem; margin: var(--space-xs) 0; min-height: 1.2em; }
.error:empty { display: none; }

.positive { color: var(--success); }
.negative { color: var(--error); }

.text-center { text-align: center; }
.hide-xs { display: none; }

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

.app-shell { display: flex; flex-direction: column; min-height: 100%; }

.app-header {
  background-color: var(--grey);
  padding: 0 var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-height: 56px;
}
.header-logo { height: 44px; padding: 4px 0; }
.header-title { font-size: 1.2rem; font-weight: bold; color: var(--white); margin: 0; text-transform: none; flex: 1; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-sm); }
.header-user { color: rgba(255,255,255,.7); font-size: .9rem; }

.header-wallet-info { flex: 1; display: flex; flex-direction: column; }
.wallet-detail-name { color: var(--white); font-weight: bold; font-size: 1rem; }
.wallet-detail-balance { color: var(--primary-light); font-size: .9rem; }

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

.login-page {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  background: linear-gradient(var(--primary), var(--primary-light));
}
.login-container { flex: auto; max-width: 480px; max-height: 100%; overflow: auto; }
.login-title { font-size: 2rem; font-weight: bold; color: var(--white); margin: var(--space-md); }
.login-logo { height: 80px; vertical-align: middle; }
.login-content { background-color: var(--background); padding: var(--space-sm); }
.login-separator { position: relative; border-top: 1px solid var(--border); opacity: .6; margin: var(--space-md) 0; }
.login-separator > span { position: relative; top: -.6em; background: var(--background); padding: var(--space-sm); }

/* ------------------------------------------------------------------ */
/* Wallet list page */
/* ------------------------------------------------------------------ */

.wallet-list-page { padding: var(--space-md); max-width: 900px; margin: 0 auto; width: 100%; }
.wallet-list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-md); }
.wallet-list-header h2 { margin: 0; }

.wallet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-md); }

.wallet-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: var(--space-md);
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s, box-shadow .15s;
}
.wallet-card:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgba(0,145,234,.15); }
.wallet-card-name { font-weight: bold; font-size: 1.1rem; color: var(--grey); margin-bottom: var(--space-xs); }
.wallet-card-balance { font-size: 1.6rem; font-weight: bold; color: var(--primary); }
.wallet-card-desc { font-size: .85rem; color: #888; margin-top: var(--space-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ */
/* Summary panel */
/* ------------------------------------------------------------------ */

.summary-panel {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  padding: var(--space-sm) var(--space-md);
  color: var(--white);
}
.summary-label { font-size: .8rem; text-transform: uppercase; opacity: .8; margin-bottom: var(--space-xs); }
.summary-week { font-weight: bold; }
.summary-stats { display: flex; gap: var(--space-xl); }
.summary-stat-label { font-size: .75rem; text-transform: uppercase; opacity: .7; }
.summary-value { font-size: 1.2rem; font-weight: bold; }
.summary-value.positive { color: #a5d6a7; }
.summary-value.negative { color: #ef9a9a; }

/* ------------------------------------------------------------------ */
/* Wallet detail page */
/* ------------------------------------------------------------------ */

.wallet-detail-page { padding: var(--space-sm) var(--space-md); max-width: 960px; margin: 0 auto; width: 100%; }
.wallet-desc { color: #777; font-size: .9rem; margin: var(--space-xs) 0 var(--space-sm); }

/* Category tabs */
.category-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-sm); }
.tab-btn {
  background: var(--white);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 20px;
  height: 32px;
  min-width: 0;
  padding: 0 var(--space-sm);
  font-size: .82rem;
  text-transform: none;
  margin: 0;
}
.tab-btn:hover { border-color: var(--primary); color: var(--primary); }
.tab-btn.active { background: var(--primary); color: var(--white); border-color: var(--primary); }

/* Table */
.table-wrapper { overflow-x: auto; }
.transactions-table {
  width: 100%;
  font-size: .95rem;
  border-spacing: 0;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.transactions-table thead th {
  background: var(--background);
  border-bottom: 2px solid var(--border);
  padding: var(--space-sm);
  text-align: left;
  font-size: .8rem;
  text-transform: uppercase;
  color: var(--accent);
}
.transactions-table td { padding: 8px var(--space-sm); border-bottom: 1px solid var(--border); }
.transactions-table tr:last-child td { border-bottom: none; }
.transactions-table tr:hover td { background: var(--background-accent); }
.transactions-table td:nth-child(4),
.transactions-table td:nth-child(5) { text-align: right; font-family: monospace; font-size: 1rem; }
.transactions-table th:nth-child(4),
.transactions-table th:nth-child(5) { text-align: right; }
.transactions-table td:last-child { width: 1%; white-space: nowrap; }

/* Category badges */
.category-badge {
  display: inline-block;
  border-radius: 20px;
  padding: 2px 8px;
  font-size: .75rem;
  font-weight: bold;
  text-transform: uppercase;
  background: #e0e0e0;
  color: #555;
}
.cat-income       { background: #c8e6c9; color: #2e7d32; }
.cat-food         { background: #fff3e0; color: #e65100; }
.cat-transport    { background: #e3f2fd; color: #1565c0; }
.cat-housing      { background: #f3e5f5; color: #6a1b9a; }
.cat-health       { background: #fce4ec; color: #880e4f; }
.cat-entertainment{ background: #e8eaf6; color: #283593; }
.cat-shopping     { background: #e0f7fa; color: #00695c; }
.cat-other        { background: #f5f5f5; color: #616161; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: var(--space-md); margin: var(--space-md) 0; }
.pagination button { min-width: 80px; height: 36px; margin: 0; font-size: .85rem; }
#pageInfo { color: var(--accent); font-size: .9rem; }

.add-tx-row { display: flex; justify-content: flex-end; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-md); }

/* ------------------------------------------------------------------ */
/* Transaction type toggle */
/* ------------------------------------------------------------------ */

.tx-type-toggle {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  margin: var(--space-sm) var(--space-md) var(--space-md);
}
.type-btn {
  flex: 1;
  height: 44px;
  margin: 0;
  border: none;
  border-radius: 0;
  font-size: 1rem;
  font-weight: bold;
  text-transform: none;
  background: var(--background);
  color: var(--accent);
  transition: background .15s, color .15s;
  min-width: 0;
}
.type-btn:focus { box-shadow: none; }
.type-income.active  { background: #e8f5e9; color: #2e7d32; }
.type-expense.active { background: #fce4ec; color: #c62828; }

/* ------------------------------------------------------------------ */
/* Input group (prefix + input) */
/* ------------------------------------------------------------------ */

.input-group {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-top: 3px;
  margin-bottom: var(--space-sm);
  background: var(--white);
}
.input-group:focus-within { border-color: var(--primary); }
.input-prefix {
  padding: 0 var(--space-sm);
  color: var(--accent);
  font-weight: bold;
  background: var(--background);
  border-right: 1px solid var(--border);
  height: 42px;
  display: flex;
  align-items: center;
  font-size: 1rem;
  white-space: nowrap;
}
.input-group input {
  border: none;
  border-radius: 0;
  margin: 0;
  flex: 1;
  height: 42px;
  font-size: 1.1rem;
}
.input-group input:focus { outline: none; box-shadow: none; border: none; }

/* ------------------------------------------------------------------ */
/* Dialogs */
/* ------------------------------------------------------------------ */

.dialog {
  display: none;
  position: fixed;
  inset: 0;
  overflow: auto;
  background: rgba(0,0,0,.45);
  animation: fadeIn .2s ease;
  justify-content: center;
  align-items: flex-start;
  z-index: 100;
}
.dialog.show { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog-content {
  flex: auto;
  background: var(--white);
  max-width: 480px;
  max-height: 100%;
  overflow: auto;
  padding: var(--space-md);
  margin-top: var(--space-xl);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.dialog-buttons { text-align: right; display: flex; justify-content: flex-end; gap: var(--space-sm); }

/* ------------------------------------------------------------------ */
/* Responsive */
/* ------------------------------------------------------------------ */

@media (min-width: 480px) {
  .hide-xs { display: initial; }
}

@media (min-width: 640px) {
  .summary-stats { gap: var(--space-xl); }
  .summary-value { font-size: 1.4rem; }
}
