:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-2: #243044;
  --line: #2e3d52;
  --text: #e8eef6;
  --muted: #8fa3b8;
  --accent: #3d9cf0;
  --accent-2: #2ee59d;
  --warn: #f0b429;
  --danger: #e85d5d;
  --ok: #3dce8a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 15px/1.5 "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.app {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: #0b1016; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
  overflow: visible;
}
header.app .brand { font-weight: 700; letter-spacing: .04em; color: #fff; white-space: nowrap; }
header.app .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; letter-spacing: .12em; }
nav { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 0; }
nav > a { margin-right: 16px; color: var(--muted); }
nav a.active, nav a:hover { color: #fff; text-decoration: none; }
.nav-dd { position: relative; display: inline-block; margin-right: 16px; }
.nav-dd-title { color: var(--muted); cursor: default; padding: 6px 0; display: inline-block; }
.nav-dd-title::after { content: " ▾"; font-size: 10px; }
.nav-dd:hover .nav-dd-title { color: #fff; }
.nav-dd-list {
  position: absolute; left: 0; top: 100%;
  min-width: 180px;
  background: #151d2a; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 0; box-shadow: 0 10px 24px #0008;
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(4px);
  transition: opacity .15s ease, transform .15s ease, visibility .15s;
  z-index: 40;
}
.nav-dd:hover .nav-dd-list {
  opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0);
}
.nav-dd-list a {
  display: block; margin: 0; padding: 8px 14px; color: var(--muted);
}
.nav-dd-list a:hover { background: var(--panel-2); color: #fff; text-decoration: none; }
.wrap { max-width: 90%; margin: 0 auto; padding: 24px 32px; }
.wrap:has(.admin-page) { max-width: 90%; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; }
.card h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.card .num { font-size: 28px; font-weight: 700; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 8px 10px; font: inherit;
}
textarea { width: 100%; min-height: 70px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.btn {
  display: inline-block; background: var(--accent); color: #071018; border: 0;
  padding: 8px 14px; border-radius: 6px; font-weight: 600; cursor: pointer; font: inherit;
}
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled, .btn[disabled] { opacity: .4; cursor: not-allowed; pointer-events: none; }
.btn.ok { background: var(--accent-2); color: #071018; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #152033; }
tr:hover td { background: rgba(61,156,240,.06); }
.indent-1 { padding-left: 18px; }
.indent-2 { padding-left: 36px; }
.indent-3 { padding-left: 54px; }
.indent-4 { padding-left: 72px; }
.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.badge.成品 { background: #1c3d2e; color: #7dffc0; }
.badge.半成品 { background: #1a3348; color: #8ecbff; }
.badge.電控 { background: #2a2a12; color: #f0d56a; }
.badge.機構 { background: #2a1c12; color: #f0a36a; }
.badge.氣壓 { background: #1c2a2a; color: #6ae0f0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid.parts-form { grid-template-columns: 1fr 1fr 1fr; gap: 12px 20px; align-items: end; }
.form-grid.parts-form > div { min-width: 0; }
.form-grid.parts-form input,
.form-grid.parts-form select { width: 100%; box-sizing: border-box; min-height: 40px; }
.form-grid.picker-grid { grid-template-columns: 1fr 1fr 1fr 1fr 1fr; gap: 14px 16px; }
.form-grid.picker-grid .span-2 { grid-column: span 2; }
.form-grid.picker-grid .span-3 { grid-column: span 3; }
.form-grid.picker-grid .span-4 { grid-column: span 4; }
.form-grid.picker-grid .pick-photo {
  grid-column: 5;
  grid-row: 2 / span 3;
  display: flex;
  flex-direction: column;
}
.form-grid.picker-grid select,
.form-grid.picker-grid input,
.form-grid.picker-grid textarea {
  font-size: 16px;
  min-height: 44px;
  line-height: 1.4;
}
.form-grid.picker-grid textarea { min-height: 140px; resize: vertical; }
#pick-notes { min-height: 140px; max-height: 140px; }
#pick-notes.is-open { min-height: 280px; max-height: 420px; }
.pick-photo-box {
  flex: 1; min-height: 220px; border: 1px solid var(--line); border-radius: 8px;
  background: #121820; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.pick-photo-box img { max-width: 100%; max-height: 280px; display: block; object-fit: contain; }
.pick-photo-box span { color: var(--muted); font-size: 13px; }

.part-preview { cursor: zoom-in; border-bottom: 1px dotted var(--accent); }
#part-preview-pop {
  position: fixed; z-index: 80; width: 260px; min-height: 160px;
  background: #121820; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,.45); padding: 8px;
  display: flex; align-items: center; justify-content: center;
}
#part-preview-pop[hidden] { display: none; }
#part-preview-pop img { max-width: 244px; max-height: 220px; object-fit: contain; }
#part-preview-pop span { color: var(--muted); font-size: 13px; }

#pick-current { min-height: 44px; font-size: 16px; width: 100%; }
#pick-name-sel { min-height: 64px; font-size: 16px; width: 100%; }

.form-grid .full { grid-column: 1 / -1; }
.flash { background: #3a2218; color: #ffc9b0; padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.picker-actions { display: flex; align-items: center; margin-top: 16px; }
.picker-actions-gap { flex: 1; min-width: 80px; }
.picker { position: relative; overflow: visible; }
.combo { position: relative; }
.combo .pick-list { left: 0; right: 0; }
.pick-list {
  position: absolute; left: 0; right: 0; z-index: 40;
  background: #0e1824; border: 1px solid var(--line); border-radius: 8px;
  max-height: 280px; overflow: auto; margin-top: 4px; box-shadow: 0 12px 30px #0008;
}
.pick-item {
  display: block; width: 100%; text-align: left; background: transparent;
  border: 0; border-bottom: 1px solid var(--line); color: var(--text);
  padding: 8px 12px; cursor: pointer; font: inherit;
}
.pick-item:hover { background: #1c3a58; }
.pick-item b { display: block; color: #7ec8ff; }
.pick-item span { display: block; font-size: 13px; }
.pick-item small { color: var(--muted); }
.pick-empty { padding: 10px 12px; color: var(--muted); }
table.sheet th { white-space: nowrap; }
table.sheet td { font-size: 13px; }
footer { color: var(--muted); font-size: 12px; padding: 24px; text-align: center; }
.modal {
  position: fixed; inset: 0; background: #0008; z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px 20px; width: min(420px, 92vw);
}
.modal-box input { width: 100%; }
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  header.app { flex-direction: column; align-items: flex-start; gap: 8px; }
}


/* 資料庫管理頁 */
.admin-page { max-width: none; width: 100%; }
.admin-lead { margin: 0 0 18px; font-size: 14px; }
.admin-jump {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px;
}
.admin-jump a {
  color: var(--muted); border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 6px 12px; font-size: 13px;
}
.admin-jump a:hover { color: #fff; border-color: var(--accent); text-decoration: none; }
.admin-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px; margin: 0 0 28px;
}
.admin-stats div {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px;
}
.admin-stats span { display: block; color: var(--muted); font-size: 12px; }
.admin-stats b { display: block; font-size: 22px; margin-top: 4px; }
.admin-sec {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 24px 20px; margin-bottom: 22px;
}
.admin-sec > header {
  display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px;
}
.admin-sec .n {
  flex: 0 0 36px; height: 36px; border-radius: 50%;
  background: #152033; color: #7ec8ff; display: flex; align-items: center;
  justify-content: center; font-weight: 700;
}
.admin-sec h3 { margin: 0 0 4px; font-size: 18px; color: #fff; font-weight: 650; }
.admin-sec header p { margin: 0; color: var(--muted); font-size: 13px; }
.admin-cols {
  display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 16px;
}
.admin-cols .col {
  background: #121a26; border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 16px 18px; display: flex; flex-direction: column; gap: 10px;
}
.admin-cols .col.danger-col { border-color: #4a2a2a; background: #1a1416; }
.admin-cols h4 {
  margin: 0 0 4px; font-size: 12px; letter-spacing: .08em; color: var(--muted); font-weight: 600;
}
.admin-cols form { display: flex; flex-direction: column; gap: 10px; }
.admin-cols input[type=file],
.admin-cols input[name=confirm] { width: 100%; }
.admin-cols .btn { width: fit-content; }
@media (max-width: 900px) {
  .admin-cols { grid-template-columns: 1fr; }
}


.cal-wrap { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; align-items: start; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wd { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }
.cal-day {
  display: block; min-height: 64px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; color: var(--text); text-decoration: none; position: relative;
}
.cal-day:hover { border-color: var(--accent); text-decoration: none; }
.cal-day.empty { background: transparent; border-color: transparent; }
.cal-day.on { border-color: var(--accent); background: #152033; }
.cal-day.today .n { color: var(--accent); font-weight: 700; }
.cal-day .dot {
  position: absolute; right: 6px; bottom: 6px; font-size: 11px;
  background: var(--panel-2); color: var(--accent); border-radius: 99px; padding: 0 6px;
}
@media (max-width: 900px) { .cal-wrap { grid-template-columns: 1fr; } }


table thead th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table thead th.sortable:hover { color: var(--accent); }
table thead th.sort-asc::after { content: " ▲"; font-size: 11px; color: var(--accent); }
table thead th.sort-desc::after { content: " ▼"; font-size: 11px; color: var(--accent); }


#xfer-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(8,12,18,.72);
  display: flex; align-items: center; justify-content: center;
}
#xfer-overlay[hidden] { display: none; }
.xfer-box {
  width: min(420px, 90vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 22px 22px 18px;
}
.xfer-title { font-weight: 700; margin-bottom: 12px; }
.xfer-bar { height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.xfer-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .15s linear;
}
.xfer-bar i.xfer-indeterminate {
  animation: xfer-slide 1.1s ease-in-out infinite;
}
@keyframes xfer-slide {
  0% { margin-left: -40%; width: 40%; }
  50% { margin-left: 30%; width: 50%; }
  100% { margin-left: 100%; width: 40%; }
}
.xfer-pct { margin-top: 8px; font-variant-numeric: tabular-nums; }
.xfer-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
