/* ================================================================ */
/*  出貨管理系統 - 主樣式表                                          */
/*  使用 Bootstrap 5 + 自訂設計                                      */
/* ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;600;700&display=swap');

/* === 全域變數 === */
:root {
  --primary: #1a2c5b;
  --primary-light: #2a4080;
  --accent: #f5820d;
  --accent-hover: #d96d00;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;
  --info: #17a2b8;
  --bg-dark: #0d1b35;
  --bg-body: #f0f4f8;
  --sidebar-w: 240px;
  --topbar-h: 60px;
  --card-radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-hover: 0 8px 30px rgba(0,0,0,0.15);
  --transition: all 0.25s ease;
}

/* === 基礎 === */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Noto Sans TC', sans-serif;
  font-size: 14px;
  background: var(--bg-body);
  color: #2d3748;
  min-height: 100vh;
}

/* === 頂部導覽列 === */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid #e8edf2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: var(--transition);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 60px;
  background: #f0f4f8;
  cursor: default;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
}

.btn-logout {
  padding: 6px 14px;
  border-radius: 8px;
  background: transparent;
  border: 1.5px solid #d0d7de;
  color: #555;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-logout:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* === 側邊欄 === */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-dark);
  background: linear-gradient(180deg, #0d1b35 0%, #1a2c5b 100%);
  overflow-y: auto;
  z-index: 200;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  padding: 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  min-height: var(--topbar-h);
}

.sidebar-logo-icon {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  margin-right: 10px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

.sidebar-logo-sub {
  color: rgba(255,255,255,0.5);
  font-size: 11px;
}

.sidebar-section {
  padding: 10px 0 4px;
}

.sidebar-section-title {
  padding: 8px 20px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-size: 13.5px;
  border-radius: 0;
  transition: var(--transition);
  gap: 10px;
  margin: 1px 8px;
  border-radius: 8px;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(245, 130, 13, 0.18);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-nav a i {
  width: 18px;
  text-align: center;
  font-size: 15px;
}

.sidebar-nav a span {
  flex: 1;
}

.sidebar-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 20px;
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.4);
  font-size: 11px;
}

/* === 主內容區 === */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: 28px;
  min-height: calc(100vh - var(--topbar-h));
}

/* === 頁面標題 === */
.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header-left h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 4px;
}

.page-header-left p {
  color: #6b7280;
  margin: 0;
  font-size: 13px;
}

