:root {
  --bg: #020617;
  --bg-soft: #020617;
  --card: #020617;
  --border: #1f2937;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --primary: #38bdf8;
  --danger: #f97373;
  --accent: #22c55e;
  --radius: 14px;
}

body[data-theme="light"] {
  --bg: #f3f4f6;
  --bg-soft: #e5e7eb;
  --card: #ffffff;
  --border: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --primary: #0ea5e9;
  --danger: #ef4444;
  --accent: #16a34a;
}

/* Reset và nền */
* { box-sizing: border-box; }

html, body {
  max-width: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  padding: 12px;
  transition: background 0.3s ease, color 0.3s ease;
  font-size: 14px;
  /* Dark Mode Gradient */
  background: radial-gradient(circle at top, #1e293b 0, #020617 55%, #020617 100%); 
}

body[data-theme="light"] {
  background: var(--bg);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Header & Links */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
  flex-wrap: wrap;
}
.top-left {
  display:flex;
  align-items:center;
  gap:8px;
}
.top-left img {
  width:32px;
  height:32px;
  border-radius:8px;
  object-fit:cover;
}
h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
}
.top-bar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
a.link, button.icon-btn {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15,23,42,0.7);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  white-space: nowrap;
}
body[data-theme="light"] a.link,
body[data-theme="light"] button.icon-btn {
  background: #ffffff;
}
a.link:hover, button.icon-btn:hover {
  border-color: var(--primary);
}
button.icon-btn {
  color: var(--text);
}

/* Filter Bar (dùng chung cho input) */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 10px;
  border: 1px solid var(--border);
}
.filter-group {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-bar label {
  font-size: 13px;
  color: var(--text-muted);
}
/* Input styles (Admin Form và Filter Bar) */
select, input[type="date"], input[type="text"], input[type="number"], textarea {
  padding: 6px 8px;
  border-radius: 8px; 
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
}
.range-info {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

/* Dashboard Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 10px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.card-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}
/* Card Màu sắc */
.card-positive .card-title,
.card-positive .card-value {
  color: var(--accent); /* Xanh lá */
}
.card-negative .card-title,
.card-negative .card-value {
  color: var(--danger); /* Đỏ */
}
/* Card Giá trị mặc định */
.card-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text); /* Đảm bảo giá trị mặc định là màu text */
}
.card-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.charts-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.chart-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
}
.chart-wrapper {
  flex: 1;
  min-height: 200px;
  width: 100%;
}
#chart12Month {
  width: 100%;
  min-height: 260px;
}

