:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --text: #16333a;
  --muted: #5b6b70;
  --border: #dde5e6;
  --accent: #1dafca;
  --accent-dark: #0e8fa8;
  --accent-light: #e6f6fa;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --success: #1a7f37;
  --success-bg: #eaf7ee;
  --warning: #b45309;
  --warning-bg: #fef3e2;
  --radius: 12px;
  /* Solid button fills always pair with white text, in both themes — so these stay dark/saturated
     enough for AA contrast (≥4.5:1) regardless of theme, unlike --accent/--danger/--warning above
     which are tuned per-theme for use as *text* color against a page/card background instead. */
  --btn-primary-bg: #0a6e80;
  --btn-primary-bg-hover: #074f5c;
  --btn-danger-bg: #a3241a;
  --btn-danger-bg-hover: #7d1b13;
  --btn-warning-bg: #9a4a08;
  --btn-warning-bg-hover: #7a3a06;
}
html.dark {
  --bg: #0f1720;
  --surface: #182430;
  --text: #e6edf0;
  --muted: #93a1a8;
  --border: #2b3945;
  --accent: #2fc6e0;
  --accent-dark: #1dafca;
  --accent-light: rgba(47, 198, 224, .14);
  --danger: #ff6b6b;
  --danger-bg: rgba(180, 35, 24, .18);
  --success: #4ade80;
  --success-bg: rgba(26, 127, 55, .18);
  --warning: #d97706;
  --warning-bg: rgba(217, 119, 6, .2);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s, color .2s;
}
a { color: var(--accent-dark); }
html.dark a { color: var(--accent); }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 5vw; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header a.brand { color: var(--text); text-decoration: none; font-weight: 700; }
nav { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
nav form { display: contents; }
.nav-item {
  margin: 0; box-sizing: border-box; height: 2.1rem; display: inline-flex; align-items: center;
  color: var(--muted); background: transparent; border: 0; text-decoration: none; font-size: .9rem;
  font-weight: 400; font-family: inherit; padding: 0 .75rem; border-radius: 999px; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--accent-light); color: var(--accent-dark); }
.nav-user { cursor: default; color: var(--text); font-weight: 600; }
.nav-user:hover { background: transparent; }
#theme-toggle { width: 2.1rem; padding: 0; justify-content: center; border: 1px solid var(--border); }

main { max-width: 1024px; margin: 2rem auto; padding: 0 1rem; }
.card { background: var(--surface); padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0, 0, 0, .04); }
.card + .card { margin-top: 1.5rem; }
h1 { margin-top: 0; font-size: 1.4rem; }
h2 { font-size: 1.1rem; }

label { display: block; margin-top: 1rem; font-weight: 600; font-size: .9rem; }
input, select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: .95rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
input[type=checkbox] { width: auto; display: inline-block; margin-right: .4rem; vertical-align: middle; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin-top: 1rem; padding: .75rem 1rem; }
legend { font-weight: 600; font-size: .85rem; color: var(--muted); padding: 0 .3rem; }

button, .btn {
  margin-top: 1rem; padding: .6rem 1.15rem; border: 0; border-radius: 999px;
  background: var(--btn-primary-bg); color: #fff; font-weight: 600; font-size: .9rem; cursor: pointer;
  transition: background .15s; font-family: inherit;
}
button:hover, .btn:hover { background: var(--btn-primary-bg-hover); }
button.btn-danger, .btn-danger { background: var(--btn-danger-bg); }
button.btn-danger:hover, .btn-danger:hover { background: var(--btn-danger-bg-hover); }
button.btn-secondary, .btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.btn-secondary:hover, .btn-secondary:hover { background: var(--bg); }
button.btn-warning, .btn-warning { background: var(--btn-warning-bg); }
button.btn-warning:hover, .btn-warning:hover { background: var(--btn-warning-bg-hover); }
button.btn-sm, .btn-sm { margin-top: 0; padding: .4rem .85rem; font-size: .82rem; }

.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.actions .btn, .actions button { margin-top: 0; padding: .4rem .85rem; font-size: .82rem; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: .9rem; }
th, td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: var(--accent-light); }

.error { color: var(--danger); background: var(--danger-bg); padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; }
.error:empty { display: none; padding: 0; }
.message { color: var(--accent-dark); background: var(--accent-light); padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; margin-bottom: 1rem; }
.muted { color: var(--muted); font-size: .9rem; }

.pagination { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; }

.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.gallery-img { width: 160px; height: 160px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--border); }
figure { display: inline-block; margin: .5rem .5rem 0 0; text-align: center; }
figure form { margin-top: .3rem; }

.product-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; margin-top: 1rem; }
@media (max-width: 900px) { .product-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .product-grid { grid-template-columns: 1fr; } }
.product-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; }
.product-image { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; cursor: zoom-in; display: block; }
.product-image.placeholder { background: var(--bg); }
.zoom-hint {
  background: none; border: 0; color: var(--accent-dark); font-size: .8rem; padding: .35rem 0;
  cursor: pointer; text-align: left; font-family: inherit; font-weight: 400; margin: 0;
}
html.dark .zoom-hint { color: var(--accent); }
.product-name { margin: .2rem 0 .4rem; font-size: 1.2rem; }
.tier-box { background: var(--bg); border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; }
.tier-box-row { display: flex; justify-content: space-between; gap: .5rem; padding: .25rem 0; font-size: .88rem; }
.unit-badge {
  display: inline-flex; align-items: center; justify-content: center; background: var(--btn-primary-bg);
  color: #fff; font-weight: 600; font-size: .8rem; padding: .2rem .7rem; border-radius: 6px; margin-top: .5rem; width: fit-content;
}
.product-card label { margin-top: .5rem; }
.product-card .qty-input { width: 100%; }

