/*
 * GIAO DIỆN CHUẨN NATIVE APP ĐIỆN THOẠI (iPhone 15 Pro Max First + Mac Desktop)
 * Triết lý: Cực ít chữ - Số to rõ - Chạm 1 ngón cái - Gọn như App Ngân hàng iOS.
 */

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

:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e5e9f0;
  --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.12);
  --warning: #d97706;
  --warning-soft: rgba(217, 119, 6, 0.13);
  --danger: #e11d48;
  --danger-soft: rgba(225, 29, 72, 0.11);
  --purple: #7c3aed;
  --purple-soft: rgba(124, 58, 237, 0.11);
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  --radius: 18px;
}

html.dark {
  --bg: #090d16;
  --surface: #131b2e;
  --surface-soft: #1a243d;
  --border: #23304f;
  --border-strong: #33456e;
  --text: #f8fafc;
  --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: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.15);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.16);
  --shadow: 0 4px 16px 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, sans-serif;
  font-size: 15px;
  line-height: 1.38;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

button, .nav-item, .quick-chip, .kpi-card, .row-item, .seg-btn {
  user-select: none;
  -webkit-user-select: none;
}

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

/* Khung App */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.desktop-sidebar {
  display: none;
}

.main-area {
  flex: 1;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding-top: calc(env(safe-area-inset-top, 0px) + 6px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 88px);
  padding-left: 12px;
  padding-right: 12px;
}

/* Thanh trên cùng siêu gọn cho Điện thoại */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 6px 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.seg-control {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  flex: 1;
}

.seg-btn {
  flex: 1;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.14s ease;
}

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

.date-mini {
  height: 40px;
  width: 40px;
  position: relative;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.date-mini input[type="date"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.icon-circle {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}

.icon-circle:active, .btn:active, .quick-chip:active, .kpi-card:active {
  transform: scale(0.96);
}

/* Thanh báo hiệu đang bỏ tích giả lập */
.sim-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  margin-bottom: 10px;
  font-size: 12.5px;
  font-weight: 700;
}

.sim-bar button {
  padding: 5px 10px;
  border-radius: 8px;
  border: none;
  background: var(--warning);
  color: #fff;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Thẻ Quỹ Tiền Tổng (Phong cách Apple Wallet / App Ngân hàng) */
.wallet-card {
  background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 58%, #047857 100%);
  color: #fff;
  border-radius: 22px;
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2);
}

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

.wallet-lbl {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.76);
}

.wallet-bal {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.12;
  margin-top: 2px;
}

.pill-glass {
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #fff;
  height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.wallet-subgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.wallet-subbox {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 13px;
  padding: 8px 11px;
}

.wallet-subbox span {
  display: block;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
}

.wallet-subbox b {
  display: block;
  font-size: 15px;
  font-weight: 800;
  margin-top: 1px;
}

.wallet-target-line {
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.wallet-target-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  font-weight: 600;
}

.mini-progress {
  height: 6px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

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

/* Lưới 4 Ô Trụ Cột 2x2 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

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

.kpi-card {
  padding: 11px 12px;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.kpi-lbl {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.kpi-num {
  font-size: 18px;
  font-weight: 800;
  margin-top: 2px;
  line-height: 1.2;
}

.kpi-foot {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.c-inc { color: var(--success); }
.c-exp { color: var(--danger); }
.c-warn { color: var(--warning); }
.c-pri { color: var(--primary); }
.c-pur { color: var(--purple); }

/* Thanh Chạm Nhanh 1 Ngón Cái */
.chips-scroll {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 8px;
  scrollbar-width: none;
}

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

.quick-chip {
  flex-shrink: 0;
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

/* Cảnh báo đến hạn cực gọn */
.alert-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 14px;
  margin-bottom: 8px;
  font-size: 13px;
}

.alert-strip.danger {
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.alert-strip.warning {
  background: var(--warning-soft);
  border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
}

/* Danh sách dòng gọn kiểu App Ngân hàng iOS (Chạm vào mới mở chi tiết) */
.list-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.row-item {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease;
}

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

.row-item:active {
  background: var(--surface-soft);
}

.row-item.excluded {
  opacity: 0.42;
}

.row-item.paid .row-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.row-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.row-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  flex-shrink: 0;
}

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

.row-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-right {
  text-align: right;
  flex-shrink: 0;
}

.row-amt {
  font-weight: 800;
  font-size: 15px;
}

.row-tag {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
}

/* Chi tiết mở ra khi chạm vào dòng */
.row-drawer {
  display: none;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--border);
  font-size: 12.5px;
}

.row-item.expanded .row-drawer {
  display: block;
}

.drawer-line {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  color: var(--text-muted);
}

.drawer-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* Nút bấm chuẩn cảm ứng */
.btn {
  min-height: 44px;
  padding: 0 15px;
  border-radius: 13px;
  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: 6px;
}

.btn-sm {
  min-height: 34px;
  padding: 0 11px;
  font-size: 12px;
  border-radius: 9px;
}

.btn-pri { background: var(--primary); color: #fff; }
.btn-inc { background: var(--success); color: #fff; }
.btn-exp { background: var(--danger-soft); color: var(--danger); }
.btn-out { background: var(--surface-soft); color: var(--text); border-color: var(--border-strong); }

.sec-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 2px 8px;
}

.sec-title {
  font-size: 14px;
  font-weight: 800;
  margin: 0;
}

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

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

.bar-val {
  font-size: 11.5px;
  font-weight: 800;
  margin-bottom: 5px;
}

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

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

.bar-label {
  font-size: 11.5px;
  font-weight: 700;
  margin-top: 6px;
}

.bar-sub { display: none; }

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

.donut-svg-box {
  position: relative;
  width: 144px;
  height: 144px;
}

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

.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: 6px; }
.donut-legend-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: 12.5px;
}
.donut-legend-left { display: flex; align-items: center; gap: 7px; }
.donut-dot { width: 9px; height: 9px; border-radius: 50%; }
.donut-name { font-weight: 600; }
.donut-legend-right { display: flex; gap: 8px; }
.donut-amt { font-weight: 700; }
.donut-pct { color: var(--text-muted); min-width: 32px; text-align: right; }
.chart-empty { padding: 26px 12px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Thanh Đáy iOS Tab Bar 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(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 4px 6px calc(env(safe-area-inset-bottom, 0px) + 4px);
  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: 10.5px;
  font-weight: 700;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  padding: 0;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke-width: 2.1;
}

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

.nav-fab {
  width: 52px;
  height: 52px;
  margin: -16px auto 0;
  border-radius: 50%;
  border: 3px solid var(--bg);
  background: linear-gradient(135deg, #2563eb, #059669);
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.36);
  cursor: pointer;
}

/* Bottom Sheet iOS mượt mà */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(9, 13, 22, 0.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

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

.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 10px 15px calc(env(safe-area-inset-bottom, 0px) + 18px);
  overflow-y: auto;
  animation: slideUp 0.18s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0.7; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--border-strong);
  margin: 0 auto 10px;
}

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

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

/* Ô nhập tiền To Rõ kiểu App Ngân Hàng */
.big-money-input {
  width: 100%;
  height: 54px;
  padding: 8px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 24px;
  font-weight: 800;
  text-align: right;
}

.big-money-input:focus, .form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.form-group { margin-bottom: 10px; }
.form-label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }

.form-input, .form-select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}

.money-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-top: 6px;
  scrollbar-width: none;
}

.money-pill {
  flex-shrink: 0;
  height: 30px;
  padding: 0 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;
}

.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cat-pill {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-soft);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
}

.cat-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  margin-bottom: 9px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  z-index: 120;
  background: #0f172a;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}

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

.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; }

/* Mở rộng tự động trên Máy Mac (>= 960px) */
@media (min-width: 960px) {
  .app-shell { flex-direction: row; }
  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100dvh;
  }
  .bottom-nav { display: none; }
  .main-area { padding: 18px 28px 40px; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .desktop-cols { display: grid; grid-template-columns: 0.9fr 1.1fr; gap: 16px; align-items: start; }
  .donut-layout { flex-direction: row; }
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal-sheet { border-radius: 22px; padding: 18px 20px; }
  .sheet-handle { display: none; }
}

.side-btn {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 11px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  margin-bottom: 4px;
}

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