/* === 卡片 === */
.card {
  background: #fff;
  border: none;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #edf2f7;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h5 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 20px; }

/* === 統計卡片（儀表板）=== */
.stat-card {
  background: #fff;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  border-left: 4px solid transparent;
}

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

.stat-card.stat-blue   { border-left-color: #4f7ff7; }
.stat-card.stat-orange { border-left-color: var(--accent); }
.stat-card.stat-green  { border-left-color: var(--success); }
.stat-card.stat-red    { border-left-color: var(--danger); }

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-icon.blue   { background: #eef2ff; color: #4f7ff7; }
.stat-icon.orange { background: #fff4e8; color: var(--accent); }
.stat-icon.green  { background: #e8f8f0; color: var(--success); }
.stat-icon.red    { background: #fef2f2; color: var(--danger); }

.stat-info h3 {
  font-size: 26px;
  font-weight: 700;
  margin: 0;
  color: #1a2c5b;
  line-height: 1.2;
}

.stat-info p {
  margin: 2px 0 0;
  font-size: 12px;
  color: #9aabb8;
}

/* === 表格 === */
.table-responsive { border-radius: 0 0 var(--card-radius) var(--card-radius); }

.table {
  margin: 0;
  font-size: 13.5px;
}

.table th {
  background: #f8fafc;
  color: #4a5568;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-color: #edf2f7;
  padding: 12px 14px;
  white-space: nowrap;
}

.table td {
  border-color: #edf2f7;
  padding: 12px 14px;
  vertical-align: middle;
  color: #2d3748;
}

.table tbody tr:hover { background: #f8fafc; }

/* === 狀態標籤 === */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.status-pending   { background: #fff4e8; color: #c05800; }
.status-shipped   { background: #e0f2fe; color: #0369a1; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-cancelled { background: #fee2e2; color: #991b1b; }

/* === 角色標籤 === */
.badge-admin    { background: #ede9fe; color: #5b21b6; border-radius: 20px; padding: 3px 10px; font-size: 11px; font-weight: 600; }
.badge-factory  { background: #fff4e8; color: #92400e; border-radius: 20px; padding: 3px 10px; font-size: 11px; font-weight: 600; }
.badge-store    { background: #d1fae5; color: #065f46; border-radius: 20px; padding: 3px 10px; font-size: 11px; font-weight: 600; }
.badge-customer { background: #e0f2fe; color: #0369a1; border-radius: 20px; padding: 3px 10px; font-size: 11px; font-weight: 600; }

/* === 庫存狀態 === */
.stock-ok   { color: #065f46; font-weight: 600; }
.stock-low  { color: #c05800; font-weight: 700; }
.stock-zero { color: #991b1b; font-weight: 700; }

/* === 按鈕 === */
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--primary-light);
  border-color: var(--primary-light);
  color: #fff;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-sm { font-size: 12px; padding: 4px 10px; }

/* === 表單 === */
.form-label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
}

.form-control, .form-select {
  border-radius: 8px;
  border: 1.5px solid #d1d5db;
  font-size: 13.5px;
  font-family: 'Noto Sans TC', sans-serif;
  transition: var(--transition);
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,44,91,0.1);
}

/* === 庫存儀表板 === */
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.inventory-card {
  background: #fff;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  padding: 18px;
  transition: var(--transition);
}

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

.inventory-card-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--primary);
  margin-bottom: 12px;
}

.inventory-location-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #f0f4f8;
  font-size: 13px;
}

.inventory-location-row:last-child {
  border-bottom: none;
}

.inventory-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 2px solid #e8edf2;
  font-weight: 700;
}

/* === 即時更新指示器 === */
.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #6b7280;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse-live 2s infinite;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

/* === 登入頁 === */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0d1b35 0%, #1a2c5b 50%, #2a4080 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  padding: 44px 40px;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo-icon {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #fff;
  margin-bottom: 14px;
  box-shadow: 0 8px 20px rgba(26,44,91,0.3);
}

.login-logo h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 4px;
}

.login-logo p {
  color: #9aabb8;
  font-size: 13px;
  margin: 0;
}

.login-btn {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border-radius: 10px;
  padding: 12px;
  width: 100%;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(26,44,91,0.3);
}

.login-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(26,44,91,0.4);
}

/* === 列印版型 === */
@media print {
  .no-print, .sidebar, .topbar, .btn, nav { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  body { background: #fff; }
}

/* === 響應式 === */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    transform: translateX(-240px);
    width: 240px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .topbar { left: 0; }
  .main-content { margin-left: 0; padding: 16px; }

  .page-header { flex-direction: column; }
  .inventory-grid { grid-template-columns: 1fr; }
  .stat-card { flex-direction: column; text-align: center; }
}

/* === 標籤編輯器 === */
.label-editor-container {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.label-canvas-wrapper {
  position: relative;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.label-field {
  position: absolute;
  cursor: move;
  user-select: none;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Noto Sans TC', sans-serif;
  line-height: 1.4;
  transition: outline 0.1s;
}

.label-field:hover { outline: 1px dashed var(--accent); }
.label-field.selected { outline: 2px solid var(--accent); }

.label-controls {
  flex: 1;
  min-width: 280px;
}

/* === 通知/警示 === */
.alert { border-radius: 10px; border: none; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-danger  { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef3cd; color: #854d0e; }
.alert-info    { background: #e0f2fe; color: #0369a1; }

/* === 分頁 === */
.pagination .page-link {
  border-radius: 8px;
  margin: 0 2px;
  border: none;
  color: var(--primary);
  font-size: 13px;
}

.pagination .page-item.active .page-link {
  background: var(--primary);
  color: #fff;
}

/* === 其他工具 === */
.section-divider {
  border: none;
  border-top: 2px solid #e8edf2;
  margin: 24px 0;
}

.text-primary-custom { color: var(--primary) !important; }
.text-accent { color: var(--accent) !important; }

.required-star { color: var(--danger); margin-left: 2px; }

.blink-alert { color: #e6a800; animation: blinkCash 1s ease-in-out infinite; display: inline-block; }
@keyframes blinkCash {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(1.2); }
}

