/* ============================================
   SAS Thu Chi - Modern Dark Theme
   ============================================ */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-card: #1e2130;
  --bg-hover: #252838;
  --bg-glass: rgba(30, 33, 48, 0.85);
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --text-primary: #e8eaed;
  --text-secondary: #9aa0b0;
  --text-muted: #5f6577;
  --accent: #6c5ce7;
  --accent-hover: #7c6ef7;
  --accent-glow: rgba(108,92,231,0.25);
  --green: #00d68f;
  --green-bg: rgba(0,214,143,0.12);
  --red: #ff6b6b;
  --red-bg: rgba(255,107,107,0.12);
  --blue: #4da6ff;
  --blue-bg: rgba(77,166,255,0.12);
  --yellow: #ffc107;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --sidebar-width: 260px;
  --transition: 0.25s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Roboto', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}
.mono-num { font-family: 'Roboto Mono', monospace; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }

/* ============================================
   Layout
   ============================================ */
.app { display: flex; height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition);
  z-index: 100;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.brand-icon .material-icons-round { color: #fff; font-size: 24px; }
.brand-text h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.5px; }
.brand-text span { font-size: 11px; color: var(--text-secondary); font-weight: 500; }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: all var(--transition);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(108,92,231,0.2), rgba(168,85,247,0.1));
  color: var(--accent-hover);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item .material-icons-round { font-size: 20px; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.user-info {
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg-hover); display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.user-avatar .material-icons-round { font-size: 18px; color: var(--text-secondary); }
.user-details { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 11px; color: var(--text-secondary); text-transform: capitalize; }
.btn-logout {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: all var(--transition);
}
.btn-logout:hover { background: rgba(255,107,107,0.15); color: var(--red); }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.main-header {
  padding: 16px 28px;
  display: flex; align-items: center; gap: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.menu-toggle {
  display: none; background: none; border: none; color: var(--text-primary);
  cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
}
.menu-toggle:hover { background: var(--bg-hover); }
.header-title { flex: 1; }
.header-title h2 { font-size: 18px; font-weight: 700; }
.header-title p { font-size: 12px; color: var(--text-secondary); }
.header-actions { display: flex; gap: 8px; }

.content-area { flex: 1; overflow-y: auto; padding: 24px 28px; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; border: none; transition: all var(--transition);
  white-space: nowrap;
}
.btn .material-icons-round { font-size: 18px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-outline { background: transparent; border: 1px solid var(--border-hover); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-hover); border-color: var(--text-muted); }
.btn-ghost { background: none; border: none; color: var(--text-secondary); padding: 8px; }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { background: none; border: none; color: var(--text-secondary); padding: 4px; cursor: pointer; border-radius: 6px; }
.btn-icon:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(255,107,107,0.2); }
.btn-danger:hover { background: rgba(255,107,107,0.2); }
.btn-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(0,214,143,0.2); }
.btn-success:hover { background: rgba(0,214,143,0.2); }

/* ============================================
   Dashboard
   ============================================ */
.dashboard-filters { margin-bottom: 24px; }
.filter-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 18px; border-radius: 20px; border: 1px solid var(--border-hover);
  background: transparent; color: var(--text-secondary);
  font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit;
  transition: all var(--transition);
}
.chip:hover { border-color: var(--accent); color: var(--text-primary); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.custom-date-range {
  display: flex; align-items: center; gap: 12px; margin-top: 12px;
  padding: 12px; background: var(--bg-card); border-radius: var(--radius-sm);
}
.custom-date-range span { color: var(--text-muted); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-bottom: 24px; }

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
  display: flex; align-items: center; gap: 18px;
  transition: all var(--transition);
}
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow); }

.stat-icon {
  width: 52px; height: 52px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}
.stat-icon .material-icons-round { font-size: 26px; }
.stat-income .stat-icon { background: var(--green-bg); color: var(--green); }
.stat-expense .stat-icon { background: var(--red-bg); color: var(--red); }
.stat-balance .stat-icon { background: var(--blue-bg); color: var(--blue); }

.stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; display: block; }
.stat-value { font-size: 24px; font-weight: 800; display: block; margin: 4px 0; letter-spacing: -0.5px; }
.stat-income .stat-value { color: var(--green); }
.stat-expense .stat-value { color: var(--red); }
.stat-balance .stat-value { color: var(--blue); }
.stat-sub { font-size: 11px; color: var(--text-muted); }

.charts-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; }

.chart-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
}
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 20px; }
.chart-container { min-height: 280px; position: relative; }

/* ============================================
   Tables
   ============================================ */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.toolbar-left h3 { font-size: 16px; font-weight: 700; }
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-group { display: flex; gap: 8px; align-items: center; }

.table-container {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 14px 16px; text-align: left; font-size: 11px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); background: rgba(0,0,0,0.15);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 16px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

