/* นำเข้าฟอนต์จาก Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Sarabun:wght@300;400;500;600;700&display=swap');

/* รีเซ็ตและสไตล์พื้นฐาน */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Outfit', 'Sarabun', sans-serif;
}

:root {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #311042 100%);
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-hover: rgba(255, 255, 255, 0.12);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-color: #6366f1;
  --accent-hover: #4f46e5;
  --card-bg: rgba(15, 23, 42, 0.6);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* คอนเทนเนอร์หลัก */
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

/* แก้วมอร์ฟิซึมระดับหรู */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  transition: var(--transition);
}

/* ส่วนหัว (Header) */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.logo-icon i {
  font-size: 20px;
  color: #fff;
}

.logo-text h1 {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(to right, #fff, #c7d2fe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text span {
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 15px;
}

.profile-info {
  text-align: right;
}

.profile-name {
  font-weight: 600;
  font-size: 15px;
}

.profile-role {
  font-size: 12px;
  color: var(--text-secondary);
}

.btn-logout {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

/* หน้าล็อกอินจำลอง */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}

.login-card {
  width: 100%;
  max-width: 480px;
  padding: 40px;
  text-align: center;
}

.header-logo-img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 50%;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
}

.login-logo-img {
  width: 110px;
  height: 110px;
  object-fit: cover;
  margin: 0 auto 20px auto;
  display: block;
  border-radius: 50%;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.4));
}

.login-icon-large {
  background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
  width: 80px;
  height: 80px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px auto;
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4);
}

.login-icon-large i {
  font-size: 38px;
  color: #fff;
}

.login-card h2 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.custom-select, .custom-input, .custom-textarea {
  width: 100%;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  color: var(--text-primary);
  padding: 12px 16px;
  font-size: 15px;
  outline: none;
  transition: var(--transition);
}

