:root {
  color-scheme: light;
  --ink: #1f1f1f;
  --muted: #6b6b6b;
  --line: #dedede;
  --panel: #ffffff;
  --panel-2: #f6f6f6;
  --bg: #eeeeee;
  --brand: #2f2f2f;
  --brand-2: #575757;
  --status-green-bg: #e6f1ea;
  --status-green-ink: #2f6848;
  --status-red-bg: #f2e6e4;
  --status-red-ink: #8a4b42;
  --status-blue-bg: #e5ecf4;
  --status-blue-ink: #3f6288;
  --status-dark-bg: #333333;
  --status-dark-ink: #ffffff;
  --red: #8a4b42;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% -10%, rgba(255, 255, 255, 0.86), transparent 30%),
    linear-gradient(135deg, #f4f4f4 0%, #e8e8e8 46%, #f1f1f1 100%);
  color: var(--ink);
  font-family: "Noto Sans TC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(0, 0, 0, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(0, 0, 0, 0.06), transparent 34%),
    var(--bg);
}

.login-panel {
  width: min(1180px, 100%);
  display: grid;
  grid-template-columns: 1fr 520px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(23, 33, 29, 0.08);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 64px;
  color: #f8fbf9;
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 255, 255, 0.24), transparent 26%),
    linear-gradient(145deg, #6f6f6f 0%, #343434 48%, #111111 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 560px;
}

.mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-logo {
  width: 92px;
  height: auto;
  display: block;
}

.login-brand .brand-logo {
  width: 132px;
}

.sidebar .brand-logo {
  width: 112px;
}

.topbar-logo {
  width: 58px;
  height: auto;
  display: block;
}

.mark-badge {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f4efe6;
  color: var(--brand);
  font-weight: 800;
}

.login-brand h1 {
  max-width: 560px;
  margin: 0 0 18px;
  font-size: clamp(34px, 4.8vw, 56px);
  line-height: 1.12;
  letter-spacing: 0;
  word-break: keep-all;
}

.login-brand h1 span {
  display: block;
  white-space: nowrap;
}

.login-brand p {
  max-width: 520px;
  margin: 0;
  color: rgba(248, 251, 249, 0.78);
  font-size: 15px;
  line-height: 1.8;
}

.login-form {
  padding: 62px 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}

.login-form h2 {
  margin: 0;
  font-size: 24px;
}

.login-form .brand-logo {
  width: 170px;
  margin-bottom: 24px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.primary,
.secondary,
.danger-btn,
.ghost,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  font-weight: 800;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease;
}

.primary {
  background: linear-gradient(135deg, #1f1f1f, #3c3c3c);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.14);
}

.secondary {
  background: linear-gradient(180deg, #ffffff, #f7f7f7);
  border-color: var(--line);
  color: var(--ink);
}

.danger-btn {
  background: linear-gradient(135deg, #7d3d36, #a25349);
  color: #fff;
  box-shadow: 0 8px 18px rgba(138, 75, 66, 0.16);
}

.danger-btn:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  transform: none;
  box-shadow: none;
}

.ghost,
.icon-btn {
  background: transparent;
  color: var(--muted);
}

.icon-btn {
  width: 38px;
  min-height: 38px;
  padding: 0;
}

.primary:hover,
.secondary:hover,
.danger-btn:hover:not(:disabled),
.ghost:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.primary:hover {
  background: linear-gradient(135deg, #111111, #4a4a4a);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

.secondary:hover {
  border-color: #c8c8c8;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
}

.danger-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #6e332d, #b15c51);
  box-shadow: 0 12px 24px rgba(138, 75, 66, 0.2);
}

.ghost:hover,
.icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.danger {
  color: var(--red);
}

.error {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.app-shell {
  position: fixed;
  inset: 0;
  z-index: 1;
  height: 100vh;
  width: 100vw;
  display: grid;
  grid-template-columns: 312px 1fr;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% -10%, rgba(255, 255, 255, 0.86), transparent 30%),
    linear-gradient(135deg, #f4f4f4 0%, #e8e8e8 46%, #f1f1f1 100%);
}

.sidebar {
  height: 100vh;
  padding: 20px;
  background: #1e1e1e;
  color: #f4f4f4;
  overflow: auto;
}

.sidebar .mark {
  margin-bottom: 28px;
}

.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.drawer-close {
  display: none;
  color: rgba(255, 255, 255, 0.76);
}

.sidebar .mark-badge {
  background: #dce9df;
}

.nav-stat {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-tile {
  padding: 13px;
  border: 1px solid rgba(238, 245, 240, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.stat-tile b {
  display: block;
  font-size: 20px;
}

.stat-tile span {
  display: block;
  color: rgba(238, 245, 240, 0.68);
  font-size: 11px;
  margin-top: 2px;
}

.filter-stack {
  display: grid;
  gap: 12px;
}

.filter-title {
  margin: 20px 0 8px;
  color: rgba(238, 245, 240, 0.72);
  font-size: 12px;
  font-weight: 800;
}

.sidebar .field span {
  color: rgba(238, 245, 240, 0.68);
}

.sidebar .field input,
.sidebar .field select {
  border-color: rgba(238, 245, 240, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar .field input::placeholder {
  color: rgba(238, 245, 240, 0.45);
}

.sidebar option {
  color: var(--ink);
}

.workspace {
  min-width: 0;
  height: 100vh;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.title-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.headline h1 {
  margin: 0 0 6px;
  font-size: clamp(22px, 2.4vw, 32px);
}

.headline p {
  margin: 0;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.analytics-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  background: linear-gradient(145deg, #ffffff 0%, #f8f8f8 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.metric-green {
  background: linear-gradient(145deg, #ffffff 0%, #eef7f1 100%);
  border-color: #d4e6da;
}

.metric-red {
  background: linear-gradient(145deg, #ffffff 0%, #f8eeee 100%);
  border-color: #ead8d8;
}

.metric-blue {
  background: linear-gradient(145deg, #ffffff 0%, #eef4fa 100%);
  border-color: #d7e2ed;
}

.metric-up {
  background: linear-gradient(145deg, #ffffff 0%, #edf6f2 100%);
  border-color: #cfe4d8;
}

.metric-down {
  background: linear-gradient(145deg, #ffffff 0%, #f7efed 100%);
  border-color: #ead5cf;
}

.metric-neutral {
  background: linear-gradient(145deg, #ffffff 0%, #f5f5f5 100%);
  border-color: #dddddd;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-card b {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.metric-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
}

.mini-gantt {
  background: linear-gradient(145deg, #ffffff 0%, #f7f7f7 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.mini-gantt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.mini-gantt-head b {
  font-size: 14px;
}

.mini-gantt-head span {
  color: var(--muted);
  font-size: 12px;
}

.gantt-row {
  display: grid;
  grid-template-columns: 42px 1fr 44px;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  color: var(--muted);
  font-size: 12px;
}

.gantt-row div {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #eeeeee;
}

.gantt-row i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--bar-color), color-mix(in srgb, var(--bar-color) 72%, #ffffff));
}

.gantt-row b {
  color: var(--ink);
  text-align: right;
}

.filter-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  background: linear-gradient(145deg, #ffffff 0%, #f9f9f9 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.filter-summary span,
.filter-summary em {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-summary b {
  display: block;
  margin-top: 2px;
  font-size: 20px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.filter-chips span {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #d4d4d4;
  border-radius: 999px;
  background: #f5f5f5;
  color: #333;
  padding: 0 10px;
  font-size: 12px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  align-items: start;
}

.table-panel,
.detail-panel,
.modal-panel {
  min-width: 0;
  background: linear-gradient(180deg, #ffffff 0%, #fcfcfc 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(23, 33, 29, 0.06);
}

.table-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.table-tools b {
  font-size: 15px;
}

.bulk-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.bulk-actions span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  max-height: calc(100vh - 430px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

.select-col {
  width: 42px;
  min-width: 42px;
  padding-left: 14px;
  padding-right: 6px;
  text-align: center;
}

.select-col input {
  width: 16px;
  height: 16px;
  accent-color: #333333;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f5f5f5;
  color: var(--muted);
  font-size: 11px;
}

tbody tr {
  transition:
    background 0.15s ease,
    box-shadow 0.15s ease;
}

tbody tr:hover,
tbody tr.active {
  background: #f6f6f6;
  box-shadow: inset 3px 0 0 #8d8d8d;
}

.item-code {
  display: grid;
  gap: 2px;
  font-weight: 800;
}

.item-code span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill.ok {
  background: var(--status-green-bg);
  color: var(--status-green-ink);
}

.pill.warn {
  background: var(--status-red-bg);
  color: var(--status-red-ink);
}

.pill.out {
  background: var(--status-blue-bg);
  color: var(--status-blue-ink);
}

.pill.bad {
  background: var(--status-dark-bg);
  color: var(--status-dark-ink);
}

.detail-panel {
  position: sticky;
  top: 22px;
  overflow: hidden;
}

.detail-empty {
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.detail-hero {
  padding: 16px;
  background: linear-gradient(145deg, #f9f9f9 0%, #eeeeee 100%);
  border-bottom: 1px solid var(--line);
}

.detail-hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-hero h2 {
  margin: 0;
  font-size: 24px;
}

.detail-hero p {
  margin: 6px 0 0;
  color: var(--muted);
}

.photo-frame {
  margin-top: 14px;
  display: grid;
  place-items: center;
  overflow: auto;
  border: 1px dashed #c8c8c8;
  border-radius: 8px;
  min-height: 280px;
  max-height: 620px;
  background:
    linear-gradient(45deg, #fafafa 25%, transparent 25%),
    linear-gradient(-45deg, #fafafa 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #fafafa 75%),
    linear-gradient(-45deg, transparent 75%, #fafafa 75%);
  background-size: 26px 26px;
  background-position: 0 0, 0 13px, 13px -13px, -13px 0;
}

.photo-frame img {
  width: 100%;
  height: auto;
  max-height: 560px;
  object-fit: contain;
  background: #fff;
}

.photo-frame img.needs-rotate {
  width: auto;
  max-width: none;
  height: min(72vw, 520px);
  max-height: none;
  transform: rotate(270deg);
}

.photo-frame .placeholder {
  display: grid;
  place-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.barcode {
  margin-top: 14px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.barcode img {
  max-width: 170px;
  height: auto;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
}

.pagination div {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pagination button {
  min-width: 36px;
}

.pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.detail-body {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.info {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  min-width: 0;
}

.info span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.info b {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.section-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(20, 35, 29, 0.58);
}

.modal-backdrop.open {
  display: grid;
}

.modal-panel {
  width: min(1080px, 100%);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.modal-head,
.modal-foot {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal-head h2 {
  margin: 0;
}

.modal-body {
  padding: 20px;
  overflow: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .wide {
  grid-column: span 2;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.scan-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  align-items: center;
}

.scan-trigger {
  border-color: var(--line);
  background: linear-gradient(180deg, #ffffff, #f4f4f4);
  color: var(--ink);
}

.scanner {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0f1714;
}

.scanner.open {
  display: block;
}

.scanner video {
  width: 100%;
  min-height: 240px;
  max-height: 320px;
  display: block;
  object-fit: cover;
  background: #050505;
}

.scanner-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  color: #fff;
}

.file-preview {
  display: grid;
  gap: 8px;
}

.preview-thumb {
  width: 100%;
  min-height: 120px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px dashed #c7d3cb;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
}

.preview-thumb img {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
}

.mobile-filter {
  display: none;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 15;
    width: min(340px, 88vw);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

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

  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 14;
    display: none;
    background: rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(2px);
  }

  .drawer-backdrop.open {
    display: block;
  }

  .drawer-close {
    display: inline-flex;
  }

  .mobile-filter {
    display: inline-flex;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .login-panel {
    grid-template-columns: 1fr;
  }

  .login-brand {
    min-height: 320px;
    padding: 32px;
  }

  .login-brand h1 {
    font-size: clamp(30px, 8vw, 42px);
  }

  .login-form {
    padding: 32px;
  }

  .workspace {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .title-lockup {
    align-items: flex-start;
  }

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .actions button {
    flex: 1;
  }

  .filter-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .wide,
  .form-grid .full {
    grid-column: auto;
  }

  .scanner video {
    min-height: 260px;
    max-height: 48vh;
  }
}

@media (max-width: 520px) {
  .login-shell {
    padding: 16px;
  }

  .login-brand {
    min-height: 260px;
    padding: 26px;
  }

  .login-brand h1 {
    font-size: clamp(28px, 11vw, 36px);
  }

  .login-brand p {
    font-size: 13px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .topbar-logo {
    width: 48px;
  }

  .table-tools {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-backdrop {
    padding: 0;
  }

  .modal-panel {
    min-height: 100vh;
    border-radius: 0;
  }
}
