/* styles.css - 橡膠墊片棧板排版計算器樣式檔 */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Noto+Sans+TC:wght@300;400;500;700&display=swap');

:root {
  /* 淺色模式變數 */
  --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  --panel-bg: rgba(255, 255, 255, 0.8);
  --panel-border: rgba(255, 255, 255, 0.4);
  --card-bg: rgba(255, 255, 255, 0.7);
  --card-border: rgba(255, 255, 255, 0.3);
  --text-primary: #2d3748;
  --text-secondary: #718096;
  --text-inverse: #ffffff;
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --accent-color: #3b82f6;
  
  /* 狀態顏色 */
  --color-safe: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-info: #06b6d4;
  
  --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.08);
  --shadow-hover: 0 12px 40px 0 rgba(31, 38, 135, 0.15);
  
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark-theme {
  /* 深色模式變數 */
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  --panel-bg: rgba(30, 41, 59, 0.7);
  --panel-border: rgba(255, 255, 255, 0.08);
  --card-bg: rgba(15, 23, 42, 0.65);
  --card-border: rgba(255, 255, 255, 0.05);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-inverse: #0f172a;
  --primary-color: #6366f1;
  --primary-hover: #818cf8;
  --accent-color: #60a5fa;
  
  --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --shadow-hover: 0 12px 40px 0 rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Outfit', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  padding: 2rem 1.5rem;
  transition: background 0.5s ease, color 0.3s ease;
  line-height: 1.5;
}

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

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--panel-border);
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(to right, var(--primary-color), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 0.6rem;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.theme-toggle-btn:hover {
  transform: rotate(30deg) scale(1.1);
  background: var(--primary-color);
  color: white;
}

/* Main Layout Grid */
.main-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.9fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

/* Glassmorphism Panel */
.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.panel:hover {
  box-shadow: var(--shadow-hover);
}

.panel-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 4px solid var(--primary-color);
  padding-left: 0.75rem;
}

/* Gasket Table styles */
.table-container {
  max-height: 580px;
  overflow-y: auto;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  margin-bottom: 1.5rem;
}

/* Custom Scrollbar for container */
.table-container::-webkit-scrollbar,
body::-webkit-scrollbar {
  width: 8px;
}
.table-container::-webkit-scrollbar-track,
body::-webkit-scrollbar-track {
  background: transparent;
}
.table-container::-webkit-scrollbar-thumb,
body::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 4px;
}

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

thead {
  position: sticky;
  top: 0;
  background: var(--primary-color);
  color: white;
  z-index: 10;
}

th, td {
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
}

tbody tr {
  border-bottom: 1px solid var(--panel-border);
  background: transparent;
  transition: var(--transition);
}

tbody tr:hover {
  background: rgba(99, 102, 241, 0.08);
}

/* Number inputs and button styling */
.quantity-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-qty {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  font-size: 1rem;
}

.btn-qty:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

input[type="number"] {
  width: 60px;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--card-bg);
  color: var(--text-primary);
  text-align: center;
  font-family: inherit;
  font-weight: 500;
  transition: var(--transition);
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Remove spin arrows from number inputs */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
}

/* Config panel toggleable */
.config-section {
  margin-top: 1rem;
  border-top: 1px dashed var(--panel-border);
  padding-top: 1rem;
}

