/* Target Path: style.css */
/* เขียนโค้ดจาก agent version: .agents-3.6 */
/* 🌌 PRESTIGE DESIGN SYSTEM - WARM BEIGE LIGHT & SLEEK DARK MODE */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  /* HSL Color Palette - Dynamic Warm Cream Base */
  --primary-h: 220;
  --primary-s: 85%;
  --primary-l: 50%;
  
  --primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
  --primary-hover: hsl(var(--primary-h), var(--primary-s), calc(var(--primary-l) - 8%));
  --primary-light: hsl(var(--primary-h), var(--primary-s), 95%);
  
  /* สีวิเคราะห์เงิน */
  --inflow-color: #16a34a;       /* เขียวเข้ม */
  --inflow-light: #e8f5e9;
  --outflow-color: #ea580c;      /* แดงอมส้ม */
  --outflow-light: #fbe9e7;
  --transfer-color: #6366f1;     /* น้ำเงิน/ม่วง */
  --transfer-light: #e0e7ff;
  
  --success: var(--inflow-color);
  --danger: var(--outflow-color);
  --warning: #eab308;
  --warning-light: #fef9c3;
  
  /* Warm Light Mode Colors */
  --bg-app: #fbf9f6;             /* Warm cream background */
  --bg-card: #ffffff;            /* Pure white panel */
  --bg-sidebar: #faf6f0;         /* Soft warm sidebar */
  --text-main: #332f2b;          /* Soft dark brown-grey */
  --text-muted: #8c8277;         /* Warm grey-brown */
  --border-color: #eae5dd;       /* Delicate warm border line */
  
  /* Typography */
  --font-family: 'Inter', 'Sarabun', system-ui, -apple-system, sans-serif;
  
  /* Utilities */
  --border-radius: 12px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 2px rgba(46, 42, 37, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(46, 42, 37, 0.06), 0 2px 6px -1px rgba(46, 42, 37, 0.03);
  --shadow-lg: 0 12px 24px -4px rgba(46, 42, 37, 0.08), 0 4px 12px -2px rgba(46, 42, 37, 0.04);
}

/* 🌙 Dark Mode Tokens */
[data-theme="dark"] {
  --bg-app: #0f1015;
  --bg-card: #181a22;
  --bg-sidebar: #0f1015;
  --text-main: #f5f3ef;
  --text-muted: #9f988e;
  --border-color: #262934;
  --primary-light: hsl(var(--primary-h), var(--primary-s), 14%);
  --inflow-light: rgba(22, 163, 74, 0.1);
  --outflow-light: rgba(234, 88, 12, 0.1);
  --transfer-light: rgba(99, 102, 241, 0.1);
}

/* ⚙️ Modern Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: hidden;
  overscroll-behavior-y: none; /* ป้องกัน Pull-to-refresh บนมือถือ */
  transition: background-color 0.3s, color 0.3s;
}

/* 🌌 Main Layout Shell */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* 🏠 Topbar Style */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.brand-icon {
  font-size: 22px;
  color: var(--primary);
}

.header-brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.last-updated-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background-color: var(--primary-light);
  color: var(--primary);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* 🧭 Sidebar Area */
.app-sidebar {
  width: 280px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  z-index: 40;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  padding-left: 8px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: var(--border-radius);
  font-family: var(--font-family);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  width: 100%;
  transition: var(--transition);
}

.nav-link:hover {
  color: var(--text-main);
  background-color: rgba(46, 42, 37, 0.04);
}

.nav-link.active {
  color: var(--primary);
  background-color: var(--primary-light);
  font-weight: 600;
}

/* Filters Styles */
.filters-section {
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
}

.filter-group {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.preset-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 150px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background-color: var(--bg-card);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input {
  cursor: pointer;
}

.custom-date-inputs {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.custom-date-divider {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.auth-status-section {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding-top: 20px;
}

.auth-status-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* 🖥️ Content Area */
.app-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}

.dashboard-section {
  scroll-margin-top: 24px;
}

/* 🧱 Cards & Layout Modules */
.card-wrapper {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: background-color 0.3s, border-color 0.3s;
}

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
}

.card-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
}

