:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #1c1b19;
  --muted: #5d5a52;
  --line: #dcd9d0;
  --line-strong: #bdb9ad;
  --accent: #1c6a4b;
  --accent-hover: #155239;
  --accent-soft: #e3f1ea;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fdf1d4;
  --side: #17211c;
  --side-text: #dfe9e3;
  --side-muted: #a4b5ab;
  --radius: 8px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scrollbar-color: var(--line-strong) var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  caret-color: var(--accent);
}

::selection {
  background: var(--accent);
  color: #fff;
}

[hidden] {
  display: none !important;
}

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

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login__form {
  width: min(100%, 360px);
  display: grid;
  gap: 16px;
}

.login__title {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 700;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  background: var(--side);
  color: var(--side-text);
}

.side__brand {
  margin: 0 8px 20px;
  font-size: 18px;
  font-weight: 700;
}

.side__brand span {
  font-weight: 400;
  color: var(--side-muted);
}

.side__nav {
  display: grid;
  gap: 2px;
}

.side__nav a {
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--side-text);
  text-decoration: none;
  transition: background-color 120ms ease;
}

.side__nav a:hover {
  background: rgba(255, 255, 255, 0.08);
}

.side__nav a[aria-current="page"] {
  background: #f5f4f0;
  color: var(--ink);
  font-weight: 700;
}

.side__foot {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 12px 12px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 14px;
  color: var(--side-muted);
}

.side__foot a,
.link-button {
  color: var(--side-text);
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.content {
  padding: 28px 32px 56px;
  outline: none;
}

.page-title {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 700;
}

.page-lead {
  margin: 0 0 24px;
  max-width: 72ch;
  color: var(--muted);
}

.section-title {
  margin: 32px 0 10px;
  font-size: 17px;
  font-weight: 700;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.facts div {
  padding: 12px 16px;
  box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line);
}

.facts dt {
  font-size: 13px;
  color: var(--muted);
}

.facts dd {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

th {
  padding: 9px 12px;
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  background: #faf9f6;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #fbfaf7;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.detail {
  min-width: 22ch;
  max-width: 60ch;
  overflow-wrap: anywhere;
}

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

.positive {
  color: var(--accent);
  font-weight: 700;
}

.negative {
  color: var(--danger);
  font-weight: 700;
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.tag--ok {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.tag--off {
  background: #ecebe6;
  color: var(--muted);
}

.tag--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.tag--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
}

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

.field__label {
  font-size: 13px;
  color: var(--muted);
}

.field__help {
  font-size: 13px;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select {
  height: 38px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  transition: border-color 120ms ease;
}

input:hover,
select:hover {
  border-color: var(--muted);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(28, 106, 75, 0.45);
  outline-offset: 1px;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.button:hover:not(:disabled) {
  background: #f0efea;
}

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

.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.button--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button--danger {
  border-color: var(--danger);
  color: var(--danger);
}

.button--danger:hover:not(:disabled) {
  background: var(--danger-soft);
}

.button--small {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.block {
  margin-bottom: 16px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.block__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 14px;
}

.block__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 18px;
  align-items: start;
}

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

.slot-group {
  margin-top: 18px;
}

.slot-group > summary {
  cursor: pointer;
  margin-bottom: 12px;
  font-weight: 700;
}

.slot-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.slot-row select {
  flex: 1;
  min-width: 0;
}

.math {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
  font-size: 14px;
}

.math div {
  display: flex;
  gap: 6px;
}

.math dt {
  color: var(--muted);
}

.math dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.block__foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.notice {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: #12402e;
}

.notice--error {
  background: var(--danger-soft);
  color: var(--danger);
}

.notice--warn {
  background: var(--warn-soft);
  color: #5c3c00;
}

.prose {
  max-width: 76ch;
  color: var(--muted);
}

.prose strong {
  color: var(--ink);
}

.dialog {
  width: min(92vw, 420px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.45);
}

.dialog::backdrop {
  background: rgba(23, 33, 28, 0.5);
}

.dialog__form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.dialog__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  max-width: min(90vw, 380px);
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 16px 30px -14px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast.is-error {
  background: var(--danger);
}

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

  .side {
    position: static;
    height: auto;
    padding: 12px;
  }

  .side__brand {
    margin-bottom: 10px;
  }

  .side__nav {
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding-bottom: 4px;
  }

  .side__nav a {
    white-space: nowrap;
  }

  .side__foot {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-top: 10px;
  }

  .content {
    padding: 20px 16px 48px;
  }

  .form-grid .field--wide {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

.media-thumb {
  display: block;
  max-width: 160px;
  max-height: 90px;
  border-radius: 4px;
}

.page-subtitle {
  margin: 28px 0 12px;
  font-size: 1.15rem;
}