.empty-state {
  text-align: center !important; padding: 48px 16px !important;
  color: var(--text-muted) !important; font-style: italic;
}

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 600;
}
.badge-in, .badge-thu { background: var(--green-bg); color: var(--green); }
.badge-out, .badge-chi { background: var(--red-bg); color: var(--red); }
.badge-classified { background: var(--blue-bg); color: var(--blue); }
.badge-pending { background: rgba(255,193,7,0.12); color: var(--yellow); }
.badge-auto { background: rgba(108,92,231,0.12); color: var(--accent-hover); }
.badge-manual { background: rgba(255,193,7,0.12); color: var(--yellow); }

.amount-in { color: var(--green); font-weight: 700; }
.amount-out { color: var(--red); font-weight: 700; }

/* ============================================
   Forms
   ============================================ */
.input-date, .input-select, .input-text {
  padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-hover); background: var(--bg-hover);
  color: var(--text-primary); font-size: 13px; font-family: inherit;
  transition: border-color var(--transition);
}
.input-date:focus, .input-select:focus, .input-text:focus {
  outline: none; border-color: var(--accent);
}
.input-select { cursor: pointer; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-group .input-text, .form-group .input-select { width: 100%; }

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  opacity: 1; transition: opacity 0.2s;
}
.modal-overlay.hidden { opacity: 0; pointer-events: none; }

.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 90%; max-width: 500px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.4);
  transform: scale(1); transition: transform 0.2s;
}
.modal-overlay.hidden .modal { transform: scale(0.95); }

.modal-header {
  padding: 20px 24px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ============================================
   Toast
   ============================================ */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  padding: 14px 20px; border-radius: var(--radius-sm);
  background: var(--bg-glass); backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  font-size: 13px; font-weight: 500; min-width: 280px;
  display: flex; align-items: center; gap: 10px;
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.toast-success { border-left: 3px solid var(--green); }
.toast-success .material-icons-round { color: var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-error .material-icons-round { color: var(--red); }
.toast-info { border-left: 3px solid var(--blue); }
.toast-info .material-icons-round { color: var(--blue); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(40px); } }

/* ============================================
   Settings
   ============================================ */
.settings-section { margin-bottom: 32px; }
.section-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.section-header h3 { font-size: 16px; font-weight: 700; }
.section-header p { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.section-actions { display: flex; gap: 8px; }

.webhook-info { display: flex; gap: 16px; flex-wrap: wrap; }
.info-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; gap: 16px; flex: 1; min-width: 280px;
}
.info-card .material-icons-round { color: var(--accent); font-size: 28px; }
.info-card label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; display: block; margin-bottom: 4px; }
.copy-field { display: flex; align-items: center; gap: 8px; }
.copy-field code { font-size: 13px; color: var(--blue); word-break: break-all; }

/* ============================================
   Pagination
   ============================================ */
.pagination {
  display: flex; justify-content: center; align-items: center; gap: 8px;
  margin-top: 16px;
}
.pagination button {
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border-hover);
  background: transparent; color: var(--text-secondary); font-size: 12px;
  font-weight: 600; cursor: pointer; font-family: inherit;
  transition: all var(--transition);
}
.pagination button:hover { background: var(--bg-hover); }
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================
   Chart: Custom Bar/Line (SVG-based)
   ============================================ */
.bar-group { transition: opacity 0.2s; }
.bar-group:hover { opacity: 0.8; }

.category-list { display: flex; flex-direction: column; gap: 12px; }
.category-item {
  display: flex; align-items: center; gap: 12px;
}
.cat-bar-wrap { flex: 1; background: rgba(255,255,255,0.04); border-radius: 6px; height: 28px; overflow: hidden; position: relative; }
.cat-bar { height: 100%; border-radius: 6px; transition: width 0.6s ease; display: flex; align-items: center; padding: 0 10px; }
.cat-bar span { font-size: 11px; font-weight: 600; white-space: nowrap; }
.cat-label { font-size: 13px; font-weight: 500; min-width: 110px; }
.cat-amount { font-size: 13px; font-weight: 700; min-width: 100px; text-align: right; }
.cat-thu .cat-bar { background: linear-gradient(90deg, rgba(0,214,143,0.3), rgba(0,214,143,0.6)); }
.cat-thu .cat-amount { color: var(--green); }
.cat-chi .cat-bar { background: linear-gradient(90deg, rgba(255,107,107,0.3), rgba(255,107,107,0.6)); }
.cat-chi .cat-amount { color: var(--red); }

/* Trend chart */
.trend-empty, .category-empty {
  display: flex; align-items: center; justify-content: center;
  height: 200px; color: var(--text-muted); font-size: 13px; font-style: italic;
}

/* ============================================
   Responsive
   ============================================ */
.hidden { display: none !important; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,0.4); }
  .menu-toggle { display: flex; }
  .charts-grid { grid-template-columns: 1fr; }
  .content-area { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .table-toolbar { flex-direction: column; align-items: flex-start; }
  .toolbar-right { width: 100%; }
  .filter-group { width: 100%; flex-wrap: wrap; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 10px 8px; }
}
