:root {
  --color-primary: #16324f;
  --color-primary-light: #1f4468;
  --color-accent: #d97706;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-bg: #eef1f6;
  --color-card: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; font-family: "Microsoft JhengHei", "Segoe UI", sans-serif; }
body { margin: 0; background: var(--color-bg); color: var(--color-text); }

h1 { font-size: 1.5em; margin: 0 0 16px; color: var(--color-primary); }
h2 { font-size: 1.15em; color: var(--color-primary); }

.topnav {
  display: flex; align-items: center; gap: 20px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  padding: 14px 24px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
}
.topnav .brand { color: #fff; font-weight: bold; margin-right: 20px; display: inline-flex; align-items: center; gap: 8px; letter-spacing: 0.02em; flex-shrink: 0; white-space: nowrap; }
.topnav .brand .logo-mark { font-size: 1.2em; }
.topnav a { color: #cbd5e1; text-decoration: none; padding: 7px 14px; border-radius: 8px; transition: background 0.15s, color 0.15s; flex-shrink: 0; white-space: nowrap; display: inline-block; }
.topnav a:hover { background: rgba(255,255,255,0.14); color: #fff; }
.topnav .nav-right { margin-left: auto; display: inline-flex; align-items: center; gap: 12px; flex-shrink: 0; white-space: nowrap; }
.topnav .nav-user { color: #b9c4d6; font-size: 0.9em; padding: 4px 10px; background: rgba(255,255,255,0.08); border-radius: 999px; white-space: nowrap; }

@media (max-width: 700px) {
  .topnav { gap: 12px; padding: 12px 16px; }
  .topnav a { padding: 6px 10px; font-size: 0.92em; }
  .topnav .brand { margin-right: 8px; font-size: 0.95em; }
}

main { padding: 28px 24px; max-width: 1400px; margin: 0 auto; }
@media (max-width: 700px) { main { padding: 16px 12px; } }

.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 12px; border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: var(--color-card); min-width: 640px; }
.table-scroll table { margin-top: 0; box-shadow: none; }
th, td { border-bottom: 1px solid var(--color-border); padding: 10px 12px; text-align: left; white-space: nowrap; }
th { background: #f1f5f9; color: var(--color-primary); font-weight: 600; letter-spacing: 0.01em; }
tbody tr:hover { background: #f8fafc; }
tr.low-stock { background: #fee2e2; }
tr.low-stock:hover { background: #fecaca; }

.muted { color: var(--color-text-muted); }

.toolbar { display: flex; gap: 10px; margin-bottom: 8px; align-items: center; }

input[type=text], input[type=number], input[type=password], input[type=date], select {
  padding: 8px 12px; border: 1px solid var(--color-border); border-radius: 8px;
  background: #fff; color: var(--color-text); font-size: 1em;
}
input:focus, select:focus { outline: none; border-color: var(--color-primary-light); box-shadow: 0 0 0 3px rgba(31,68,104,0.12); }

button {
  padding: 8px 16px; border: none; border-radius: 8px;
  background: var(--color-primary-light); color: #fff; cursor: pointer;
  font-size: 0.95em; font-weight: 500; transition: filter 0.15s, transform 0.05s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button.secondary { background: #94a3b8; }

.scan-layout { display: flex; align-items: flex-start; gap: 24px; }
.scan-layout .scan-col { flex: 0 0 320px; }
.scan-layout .log-col { flex: 1 1 auto; min-width: 0; }
@media (max-width: 800px) {
  .scan-layout { flex-direction: column; }
  .scan-layout .scan-col { flex: 0 0 auto; width: 100%; }
}

.scan-panel { background: var(--color-card); padding: 20px; border-radius: var(--radius); display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.scan-panel input { font-size: 1.4em; padding: 10px; }
.camera-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.camera-controls button { background: var(--color-success); }
#torchBtn { background: var(--color-accent); }
#reader { width: 100%; border-radius: 8px; overflow: hidden; }
#reader video { border-radius: 8px; }

.msg { font-weight: bold; min-height: 24px; }
.msg.ok { color: var(--color-success); }
.msg.error { color: var(--color-danger); }
.msg.warn { color: var(--color-accent); }

.new-product-form { background: #fff7ed; border: 1px solid #fdba74; padding: 16px; border-radius: var(--radius); margin-top: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }

.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); display:flex; align-items:center; justify-content:center; z-index: 50; }
.modal { background: #fff; padding: 26px; border-radius: var(--radius); display:flex; flex-direction:column; gap:8px; width: 340px; box-shadow: var(--shadow-md); }
.modal h2 { margin-top: 0; }
.modal-actions { display:flex; gap:8px; margin-top:8px; }

.print-only { display: none; }

@media print {
  .topnav, .toolbar, .modal-bg, .new-product-form, .msg, .no-print { display: none !important; }
  body { background: #fff; }
  main { max-width: 100%; padding: 0; }
  .print-only { display: block; margin-bottom: 12px; font-weight: bold; }
  .table-scroll { overflow: visible; box-shadow: none; }
  table { font-size: 12px; box-shadow: none; min-width: 0; }
  th, td { white-space: normal; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  tr.low-stock { background: #fdecea !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- 登入頁 ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--color-primary) 0%, #0b1c2e 100%);
  padding: 24px;
}
.login-card {
  background: var(--color-card); border-radius: 16px; box-shadow: var(--shadow-md);
  padding: 40px 36px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 10px;
}
.login-logo { font-size: 2.4em; text-align: center; margin-bottom: 4px; }
.login-title { text-align: center; font-size: 1.3em; font-weight: 700; color: var(--color-primary); margin: 0; }
.login-subtitle { text-align: center; color: var(--color-text-muted); font-size: 0.9em; margin: 0 0 14px; }
.login-card form { display: flex; flex-direction: column; gap: 6px; }
.login-card label { font-size: 0.9em; color: var(--color-text-muted); margin-top: 6px; }
.login-card button { margin-top: 14px; padding: 10px; font-size: 1.05em; background: var(--color-primary-light); }
.login-footer { text-align: center; margin-top: 18px; font-size: 0.8em; color: var(--color-text-muted); }
.login-footer a { color: var(--color-primary-light); text-decoration: none; }
.login-footer a:hover { text-decoration: underline; }