/* Admin Layout & Form */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch; /* Đảm bảo các cột kéo dài bằng nhau */
}
/* Form inputs specifics */
.layout input[type="text"],
.layout input[type="number"],
.layout select,
.layout textarea {
  width: 100%; 
  padding: 7px 9px;
  border-radius: 8px; 
  margin-bottom: 8px;
}
label {
  font-size: 12px;
  color: var(--text-muted);
  display:block;
  margin-bottom:3px;
}
.form-row {
  display:flex;
  gap:8px;
}
.form-row > div {
  flex:1;
  min-width:0;
}
.form-actions {
  display:flex;
  justify-content:flex-end;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
button.primary {
  padding: 6px 12px;
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: #0b1120;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
button.secondary, a.secondary {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
button.secondary:hover, a.secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.status {
  font-size:11px;
  color:var(--text-muted);
  margin-top:4px;
  min-height:14px;
}

/* 🚀 FIX SCROLL & LAYOUT STICKY */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 10px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  /* Đảm bảo Form Card cũng có thể cuộn nếu nó quá dài */
  max-height: calc(100vh - 120px); 
  overflow-y: auto; 
}
.table-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px;
  border: 1px solid var(--border);
  /* Giới hạn chiều cao cho cột bên phải */
  max-height: calc(100vh - 120px); 
  display: flex;
  flex-direction: column;
  overflow: hidden; 
}
/* Table Header, Footer - phải cố định */
.table-header, .table-footer {
    flex-shrink: 0; 
}
/* Bảng cuộn */
.table-scroll {
  flex-grow: 1; 
  overflow-y: auto; /* Bật cuộn */
  overscroll-behavior: contain;
  padding-right: 2px;
}
/* END FIX SCROLL & LAYOUT STICKY */


/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th, td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
thead {
  background: var(--bg-soft);
  flex-shrink: 0;
}
th {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
tbody tr:nth-child(even) {
  background: rgba(148, 163, 184, 0.05);
}
.text-right { text-align: right; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge--thu { color: var(--accent); border-color: var(--accent); }
.badge--chi { color: var(--danger); border-color: var(--danger); }
.badge--vay { color: var(--primary); border-color: var(--primary); }

/* Nút Sửa/Xóa (TINH CHỈNH) */
.actions-cell a {
  font-size: 11px;
  padding: 3px 6px; 
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  margin-right: 4px;
  margin-bottom: 2px;
  text-decoration: none;
  display: inline-block;
  transition: all 0.2s ease;
}
.actions-cell a.edit-btn {
  color: var(--primary); 
  border-color: var(--primary);
}
.actions-cell a.edit-btn:hover {
  background: var(--primary);
  color: var(--bg);
}
.actions-cell a.delete-btn {
  color: var(--danger);
  border-color: var(--danger);
}
.actions-cell a.delete-btn:hover {
  background: var(--danger);
  color: var(--text);
}

/* Footer & Load More Styling */
.table-footer {
    display: flex;
    justify-content: flex-end; 
    align-items: center;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
    gap: 12px; 
    flex-wrap: wrap;
    padding: 4px 0; 
}
.btn-secondary {
    background: transparent;
    color: var(--primary); 
    border: 1px solid var(--primary); 
    padding: 6px 12px;
    border-radius: 999px;
    cursor:pointer;
    font-size: 12px; 
    font-weight: 500;
    transition: all 0.2s ease;
}
.btn-secondary:hover {
    color: var(--bg); 
    border-color: var(--primary);
    background: var(--primary); 
}
.copyright {
    text-align: center; 
    margin-top: 16px;
    font-size: 11px;
    color: var(--text-muted);
}
.copyright a { color: var(--primary); text-decoration: none; }


/* Auth overlay (BỐ CỤC MỚI) */
.auth-overlay {
  position:fixed;
  inset:0;
  background:rgba(15,23,42,0.92);
  display:none;
  justify-content:center;
  align-items:center;
  z-index:9999;
}
.auth-box {
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 25px 20px;
  width:100%;
  max-width:320px;
  color: var(--text);
  text-align: center;
}
.auth-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 15px; 
}
.auth-header img {
  width: 48px; 
  height: 48px;
  border-radius: 10px;
  margin-bottom: 8px;
}
.auth-box h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.auth-box p {
  margin: 8px 0 15px 0; 
  font-size: 13px;
  color: var(--text-muted);
}
.auth-box input {
  width:100%;
  padding: 10px 12px; 
  border-radius: 8px; 
  border:1px solid var(--border);
  background:var(--bg-soft);
  color:var(--text);
  font-size:14px;
  margin-bottom:12px; 
}
.auth-box input:focus {
  outline:none;
  border-color:var(--primary);
}
.auth-error {
  font-size:11px;
  color:var(--danger);
  min-height:14px;
  margin-bottom:8px;
  text-align: left;
}
.auth-actions {
  display:flex;
  justify-content:center;
}
.auth-actions button {
  padding: 8px 24px; 
  border-radius: 8px; 
  border:none;
  background:var(--primary);
  color:var(--bg); 
  font-size:15px;
  font-weight: 600;
  cursor:pointer;
}


/* ======================================= */
/* CSS CHO BIỂU ĐỒ CỘT 12 THÁNG (LABEL) */
/* ======================================= */

/* KHUNG BIỂU ĐỒ CHÍNH */
.bar-chart-container {
    display: flex;
    width: 100%;
    height: 250px; 
    padding: 15px 10px; 
    position: relative; 
}

/* Biểu đồ chính */
.bar-chart-12m {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;   /* đảm bảo 12 cột fit ngang */
    height: 100%; 
    padding: 0 2px;                   /* giảm padding ngang để không tràn */
    border-bottom: 1px solid var(--border); 
    flex-grow: 1;
}
.chart-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 calc(100% / 12);        /* mỗi tháng chiếm 1/12 chiều rộng */
    max-width: calc(100% / 12);
    height: 100%;
    position: relative;
}
.bars {
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    gap: 2px; 
}
.bar {
    width: 45%;
    transition: height 0.3s ease;
    position: relative;
    border-radius: 2px 2px 0 0;
    min-height: 1px; 
    opacity: 0.8;
}
.bar:hover {
    opacity: 1;
}
.bar-income {
    background-color: var(--accent); 
}
.bar-expense {
    background-color: var(--danger); 
}
.chart-label {
    margin-top: 5px;
    font-size: 10px;
    color: var(--text-muted);
}
/* Nhãn số tiền ở trên đỉnh cột (Dành cho PC) */
.bar-label-top {
    display: block !important; 
    position: absolute;
    top: -15px; 
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px; 
    font-weight: 600; 
    color: var(--text); 
    white-space: nowrap;
    text-shadow: 0 0 5px var(--bg-soft); 
}


/* Media Queries */
@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-row { grid-template-columns: 1fr; }
  .chart-card { min-height: 230px; }
  .layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}
