/* =========================================
   1. CẤU HÌNH & BIẾN (COMPACT & RESPONSIVE)
   ========================================= */
:root {
  /* Màu chủ đạo */
  --primary: #10b981;           /* Emerald 500 */
  --primary-hover: #059669;     /* Emerald 600 */
  --primary-gradient: linear-gradient(135deg, #34d399 0%, #059669 100%);
  --primary-light: #ecfdf5;     /* Emerald 50 */
  
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  
  /* Typography */
  --text-main: #334155;    /* Slate 700 */
  --text-heading: #0f172a; /* Slate 900 */
  --text-sub: #64748b;     /* Slate 500 */
  
  /* Effects */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
  --shadow-glow: 0 0 0 3px rgba(16, 185, 129, 0.15); 
  
  /* Radius */
  --radius-xl: 24px; 
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-btn: 99px;
}

*, *::before, *::after { 
  box-sizing: border-box; 
  -webkit-tap-highlight-color: transparent; 
}

/* --- RESPONSIVE BASE FONT SIZE --- */
html { 
  font-size: 14px; /* Mobile nhỏ gọn */
}
@media (min-width: 640px) { html { font-size: 15px; } } /* Tablet */
@media (min-width: 1024px) { html { font-size: 16px; } } /* Desktop chuẩn */

body {
  font-family: "Baloo 2", sans-serif;
  font-weight: 500;
  background-color: var(--bg-body);
  /* Pattern nền nhạt */
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--text-main);
  margin: 0;
  min-height: 100vh;
  line-height: 1.5;
}

::selection { background-color: #a7f3d0; color: var(--text-heading); }
h1, h2, h3, h4 { color: var(--text-heading); letter-spacing: -0.01em; margin-top: 0; }
.font-extrabold { font-weight: 700 !important; }

/* =========================================
   2. HEADER & STEPS (Mobile Optimized)
   ========================================= */
header > div.bg-white { background: transparent !important; box-shadow: none !important; padding: 0 !important; }
header .flex-1.h-1 { background: #cbd5e1; opacity: 0.4; height: 2px !important; border-radius: 4px; transition: all 0.4s ease; }

.step-block {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-btn);
  padding: 4px 10px; /* Mobile: padding nhỏ */
  display: flex; align-items: center; gap: 6px;
  transition: all 0.5s ease; 
  transform: scale(0.98); opacity: 0.7; filter: grayscale(100%);
}
@media (min-width: 640px) { .step-block { padding: 8px 20px; gap: 10px; } }

.step-active {
  background: #ffffff; border: 1px solid var(--primary); 
  transform: scale(1);
  box-shadow: 0 4px 12px -2px rgba(16, 185, 129, 0.15);
  z-index: 20; opacity: 1 !important; filter: grayscale(0%) !important;
}

.step-circle {
  width: 28px !important; height: 28px !important; font-size: 0.85rem !important;
  background: #e2e8f0; color: #94a3b8; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-weight: 700 !important;
}
@media (min-width: 640px) { .step-circle { width: 36px !important; height: 36px !important; font-size: 1rem !important; } }

.step-active .step-circle { background: var(--primary-gradient); color: #fff; }

.step-label { font-size: 0.9rem; font-weight: 600; color: var(--text-sub); }
.step-active .step-label { color: var(--text-heading); font-weight: 700; }

/* =========================================
   3. CÁC KHỐI MÀN HÌNH (CONTAINERS)
   ========================================= */
#screenUpload, #screenDashboard, #screenGuide, .tips-section {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card); border: 1px solid #fff;
  overflow: hidden; margin-bottom: 24px; transition: height 0.4s ease;
  width: 100%;
}
@media (min-width: 768px) {
  #screenUpload, #screenDashboard, #screenGuide, .tips-section { 
    border-radius: 32px; margin-bottom: 30px; 
  }
}