.custom-select:focus, .custom-input:focus, .custom-textarea:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.custom-select option {
  background-color: #1e1b4b;
  color: #ffffff;
  padding: 8px;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: white;
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

/* แดชบอร์ดหัวหน้างาน (Supervisor View) */
.supervisor-view {
  display: none; /* สลับแสดงผลด้วย JS */
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-info h3 {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
}

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

/* สีเฉพาะแต่ละการ์ดสถิติ */
.stat-total .stat-icon { background: rgba(99, 102, 241, 0.15); color: var(--accent-color); }
.stat-pending .stat-icon { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.stat-done .stat-icon { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.stat-overdue .stat-icon { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* โครงสร้าง Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

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

/* แผงวิเคราะห์และกราฟ */
.chart-panel {
  padding: 24px;
  min-height: 400px;
}

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

.panel-title {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

/* รายชื่อและตัวควบคุมหน้าตาราง */
.table-panel {
  padding: 24px;
}

.table-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.control-search {
  flex-grow: 1;
  min-width: 200px;
}

.control-filter {
  min-width: 150px;
}

.btn-icon {
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.btn-secondary-custom {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
}

.btn-secondary-custom:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* สไตล์ตารางสเปรดชีตในเว็บแอป */
.table-responsive {
  overflow-x: auto;
  width: 100%;
}

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

.custom-table th {
  background: rgba(255, 255, 255, 0.04);
  padding: 14px 16px;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 2px solid var(--glass-border);
}

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

.custom-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* ป้ายสถานะ (Status Badges) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-todo { background: rgba(6, 182, 212, 0.15); color: var(--info); border: 1px solid rgba(6, 182, 212, 0.3); }
.badge-progress { background: rgba(245, 158, 11, 0.15); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-done { background: rgba(16, 185, 129, 0.15); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.3); }

/* ป้ายลำดับความสำคัญ (Priority Badges) */
.priority-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
}

.priority-high { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); }
.priority-medium { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.priority-low { background: rgba(59, 130, 246, 0.2); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.4); }

/* ปุ่มจัดการแถว */
.actions-cell {
  display: flex;
  gap: 8px;
}

.btn-small {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.btn-edit { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }
.btn-edit:hover { background: var(--accent-color); color: white; }

.btn-delete { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.btn-delete:hover { background: var(--danger); color: white; }

/* หน้าบอร์ด Kanban ของทีมงาน (Member View) */
.member-view {
  display: none; /* สลับแสดงผลด้วย JS */
}

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

/* โครงสร้างบอร์ด Kanban */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  align-items: start;
}

.kanban-column {
  padding: 20px;
  min-height: 500px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
}

.column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--glass-border);
}

.column-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* สีหัวช่อง Kanban */
.col-todo { background: rgba(6, 182, 212, 0.03); border: 1px solid rgba(6, 182, 212, 0.1); }
.col-todo .column-header { border-bottom-color: var(--info); }
.col-todo .column-title { color: var(--info); }

.col-progress { background: rgba(245, 158, 11, 0.03); border: 1px solid rgba(245, 158, 11, 0.1); }
.col-progress .column-header { border-bottom-color: var(--warning); }
.col-progress .column-title { color: var(--warning); }

.col-done { background: rgba(16, 185, 129, 0.03); border: 1px solid rgba(16, 185, 129, 0.1); }
.col-done .column-header { border-bottom-color: var(--success); }
.col-done .column-title { color: var(--success); }

.task-count {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.kanban-cards-area {
  flex-grow: 1;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* สไตล์การ์ดงาน (Task Card) */
.task-card {
  background: var(--card-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  cursor: grab;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.task-card:hover {
  transform: translateY(-3px) scale(1.02);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  background: rgba(15, 23, 42, 0.85);
}

.task-card:active {
  cursor: grabbing;
}

/* แถบสีแสดงความสำคัญที่ขอบการ์ด */
.task-card.priority-high-card { border-left: 4px solid var(--danger); }
.task-card.priority-medium-card { border-left: 4px solid var(--warning); }
.task-card.priority-low-card { border-left: 4px solid var(--info); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.card-id {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.4;
  color: #fff;
}

.card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.card-date {
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-date.overdue {
  color: #fca5a5;
  font-weight: 600;
}

.card-date i {
  font-size: 11px;
}

/* ลากและวาง (SortableJS Ghost) */
.sortable-ghost {
  opacity: 0.4;
  border: 2px dashed var(--accent-color);
  background: rgba(99, 102, 241, 0.05) !important;
}

.sortable-drag {
  opacity: 0.8;
  transform: rotate(2deg);
}

/* หน้าต่างป๊อปอัป SweetAlert2 (แต่งธีมมืดให้กลมกลืน) */
.swal2-popup-dark {
  background: #1e1b4b !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: 20px !important;
}

.swal2-title-dark {
  color: var(--text-primary) !important;
  font-weight: 700 !important;
}

.swal2-html-container-dark {
  color: var(--text-secondary) !important;
}

/* การจัดวางปุ่มแก้ไขในรายละเอียดบอร์ด */
.task-detail-info {
  text-align: left;
  margin-top: 15px;
}

.task-detail-info p {
  margin-bottom: 8px;
  font-size: 14px;
}

.task-detail-info strong {
  color: var(--text-primary);
}

/* ปุ่มและฟอร์มในโมดอล */
.modal-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  text-align: left;
  padding: 10px 0;
}

@media (min-width: 600px) {
  .modal-form-grid {
    grid-template-columns: 1fr 1fr;
  }
  .modal-form-full {
    grid-column: span 2;
  }
}

/* ส่วนท้าย (Footer) */
footer {
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 40px;
  border-top: 1px solid var(--glass-border);
}

footer a {
  color: var(--accent-color);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* เอฟเฟกต์โหลดหน้าเว็บ (Loading Spinner) */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(99, 102, 241, 0.1);
  border-left-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 500;
}