/*
 * GIAO DIỆN VẬN HÀNH TIẾNG VIỆT CHUẨN MỰC (app.css)
 * Tối ưu đồng thời cho iPhone 15 Pro Max (PWA tràn viền, Safe Area Dynamic Island, chạm 1 ngón cái)
 * và Máy Mac / Trình duyệt Web (Bố cục Sidebar + Bảng điều khiển đa cột rộng rãi).
 */

@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.11);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.11);
  --purple: #7c3aed;
  --purple-soft: rgba(124, 58, 237, 0.11);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --radius: 16px;
  --radius-sm: 11px;
}

html.dark {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-soft: #1a2642;
  --border: #243252;
  --border-strong: #334670;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.16);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.16);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.48;
  overscroll-behavior-y: none;
}

.num {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
}

/* Bố cục App Shell: Mobile trước, tự mở rộng Sidebar trên Mac */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.desktop-sidebar {
  display: none;
}

.main-area {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 92px);
  padding-left: 14px;
  padding-right: 14px;
}

/* Thanh tiêu đề & Chọn kỳ thời gian dính ở trên */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 8px 0 10px;
  margin-bottom: 10px;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.brand-mobile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  box-shadow: var(--shadow);
}

.brand-title {
  font-weight: 800;
  font-size: 16px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  min-width: 42px;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.96);
}

/* Bộ lọc Ngày / Tuần / Tháng / Năm */
.period-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.period-tabs {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  flex: 1;
  min-width: 240px;
}

.period-tab {
  flex: 1;
  min-height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.period-tab.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.28);
}

.date-picker-pill {
  height: 42px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
}

/* Thanh báo hiệu đang bật chế độ Giả lập Tích/Bỏ tích */
.sim-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 13px;
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
}

.sim-banner button {
  padding: 6px 12px;
  border-radius: 9px;
  border: none;
  background: var(--warning);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

/* Thẻ chính (Hero Card) hiển thị Tổng Tiền Hiện Có */
.hero-wallet {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #065f46 100%);
  color: #ffffff;
  border-radius: 20px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
  margin-bottom: 14px;
}

.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hero-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
}

.hero-cash {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.15;
  margin-top: 4px;
}

.hero-reconcile-btn {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.26);
  color: #ffffff;
  padding: 8px 12px;
  border-radius: 11px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.hero-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.hero-split-box {
  background: rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  padding: 10px 12px;
}

.hero-split-lbl {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
}

.hero-split-val {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

/* Lưới các thẻ chỉ số */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
}

.kpi-card {
  padding: 13px 14px;
}

.kpi-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-val {
  font-size: 19px;
  font-weight: 800;
  margin-top: 4px;
  line-height: 1.2;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.text-purple { color: var(--purple); }

/* Thẻ mục tiêu kiếm mỗi ngày & thanh tiến độ */
.daily-target-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius);
  padding: 14px 15px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 9px;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Mục tiêu đề từng phần */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 15px;
  font-weight: 800;
  margin: 0;
}

/* Nút bấm chuẩn chạm ngón cái >= 44px */
.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 10px;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

/* Danh sách Nút Mẫu Nhập Nhanh 3 Giây */
.quick-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.quick-chips::-webkit-scrollbar {
  display: none;
}

.quick-chip {
  flex-shrink: 0;
  min-height: 42px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.quick-chip .chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* Hộp Chuông Cảnh Báo Đến Hẹn */
.alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 13px;
  border: 1px solid var(--border);
}

.alert-item.danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.alert-item.warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 40%, transparent);
}

/* Danh sách Giao dịch & Sổ Nợ */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.record-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 13px 14px;
  transition: border-color 0.15s ease, opacity 0.15s ease;
}

.record-card.excluded {
  opacity: 0.46;
  border-style: dashed;
}

.record-card.paid-debt {
  opacity: 0.68;
  background: var(--surface-soft);
}

.record-card.paid-debt .record-title {
  text-decoration: line-through;
}

.record-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.record-title {
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.32;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-income { background: var(--success-soft); color: var(--success); }
.badge-expense { background: var(--danger-soft); color: var(--danger); }
.badge-debt { background: var(--warning-soft); color: var(--warning); }
.badge-sinking { background: var(--primary-soft); color: var(--primary); }
.badge-borrow { background: var(--purple-soft); color: var(--purple); }

/* Hộp Truy xuất nguồn gốc vốn (Bóc tách bên trong khoản Thu) */
.trace-box {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  font-size: 12.5px;
}

.trace-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.record-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Biểu đồ Cột & Tròn */
.bar-chart-wrap {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  height: 210px;
  align-items: end;
  padding: 14px 6px 4px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.bar-val {
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  flex: 1;
  width: 100%;
  max-width: 52px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  border-radius: 10px 10px 0 0;
  transition: height 0.25s ease;
}

.bar-label {
  font-size: 12px;
  font-weight: 700;
  margin-top: 7px;
  text-align: center;
}

.bar-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.donut-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.donut-svg-box {
  position: relative;
  width: 152px;
  height: 152px;
  flex-shrink: 0;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.donut-center-lbl {
  font-size: 11px;
  color: var(--text-muted);
}

.donut-center-val {
  font-size: 15px;
  font-weight: 800;
}

.donut-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.donut-legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-soft);
}

.donut-legend-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.donut-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.donut-legend-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.donut-amt { font-weight: 700; }
.donut-pct {
  font-size: 11.5px;
  color: var(--text-muted);
  min-width: 34px;
  text-align: right;
}

.chart-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* Thanh Điều Hướng Đáy chuẩn iPhone 15 Pro Max */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  padding-top: 6px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
  padding-left: 8px;
  padding-right: 8px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 2px;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
}

.nav-item.active {
  color: var(--primary);
  font-weight: 800;
}

.nav-fab {
  width: 50px;
  height: 50px;
  margin: -14px auto 0;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, #2563eb, #059669);
  color: #ffffff;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.38);
  cursor: pointer;
}

/* Hộp thoại trượt từ đáy trên iPhone / Giữa màn hình trên Mac */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.open {
  display: flex;
}

.modal-sheet {
  width: 100%;
  max-width: 580px;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 20px);
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.modal-title {
  font-size: 17px;
  font-weight: 800;
  margin: 0;
}

/* Biểu mẫu nhập liệu lớn, rõ chữ, không bị Safari tự zoom trên iPhone (font >= 16px) */
.form-group {
  margin-bottom: 13px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 5px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* >= 16px để iPhone 15 Pro Max không bị giật phóng to khi chạm ô nhập */
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
  background: var(--surface);
}

.money-quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.money-pill {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.toggle-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  cursor: pointer;
}

/* Nút thông báo nhỏ góc trên (Toast) */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 120;
  background: #0f172a;
  color: #ffffff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  max-width: 92vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Màn hình khóa mã PIN */
.pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.pin-overlay.open {
  display: flex;
}

/* Giao diện Máy Mac / Màn hình lớn (>= 960px) */
@media (min-width: 960px) {
  .app-shell {
    flex-direction: row;
  }

  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    width: 270px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100dvh;
  }

  .brand-mobile {
    display: none;
  }

  .bottom-nav {
    display: none;
  }

  .main-area {
    padding: 22px 30px 48px;
  }

  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
  }

  .two-col-desktop {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 18px;
    align-items: start;
  }

  .donut-layout {
    flex-direction: row;
  }

  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }

  .modal-sheet {
    border-radius: 20px;
    padding: 22px;
  }
}

.side-nav-btn {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 4px;
}

.side-nav-btn:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.side-nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
}