@media (max-width: 640px) {
  .card { max-height: none; overflow-y: visible; } 
  .table-card { max-height: none; overflow-y: visible; } 
  
  .bar-chart-container {
    padding: 12px 4px; /* thu padding ngang trên mobile cho rộng thêm */
  }

  body { padding: 8px; font-size: 13px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .top-bar { flex-direction: column; align-items: flex-start; }
  th, td { padding: 5px 4px; }
  table { font-size: 11px; }
  .filter-bar { flex-direction: column; align-items: flex-start; }
  .range-info { margin-left: 0; }
  .filter-group { width: 100%; justify-content: flex-start; }
  .chart-wrapper { min-height: 220px; }
  .top-left img { width:28px; height:28px; }
  .top-bar-right { width: 100%; justify-content: flex-start; }
  
  /* ẨN LABEL TRÊN MOBILE */
  .bar-label-top {
      display: none !important; 
  }

  /* Admin mobile table view */
  table, thead, tbody, th, tr, td { display: block; }
  thead { display: none; }
  tbody tr {
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 8px;
    background: rgba(15,23,42,0.8);
  }
  td {
    white-space: normal;
    padding: 3px 0;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 6px;
  }
  td::before {
    content: attr(data-label);
    font-weight: 500;
    font-size: 11px;
    color: var(--text-muted);
  }
  .actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: flex-start;
  }
  .actions-cell::before {
    content: "Hành động";
  }
}
/* GRIDLINE cho biểu đồ 12 tháng */
.bar-chart-gridline {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed rgba(148,163,184,0.25);
    pointer-events: none;
}

.bar-chart-gridlabel {
    position: absolute;
    left: 0;
    margin-left: 2px;
    transform: translateY(-50%);
    font-size: 9px;
    color: var(--text-muted);
    background: linear-gradient(to right, var(--bg) 0%, transparent 60%);
}

.chart-12m-info {
    padding: 4px 15px 0 15px;
    font-size: 11px;
    color: var(--text-muted);
}

@media (max-width: 640px) {
    .chart-12m-info {
        font-size: 12px;
    }
}
.bar-chart-gridline {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed rgba(148,163,184,0.25);
    pointer-events: none;
}

.bar-chart-gridlabel {
    position: absolute;
    left: 0;
    margin-left: 2px;
    transform: translateY(-50%);
    font-size: 9px;
    color: var(--text-muted);
    background: linear-gradient(to right, var(--bg) 0%, transparent 60%);
}

.chart-12m-info {
    padding: 4px 15px 0 15px;
    font-size: 11px;
    color: var(--text-muted);
}

@media (max-width: 640px) {
    .chart-12m-info {
        font-size: 12px;
    }
}
