:root {
  --primary: #1e5128;
  --primary-hover: #2d5a27;
  --bg: #F9FAFB;
  --card-bg: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(255, 255, 255, 0.3);
  --text: #1F2937;
  --text-light: #6B7280;
  --accent: #10B981;
  --danger: #EF4444;
  --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Noto Sans TC', -apple-system, sans-serif;
}

body {
  background: linear-gradient(135deg, #1e5128 0%, #2d5a27 100%);
  color: var(--text);
  min-height: 100vh;
  padding: 3rem 1rem;
  line-height: 1.6;
}

.main-logo {
  height: 70px;
  margin-bottom: 0;
  justify-self: start;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2)) brightness(0) invert(1);
  transition: transform 0.3s ease;
}

.main-logo:hover {
  transform: scale(1.05);
}


.container {
  max-width: 1100px;
  margin: 0 auto;
}

header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 4rem;
  color: white;
}

.header-text {
  text-align: center;
}

.header-spacer {
  display: block;
}


h1 {
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 0.25rem;
  letter-spacing: -0.025em;
  text-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

p.subtitle {
  opacity: 0.9;
  font-size: 1.2rem;
  font-weight: 500;
}

/* Card Style */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 2rem;
  padding: 3rem;
  box-shadow: var(--shadow);
  margin-bottom: 3rem;
  transition: transform 0.3s ease;
}

.card-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--primary);
  border-bottom: 2px solid #E5E7EB;
  padding-bottom: 1rem;
}

/* Form Styles */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 2rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  font-size: 0.9rem;
  font-weight: 700;
  color: #374151;
  letter-spacing: 0.05em;
}

input,
select {
  padding: 1rem;
  border-radius: 1rem;
  border: 2px solid #E5E7EB;
  background: white;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 1rem;
  font-weight: 500;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(30, 81, 40, 0.1);
  transform: translateY(-2px);
}

.button-container {
  display: flex;
  justify-content: center;
  margin-top: 3rem;
}

button {
  padding: 1rem 2.5rem;
  border-radius: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center; /* Center horizontally */
  gap: 0.75rem;
  border: none;
  font-size: 1.1rem;
}

button.primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
}

button.primary:hover {
  background: var(--primary-hover);
  transform: translateY(-4px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25);
}

button.secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
}

button.secondary:hover {
  background: #EEF2FF;
  transform: translateY(-2px);
}

/* Nutrition Label Preview Container */
.label-preview-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 3rem;
  padding: 1rem;
}

.label-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.label-heading {
  font-weight: 800;
  color: var(--text-light);
  font-size: 1rem;
  background: #F3F4F6;
  padding: 0.5rem 1.5rem;
  border-radius: 2rem;
}

/* Authentic Nutrition Label Styles */
.nutrition-label {
  background: white;
  color: black;
  padding: 12px 20px;
  /* Reduced vertical padding */
  border: 1.5px solid black;
  width: 900px;
  min-height: auto;
  display: flex !important;
  flex-direction: column !important;
  font-family: "PMingLiU", "MingLiU", serif !important;
  /* Force PMingLiU */
  font-weight: 400 !important;
  /* Global remove bold */
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  page-break-inside: avoid;
  break-inside: avoid;
  box-sizing: border-box;
}

.nutrition-label * {
  font-weight: 400 !important;
  /* Ensure all children are not bold */
}

/* PDF Export Specific Container styles */
.pdf-export-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  background: white;
  padding: 20px;
  width: 100%;
}

.pdf-export-container .nutrition-label {
  box-shadow: none;
  /* Remove shadows in PDF for cleanliness */
  margin-bottom: 20px;
}

.label-header {
  font-size: 26px;
  font-weight: 900;
  border-bottom: 12px solid black;
  padding-bottom: 4px;
  margin-bottom: 6px;
  text-align: center;
  letter-spacing: 2px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1.5px solid black;
  padding-top: 2px;
  padding-bottom: 0px;
  /* Bring line closer to numbers */
  font-size: 15px;
  align-items: baseline;
  line-height: 1.2;
}

.nutrition-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-top: 5px;
}

.nutrition-table th,
.nutrition-table td {
  padding: 2px 0;
  vertical-align: baseline;
  border-bottom: 1.5px solid black;
  font-family: inherit;
}

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

/* 名稱欄位 (第一欄) */
.nutrition-table th:nth-child(1),
.nutrition-table td:nth-child(1) {
  width: 34%;
  text-align: left;
  font-weight: 400 !important;
}

/* 數據欄位 (第二、三欄) */
.nutrition-table th:nth-child(2),
.nutrition-table td:nth-child(2),
.nutrition-table th:nth-child(3),
.nutrition-table td:nth-child(3) {
  width: 33%;
}

.data-wrapper {
  display: flex;
  justify-content: center;
  align-items: baseline;
  width: 100%;
}

.v-num {
  width: 4.5em; /* 固定數值區寬度，確保所有小數點垂直對齊 */
  text-align: right;
  padding-right: 0.1rem;
}

