:root {
  --primary: #0f766e;
  --primary-dark: #0d5c56;
  --primary-light: #14b8a6;
  --income: #059669;
  --expense: #dc2626;
  --warning: #d97706;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 12px;
  --header-h: 56px;
  --bottom-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font-family: inherit; font-size: 16px; }
a { text-decoration: none; color: inherit; }

/* Header */
.header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h);
  background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; z-index: 100; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header h1 { font-size: 1.15rem; font-weight: 600; }
.header-right { display: flex; gap: 8px; }
.btn-icon { background: transparent; border: none; color: white; font-size: 1.25rem; padding: 8px; cursor: pointer; border-radius: 8px; }
.btn-icon:hover { background: rgba(255,255,255,0.15); }
.btn-quick { border: none; border-radius: 20px; padding: 6px 12px; font-size: 0.85rem; font-weight: 600; cursor: pointer; color: white; display: flex; align-items: center; gap: 4px; }
.btn-quick.income { background: var(--income); }
.btn-quick.expense { background: var(--expense); }

/* Sidebar */
.sidebar {
  position: fixed; top: 0; left: -280px; width: 280px; height: 100%;
  background: var(--card); z-index: 200; transition: left 0.25s ease;
  display: flex; flex-direction: column; box-shadow: 4px 0 20px rgba(0,0,0,0.1);
}
.sidebar.open { left: 0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.sidebar-header .logo { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.sidebar-header .btn-icon { color: var(--text); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; color: var(--text); font-weight: 500; transition: background 0.15s; }
.nav-item i { width: 22px; text-align: center; color: var(--text-muted); }
.nav-item:hover, .nav-item.active { background: #f0fdfa; color: var(--primary); }
.nav-item.active i { color: var(--primary); }
.sidebar-footer { padding: 12px 20px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.8rem; }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 150; opacity: 0; pointer-events: none; transition: opacity 0.25s; }
.sidebar-overlay.show { opacity: 1; pointer-events: auto; }

/* Main */
.main-content {
  margin-top: var(--header-h);
  margin-bottom: var(--bottom-h);
  padding: 16px;
  min-height: calc(100vh - var(--header-h) - var(--bottom-h));
}

/* Bottom Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottom-h);
  background: var(--card); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center; z-index: 100;
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 0.7rem; color: var(--text-muted); padding: 6px 8px; border-radius: 8px;
}
.bottom-nav-item i { font-size: 1.2rem; }
.bottom-nav-item.active { color: var(--primary); font-weight: 600; }

/* Cards */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 12px;
}
.card-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 12px; color: var(--text); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); text-align: center;
}
.stat-card .label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .value { font-size: 1.25rem; font-weight: 700; }
.stat-card.income .value { color: var(--income); }
.stat-card.expense .value { color: var(--expense); }
.stat-card.balance .value { color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: none; border-radius: 8px; font-weight: 600;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--income); color: white; }
.btn-danger { background: var(--expense); color: white; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 4px; color: var(--text-muted); }
.form-control {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; background: #fff; transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Transaction list */
.tx-list { list-style: none; }
.tx-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-icon {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: white; flex-shrink: 0;
}
.tx-icon.income { background: var(--income); }
.tx-icon.expense { background: var(--expense); }
.tx-info { flex: 1; min-width: 0; }
.tx-info .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-info .meta { font-size: 0.8rem; color: var(--text-muted); }
.tx-amount { font-weight: 700; white-space: nowrap; }
.tx-amount.income { color: var(--income); }
.tx-amount.expense { color: var(--expense); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 300;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); width: 100%; max-width: 480px; max-height: 90vh;
  border-radius: 16px 16px 0 0; overflow: hidden; display: flex; flex-direction: column;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 10px; }

/* Toast */
.toast {
  position: fixed; bottom: calc(var(--bottom-h) + 16px); left: 50%; transform: translateX(-50%);
  background: #1e293b; color: white; padding: 10px 20px; border-radius: 8px;
  font-size: 0.9rem; z-index: 400; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* Empty state */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state i { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.4; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-muted); font-size: 0.8rem; }