.lightbox-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .8); display: flex; align-items: center;
  justify-content: center; z-index: 100; cursor: zoom-out; padding: 2rem;
}
.lightbox-overlay.hidden { display: none; }
.lightbox-overlay img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, .15);
  color: #fff; border: none; font-size: 2rem; line-height: 1; width: 3rem; height: 3rem; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, .3); }
.lightbox-nav.hidden { display: none; }
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }
.lightbox-counter {
  position: absolute; bottom: 1.25rem; left: 50%; transform: translateX(-50%); color: #fff;
  font-size: .85rem; background: rgba(0, 0, 0, .5); padding: .2rem .7rem; border-radius: 999px;
}

.budget-banner { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: baseline; background: var(--accent-light); border-color: var(--accent); }
.budget-banner div { display: flex; flex-direction: column; gap: .15rem; }
.budget-banner strong { font-size: 1.3rem; color: var(--accent-dark); }
.summary-card { margin-top: 1.5rem; background: var(--bg); }
.summary-card p { display: flex; justify-content: space-between; margin: .5rem 0; }
.summary-card hr { border: 0; border-top: 1px solid var(--border); margin: .75rem 0; }
.summary-card button { width: 100%; }
#summary-remaining.over-budget { color: var(--danger); }
.summary-item { padding: .5rem 0; border-bottom: 1px solid var(--border); }
.summary-item:last-child { border-bottom: 0; }
.summary-item p { margin: .15rem 0; }
.summary-item p:first-child { font-size: .95rem; }
.summary-item p.muted { font-size: .8rem; }

.stat-bar { display: flex; flex-wrap: wrap; gap: 2rem; margin-top: 1rem; padding: 1rem 1.25rem; background: var(--bg); border-radius: var(--radius); }
.stat-bar > div { display: flex; flex-direction: column; gap: .2rem; }
.stat-bar strong { font-size: 1.3rem; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-right { text-align: right; }

.filter-form { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-end; margin: 1rem 0; padding: 1rem 1.25rem; background: var(--bg); border-radius: var(--radius); }
.filter-group { display: flex; flex-direction: column; gap: .3rem; }
.filter-group label { font-size: .85rem; font-weight: 600; }
.filter-group select[multiple] { min-width: 220px; }
.filter-form .actions { margin-bottom: 2px; }

.table-scroll { overflow-x: auto; }
.review-table td { vertical-align: top; }
.review-item { margin-bottom: .6rem; }
.review-item:last-child { margin-bottom: 0; }
.review-table .actions { margin-bottom: .4rem; }
.review-table details { position: relative; display: inline-flex; }
.review-table summary { display: inline-flex; align-items: center; list-style: none; cursor: pointer; }
.review-table summary::-webkit-details-marker { display: none; }
.review-table details form {
  position: absolute; top: 2.2rem; right: 0; z-index: 5; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem; width: 240px; box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
}
.review-table .loose-lines > div { line-height: 1.6; margin: .35rem 0; }
.review-table .muted { margin-top: .5rem; }
.review-table .actions-cell > div { margin-top: .5rem; }

.application-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-top: 1rem; }
.application-card h2 { margin: 0 0 .4rem; font-size: 1rem; }
.status-badge { display: inline-block; margin-left: .6rem; padding: .15rem .65rem; border-radius: 999px; font-size: .75rem; font-weight: 600; vertical-align: middle; }
.status-submitted { background: var(--accent-light); color: var(--accent-dark); }
.status-returned { background: var(--warning-bg); color: var(--warning); }
.status-approved, .status-completed { background: var(--success-bg); color: var(--success); }
.status-cancelled, .status-draft { background: var(--border); color: var(--muted); }
.status-pending { background: var(--border); color: var(--muted); }
.status-scheduled { background: var(--accent-light); color: var(--accent-dark); }
.status-shipped { background: var(--success-bg); color: var(--success); }
.status-disabled { background: var(--btn-danger-bg); color: #fff; }
.status-tax-included { background: var(--warning-bg); color: var(--warning); }
.status-tax-excluded { background: var(--danger-bg); color: var(--danger); }
.application-card .actions { margin-top: .75rem; }
.application-card details { position: relative; }
.application-card summary { list-style: none; cursor: pointer; }
.application-card summary::-webkit-details-marker { display: none; }
.application-card .actions details form { position: absolute; top: 2.2rem; left: 0; z-index: 5; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; width: 260px; box-shadow: 0 4px 12px rgba(0, 0, 0, .12); }
.detail-toggle { margin-top: .75rem; }
.detail-toggle[open] summary { margin-bottom: .5rem; }
.detail-panel { border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; margin-top: .5rem; background: var(--bg); }
.detail-panel h4 { margin: .75rem 0 .3rem; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.detail-panel h4:first-child { margin-top: 0; }
.detail-panel table { margin-top: .3rem; font-size: .85rem; }
.history-list { list-style: none; padding: 0; margin: .3rem 0 0; font-size: .85rem; color: var(--muted); }
.history-list li { padding: .3rem 0; border-bottom: 1px solid var(--border); }
.history-list li:last-child { border-bottom: 0; }

.print-page { background: var(--bg); color: var(--text); font-family: inherit; margin: 0; padding: 1.5rem; }
.print-sheet { max-width: 800px; margin: 0 auto; }
.print-sheet table { width: 100%; }
.checkbox-cell { font-size: 1.1rem; text-align: center; }
.signature-row { display: flex; justify-content: space-between; margin-top: 2.5rem; font-size: .9rem; }
@media print {
  .no-print { display: none; }
  .print-sheet { border: none; box-shadow: none; }
  body { background: #fff; color: #000; }
}
