:root {
  color-scheme: light;
  --ink: #17211e;
  --muted: #64716c;
  --line: #d6dfdb;
  --line-strong: #b8c8c1;
  --surface: #ffffff;
  --surface-soft: #f4f7f5;
  --page: #eaf1ee;
  --sidebar: #0d2923;
  --sidebar-active: #19483f;
  --green: #087d70;
  --green-dark: #075f56;
  --gold: #9b6810;
  --gold-soft: #fff5dc;
  --red: #b8322a;
  --red-soft: #fff1f0;
  --blue: #245a9b;
  --blue-soft: #edf4ff;
  --shadow: 0 8px 26px rgba(20, 45, 37, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--page); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

:focus-visible {
  outline: 3px solid rgba(36, 90, 155, .34);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

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

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 22px 18px;
  background: var(--sidebar);
  color: #f5fbf8;
  border-right: 1px solid #163a32;
}

.brand-block {
  display: grid;
  gap: 3px;
  padding: 18px 16px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
}

.brand-block strong { font-size: 30px; letter-spacing: 0; }
.brand-block span { color: #b9ccc5; font-weight: 700; }

.case-identity, .profile-block {
  display: grid;
  gap: 2px;
  margin-top: 16px;
  padding: 14px 15px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 8px;
  background: rgba(255, 255, 255, .035);
}

.case-identity span, .profile-block span { color: #aebfb9; font-size: 13px; }
.case-identity small { color: #d1ddd8; }

.section-nav { display: grid; gap: 4px; margin-top: 18px; }

.section-nav button {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 46px;
  padding: 7px 10px;
  color: #cfddd8;
  text-align: left;
  font-weight: 800;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
}

.section-nav button span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, .08);
  font-size: 13px;
}

.section-nav button small { color: #9fb7af; }
.section-nav button:hover { background: rgba(255, 255, 255, .055); }
.section-nav button.active { color: #fff; background: var(--sidebar-active); border-color: #2c665b; }
.section-nav button.active span { background: rgba(255, 255, 255, .14); }

.profile-block { margin-top: 18px; }

.main-content {
  min-width: 0;
  padding: 22px 28px 48px;
}

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

.topbar h1, .panel h2, .login-panel h1, dialog h2 { margin: 0; line-height: 1.2; }
.topbar h1 { font-size: 29px; }
.eyebrow { margin: 0 0 3px; color: var(--green); font-size: 12px; font-weight: 900; text-transform: uppercase; }

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

.button, .icon-button {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.button { padding: 9px 14px; }
.icon-button { display: grid; width: 42px; padding: 0; place-items: center; font-size: 23px; }
.button:hover, .icon-button:hover { border-color: var(--green); }
.button.primary { color: #fff; background: var(--green); border-color: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: #fff; }
.button.accent { color: #fff; background: var(--gold); border-color: var(--gold); }
.button.danger { color: #fff; background: var(--red); border-color: var(--red); }
.button.wide { width: 100%; }
.button.small { min-height: 34px; padding: 5px 9px; font-size: 13px; }

.save-state {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  gap: 7px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, .66);
}

.save-state i { width: 9px; height: 9px; border-radius: 50%; background: #8aa198; }
.save-state.saving i { background: var(--gold); }
.save-state.saved i { background: var(--green); }
.save-state.error i { background: var(--red); }

.alert {
  margin: 0 0 14px;
  padding: 11px 14px;
  border: 1px solid #9dc9bf;
  border-radius: 7px;
  background: #edf9f5;
  color: #145b50;
  font-weight: 700;
}

.alert.error { border-color: #f0aaa5; background: var(--red-soft); color: #8c221d; }
.alert.warning { border-color: #e4c57f; background: var(--gold-soft); color: #77500d; }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-strip > div {
  display: grid;
  gap: 2px;
  min-height: 82px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 3px 14px rgba(20, 45, 37, .04);
}

.summary-strip span { color: var(--muted); font-size: 12px; font-weight: 800; }
.summary-strip strong { align-self: end; font-size: 24px; }

.panel {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 { font-size: 20px; }
.panel-body { padding: 18px; }
.panel-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

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

.kpi {
  min-height: 96px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.kpi span, .kpi small { display: block; color: var(--muted); font-weight: 700; }
.kpi strong { display: block; margin: 5px 0 1px; font-size: 27px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.toolbar input[type="search"] { flex: 1 1 300px; }

input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

textarea { min-height: 82px; resize: vertical; }
input:read-only { background: var(--surface-soft); color: #56625e; }
input[type="checkbox"], input[type="radio"] { width: 18px; min-height: 18px; padding: 0; accent-color: var(--green); }

label { display: grid; align-content: start; gap: 5px; color: #52615b; font-size: 13px; font-weight: 800; }
label .required { color: var(--red); }
.field-note { margin: 4px 0 0; color: var(--muted); font-size: 12px; font-weight: 600; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.spaced-top { margin-top: 16px; }

.notice-box {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-left: 4px solid var(--green);
  background: #eef8f5;
  color: #31564d;
}

.notice-box.warning { border-left-color: var(--gold); background: var(--gold-soft); color: #68490f; }
.notice-box.danger { border-left-color: var(--red); background: var(--red-soft); color: #7c241f; }
.notice-box strong { display: block; margin-bottom: 2px; }

.case-table, .compact-table { width: 100%; border-collapse: collapse; }
.case-table th, .case-table td, .compact-table th, .compact-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.case-table th, .compact-table th { color: var(--muted); font-size: 12px; }
.case-table tr:last-child td, .compact-table tr:last-child td { border-bottom: 0; }
.case-table tr:hover td { background: #f7faf8; }
.case-name { display: grid; gap: 1px; }
.case-name strong { font-size: 16px; }
.case-name small { color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #edf1ef;
  color: #52615b;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.green { background: #dff3ec; color: #086355; }
.badge.gold { background: var(--gold-soft); color: #80560e; }
.badge.red { background: var(--red-soft); color: #a22721; }
.badge.blue { background: var(--blue-soft); color: var(--blue); }

.checklist { display: grid; gap: 8px; }
.check-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.6fr) minmax(140px, .7fr) minmax(130px, .6fr) minmax(150px, .8fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.check-name { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 14px; }
.check-name input { flex: 0 0 auto; }

.property-wrap { overflow-x: auto; }
.property-table { min-width: 1680px; table-layout: fixed; }
.property-table input, .property-table select { min-width: 86px; }
.property-table .property-name { min-width: 190px; }
.property-table .property-note { min-width: 230px; }
.property-table th:nth-child(1), .property-table td:nth-child(1) { width: 54px; min-width: 54px; text-align: center; }
.property-table th:nth-child(2), .property-table td:nth-child(2) { width: 110px; min-width: 110px; }
.property-table th:nth-child(3), .property-table td:nth-child(3) { width: 220px; min-width: 220px; }
.property-table th:nth-child(4), .property-table td:nth-child(4) { width: 120px; min-width: 120px; }
.property-table th:nth-child(5), .property-table td:nth-child(5),
.property-table th:nth-child(6), .property-table td:nth-child(6) { width: 86px; min-width: 86px; }
.property-table th:nth-child(7), .property-table td:nth-child(7) { width: 150px; min-width: 150px; }
.property-table th:nth-child(8), .property-table td:nth-child(8) { width: 126px; min-width: 126px; }
.property-table th:nth-child(9), .property-table td:nth-child(9) { width: 155px; min-width: 155px; }
.property-table th:nth-child(10), .property-table td:nth-child(10) { width: 130px; min-width: 130px; }
.property-table th:nth-child(11), .property-table td:nth-child(11) { width: 260px; min-width: 260px; }
.property-table th:nth-child(12), .property-table td:nth-child(12) { width: 155px; min-width: 155px; }

.warning-list { display: grid; gap: 8px; }
.warning-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.warning-item.error { border-color: #efb4af; background: #fff8f7; }
.warning-item.warning { border-color: #e5cb91; background: #fffbf1; }
.warning-item.info { background: #f4f8fb; }

.legal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.legal-item { padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-soft); }
.legal-item strong { display: block; margin-bottom: 3px; }

.signature-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.signature-card { min-height: 158px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.signature-card header { display: flex; justify-content: space-between; gap: 8px; }
.signature-card img { display: block; width: 100%; height: 68px; margin: 10px 0; object-fit: contain; border: 1px solid var(--line); background: #fff; }
.signature-card p { margin: 9px 0; color: var(--muted); font-size: 12px; }
.signature-empty { padding: 18px 0 7px; }

.workflow-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.audit-list { margin: 0; padding: 0; list-style: none; }
.audit-list li { display: grid; grid-template-columns: 180px 160px 1fr; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.audit-list li:last-child { border-bottom: 0; }
.audit-list time, .audit-list span { color: var(--muted); }

.empty-state { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; margin-bottom: 6px; color: var(--ink); font-size: 19px; }

.login-view { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: #e8f0ed; }
.login-panel { width: min(430px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.login-panel { display: grid; gap: 15px; }
.login-brand { padding-bottom: 16px; border-bottom: 1px solid var(--line); font-size: 30px; font-weight: 900; letter-spacing: 0; }

dialog {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .28);
}

dialog::backdrop { background: rgba(7, 24, 20, .58); }
dialog form { padding: 20px; }
dialog header, dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
dialog footer { justify-content: flex-end; margin-top: 15px; }
.signature-canvas-wrap { margin-top: 12px; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; background: #fff; touch-action: none; }
#signature-canvas { display: block; width: 100%; height: 200px; touch-action: none; }
.confirm-dialog { width: min(480px, calc(100vw - 28px)); }
.confirm-dialog p { white-space: pre-line; }
.evidence-dialog { width: min(760px, calc(100vw - 28px)); }
.evidence-list { display: grid; gap: 8px; margin-top: 16px; }
.evidence-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}
.evidence-row strong, .evidence-row small { display: block; overflow-wrap: anywhere; }
.evidence-row small { margin-top: 2px; color: var(--muted); }
.evidence-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }

.mobile-only { display: none; }

@media (max-width: 1120px) {
  .app-shell { grid-template-columns: 218px minmax(0, 1fr); }
  .sidebar { padding: 16px 12px; }
  .main-content { padding: 18px 20px 42px; }
  .summary-strip { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
  .signature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .check-row { grid-template-columns: minmax(220px, 1fr) minmax(140px, .6fr); }
}

@media (max-width: 780px) {
  body { font-size: 16px; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; overflow: visible; padding: 10px 12px; }
  .brand-block { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; }
  .brand-block strong { font-size: 23px; }
  .case-identity, .profile-block { display: none; }
  .section-nav { display: flex; gap: 6px; margin: 9px 0 1px; padding-bottom: 4px; overflow-x: auto; }
  .section-nav button { display: flex; flex: 0 0 auto; width: auto; min-height: 40px; padding: 5px 10px; }
  .section-nav button span, .section-nav button small { display: none; }
  .main-content { padding: 14px 12px 96px; }
  .topbar { display: grid; gap: 10px; }
  .topbar h1 { font-size: 25px; }
  .top-actions { justify-content: flex-start; flex-wrap: wrap; padding-bottom: 3px; }
  .top-actions .button, .top-actions .save-state { flex: 0 0 auto; }
  .summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-strip > div { min-height: 76px; padding: 10px 12px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .panel-header { align-items: flex-start; padding: 12px 14px; }
  .panel-body { padding: 14px; }
  .case-table thead { display: none; }
  .case-table, .case-table tbody, .case-table tr, .case-table td { display: block; width: 100%; }
  .case-table tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .case-table td { display: flex; justify-content: space-between; gap: 14px; padding: 5px 0; border: 0; }
  .case-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 800; }
  .case-table td:first-child { display: block; }
  .case-table td:first-child::before { display: none; }
  .check-row { grid-template-columns: 1fr; }
  .signature-grid, .legal-grid { grid-template-columns: 1fr; }
  .audit-list li { grid-template-columns: 1fr; gap: 2px; }
  .mobile-only { display: initial; }
}

@media (max-width: 420px) {
  .summary-strip, .kpi-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
  .summary-strip strong, .kpi strong { font-size: 21px; }
  .button { padding-inline: 11px; }
  .button.small { min-height: 42px; }
  .evidence-row { grid-template-columns: 1fr; }
  .evidence-actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