.text-right { text-align: right; }
.text-income { color: var(--income); font-weight: 600; }
.text-expense { color: var(--expense); font-weight: 600; }

/* Filter bar */
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar select, .filter-bar input { flex: 1; min-width: 120px; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; background: #e2e8f0; border-radius: 8px; padding: 3px; }
.tab { flex: 1; text-align: center; padding: 8px; border-radius: 6px; font-weight: 500; font-size: 0.9rem; cursor: pointer; color: var(--text-muted); }
.tab.active { background: white; color: var(--primary); box-shadow: var(--shadow); }

/* Badge */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-success { background: #d1fae5; color: var(--income); }
.badge-danger { background: #fee2e2; color: var(--expense); }
.badge-warning { background: #fef3c7; color: var(--warning); }

/* Responsive */
@media (min-width: 768px) {
  .sidebar { left: 0; }
  .main-content { margin-left: 280px; }
  .bottom-nav { display: none; }
  .main-content { margin-bottom: 0; }
  .header-left .btn-icon#btn-menu { display: none; }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; max-height: 85vh; }
}

/* Utility */
.hidden { display: none !important; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text-muted); }
.fw-600 { font-weight: 600; }

/* Charts – kích thước gọn, 2 cột trên màn rộng */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 720px) {
  .chart-grid {
    grid-template-columns: 1fr 1fr;
  }
}
.chart-card .card-title {
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.chart-box {
  position: relative;
  width: 100%;
  height: 160px;
  max-height: 160px;
}
.chart-box canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Hỗ trợ trực tiếp */
#support-fab {
  position: fixed;
  right: 16px;
  bottom: 72px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: none;
  border-radius: 999px;
  background: var(--primary, #0f766e);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(15, 118, 110, 0.35);
  cursor: pointer;
}
#support-fab span { font-size: 0.9rem; }
@media (max-width: 480px) {
  #support-fab span { display: none; }
  #support-fab { padding: 14px; border-radius: 50%; }
}
#support-panel {
  position: fixed;
  right: 16px;
  bottom: 130px;
  width: min(380px, calc(100vw - 24px));
  height: min(520px, calc(100vh - 160px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
  z-index: 910;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border, #e2e8f0);
}
#support-panel.hidden { display: none !important; }
.support-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 14px 10px;
  background: linear-gradient(135deg, #0f766e, #0d9488);
  color: #fff;
}
.support-title { font-weight: 700; font-size: 1rem; }
.support-sub { font-size: 0.75rem; opacity: 0.9; margin-top: 4px; max-width: 280px; }
.support-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.support-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border, #e2e8f0);
  background: #f8fafc;
}
.support-quick button {
  border: 1px solid var(--border, #e2e8f0);
  background: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  color: #334155;
}
.support-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #f1f5f9;
}
.support-msg {
  max-width: 92%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.support-msg.user {
  margin-left: auto;
  background: #0f766e;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.support-msg.bot {
  background: #fff;
  color: #0f172a;
  border: 1px solid var(--border, #e2e8f0);
  border-bottom-left-radius: 4px;
}
.support-msg.bot.error { border-color: #fecaca; background: #fef2f2; }
.support-msg.loading { color: #64748b; font-style: italic; }
.support-input-row {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border, #e2e8f0);
  background: #fff;
}
.support-input-row input {
  flex: 1;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}
.support-input-row button { flex-shrink: 0; }
.support-foot { padding: 0 12px 10px; background: #fff; font-size: 0.7rem !important; }

.ca-badge { display:inline-block; background:#1e3a5f; color:#fff; font-size:0.7rem; padding:2px 8px; border-radius:999px; margin-left:6px; }
.stat-card.tax { border-left:4px solid #b45309; }

/* Charts – readable size on mobile & desktop */
.chart-card { overflow: hidden; }
.chart-card canvas {
  width: 100% !important;
  max-height: 260px;
}
@media (min-width: 768px) {
  .chart-card canvas { max-height: 300px; }
}
.badge-success { background: #d1fae5; color: #065f46; }