.card-header-flex h3 {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.card-body {
  padding: 24px;
}

/* KPI Cards Layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-size: 18px;
  flex-shrink: 0;
}

.card-balance .stat-icon-wrapper {
  background-color: var(--primary-light);
  color: var(--primary);
}

.card-income .stat-icon-wrapper {
  background-color: var(--inflow-light);
  color: var(--inflow-color);
}

.card-expense .stat-icon-wrapper {
  background-color: var(--outflow-light);
  color: var(--outflow-color);
}

.card-net .stat-icon-wrapper {
  background-color: var(--transfer-light);
  color: var(--transfer-color);
}

.stat-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.stat-info h3 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-info p {
  font-size: 1.45rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-subtext {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.tooltip-icon {
  cursor: help;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Charts Containers */
.chart-container {
  position: relative;
  height: 320px;
  width: 100%;
}

.chart-container-bar {
  position: relative;
  height: 250px;
  width: 100%;
}

/* Flex Grid System (Symmetric Layout) */
.flex-grid {
  display: flex;
  gap: 20px;
}

.flex-col-8 {
  flex: 8;
  min-width: 0;
}

.flex-col-6 {
  flex: 6;
  min-width: 0;
}

.flex-col-4 {
  flex: 4;
  min-width: 0;
}

/* Donut & Ranking Double Panel */
.grid-donut-ranking {
  display: grid;
  grid-template-columns: 5fr 7fr;
  gap: 16px;
  align-items: center;
}

.donut-chart-wrapper {
  position: relative;
  height: 180px;
  width: 100%;
}

.ranking-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ranking-panel h4 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ranking-list {
  list-style: decimal inside;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
}

.ranking-item {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 4px;
}

.ranking-name {
  font-weight: 500;
}

.ranking-val {
  font-weight: 600;
}

/* 📋 Tables Styling */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.simple-table, .data-table, .matrix-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.simple-table th, .simple-table td,
.data-table th, .data-table td,
.matrix-table th, .matrix-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.simple-table th, .data-table th {
  font-weight: 600;
  color: var(--text-muted);
  background-color: var(--bg-sidebar);
}

.data-table tbody tr {
  cursor: pointer;
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background-color: rgba(46, 42, 37, 0.03);
}

/* Transfer Matrix */
.matrix-table {
  font-size: 0.8rem;
}

.matrix-table th {
  background-color: var(--bg-sidebar);
  font-weight: 600;
  color: var(--text-main);
  text-align: center;
}

.matrix-table th:first-child {
  text-align: left;
}

.matrix-table td {
  text-align: center;
  font-weight: 600;
}

.matrix-table td:first-child {
  text-align: left;
  background-color: var(--bg-sidebar);
  font-weight: 600;
}

.matrix-cell-active {
  cursor: pointer;
  background-color: var(--transfer-light);
  color: var(--transfer-color);
  transition: var(--transition);
}

.matrix-cell-active:hover {
  background-color: var(--transfer-color);
  color: #ffffff;
}

.matrix-cell-empty {
  color: var(--text-muted);
  font-weight: normal;
  opacity: 0.4;
}

/* Pagination Styling */
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-color);
}

.pagination-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pagination-buttons {
  display: flex;
  gap: 8px;
}

/* Search bar control */
.search-input-wrapper {
  position: relative;
  width: 240px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-input-wrapper input {
  padding-left: 36px;
  font-size: 0.85rem;
}

/* Form Controls & Date wrappers */
.form-control {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-main);
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.date-input-wrapper {
  position: relative;
  display: flex;
  width: 100%;
}

.calendar-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 10;
}