.v-unit {
  width: 3.5em; /* 固定單位區寬度，確保對齊標題重心 */
  text-align: left;
  padding-left: 0.1rem;
}

/* 標頭欄位特化 */
.nutrition-table thead th {
  text-align: center;
  font-weight: 400 !important;
  border-bottom: 2px solid black;
}

.nutrition-table.indent td:nth-child(1),
.nutrition-table .indent td:nth-child(1) {
  padding-left: 18px;
}

.label-row.bold {
  font-weight: 400 !important;
  /* Set to normal */
}

.label-row.indent {
  padding-left: 18px;
}

.label-footer {
  font-size: 16px;
  margin-top: 8px;
  line-height: 1.4;
  text-align: justify;
}

/* Row generated by JS adjustments */
.nutrient-rows,
.nutrient-rows-percent {
  width: 100%;
}

/* Specific animations */
#result-section {
  display: none;
  animation: slideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(40px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* @media print for PDF generation */
@media print {
  body {
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  header,
  .card:not(#result-section .card),
  .button-container,
  .card-title,
  .label-heading {
    display: none !important;
  }

  #result-section {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #result-section .card {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    backdrop-filter: none !important;
  }

  .label-preview-container {
    display: block !important;
    /* Forces vertical stack on paper */
    padding: 20px !important;
    gap: 40px !important;
  }

  .label-wrapper {
    page-break-after: always;
    page-break-inside: avoid;
    break-after: always;
    break-inside: avoid;
    margin-bottom: 50px !important;
    display: flex !important;
    align-items: center !important;
  }

  .nutrition-label {
    box-shadow: none !important;
    border: 1.5px solid black !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

@media (max-width: 768px) {
  header {
    display: flex;
    flex-direction: column;
    text-align: center;
    gap: 1.5rem;
  }

  .header-spacer {
    display: none;
  }

  .main-logo {
    height: 60px;
  }

  .card {
    padding: 1.5rem;
  }

  h1 {
    font-size: 1.75rem;
  }

  .label-preview-container {
    padding: 0;
    gap: 1.5rem;
  }

  /* Responsive Nutrition Label */
  .nutrition-label {
    width: 100% !important;
    max-width: 450px !important;
    margin: 0 auto;
    padding: 10px 12px !important;
    font-size: 0.8rem !important; /* Shrink font to prevent wrapping */
  }

  .nutrition-table td:nth-child(1) {
    width: 38% !important; /* Give more space to labels on mobile */
  }

  .label-header {
    font-size: 18px !important;
  }

  /* Mobile Button Optimization */
  .button-container {
    flex-direction: row !important;
    gap: 0.8rem !important;
    width: 100%;
    justify-content: center !important;
  }

  button {
    padding: 0.8rem 0.5rem !important;
    font-size: 1rem !important;
    flex: 1;
    white-space: nowrap !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    text-align: center !important;
    min-width: 0;
    border-radius: 0.8rem !important;
  }

  /* Hide icons on mobile to ensure text is perfectly centered */
  button i {
    display: none !important;
  }

  .label-heading {
    width: 100%;
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
  }
}

/* --- Unified & Optimized Modal System (Responsive) --- */
.modal-wrapper {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 20px;
}

.modal-wrapper.active {
  display: flex !important;
}

.modal-card {
  background: white;
  padding: 2.5rem 3rem;
  border-radius: 2rem;
  width: fit-content !important;
  min-width: 400px;
  max-width: 95vw;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.3);
  animation: modalScale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.modal-icon.reset-icon { background: #FEE2E2; color: #EF4444; }
.modal-icon.validation-icon { background: #DCFCE7; color: var(--primary); }

.modal-card h3 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: #111827;
}

.modal-card p {
  color: #4B5563;
  margin-bottom: 2rem;
  line-height: 1.6;
}

#validation-msg-container {
  background: #F8FAFC;
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  padding: 1.25rem 2rem;
  margin: 1.5rem 0;
  text-align: left;
  width: fit-content;
  max-width: 100%;
}

#validation-msg-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

#validation-msg-list li {
  white-space: nowrap; /* Keep single line as requested */
  color: #334155;
  font-weight: 500;
  margin-bottom: 0.5rem;
  position: relative;
  padding-left: 1.5rem;
  font-size: 0.95rem;
}

#validation-msg-list li:last-child { margin-bottom: 0; }

#validation-msg-list li::before {
  content: "•";
  color: var(--primary);
  position: absolute;
  left: 0;
  font-weight: 900;
  font-size: 1.2rem;
}

.modal-buttons {
  margin-top: 1rem;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 1.25rem;
}

/* Ensure buttons in modal are properly sized */
.modal-buttons button {
  padding: 0.8rem 2rem;
  font-size: 1rem;
  min-width: 120px;
}

#closeValidation {
  min-width: 150px;
}

button.danger {
  background: #EF4444;
  color: white;
}

button.danger:hover {
  background: #DC2626;
  box-shadow: 0 10px 15px -3px rgba(239, 68, 68, 0.3);
}
