:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-2: #f8faf8;
  --ink: #182722;
  --muted: #65756e;
  --line: #e0e7e2;
  --brand: #106b50;
  --brand-ink: #0b4d39;
  --brand-soft: #e6f2ec;
  --warn: #a45a09;
  --warn-soft: #fdf3e3;
  --danger: #ac2c22;
  --danger-soft: #fdeceb;
  --ok: #106b50;
  --shadow: 0 1px 2px rgba(20, 45, 35, .06), 0 8px 24px rgba(20, 45, 35, .06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: 15px; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.3; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0 0 .8em; }
ul { margin: 0; padding-left: 1.2em; }

/* ------------------------------------------------------------ 版面 */
.app { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 16px; flex: none;
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--ink); font-size: 14.5px; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.nav .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warn); margin-left: auto; }
.nav-section { font-size: 11px; letter-spacing: .08em; color: var(--muted); padding: 16px 12px 6px; }
.sidebar-foot { margin-top: 20px; padding: 14px 10px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 26px; background: rgba(244, 247, 245, .92); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(8px);
}
.topbar-title { font-weight: 650; font-size: 16px; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
}
.content { padding: 22px 26px 60px; max-width: 1180px; width: 100%; }
.mobile-nav { display: none; }

/* ------------------------------------------------------------ 元件 */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; min-height: 38px; border-radius: 10px; cursor: pointer; font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-soft); }
.btn-danger { color: var(--danger); border-color: #f0cfcc; background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px;
  font-size: 12px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.ok { background: var(--brand-soft); color: var(--brand-ink); border-color: #cbe5d9; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: #f3dcb8; }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: #f2cfcc; }
.chip.brand { background: var(--brand); color: #fff; border-color: var(--brand); }

.list { display: flex; flex-direction: column; }
.list-item {
  padding: 14px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px;
  align-items: flex-start; justify-content: space-between;
}
.list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.list-item:first-child { padding-top: 0; }
.list-item .main-text { min-width: 0; }
.list-item h3 { margin: 0 0 3px; font-size: 15px; }
.list-item .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover h3 { color: var(--brand); }

.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 12.5px; color: var(--muted); }
.stat.warn .num { color: var(--warn); }
.stat.danger .num { color: var(--danger); }
.stat.ok .num { color: var(--ok); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > label { font-size: 13px; color: var(--muted); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #cfd9d3; border-radius: 10px;
  background: #fff; color: var(--ink); min-height: 40px;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid #b9dbcd; border-color: var(--brand); }
.hint { font-size: 12px; color: var(--muted); }
.error-text { color: var(--danger); font-size: 13px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.table tr:last-child td { border-bottom: 0; }

.empty { text-align: center; padding: 32px 12px; color: var(--muted); font-size: 14px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner {
  width: 18px; height: 18px; border: 2px solid #cfe0d7; border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar { height: 9px; border-radius: 99px; background: #e9efeb; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }
.bar.warn > span { background: #c98a2e; }
.result-row { display: grid; grid-template-columns: minmax(0, 1fr) 56px; gap: 10px; align-items: center; margin-bottom: 10px; }
.result-row .label { font-size: 14px; margin-bottom: 5px; }
.result-row .count { text-align: right; font-variant-numeric: tabular-nums; font-size: 13.5px; }

.banner {
  border-radius: 12px; padding: 12px 14px; font-size: 13.5px; border: 1px solid;
  background: var(--brand-soft); border-color: #cbe5d9; color: var(--brand-ink);
}
.banner.warn { background: var(--warn-soft); border-color: #f3dcb8; color: #7a4307; }
.banner.danger { background: var(--danger-soft); border-color: #f2cfcc; color: #7d211a; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 12px;
  color: var(--muted); cursor: pointer; white-space: nowrap; font-size: 14px;
}
.tabs button.active { color: var(--brand-ink); border-bottom-color: var(--brand); font-weight: 600; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .input, .filters .select { width: auto; min-width: 140px; }

/* ------------------------------------------------------------ 登入 */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 10% -10%, #e4f1ea 0%, transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 430px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.auth-foot { margin-top: 18px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ------------------------------------------------------------ 彈窗與提示 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 28, 22, .42); display: grid; place-items: center;
  padding: 20px; z-index: 100; animation: fade .15s ease-out;
}
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 620px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 24px 70px rgba(10, 30, 22, .28);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px;
  position: sticky; bottom: 0; background: var(--surface); }
.icon-btn { border: 0; background: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }

.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: #1d3229; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: 340px; animation: fade .2s ease-out;
}
.toast.err { background: #6d221c; }
.toast.ok { background: #14523e; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 6px 10px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-nav {
    display: flex; gap: 2px; overflow-x: auto; padding: 8px 12px; background: var(--surface);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30;
  }
  .mobile-nav a {
    padding: 8px 11px; border-radius: 9px; font-size: 13.5px; color: var(--muted);
    white-space: nowrap; text-decoration: none;
  }
  .mobile-nav a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
  .topbar { display: none; }
  .content { padding: 16px 14px 80px; }
  .grid-2, .grid-3, .grid-4, .form-row, .detail-grid { grid-template-columns: 1fr; }
  h1 { font-size: 20px; }
  .card { padding: 15px; }
}
@media (max-width: 420px) {
  .stat .num { font-size: 22px; }
  .btn { min-height: 42px; }
}

/* 手機可用性（需求 15.3）：主要點擊區至少 44px、字號不小於 14px、
   表格在自身容器內橫向滾動而不撐破頁面。 */
@media (max-width: 600px) {
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 44px; padding: 10px 14px; font-size: 14px; }
  .input, .select, .textarea { min-height: 44px; font-size: 16px; } /* 16px 避免 iOS 自動放大 */
  .mobile-nav a { min-height: 44px; display: inline-flex; align-items: center; padding: 10px 12px; }
  .list-item { padding: 12px 14px; }
  .list-item h3 { font-size: 15px; }
  .small, .hint { font-size: 13.5px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .icon-btn { min-width: 44px; min-height: 44px; }
}