.date-input-native {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  opacity: 0;
  cursor: pointer;
  z-index: 11;
}

/* 🔘 Buttons styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--border-radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

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

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.btn-secondary {
  background-color: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  background-color: rgba(46, 42, 37, 0.04);
}

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

.btn-danger:hover:not(:disabled) {
  background-color: hsl(20, 85%, 45%);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover:not(:disabled), .btn-outline.active {
  border-color: var(--primary);
  color: var(--primary);
  background-color: var(--primary-light);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.15rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.icon-btn:hover {
  background-color: rgba(46, 42, 37, 0.05);
  color: var(--text-main);
}

.icon-btn-text {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* 📑 Sidebar Drawer สำหรับดูรายละเอียด Read-only (Detail Drawer) */
.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100%;
  background-color: var(--bg-card);
  border-left: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  transform: translateX(100%);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.detail-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.drawer-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 80px); /* คุมความสูงและ scrollbar */
}

.detail-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-group label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.detail-value {
  font-size: 0.95rem;
  font-weight: 500;
  background-color: var(--bg-app);
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-main);
  word-break: break-all;
}

.highlight-amount {
  font-size: 1.25rem;
  font-weight: 700;
}

/* 📑 Modal สำหรับ Data Quality warnings */
.modal-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(46, 42, 37, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal-wrapper.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  max-width: 680px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-wrapper.open .modal-container {
  transform: translateY(0);
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-body {
  padding: 24px;
}

.max-h-300 {
  max-height: 300px;
  overflow-y: auto;
}

/* Alert Bar */
.alert-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-radius: var(--border-radius);
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.alert-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-warning {
  background-color: var(--warning-light);
  color: #854d0e;
  border: 1px solid #fef08a;
}

.btn-outline-warning {
  background-color: transparent;
  border-color: #eab308;
  color: #854d0e;
}

.btn-outline-warning:hover {
  background-color: #eab308;
  color: #ffffff;
}

/* Badges & Classes */
.text-green { color: var(--inflow-color) !important; }
.text-red { color: var(--outflow-color) !important; }
.text-yellow { color: var(--warning) !important; }
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-inflow { background-color: var(--inflow-light); color: var(--inflow-color); }
.badge-outflow { background-color: var(--outflow-light); color: var(--outflow-color); }
.badge-transfer { background-color: var(--transfer-light); color: var(--transfer-color); }

.numeric-text {
  font-variant-numeric: tabular-nums; /* จัดตัวเลขให้เรียงหลักตรงกัน */
}

/* Indicators */
.offline-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: #2e2a25;
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.offline-toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* 📱 Bottom Navigation Bar (Hidden on Desktop) */
.app-bottom-nav {
  display: none;
}

/* CSS Styles helper */
.p-0 { padding: 0 !important; }
.py-3 { padding-top: 12px !important; padding-bottom: 12px !important; }
.py-4 { padding-top: 16px !important; padding-bottom: 16px !important; }
.pb-2 { padding-bottom: 8px !important; }
.mt-2 { margin-top: 8px !important; }
.ml-3 { margin-left: 12px !important; }
.py-4 { padding-top: 16px !important; padding-bottom: 16px !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

/* 📱 Responsive Adjustments */
@media (max-width: 1100px) {
  .flex-grid {
    flex-direction: column;
  }
  .flex-col-8, .flex-col-6, .flex-col-4 {
    flex: 1;
  }
}

@media (max-width: 900px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .app-sidebar {
    display: none;
  }
  
  .app-bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding: 8px 0;
    z-index: 50;
  }
  
  .bottom-nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    background: none;
    border: none;
    font-family: var(--font-family);
  }
  
  .bottom-nav-link i {
    font-size: 1.2rem;
  }
  
  .bottom-nav-link.active {
    color: var(--primary);
    font-weight: 600;
  }
  
  .app-content {
    padding: 16px;
  }
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fadeIn 0.35s ease-out forwards;
}
