/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
  /* HSL Color System */
  --hue: 220; /* Royal/Executive Blue Hue */
  
  /* Light Theme (Default) */
  --bg-app: #f4f6fc;
  --bg-sidebar: #0f1e36;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #eef2ff;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --text-on-primary: #ffffff;
  
  --primary: hsl(var(--hue), 85%, 42%);
  --primary-hover: hsl(var(--hue), 85%, 35%);
  --primary-light: hsl(var(--hue), 85%, 95%);
  
  --success: #10b981;
  --success-hover: #059669;
  --success-light: #ecfdf5;
  
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fee2e2;
  
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.03);
  
  --border-radius-sm: 6px;
  --border-radius-md: 12px;
  --border-radius-lg: 20px;
  
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-app: 'Inter', 'Sarabun', -apple-system, sans-serif;
  --font-memo: 'Sarabun', 'TH Sarabun PSK', sans-serif;
  
  --header-height: 70px;
  --sidebar-width: 260px;
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-app: #0b0f19;
  --bg-sidebar: #050811;
  --bg-card: #131a2c;
  --bg-input: #1b2438;
  --bg-hover: #1e2942;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  
  --primary: hsl(var(--hue), 85%, 55%);
  --primary-hover: hsl(var(--hue), 85%, 65%);
  --primary-light: rgba(30, 64, 175, 0.3);
  
  --border-color: #1e293b;
  --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   BASE STYLES & RESET
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-app);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
  height: 100vh;
  overflow: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--text-light);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Hide helper */
.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-family: var(--font-app);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--border-radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-primary {
  background-color: var(--primary);
  color: var(--text-on-primary);
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.25);
}

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

.btn-success {
  background-color: var(--success);
  color: white;
}
.btn-success:hover {
  background-color: var(--success-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.25);
}

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

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

.btn:active {
  transform: translateY(0);
}

/* Badge */
.badge {
  display: inline-flex;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 50px;
  text-transform: uppercase;
}

.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }

/* ==========================================================================
   APP LAYOUT & HEADER
   ========================================================================== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

.main-header {
  height: var(--header-height);
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.3s, border-color 0.3s;
}

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

.logo-icon {
  width: 40px;
  height: 40px;
  background-color: var(--primary-light);
  color: var(--primary);
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

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

.logo-text span {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  margin-top: -2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Notification Bell Styling */
.notification-bell-container {
  position: relative;
}

.notif-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  position: relative;
  transition: var(--transition-smooth);
}

.notif-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}

.notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background-color: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-card);
}

.notif-panel {
  position: absolute;
  top: 50px;
  right: 0;
  width: 320px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 1000;
  animation: slideDown 0.25s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.notif-header {
  padding: 12px 16px;
  background-color: var(--bg-hover);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.notif-header h3 {
  font-size: 14px;
  font-weight: 700;
}

.clear-all-btn {
  background: transparent;
  border: none;
  font-size: 11px;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}

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

.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
  transition: var(--transition-smooth);
}

.notif-item:hover {
  background-color: var(--bg-hover);
}

.notif-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notif-item.success .notif-icon {
  background-color: var(--success-light);
  color: var(--success);
}

.notif-item.warning .notif-icon {
  background-color: var(--warning-light);
  color: var(--warning);
}

.notif-body p {
  font-size: 12px;
  color: var(--text-main);
  line-height: 1.4;
}

.notif-time {
  font-size: 10px;
  color: var(--text-light);
  margin-top: 4px;
  display: block;
}

.empty-notif {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.theme-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.theme-toggle-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}

/* User Role Selector */
.role-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 1px solid var(--border-color);
  padding-left: 16px;
}