/* --- STEP 1: UPLOAD --- */
#screenUpload .detect-grid { height: auto; } /* Mobile: chiều cao tự động */
@media (min-width: 1024px) { #screenUpload .detect-grid { min-height: 450px; } }

/* Cột ảnh Mascot */
#screenUpload .detect-grid > div:first-child {
  background: #f8fafc !important; border-right: none; border-bottom: 1px solid #f1f5f9;
  position: relative; padding: 0 !important; display: flex; 
  height: 220px; /* Mobile: ảnh thấp hơn */
  align-items: flex-end; justify-content: center;
}
@media (min-width: 1024px) { 
  #screenUpload .detect-grid > div:first-child { 
    height: auto; border-right: 1px solid #f1f5f9; border-bottom: none; 
  } 
}

#screenUpload .detect-grid > div:first-child img { 
  width: 100% !important; height: 100% !important; object-fit: cover !important; 
  object-position: center bottom; 
}

/* Cột nội dung */
#screenUpload .detect-grid > div:last-child { padding: 24px !important; }
@media (min-width: 640px) { #screenUpload .detect-grid > div:last-child { padding: 40px !important; } }
@media (min-width: 1024px) { #screenUpload .detect-grid > div:last-child { padding: 60px !important; } }

/* =========================================
   4. FORM & DASHBOARD COMPONENTS
   ========================================= */
/* TABLE */
#materialTableBody { display: block; width: 100%; background: #ffffff; border: 1px solid #e2e8f0; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 16px; }
#materialTableBody tr { display: flex; justify-content: space-between; align-items: center; width: 100%; background: #fff; border-bottom: 1px solid #f1f5f9; padding: 10px 16px; margin: 0 !important; }
#materialTableBody tr:last-child { border-bottom: none; }

#materialTableBody td:first-child { padding: 0 !important; border: none !important; font-size: 0.95rem; font-weight: 600; color: var(--text-main); display: flex; align-items: center; gap: 8px; flex: 1; }
#materialTableBody td:first-child::before { content: ""; display: block; width: 6px; height: 6px; border-radius: 50%; background: #cbd5e1; }
#materialTableBody tr:hover td:first-child::before { background: var(--primary); }

#materialTableBody td:last-child { padding: 0 !important; border: none !important; width: auto; margin-left: auto; display: flex; align-items: center; gap: 8px; }
#materialTableBody td:last-child span { display: inline-flex; align-items: center; justify-content: center; font-size: 0.85rem !important; font-weight: 700 !important; color: var(--primary) !important; background: var(--primary-light) !important; height: 26px; min-width: 26px; padding: 0 8px; border-radius: 99px; }

.btn-delete-material { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: none; background: transparent; color: #cbd5e1; cursor: pointer; }
@media (hover: hover) { .btn-delete-material:hover { background-color: #fee2e2; color: #ef4444; } }

/* MANUAL ADD SECTION */
#manualAddSection > div { padding: 20px !important; margin-top: 20px; }
@media (min-width: 640px) { #manualAddSection > div { padding: 24px 32px !important; } }

#manualMaterialSelect, #manualMaterialQty { 
  height: 48px; border-radius: 12px !important; font-weight: 600; color: var(--text-heading); width: 100%; font-size: 0.95rem;
}
@media (min-width: 640px) { #manualMaterialSelect, #manualMaterialQty { height: 52px; } }

#manualMaterialSelect:focus, #manualMaterialQty:focus { border-color: var(--primary); box-shadow: var(--shadow-glow); }

#manualMaterialAddBtn { 
  height: 48px; width: 100% !important; margin-top: 10px;
}
@media (min-width: 640px) { #manualMaterialAddBtn { height: 52px; width: auto !important; min-width: 120px; margin-top: 2px; } }

/* =========================================
   5. PROJECT CARDS (Grid & Flex)
   ========================================= */
.project-card { 
  background: #ffffff; border: 1px solid #f1f5f9; border-radius: 16px; 
  overflow: hidden; display: flex; flex-direction: column; 
  transition: transform 0.3s, box-shadow 0.3s; 
  cursor: pointer; position: relative; height: 100%; 
}
/* Chỉ hover trên PC để tránh lỗi sticky hover trên mobile */
@media (hover: hover) {
  .project-card:hover { transform: translateY(-4px); border-color: var(--primary-light); box-shadow: var(--shadow-hover); }
  .project-card:hover .project-img-wrapper img { transform: scale(1.05); }
}
.project-card:active { transform: scale(0.98); }

.project-img-wrapper { width: 100%; aspect-ratio: 16/10; overflow: hidden; position: relative; background: #f1f5f9; }
.project-img-wrapper img { width: 100%; height: 100%; object-fit: cover; transition: 0.5s; }
.project-badge { position: absolute; top: 10px; right: 10px; padding: 3px 10px; border-radius: 99px; font-size: 0.7rem; font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,0.1); backdrop-filter: blur(4px); }

.project-content { padding: 16px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.project-title { font-size: 1.1rem; font-weight: 700; color: var(--text-heading); margin: 0; line-height: 1.3; }
.project-desc { font-size: 0.9rem; color: var(--text-sub); margin-bottom: 4px; }

.project-footer { margin-top: 0; display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid #f1f5f9; }
.project-btn { color: var(--primary); background: transparent; border: none; font-weight: 700; font-size: 0.85rem; display: flex; align-items: center; gap: 4px; }

/* CHIPS (Nhãn vật liệu) */
.material-chips-container { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; margin-bottom: 8px; }
.material-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 4px 4px 8px; border-radius: 8px;
  font-size: 0.8rem; font-weight: 600; border: 1px solid transparent; cursor: default;
}
.material-chip i { font-size: 0.9rem; }
.material-chip.is-enough { background-color: #ecfdf5; color: #047857; border-color: #d1fae5; }
.material-chip.is-missing { background-color: #f8fafc; color: #64748b; border-color: #e2e8f0; }

.material-qty-badge {
  display: flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 6px;
  font-size: 0.75rem; font-weight: 800;
}
.material-chip.is-enough .material-qty-badge { background-color: #10b981; color: white; }
.material-chip.is-missing .material-qty-badge { background-color: #cbd5e1; color: #475569; }

/* =========================================
   6. GLOBAL BUTTONS & UTILS
   ========================================= */
button { border-radius: var(--radius-btn) !important; text-transform: none; font-weight: 700; transition: all 0.2s; cursor: pointer; user-select: none; }
button:active { transform: scale(0.96) !important; }

#pickImageButton, #detectButton { 
  padding: 12px 20px; font-size: 0.95rem; font-weight: 700; 
}
@media (min-width: 640px) { #pickImageButton, #detectButton { padding: 14px 28px; font-size: 1rem; } }

#toggleManualAddBtn .w-12.h-12 { width: 40px; height: 40px; transition: all 0.4s; }
@media (hover: hover) { #toggleManualAddBtn:hover .w-12.h-12 { background: var(--primary-gradient); color: white; border-color: transparent; transform: scale(1.15) rotate(90deg); } }

/* GUIDE IFRAME & SLIDE */
.canva-wrapper { position: relative; width: 100%; height: auto; min-height: 250px; border-radius: 16px; border: 2px solid #fff; background: #f8fafc; overflow: hidden; }
@media (min-width: 768px) { .canva-wrapper { min-height: 400px; } }
.canva-wrapper iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; }

.btn-celebrate { position: relative; overflow: hidden; width: 100%; }
@media (min-width: 640px) { .btn-celebrate { width: auto; } }
.btn-celebrate::before { content: ""; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent); transition: 0.5s; }
@media (hover: hover) { .btn-celebrate:hover::before { left: 100%; } }

#guideMaterials li { font-weight: 500; font-size: 0.95rem; color: var(--text-main); padding: 10px; border-radius: 10px; background: #f8fafc; border: 1px solid #f1f5f9; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
#guideMaterials li i { font-size: 1.1rem; color: var(--primary); flex-shrink: 0; }

/* --- SCROLLBAR --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* --- ANIMATIONS --- */
.fade-in { animation: fadeIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }