/* นำเข้าฟอนต์ของ Google: Prompt (สำหรับข้อความภาษาไทย) และ Inter (สำหรับตัวเลขและคำศัพท์ทั่วไป) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Prompt:wght@300;400;500;600;700&display=swap');

:root {
  /* ระบบโทนสีหลัก (Slate Indigo Design System) */
  --bg-base: #0f172a;       /* สีพื้นหลังของระบบ (Slate 900) */
  --bg-surface: #1e293b;    /* สีพื้นหลังการ์ด/เนื้อหา (Slate 800) */
  --bg-surface-hover: #293548;
  --bg-border: #334155;     /* สีเส้นขอบ (Slate 700) */
  
  --primary: #6366f1;       /* สีหลักน้ำเงินคราม (Indigo 500) */
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.15);
  
  --text-main: #f8fafc;     /* สีตัวหนังสือหลัก (Slate 50) */
  --text-muted: #94a3b8;    /* สีตัวหนังสือรอง (Slate 400) */
  
  /* สีแจ้งสถานะต่างๆ */
  --status-planned: #64748b;    /* วางแผน (Slate 500) */
  --status-requested: #f59e0b;  /* รออนุมัติ (Amber 500) */
  --status-approved: #3b82f6;   /* อนุมัติแล้ว (Blue 500) */
  --status-executed: #10b981;   /* ดำเนินการแล้ว (Emerald 500) */
  --status-rejected: #ef4444;   /* ไม่อนุมัติ (Rose 500) */

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* รีเซ็ตดีฟอลต์สไตล์ของเบราว์เซอร์ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Prompt', 'Inter', -apple-system, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* โครงสร้างหน้าจอหลัก (Layout Structure) */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* แถบเมนูด้านซ้ายบน Desktop (Sidebar) */
.sidebar {
  width: 280px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--bg-border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 10;
  transition: var(--transition-normal);
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--bg-border);
  margin-bottom: 24px;
}

.logo-icon {
  background: var(--primary);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
}

.logo-text h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* เมนูหลักนำทาง (Navigation Links) */
.nav-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.95rem;
  transition: var(--transition-fast);
}

.nav-item a i {
  font-size: 1.1rem;
}

.nav-item a:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-main);
}

.nav-item.active a {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* แถบสลับผู้ใช้จำลอง (User Switcher Footer) */
.user-panel {
  padding-top: 16px;
  border-top: 1px solid var(--bg-border);
}

.user-selector-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-selector-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.user-select {
  width: 100%;
  background-color: var(--bg-base);
  border: 1px solid var(--bg-border);
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-family: 'Prompt', sans-serif;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: var(--transition-fast);
}

.user-select:focus {
  border-color: var(--primary);
}

.current-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background-color: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

.user-avatar {
  background-color: var(--bg-border);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--primary);
}

.user-details {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-name-text {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.user-role-text {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* พื้นที่แสดงเนื้อหาหลัก (Main Content Area) */
.main-content {
  flex-grow: 1;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* หัวข้อประจำหน้า (Page Header) */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.page-title h2 {
  font-size: 1.5rem;
  font-weight: 600;
}

.page-title p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* หน้าจอแดชบอร์ด (Dashboard widgets) */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: transform var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.stat-icon.total {
  background-color: rgba(99, 102, 241, 0.1);
  color: var(--primary);
}

.stat-icon.spent {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--status-executed);
}

.stat-icon.remaining {
  background-color: rgba(59, 130, 246, 0.1);
  color: var(--status-approved);
}

/* กราฟิกการใช้งบประมาณในแดชบอร์ด (Progress Card) */
.dashboard-detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

@media (max-width: 1024px) {
  .dashboard-detail-grid {
    grid-template-columns: 1fr;
  }
}

.content-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
}

/* แถบแสดงความคืบหน้า (Custom Progress Bars) */
.budget-progress-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.progress-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

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

.progress-percent {
  font-weight: 600;
  color: var(--primary);
}

.progress-bar-bg {
  height: 8px;
  background-color: var(--bg-base);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--status-executed));
  border-radius: 4px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0%;
}

/* ตารางแสดงข้อมูลโครงการ/กิจกรรม (Standard Desktop Table) */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-border);
}

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

.data-table th {
  background-color: var(--bg-base);
  padding: 16px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--bg-border);
}

.data-table td {
  padding: 16px;
  border-bottom: 1px solid var(--bg-border);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.01);
}

/* สัญลักษณ์แสดงป้ายสถานะ (Badges) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge i {
  font-size: 0.7rem;
}

.badge.planned {
  background-color: rgba(100, 116, 139, 0.1);
  color: var(--status-planned);
  border: 1px solid rgba(100, 116, 139, 0.2);
}

.badge.requested {
  background-color: rgba(245, 158, 11, 0.1);
  color: var(--status-requested);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge.approved {
  background-color: rgba(59, 130, 246, 0.1);
  color: var(--status-approved);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge.executed {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--status-executed);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge.rejected {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--status-rejected);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ปุ่มกดสไตล์ต่างๆ (Buttons Style) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-family: 'Prompt', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: var(--transition-fast);
  outline: none;
}

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

.btn-primary:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.btn-secondary {
  background-color: transparent;
  color: var(--text-main);
  border: 1px solid var(--bg-border);
}

.btn-secondary:hover {
  background-color: var(--bg-surface-hover);
}

.btn-success {
  background-color: var(--status-executed);
  color: white;
}

.btn-success:hover {
  background-color: #059669;
}

.btn-danger {
  background-color: var(--status-rejected);
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.75rem;
  border-radius: 6px;
}

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

/* การพับโครงการในหน้ารายการ (Project / Activity Accordion) */
.project-group {
  margin-bottom: 20px;
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: var(--bg-surface);
}