.profile-avatar {
  width: 36px;
  height: 36px;
  background-color: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.profile-info {
  display: flex;
  flex-direction: column;
}

.user-role-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.profile-select-wrapper {
  position: relative;
}

.role-select {
  background: transparent;
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  padding-right: 16px;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  font-family: var(--font-app);
}

.profile-select-wrapper::after {
  content: '\f107';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  pointer-events: none;
  color: var(--text-muted);
}

/* ==========================================================================
   APP BODY GRID LAYOUT
   ========================================================================== */
.app-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* Sidebar Navigation */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
  z-index: 90;
  transition: transform 0.3s ease;
}

.nav-menu {
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-section-label {
  font-size: 10px;
  color: #475569;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 1px;
  margin-top: 15px;
  margin-bottom: 5px;
  padding-left: 12px;
}

.nav-section-label:first-child {
  margin-top: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-family: var(--font-app);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  position: relative;
  transition: var(--transition-smooth);
  width: 100%;
}

.nav-item i {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: #f8fafc;
}

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

.nav-item-primary {
  background-color: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  margin-top: 10px;
}

.nav-item-primary:hover {
  background-color: rgba(59, 130, 246, 0.25);
  color: #93c5fd;
}

.approval-badge {
  background-color: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-data-sync {
  background-color: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--border-radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-data-sync:hover {
  background-color: rgba(255,255,255,0.08);
  color: white;
}

.system-version {
  font-size: 10px;
  text-align: center;
  color: #475569;
}

/* Main Content Area */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 30px;
  position: relative;
}

/* ==========================================================================
   PAGES VIEW CONTROLS
   ========================================================================== */
.page-view {
  display: none;
  animation: fadeIn 0.4s ease;
}

.page-view.active-page {
  display: block;
}

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

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.page-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 2px;
}

/* ==========================================================================
   CARDS & STATS
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

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

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

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

.stat-data {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Card Accent Colors */
.stat-card.blue .stat-icon { background-color: var(--primary-light); color: var(--primary); }
.stat-card.green .stat-icon { background-color: var(--success-light); color: var(--success); }
.stat-card.purple .stat-icon { background-color: #f3e8ff; color: #a855f7; }
.stat-card.orange .stat-icon { background-color: var(--warning-light); color: var(--warning); }

[data-theme="dark"] .stat-card.purple .stat-icon { background-color: rgba(168, 85, 247, 0.2); color: #c084fc; }

/* General Content Card */
.content-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.content-card.narrow {
  flex-shrink: 0;
}

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

.card-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.card-body {
  padding: 20px;
}

.card-body.pad-zero {
  padding: 0;
}

/* ==========================================================================
   TABLES
   ========================================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

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

.data-table th {
  padding: 12px 16px;
  background-color: var(--bg-hover);
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

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

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover td {
  background-color: var(--bg-hover);
}

.table-toolbar {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background-color: var(--bg-input);
  color: var(--text-main);
  outline: none;
  font-family: var(--font-app);
  font-size: 13.5px;
  transition: var(--transition-smooth);
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-group {
  display: flex;
  gap: 10px;
}

.filter-group select {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-app);
  font-size: 13.5px;
  outline: none;
  cursor: pointer;
}

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

/* ==========================================================================
   TEACHER DASHBOARD GRID & PROGRESS
   ========================================================================== */
.dashboard-details-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

.centered-flex {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

/* Progress Circular Ring */
.progress-ring-container {
  margin: 20px 0;
}

.circle-progress {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--percent) * 1%), var(--border-color) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.circle-inner {
  width: 124px;
  height: 124px;
  background-color: var(--bg-card);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.progress-number {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.progress-sub {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 2px;
}

.progress-description {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 220px;
}

/* ==========================================================================
   FORMS & INPUTS
   ========================================================================== */
.form-container {
  max-width: 800px;
  margin: 0 auto 40px auto;
}

.responsive-form {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.form-section {
  padding: 30px;
  border-bottom: 1px solid var(--border-color);
}

.form-section h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

.form-row:last-child {
  margin-bottom: 0;
}

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

.form-group.colspan-2 {
  grid-column: span 2;
}

.form-group label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main);
}

.form-group label.required::after {
  content: ' *';
  color: var(--danger);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-app);
  font-size: 14px;
  outline: none;
  transition: var(--transition-smooth);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-actions-bar {
  padding: 20px 30px;
  background-color: var(--bg-hover);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Brief view for reporting */
.training-brief-box {
  background-color: var(--primary-light);
  border-left: 4px solid var(--primary);
  border-radius: var(--border-radius-sm);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.training-brief-box h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.training-brief-box p {
  font-size: 12.5px;
  color: var(--text-main);
  margin-top: 4px;
}

/* Image Upload Area */
.image-upload-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upload-trigger {
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius-md);
  padding: 30px;
  text-align: center;
  cursor: pointer;
  background-color: var(--bg-hover);
  transition: var(--transition-smooth);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.upload-trigger:hover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.upload-trigger i {
  font-size: 32px;
  color: var(--primary);
  margin-bottom: 12px;
}

.upload-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}

.upload-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}

.image-preview-card {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.image-preview-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.remove-img-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(239, 68, 68, 0.9);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: var(--transition-smooth);
}

.remove-img-btn:hover {
  background-color: var(--danger-hover);
}

/* ==========================================================================
   DIRECTOR CHARTS & DASHBOARD
   ========================================================================== */
.charts-layout-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.chart-container-box {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.colspan-2 {
  grid-column: span 2;
}

.horizontal-bar-container {
  height: 280px;
}

/* ==========================================================================
   STAFF LIST LAYOUT
   ========================================================================== */
.staff-records-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}

.staff-vertical-list {
  list-style: none;
  max-height: 500px;
  overflow-y: auto;
}

.staff-li-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition-smooth);
}

.staff-li-item:hover {
  background-color: var(--bg-hover);
}

.staff-li-item.active {
  background-color: var(--primary-light);
  border-left: 4px solid var(--primary);
  color: var(--primary);
  font-weight: 700;
}

.staff-li-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--border-color);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.staff-li-item.active .staff-li-avatar {
  background-color: var(--primary);
  color: white;
}

.staff-li-details {
  display: flex;
  flex-direction: column;
}

.staff-li-name {
  font-size: 13.5px;
}

.staff-li-pos {
  font-size: 10.5px;
  color: var(--text-muted);
}

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

.border-bottom {
  border-bottom: 1px solid var(--border-color);
}

/* ==========================================================================
   MODALS AND INTERACTION OVERLAYS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  transition: var(--transition-smooth);
}

.modal-card {
  width: 100%;
  max-width: 600px;
  background-color: var(--bg-card);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--border-color);
  animation: modalScale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalScale {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.close-modal-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.sync-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.sync-action-box {
  padding: 16px;
  background-color: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  display: flex;
  flex-direction: column;
}

.sync-action-box h4 {
  font-size: 13.5px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
}

.sync-action-box p {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 16px;
  flex: 1;
}

.file-name-info {
  display: block;
  font-size: 11px;
  text-align: center;
  color: var(--text-light);
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.danger-zone {
  border-top: 1px dashed var(--border-color);
  padding-top: 16px;
}

.danger-zone h4 {
  color: var(--danger);
  font-size: 13.5px;
  margin-bottom: 6px;
}

.danger-zone p {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Toast Notification Overlay */
.toast-wrapper {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  background-color: var(--bg-card);
  border-left: 4px solid var(--primary);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 400px;
  transform: translateX(120%);
  animation: slideInLeft 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  border: 1px solid var(--border-color);
}

@keyframes slideInLeft {
  to { transform: translateX(0); }
}

.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
.toast.danger { border-left-color: var(--danger); }

.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}
.toast.success .toast-icon { color: var(--success); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.danger .toast-icon { color: var(--danger); }

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: 13px;
  font-weight: 700;
}

