/* =====================================================
   Chi Tiêu — UI theo phong cách shadcn/ui
   Design tokens: bảng màu HSL mặc định của shadcn (New York)
   ===================================================== */

:root {
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 222.2 84% 4.9%;
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;
  --success: 142.1 76.2% 36.3%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 222.2 84% 4.9%;
  --radius: 0.5rem;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  -webkit-font-smoothing: antialiased;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea, [contenteditable] {
  -webkit-user-select: auto !important;
  user-select: auto !important;
}

.hidden { display: none !important; }

/* ============ App container (fixed height) ============ */
.app {
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  position: relative;
  overflow: hidden;
}

/* ============ Page + chuyển trang dùng chung ============ */
.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: hsl(var(--background));
  transition: transform .34s var(--ease), opacity .34s ease;
  will-change: transform, opacity;
}
.page-all { transform: translateX(100%); opacity: 0; pointer-events: none; }
.app.show-all .page-main { transform: translateX(-28%); opacity: .45; }
.app.show-all .page-all { transform: translateX(0); opacity: 1; pointer-events: auto; }

/* ============ Topbar ============ */
.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px;
}
.month-box { display: flex; align-items: baseline; gap: 8px; }
.month-box #monthLabel { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.month-box #yearLabel { font-size: 14px; color: hsl(var(--muted-foreground)); font-weight: 500; }
#allTitle { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }

/* ============ Button (shadcn) ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  height: 40px; padding: 0 16px;
  font-size: 14px; font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  user-select: none;
  transition: transform .14s var(--ease), background-color .15s ease, color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.96); }
.btn:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }

.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.btn-primary:hover { background: hsl(var(--primary) / .9); }

.btn-outline { border-color: hsl(var(--input)); background: hsl(var(--background)); color: hsl(var(--foreground)); }
.btn-outline:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover { background: hsl(var(--secondary) / .8); }

.btn-icon { height: 40px; width: 40px; padding: 0; border-radius: calc(var(--radius) - 2px); }

/* ============ Card (shadcn) ============ */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
  margin: 10px 16px;
}
.card-header { display: flex; flex-direction: column; gap: 4px; padding: 16px 20px 0; }
.card-title { font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-description { font-size: 13px; color: hsl(var(--muted-foreground)); line-height: 1.45; }
.card-content { padding: 12px 20px 18px; }

/* Nút sắp xếp (dùng chung) */
.sort-btn { height: 32px; padding: 0 10px; font-size: 12px; color: hsl(var(--muted-foreground)); gap: 4px; }
.sort-btn svg { width: 14px; height: 14px; }
.sort-btn:hover { color: hsl(var(--foreground)); }

/* ============ Tổng quan ============ */
.summary-card .card-content { padding: 10px 20px 16px; }
.sum-value { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; margin: 2px 0 12px; }

.progress-track { height: 8px; width: 100%; overflow: hidden; border-radius: 9999px; background: hsl(var(--secondary)); }
.progress-fill { height: 100%; border-radius: 9999px; background: hsl(var(--primary)); transition: width .4s var(--ease); }

.summary-rows { display: flex; flex-direction: column; margin-top: 14px; }
.sum-row { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 10px 0; }
.sum-row + .sum-row { border-top: 1px solid hsl(var(--border)); }
.sum-row b { margin-left: auto; font-size: 14px; font-weight: 600; }
.sum-row .income { color: hsl(var(--success)); }
.sum-row .expense { color: hsl(var(--destructive)); }
.dot { width: 8px; height: 8px; border-radius: 9999px; flex-shrink: 0; }
.dot-income { background: hsl(var(--success)); }
.dot-expense { background: hsl(var(--destructive)); }

/* ============ Giao dịch (card co giãn, scroll bên trong) ============ */
.tx-card { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.tx-card .card-header { flex: none; }
.tx-card .tx-scroll { flex: 1 1 0; min-height: 0; padding: 2px 20px 6px; }

/* Vùng scroll ẩn thanh cuộn (dùng chung) */
.tx-scroll {
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tx-scroll::-webkit-scrollbar { display: none; width: 0; height: 0; }

.tx-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; }
.tx-item + .tx-item { border-top: 1px solid hsl(var(--border)); }
.tx-icon {
  width: 38px; height: 38px; border-radius: 9999px;
  display: grid; place-items: center;
  background: hsl(var(--muted)); flex-shrink: 0;
}
.tx-icon svg { width: 18px; height: 18px; }
.tx-main { flex: 1; min-width: 0; }
.tx-note { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-date { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 2px; }
.tx-amount { font-size: 14px; font-weight: 600; }
.tx-amount.expense { color: hsl(var(--destructive)); }
.tx-amount.income { color: hsl(var(--success)); }
.tx-del {
  display: inline-flex; align-items: center; justify-content: center;
  height: 34px; width: 34px; margin-right: -6px;
  border: none; border-radius: calc(var(--radius) - 2px);
  background: transparent; color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: transform .14s var(--ease), background-color .15s ease, color .15s ease;
}
.tx-del:active { transform: scale(.9); }
.tx-del svg { width: 16px; height: 16px; }
.tx-del:hover { background: hsl(var(--destructive) / .1); color: hsl(var(--destructive)); }

.empty { text-align: center; color: hsl(var(--muted-foreground)); font-size: 14px; padding: 26px 0 8px; }

/* Footer "Xem tất cả giao dịch" */
.view-all-footer {
  flex: none;
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 13px 20px;
  font-size: 13px; font-weight: 500;
  color: hsl(var(--primary));
  border-top: 1px solid hsl(var(--border));
  border-radius: 0 0 var(--radius) var(--radius);
  background: transparent;
  height: auto;
}
.view-all-footer svg { width: 15px; height: 15px; transition: transform .18s var(--ease); }
.view-all-footer:active svg { transform: translateX(3px); }

/* ============ Page "Tất cả giao dịch" ============ */
.range-label {
  flex: none;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 4px 20px 8px;
  font-size: 13px; color: hsl(var(--muted-foreground));
}
.range-date { font-weight: 600; color: hsl(var(--foreground)); }
.range-totals b { font-weight: 600; }
.range-totals .income { color: hsl(var(--success)); }
.range-totals .expense { color: hsl(var(--destructive)); }

.all-card { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.all-card .tx-scroll { flex: 1 1 0; min-height: 0; padding: 2px 20px 14px; }

/* ============ Toolbar (backup + FAB) ============ */
.toolbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid hsl(var(--border));
  background: hsl(var(--card));
}
.toolbar-backup { display: flex; gap: 2px; }
.toolbar-backup .btn-icon { color: hsl(var(--muted-foreground)); }
.toolbar-backup .btn-icon:hover { color: hsl(var(--foreground)); }

/* FAB (nằm trong toolbar) */
.fab {
  flex: none;
  height: 56px; width: 56px;
  border-radius: 9999px; border: none;
  background: hsl(var(--primary)); color: hsl(var(--primary-foreground));
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(2, 8, 20, .28);
  cursor: pointer;
  transition: transform .14s var(--ease), background-color .15s ease;
}
.fab:active { transform: scale(.92); background: hsl(var(--primary) / .9); }
.fab:focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 2px; }

/* ============ Overlay / Sheet (shadcn mobile) ============ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(2, 8, 20, .5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }

.overlay.hidden {
  display: flex !important; /* Override .hidden's display: none */
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.sheet {
  background: hsl(var(--card));
  width: 100%; max-width: 480px;
  border: 1px solid hsl(var(--border));
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp .28s var(--ease);
  max-height: 88vh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(60px); opacity: .6; } }

.handle { width: 40px; height: 4px; border-radius: 9999px; background: hsl(var(--muted-foreground) / .25); margin: 4px auto 12px; }

.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-header .btn-icon { height: 36px; width: 36px; }
.sheet-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }

/* ============ Tabs (shadcn) ============ */
.tabs-list {
  display: flex; align-items: center;
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}
.tabs-trigger {
  flex: 1;
  display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap;
  border: none; border-radius: calc(var(--radius) - 4px);
  padding: 9px 12px;
  font-size: 14px; font-weight: 500;
  font-family: inherit;
  color: inherit; background: transparent;
  cursor: pointer;
  transition: transform .14s var(--ease), background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.tabs-trigger:active { transform: scale(.96); }
.tabs-trigger.active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
  font-weight: 600;
}

/* ============ Lưới danh mục ============ */
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.cat-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  padding: 12px 4px;
  font-size: 12px; color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: transform .14s var(--ease), background-color .15s ease, border-color .15s ease, color .15s ease;
}
.cat-opt:active { transform: scale(.95); }
.cat-opt .em { display: flex; }
.cat-opt .em svg { width: 20px; height: 20px; }
.cat-opt:hover { background: hsl(var(--accent)); }
.cat-opt.selected {
  border-color: hsl(var(--primary));
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-weight: 600;
}

/* ============ Input (shadcn) ============ */
.field { margin-bottom: 16px; position: relative; z-index: 1; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.input {
  width: 100%; height: 44px;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  padding: 0 12px;
  font-size: 16px;
  font-family: inherit;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  -webkit-appearance: none;
  appearance: none;
  -webkit-user-select: text;
  user-select: text;
  cursor: text;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus { outline: none; border-color: hsl(var(--ring)); box-shadow: 0 0 0 2px hsl(var(--ring) / .12); }

/* ============ Dialog (shadcn) ============ */
.overlay.dialog-centered { align-items: center; padding: 20px; background: rgba(2, 8, 20, .72); backdrop-filter: blur(2px); }
.dialog {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(2, 8, 20, .24);
  padding: 28px 24px;
  width: 100%; max-width: 340px;
  animation: zoomIn .22s var(--ease);
}
@keyframes zoomIn { from { transform: scale(.94); opacity: 0; } }
.dialog-icon { display: flex; justify-content: center; color: hsl(var(--primary)); margin-bottom: 12px; }
.dialog-icon svg { width: 38px; height: 38px; }
.dialog-title { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; text-align: center; margin-bottom: 6px; }
.dialog-desc { font-size: 13px; color: hsl(var(--muted-foreground)); text-align: center; margin-bottom: 20px; line-height: 1.55; }

/* ============ Toast (shadcn) ============ */
.toast {
  position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(2, 8, 20, .16);
  padding: 11px 18px;
  font-size: 13px; font-weight: 500;
  max-width: 90vw;
  z-index: 200;
  animation: toastIn .22s var(--ease);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }
