/* Target Path: style.css */
/* 🌌 PRESTIGE DESIGN SYSTEM - STYLE SHEET */
@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');

:root {
  /* HSL Color Palette - Dynamic Theme Base */
  --primary-h: 224;
  --primary-s: 76%;
  --primary-l: 48%;
  
  --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%);
  
  --success: hsl(142, 72%, 29%);
  --success-light: hsl(142, 70%, 95%);
  --danger: hsl(350, 89%, 43%);
  --danger-light: hsl(350, 80%, 95%);
  --warning: hsl(38, 92%, 50%);
  
  /* Light Mode Colors */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  
  /* Typography */
  --font-family: 'Outfit', 'Sarabun', system-ui, -apple-system, sans-serif;
  
  /* Utilities */
  --border-radius: 12px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.02);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.02);
}

/* 🌙 Dark Mode Tokens */
[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-card: #131b2e;
  --bg-sidebar: #090d16;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
  --primary-light: hsl(var(--primary-h), var(--primary-s), 12%);
  --success-light: hsl(142, 60%, 10%);
  --danger-light: hsl(350, 70%, 10%);
}

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

/* 🎯 Outline Reset: ลบขอบดำเวลาคลิกเมาส์ แต่ยังคงขอบ Focus เมื่อใช้ Keyboard Tab Navigation (Accessibility Standard) */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none !important;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  overflow-x: hidden;
  overscroll-behavior-y: none; /* ป้องกัน Pull-to-Refresh เผลอปัดหน้า (กฎข้อ 19) */
  transition: background-color 0.3s, color 0.3s;
}

/* 🌌 Main Layout Shell */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  z-index: 50;
  transition: background-color 0.3s, border-color 0.3s;
}

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

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

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

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

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

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

/* 🧭 Sidebar Navigation */
.app-sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: #f8fafc;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  z-index: 40;
}

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

.nav-link, .bottom-nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: #94a3b8;
  border-radius: var(--border-radius);
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.nav-link:hover, .nav-link.active {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.08);
}

.nav-link.active {
  background-color: var(--primary);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

/* 🖥️ Content Area */
.app-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  position: relative;
}

.content-view {
  display: none;
}

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

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

.view-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

/* 🧱 Premium Components */
.detail-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  transition: background-color 0.3s, border-color 0.3s;
}

/* Cards Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

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

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

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

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

.card-success .stat-icon {
  background-color: var(--success-light);
  color: var(--success);
}

.stat-info h3 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.stat-info p {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 4px;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
  margin-top: 16px;
}

/* 📝 Forms & Inputs */
.form-card {
  max-width: 600px;
  margin: 0 auto;
}

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

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.required-label {
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: normal;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  font-family: var(--font-family);
  font-size: 1rem;
  background-color: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-main);
  transition: var(--transition);
}

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

.error-feedback {
  display: block;
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 4px;
}

/* 📅 Datepicker Layout */
.date-input-wrapper {
  position: relative;
  display: flex;
}

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

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

/* 🔘 Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.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.2);
}

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

.btn-secondary:hover:not(:disabled) {
  background-color: var(--text-muted);
  color: #ffffff;
}

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

.btn-danger:hover:not(:disabled) {
  background-color: hsl(350, 89%, 35%);
}

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

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

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  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: var(--border-color);
  color: var(--text-main);
}

/* 📋 Data Table */
.filter-bar {
  margin-bottom: 16px;
}

.search-input-wrapper {
  position: relative;
  max-width: 320px;
}

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

.search-control {
  padding-left: 40px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

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

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

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

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

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

/* 📶 Offline and PWA Update UI Components */
.offline-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: #0f172a;
  color: #ffffff;
  padding: 12px 24px;
  border-radius: 30px;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.update-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.update-dialog.visible {
  opacity: 1;
  pointer-events: auto;
}

.update-dialog-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 32px;
  border-radius: 16px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.update-dialog.visible .update-dialog-content {
  transform: scale(1);
}

.update-icon {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 16px;
}

.update-dialog-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  justify-content: center;
}

/* UI Settings */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

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

.auth-btn-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.settings-info h4 {
  font-weight: 600;
  font-size: 1rem;
}

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

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

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

/* 📱 Responsive & Layout Framing Standard */
.app-bottom-nav {
  display: none;
}

/* 💻 Desktop PC Mobile-Framed Mode (สำหรับจำลองหน้าตาแอปมือถือบนจอ PC)
   ให้ใส่ class="mobile-framed" ที่แท็ก <body> เมื่อต้องการจำลองกรอบมือถือบน PC Desktop */
@media (min-width: 769px) {
  body.mobile-framed {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #0f172a; /* สีพื้นหลังรอบนอกบนจอ PC */
  }

  body.mobile-framed .app-container {
    max-width: 430px;
    height: 92vh;
    border-radius: 28px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    border: 1px solid var(--border-color);
  }
}

/* 📱 Real Mobile Device (เปิดเต็มจอ 100dvh ขอบเหลี่ยม ไร้เงา) */
@media (max-width: 768px) {
  .app-container {
    height: 100dvh;
    max-width: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }

  .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;
  }
  
  .bottom-nav-link i {
    font-size: 1.25rem;
  }
  
  .bottom-nav-link.active {
    color: var(--primary);
  }
  
  .app-content {
    padding: 16px;
  }
}

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

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.animate-bounce {
  animation: bounce 2s infinite;
}

/* ==========================================
   📋 TASK APP COMPONENTS (ตามไฟล์ prototype.html ล่าสุด)
   ========================================== */

/* 🎴 View Subtitle */
.view-header .view-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* 🎴 Task Card */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.task-card:hover {
  box-shadow: var(--shadow-md);
}

.task-card.is-done {
  opacity: 0.65;
}

.task-card.is-done .task-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* ✅ ปุ่มติ๊กสถานะ (Min 44px เพื่อมาตรฐาน Mobile Accessibility) */
.task-check {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  background: transparent;
  color: #fff;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  min-width: 44px;
  min-height: 44px;
}

.task-check.is-done {
  background-color: var(--success);
  border-color: var(--success);
}

.task-main {
  flex: 1;
  min-width: 0;
}

.task-title {
  font-weight: 600;
  font-size: 1rem;
  word-break: break-word;
}

.task-desc {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 2px;
  word-break: break-word;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}

.task-meta i {
  font-size: 0.8rem;
  margin-right: 4px;
}

/* 🏷️ Status & Priority Badges */
.task-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-todo {
  background-color: var(--primary-light);
  color: var(--primary);
}

.badge-doing {
  background-color: hsl(38, 90%, 92%);
  color: hsl(30, 90%, 30%);
}

.badge-done {
  background-color: var(--success-light);
  color: var(--success);
}

.badge-pri-high {
  background-color: var(--danger-light);
  color: var(--danger);
}

.badge-pri-mid {
  background-color: hsl(38, 90%, 92%);
  color: hsl(30, 90%, 30%);
}

.badge-pri-low {
  background-color: var(--primary-light);
  color: var(--primary);
}

.badge-due-overdue {
  background-color: var(--danger-light);
  color: var(--danger);
}

/* 🔎 Filter Chips */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-card);
  color: var(--text-muted);
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  min-height: 44px;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.chip.active {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* 📊 Dashboard Stat Notes */
.stat-card .stat-info .stat-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 📋 Recent / Urgent List */
.recent-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.recent-item:last-child {
  border-bottom: none;
}

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

.recent-item .recent-date {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* 🪹 Empty State */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* ⚙️ Settings Note */
.settings-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 12px;
}

/* 📝 Textarea Auto-expand Limit (กฎข้อ 10 — Scrollbar ภายในถ้ายาวเกิน) */
textarea.form-control {
  resize: vertical;
  max-height: 200px;
}