.project-header {
  padding: 18px 24px;
  background-color: rgba(255, 255, 255, 0.02);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  gap: 16px;
}

.project-header:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

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

.project-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.project-meta {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.project-meta span i {
  margin-right: 4px;
}

.project-budgets {
  display: flex;
  align-items: center;
  gap: 16px;
}

.project-budget-val {
  text-align: right;
}

.project-budget-val p {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.project-budget-val span {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

.toggle-icon {
  font-size: 1.25rem;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.project-group.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.project-activities-list {
  border-top: 1px solid var(--bg-border);
  padding: 0;
  transition: max-height var(--transition-normal) ease-out;
  max-height: 2000px;
  overflow: hidden;
}

.project-group.collapsed .project-activities-list {
  max-height: 0;
  border-top-color: transparent;
}

/* การ์ดหน้าตาของกิจกรรมจำลองสำหรับ Mobile */
.activity-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--bg-border);
  background-color: var(--bg-surface);
}

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

.activity-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.activity-title {
  font-size: 0.95rem;
  font-weight: 500;
}

.activity-meta {
  display: flex;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.activity-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* หน้าต่างขออนุมัติ Pop-up (Modal) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  padding: 16px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background-color: var(--bg-surface);
  border: 1px solid var(--bg-border);
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
  transform: translateY(20px);
  transition: transform var(--transition-fast);
  overflow: hidden;
}

.modal-overlay.active .modal-container {
  transform: translateY(0);
}

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

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.form-control {
  background-color: var(--bg-base);
  border: 1px solid var(--bg-border);
  color: var(--text-main);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-family: 'Prompt', sans-serif;
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-fast);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--bg-border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background-color: rgba(255, 255, 255, 0.01);
}

/* แถบตัวกรองเมนูแผนกในหน้าโครงการ (Tab Filters) */
.dept-tabs-wrapper {
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 8px;
}

.dept-tabs {
  display: flex;
  gap: 8px;
  list-style: none;
  width: max-content;
}

.dept-tab {
  padding: 10px 18px;
  background-color: var(--bg-surface);
  border: 1px solid var(--bg-border);
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition-fast);
  white-space: nowrap;
}

.dept-tab:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-main);
}

.dept-tab.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ประวัติตารางการขออนุมัติเงิน (Request Tables) */
.request-card {
  border: 1px solid var(--bg-border);
  border-radius: var(--radius-md);
  padding: 20px;
  background-color: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.request-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.request-card-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.request-card-proj {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.request-card-body {
  font-size: 0.875rem;
  color: var(--text-muted);
  background-color: rgba(0, 0, 0, 0.1);
  padding: 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
}

.request-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.request-actions {
  display: flex;
  gap: 8px;
}

/* แถบการแจ้งเตือนเมื่อไม่มีข้อมูล */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.empty-state i {
  font-size: 3rem;
  color: var(--bg-border);
}

/* ----------------- MOBILE RESPONSIVENESS (CSS FOR PHONE) ----------------- */

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  /* ซ่อน Sidebar ด้านซ้าย และแปลงเป็นแถบสลับผู้ใช้ด้านบนสำหรับโทรศัพท์ */
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--bg-border);
    padding: 16px;
    gap: 12px;
  }
  
  .logo-section {
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: none;
  }
  
  /* ซ่อนเมนูนำทางแนวตั้งเดิม เพื่อใช้ Bottom Navigation */
  .sidebar .nav-links {
    display: none;
  }
  
  .user-panel {
    border-top: none;
    padding-top: 0;
  }
  
  .current-user-card {
    margin-top: 4px;
  }
  
  .main-content {
    padding: 16px;
    padding-bottom: 90px; /* เว้นระยะห่างด้านล่างสำหรับ Bottom Nav */
    gap: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .page-title h2 {
    font-size: 1.3rem;
  }

  /* ตารางแบบเลื่อนแนวนอนสำหรับมือถือ */
  .table-responsive {
    border: none;
  }
  
  .data-table th, .data-table td {
    padding: 12px;
  }

  /* การ์ดกิจกรรม ปรับขนาดปุ่มกดในมือถือ */
  .activity-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }
  
  .activity-actions {
    width: 100%;
    justify-content: flex-end;
  }
  
  .btn {
    padding: 12px 18px; /* เพิ่ม Touch Target ให้กดได้ง่ายขึ้น */
    font-size: 0.9rem;
    flex-grow: 1; /* ให้ปุ่มขยายตัวตามหน้าจอมือถือ */
  }
  
  .btn-sm {
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  /* เมนูนำทางแบบแอปพลิเคชันมือถือ (Bottom Navigation) */
  .bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--bg-border);
    height: 64px;
    z-index: 50;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.3);
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7rem;
    gap: 4px;
    width: 20%;
    height: 100%;
    transition: var(--transition-fast);
  }

  .bottom-nav-item i {
    font-size: 1.35rem;
  }

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

/* เริ่มต้นให้แถบนำทางล่างซ่อนไว้บน Desktop */
.bottom-nav {
  display: none;
}