.toast-text {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.toast-close {
  background: transparent;
  border: none;
  font-size: 12px;
  color: var(--text-light);
  cursor: pointer;
}

/* Action button icons in tables */
.btn-action-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: var(--transition-smooth);
}

.btn-action-sm.edit { background-color: var(--primary-light); color: var(--primary); }
.btn-action-sm.edit:hover { background-color: var(--primary); color: white; }
.btn-action-sm.delete { background-color: var(--danger-light); color: var(--danger); }
.btn-action-sm.delete:hover { background-color: var(--danger); color: white; }
.btn-action-sm.report { background-color: var(--success-light); color: var(--success); }
.btn-action-sm.report:hover { background-color: var(--success); color: white; }

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

.action-buttons-group .btn {
  padding: 8px 14px;
}

/* ==========================================================================
   OFFICIAL PAPER/MEMO DESIGN (บันทึกข้อความ)
   ========================================================================== */
.official-paper-container {
  width: 21cm;
  min-height: 29.7cm;
  background-color: #ffffff;
  color: #000000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08), 0 1px 8px rgba(0, 0, 0, 0.04);
  margin: 0 auto 50px auto;
  padding: 2.5cm 2cm 2cm 3cm; /* บน 2.5 ซม, ขวา 2 ซม, ล่าง 2 ซม, ซ้าย 3 ซม ตามระเบียบหนังสือราชการ */
  font-family: var(--font-memo);
  box-sizing: border-box;
  position: relative;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Render official elements nicely inside app even if it has dark mode */
[data-theme="dark"] .official-paper-container {
  background-color: #ffffff;
  color: #000000;
  border-color: #ffffff;
}

.memo-header {
  display: flex;
  align-items: flex-end;
  position: relative;
  margin-bottom: 1.5cm;
  height: 1.5cm; /* ขนาดความสูงของครุฑราชการคือ 1.5 ซม. */
}

.garuda-logo-wrapper {
  width: 1.5cm;
  height: 1.5cm;
  display: flex;
  align-items: center;
  justify-content: center;
}

.garuda-logo-wrapper svg {
  width: 100%;
  height: 100%;
}

.memo-title-text {
  font-family: var(--font-memo);
  font-size: 29pt; /* คำว่า บันทึกข้อความ ขนาด 29พอยท์ ตัวหนา */
  font-weight: 700;
  text-align: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  line-height: 1;
  letter-spacing: 0.05em;
  color: #000000;
}

.memo-metadata {
  border-bottom: 3px double #000000;
  padding-bottom: 8px;
  margin-bottom: 16px;
}

.metadata-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 6px;
}

.metadata-field {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.field-label {
  font-weight: 700;
  font-size: 20pt; /* คำว่า ส่วนราชการ ที่ วันที่ เรื่อง ขนาด 20พอยท์ ตัวหนา */
  white-space: nowrap;
  color: #000000;
}

.field-value {
  border-bottom: 1px dotted #a1a1aa;
  flex: 1;
  padding-bottom: 2px;
  min-height: 24px;
  font-size: 16pt; /* ข้อความตัวหนังสือทั่วไป ขนาด 16พอยท์ ตัวธรรมดา */
  color: #111827;
  word-break: normal;
  word-wrap: break-word;
  line-break: loose;
}

.font-weight-bold {
  font-weight: 700;
}

.memo-to {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 24px;
  font-size: 16pt;
}

.memo-to .field-label {
  font-size: 16pt; /* คำขึ้นต้น เรียน ขนาด 16พอยท์ ตัวหนา */
  font-weight: 700;
  color: #000000;
}

.memo-body {
  text-align: justify;
  color: #111827;
}

.memo-body p {
  text-indent: 2.5cm; /* ย่อหน้ายื่นเข้ามา 2.5 ซม. ตามระเบียบหนังสือราชการ */
  margin-bottom: 18px;
  font-size: 16pt; /* ข้อความตัวเรื่อง ขนาด 16พอยท์ ตัวธรรมดา */
  line-height: 1.85; /* เพิ่มระยะห่างบรรทัดสำหรับการแสดงผลอักษรไทยที่สวยงาม ไม่ทับซ้อนวรรณยุกต์ */
  word-break: normal;
  word-wrap: break-word;
  line-break: loose;
}

.data-fill {
  display: inline;
  font-weight: 600; /* ทำให้ข้อมูลที่ป้อนมีความเข้มขึ้นเล็กน้อยเพื่อแยกจากข้อความเทมเพลตบนหน้าจอ */
  color: #1e3a8a; /* ใช้สีน้ำเงินเข้มหรูหราบนหน้าจอ */
}

/* ลบสีน้ำเงินและเปลี่ยนเป็นดำปกติเวลาสั่งพิมพ์ */
@media print {
  .data-fill {
    font-weight: normal !important;
    color: #000000 !important;
  }
  .field-value {
    border-bottom: none !important; /* ลบจุดไข่ปลาด้านล่างเมื่อพิมพ์ */
    color: #000000 !important;
  }
  .memo-body, .memo-body p {
    color: #000000 !important;
  }
}

.memo-sub-section {
  margin: 20px 0 20px 2.5cm;
}

.memo-sub-section .section-title {
  font-weight: 700;
  font-size: 16pt;
  margin-bottom: 8px;
  color: #000000;
}

.section-text-block {
  border-left: 2px solid #cbd5e1;
  padding-left: 16px;
  font-style: italic;
  white-space: pre-wrap;
  color: #334155;
  font-size: 16pt;
  line-height: 1.7;
}

/* Official document table styling */
.official-document-table {
  width: 100%;
  border-collapse: collapse !important;
  margin-bottom: 24px;
  background-color: transparent !important;
}

.official-document-table th {
  padding: 8px 10px !important;
  border-top: 2px solid #000000 !important;
  border-bottom: 2px solid #000000 !important;
  font-family: var(--font-memo) !important;
  font-size: 16pt !important;
  font-weight: 700 !important;
  color: #000000 !important;
  background-color: transparent !important;
}

.official-document-table td {
  padding: 8px 10px !important;
  border-bottom: 1px solid #666666 !important;
  font-family: var(--font-memo) !important;
  font-size: 16pt !important;
  color: #000000 !important;
  background-color: transparent !important;
  vertical-align: top;
}

.official-document-table tr:hover td {
  background-color: transparent !important;
}

/* Page Break Simulator on Screen */
.page-break-simulator {
  border-top: 2px dashed #cbd5e1;
  margin: 40px -2cm 40px -3cm; /* Expand to the padding limits of paper */
  position: relative;
  height: 0;
  clear: both;
}

.page-break-simulator span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #f1f5f9;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 9999px;
  border: 1px solid #cbd5e1;
  font-family: var(--font-app);
  white-space: nowrap;
}

/* Hide simulator during print */
@media print {
  .page-break-simulator {
    display: none !important;
  }
}

/* Signatures layout */
.signature-block {
  margin-left: auto; /* จัดวางขวาของหน้ากระดาษ */
  width: 8cm;
  margin-top: 1.5cm;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.7;
  clear: both;
}

.signature-block .sign-line {
  font-size: 16pt;
}
.signature-block .sign-name-text {
  margin-top: 4px;
  font-size: 16pt;
}
.signature-block .sign-pos-text {
  font-size: 16pt;
  color: #000000;
}

.memo-divider {
  border: none;
  border-top: 1px dashed #e2e8f0;
  margin: 40px 0;
  clear: both;
}

/* Printed attached photos */
.memo-photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-top: 14px;
  clear: both;
}

.memo-photo-card {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.memo-photo-card img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: 2px;
}

.memo-photo-caption {
  font-size: 12pt;
  color: #555555;
  margin-top: 6px;
  text-align: center;
}

/* Director Action block inside Memo */
.director-action-memo {
  border: 1px solid #000000;
  border-radius: 4px;
  padding: 16px;
  margin-top: 40px;
  width: 100%;
  clear: both;
  background-color: #fafafa;
}

.action-box {
  line-height: 1.4;
}

.action-title-label {
  font-size: 15px;
  margin-bottom: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.box-check {
  font-size: 15px;
}

/* ==========================================================================
   PRINT MEDIA STYLESHEET
   ========================================================================== */
@media print {
  @page {
    size: A4;
    margin: 2.5cm 2cm 2cm 3cm; /* บน 2.5 ซม, ขวา 2 ซม, ล่าง 2 ซม, ซ้าย 3 ซม ตามระเบียบหนังสือราชการ */
  }

  /* Hide every normal browser layout element */
  body, html {
    background-color: #ffffff !important;
    color: #000000 !important;
    height: auto !important;
    overflow: visible !important;
    font-size: 16px !important;
  }
  
  .app-container {
    display: block !important;
    height: auto !important;
  }

  .main-header, 
  .sidebar, 
  .print-hide, 
  .modal-overlay,
  .toast-wrapper,
  .page-header,
  .nav-menu,
  .sidebar-footer {
    display: none !important;
  }

  .app-layout {
    display: block !important;
    height: auto !important;
  }

  .main-content {
    padding: 0 !important;
    overflow: visible !important;
    height: auto !important;
  }

  /* Only display the active page-view when printing */
  .page-view {
    display: none !important;
  }

  .page-view.active-page {
    display: block !important;
  }

  .official-paper-container {
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
    color: #000000 !important;
    background-color: #ffffff !important;
  }

  [data-theme="dark"] .official-paper-container {
    color: #000000 !important;
    background-color: #ffffff !important;
  }

  .page-break-before {
    page-break-before: always;
  }

  /* Adjust photo grid for paper printing */
  .memo-photos-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .director-action-memo {
    background-color: #ffffff !important;
    border: 1px solid #000000 !important;
  }
}

/* ==========================================================================
   RESPONSIVE LAYOUTS
   ========================================================================== */
@media (max-width: 991px) {
  --sidebar-width: 80px;

  .nav-item span,
  .nav-section-label,
  .sidebar-footer span {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 14px;
  }

  .nav-item i {
    font-size: 20px;
  }

  .btn-data-sync {
    padding: 10px;
    border-radius: 50%;
  }
  
  .staff-records-layout {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    width: 100vw;
    height: 60px;
    border-right: none;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-direction: row;
    position: absolute;
    bottom: 0;
    left: 0;
  }

  .nav-menu {
    flex-direction: row;
    width: 100%;
    padding: 0 10px;
    justify-content: space-around;
    align-items: center;
    gap: 0;
  }

  .nav-section-label,
  .sidebar-footer {
    display: none !important;
  }

  .nav-item {
    height: 100%;
    border-radius: 0;
    justify-content: center;
    padding: 0;
    flex: 1;
  }

  .nav-item-primary {
    margin-top: 0;
    background: transparent;
    color: #94a3b8;
  }

  .main-content {
    height: calc(100vh - var(--header-height) - 60px);
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .dashboard-details-grid {
    grid-template-columns: 1fr;
  }
  
  .charts-layout-grid {
    grid-template-columns: 1fr;
  }
  
  .colspan-2 {
    grid-column: span 1;
  }

  .official-paper-container {
    padding: 20px 24px;
    font-size: 15px;
  }

  .memo-header {
    grid-template-columns: 80px 1fr;
  }

  .garuda-logo-wrapper {
    width: 48px;
    height: 48px;
  }

  .memo-title-text {
    font-size: 22px;
  }
  
  .sync-actions-grid {
    grid-template-columns: 1fr;
  }
}