.config-toggle {
  background: none;
  border: none;
  color: var(--accent-color);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.config-toggle:hover {
  text-decoration: underline;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-out;
}

.config-grid.open {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.config-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 0.5rem;
  align-items: center;
  padding: 0.25rem 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.config-row label {
  font-size: 0.85rem;
  font-weight: 500;
}

.config-row input {
  width: 100%;
}

/* Action buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  font-family: inherit;
  font-size: 1rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  width: 100%;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

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

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

.btn-secondary:hover {
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-color);
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  border-radius: 8px;
}

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

.btn-group {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* Results Section styling */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.summary-badges {
  display: flex;
  gap: 0.75rem;
}

.badge {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 0.35rem 0.75rem;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

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

.badge-accent {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

/* Pallets Grid */
.pallets-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.pallet-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.pallet-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary-color);
}

.pallet-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 4px;
  width: 100%;
  background: var(--primary-color);
}

.pallet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.pallet-title {
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Progress bar container */
.limits-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 576px) {
  .limits-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

.limit-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.limit-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.limit-value {
  font-weight: 700;
  color: var(--text-primary);
}

.progress-track {
  height: 10px;
  background: rgba(0,0,0,0.08);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.dark-theme .progress-track {
  background: rgba(255,255,255,0.08);
}

.progress-bar {
  height: 100%;
  border-radius: 5px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease;
}

/* Dynamic color states for progress bar */
.bg-safe { background-color: var(--color-safe); }
.bg-warning { background-color: var(--color-warning); }
.bg-danger { background-color: var(--color-danger); }
.bg-info { background-color: var(--color-info); }

/* Stack Loading Direction Sign */
.stack-direction {
  background: rgba(99, 102, 241, 0.06);
  border: 1px dashed var(--primary-color);
  padding: 0.6rem;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* Bundling instructions badge */
.bundling-info {
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid var(--color-info);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-info);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

/* Pallet inner table */
.pallet-table {
  width: 100%;
  font-size: 0.85rem;
}

.pallet-table th {
  padding: 0.5rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--panel-border);
}

.pallet-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--panel-border);
}

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

.highlight-row {
  font-weight: 600;
}

.bottom-tag {
  background: var(--primary-color);
  color: white;
  font-size: 0.7rem;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  margin-left: 0.35rem;
}

/* Custom Gasket Add Row Form */
.add-custom-form {
  display: grid;
  grid-template-columns: 1fr 1fr 0.5fr;
  gap: 0.5rem;
  margin-top: 1rem;
  align-items: end;
}

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

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input {
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-family: inherit;
}

/* Empty state styling */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.empty-state svg {
  width: 64px;
  height: 64px;
  stroke: var(--text-secondary);
  opacity: 0.5;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #333;
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* MOBILE OPTIMIZATION CSS */
@media (max-width: 768px) {
  body {
    padding: 1rem 0.5rem;
  }
  
  header h1 {
    font-size: 1.4rem;
  }
  
  .panel {
    padding: 1rem;
    border-radius: 16px;
  }
  
  .panel-title {
    font-size: 1.1rem;
    margin-bottom: 1rem;
  }
  
  .shipping-info-fields {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
    margin-bottom: 1rem !important;
  }
  
  th, td {
    padding: 0.5rem;
    font-size: 0.85rem;
  }
  
  .btn-qty {
    width: 24px;
    height: 24px;
    font-size: 0.9rem;
  }
  
  input[type="number"] {
    width: 48px;
    padding: 0.25rem;
    font-size: 0.85rem;
  }
  
  .quantity-control {
    gap: 0.2rem;
  }
  
  .add-custom-form {
    grid-template-columns: 1fr 1fr !important;
  }
  
  .add-custom-form button {
    grid-column: span 2;
    width: 100%;
    margin-top: 0.5rem;
  }
  
  .config-row {
    grid-template-columns: 1fr !important;
    gap: 0.25rem;
    padding: 0.5rem 0;
  }
  
  .config-row input {
    margin-top: 0.25rem;
  }
  
  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .summary-badges {
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  
  .btn-group {
    flex-direction: column;
    width: 100%;
    gap: 0.5rem;
  }
  
  .btn-group .btn {
    width: 100%;
  }
  
  .pallet-card {
    padding: 1rem;
    border-radius: 12px;
  }
  
  .pallet-title {
    font-size: 1.05rem;
  }
  
  .limits-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }
  
  .stack-direction {
    font-size: 0.75rem;
    padding: 0.5rem;
    line-height: 1.3;
  }
  
  .bundling-info {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    width: 100%;
  }
  
  .print-shipping-header {
    flex-direction: column;
    gap: 0.5rem !important;
    padding: 0.6rem 0.8rem !important;
    font-size: 0.85rem;
  }
}

/* PRINT OPTIMIZATION CSS */
@media print {
  body {
    background: white;
    color: black;
    padding: 0;
  }
  
  .container {
    max-width: 100%;
  }
  
  /* 隱藏不需要列印的元素 */
  header,
  .main-grid > .panel:first-child, /* 左側輸入面板 */
  .theme-toggle-btn,
  .btn-group,
  .btn,
  .summary-badges,
  .config-section,
  .add-custom-form {
    display: none !important;
  }
  
  /* 重設列印排版 */
  .main-grid {
    grid-template-columns: 1fr !important;
    gap: 0 !important;
  }
  
  .panel {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
  }
  
  /* 縮小標題與基本資訊的留白，避免第一頁空白過多 */
  .print-shipping-header {
    margin-bottom: 0.5rem !important;
    padding: 0.4rem 0.6rem !important;
    font-size: 0.85rem !important;
    border: 1px solid #ccc !important;
    border-radius: 6px !important;
    background: transparent !important;
    display: flex !important;
  }
  
  .results-header {
    margin-bottom: 0.5rem !important;
  }
  
  .results-header h2 {
    font-size: 1.1rem !important;
  }
  
  /* 棧板容器間距縮小 */
  .pallets-container {
    gap: 1rem !important;
  }
  
  /* 棧板卡片優化：高度縮減，使其更容易裝載 */
  .pallet-card {
    border: 1px solid #000 !important; /* 較細邊框，省空間且美觀 */
    background: transparent !important;
    box-shadow: none !important;
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 1rem !important; /* 縮小邊距 */
    padding: 0.75rem !important; /* 縮小內距 */
    border-radius: 8px !important;
  }
  
  .pallet-card::before {
    display: none;
  }
  
  .pallet-title {
    font-size: 1rem !important;
    margin-bottom: 0.5rem !important;
  }
  
  /* 隱藏進度條軌道，只保留數值，大幅節省高度空間 */
  .progress-track {
    display: none !important;
  }
  
  .limits-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.75rem !important;
    margin-bottom: 0.5rem !important;
  }
  
  .limit-item {
    gap: 0.1rem !important;
  }
  
  .limit-label {
    font-size: 0.8rem !important;
  }
  
  /* 縮小提示橫幅高度 */
  .stack-direction {
    font-size: 0.75rem !important;
    padding: 0.25rem 0.5rem !important;
    margin-bottom: 0.5rem !important;
    border: 1px dashed #000 !important;
    color: #000 !important;
    background: transparent !important;
  }
  
  .bundling-info {
    font-size: 0.75rem !important;
    padding: 0.25rem 0.5rem !important;
    margin-bottom: 0.5rem !important;
    border: 1px solid #000 !important;
    color: #000 !important;
    background: transparent !important;
  }
  
  /* 表格緊湊化 */
  .pallet-table {
    font-size: 0.8rem !important;
  }
  
  .pallet-table th {
    border-bottom: 2px solid #000 !important;
    color: #000 !important;
    padding: 0.25rem !important;
  }
  
  .pallet-table td {
    border-bottom: 1px solid #ccc !important;
    padding: 0.25rem !important;
  }
  
  .pallet-table tbody tr:last-child td {
    border-bottom: none !important;
  }
  
  .bottom-tag {
    border: 1px solid #000 !important;
    color: #000 !important;
    background: transparent !important;
    font-size: 0.65rem !important;
  }
}



