:root {
  color-scheme: light;
  --ink: #2f2021;
  --muted: #78696a;
  --line: #d8c9bb;
  --paper: #fffaf6;
  --canvas: #f5efe9;
  --deep: #540D15;
  --teal: #7a1d28;
  --teal-soft: #E0D4C6;
  --gold: #b38b62;
  --rose: #a9505c;
  --danger: #9b2632;
  --shadow: 0 18px 50px rgba(84, 13, 21, .10);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
.test-environment-banner {
  padding: 10px 18px;
  color: #540D15;
  background: #E0D4C6;
  border-bottom: 1px solid #c7b29d;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.loading-screen, .error-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top left, #eadfd3, transparent 38%), var(--canvas);
}
.loading-card, .error-card {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: center;
}
.loading-card strong, .loading-card small { display: block; }
.loading-card strong { margin-top: 16px; font-size: 20px; }
.loading-card small { margin-top: 8px; color: var(--muted); }
.login-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
.button-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #540D15, #7a1d28);
  font-family: Georgia, serif;
  font-size: 23px;
  box-shadow: 0 10px 24px rgba(84, 13, 21, .24);
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  color: white;
  background: linear-gradient(180deg, #540D15, #3d090f);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 2px; color: rgba(255,255,255,.66); font-size: 12px; }
.navigation { display: grid; gap: 7px; }
.nav-button {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: rgba(255,255,255,.78);
  background: transparent;
  text-align: left;
}
.nav-button:hover, .nav-button.active {
  color: white;
  border-color: rgba(255,255,255,.14);
  background: rgba(255,255,255,.10);
}
.sidebar-user { margin-top: auto; padding: 16px 10px 2px; border-top: 1px solid rgba(255,255,255,.14); }
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user small { margin-top: 4px; color: rgba(255,255,255,.6); overflow-wrap: anywhere; }
.role-badge { display: inline-flex; margin-top: 9px; padding: 4px 9px; border-radius: 999px; color: white; background: rgba(255,255,255,.14); font-size: 12px; font-weight: 800; }
.sidebar-logout { margin-top: 12px; padding: 0; border: 0; color: rgba(255,255,255,.7); background: transparent; font-size: 12px; }
.sidebar-logout:hover { color: white; text-decoration: underline; }

.workspace { min-width: 0; padding: 32px clamp(22px, 4vw, 58px) 54px; }
.topbar, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.topbar { margin-bottom: 28px; flex-wrap: wrap; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(25px, 3vw, 36px); }
h2 { margin-bottom: 8px; }
.eyebrow { margin-bottom: 6px; color: var(--teal); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.view-switcher-wrap { min-width: 210px; }
.view-switcher-wrap label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
select, input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
}
select:focus, input:focus { outline: 3px solid rgba(84, 13, 21, .14); border-color: var(--teal); }
.hero-card {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: clamp(24px, 4vw, 38px);
  border-radius: 24px;
  color: white;
  background: linear-gradient(135deg, var(--deep), var(--teal));
  box-shadow: var(--shadow);
}
.hero-card.executive { background: linear-gradient(135deg, #540D15, #8a3a43); }
.hero-card p:last-child { max-width: 680px; margin-bottom: 0; color: rgba(255,255,255,.78); }
.status-chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 18px; }
.summary-card, .empty-card, .account-list-panel, .account-editor, .account-empty,
.list-card, .form-card, .detail-card, .notification-item {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 8px 28px rgba(29,48,51,.06);
}
.summary-card { padding: 20px; }
.summary-card span, .summary-card strong, .summary-card small { display: block; }
.summary-card span, .summary-card small { color: var(--muted); }
.summary-card strong { margin: 8px 0; font-size: 30px; }
.empty-card { margin-top: 18px; padding: 28px; text-align: center; }
.empty-card p { margin-bottom: 0; color: var(--muted); }

.list-card, .form-card, .detail-card { margin-top: 18px; padding: 24px; }
.card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.card-heading h3, .card-heading p { margin-bottom: 0; }
.card-heading p { margin-top: 5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.compact { gap: 8px 12px; }
.full-span { grid-column: 1 / -1; }
.flow-tag { display: inline-flex; align-items: center; min-height: 34px; padding: 7px 12px; border: 1px solid #ccb9a7; border-radius: 999px; color: var(--deep); background: var(--teal-soft); font-size: 12px; font-weight: 800; white-space: nowrap; }
.registration-stepper { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 24px; }
.registration-step { display: flex; align-items: center; gap: 9px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 13px; color: var(--muted); background: white; text-align: left; }
.registration-step b { display: grid; width: 28px; height: 28px; place-items: center; flex: 0 0 auto; border-radius: 9px; color: var(--deep); background: var(--teal-soft); }
.registration-step.active { color: white; border-color: var(--deep); background: var(--deep); }
.registration-step.active b { color: var(--deep); background: white; }
.registration-step.done { color: var(--deep); border-color: #c5ae99; background: #f0e6dc; }
.registration-panel h3 { margin-bottom: 16px; }
.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.choice-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; padding: 18px; border: 1px solid var(--line); border-radius: 15px; background: white; cursor: pointer; }
.choice-card:has(input:checked) { border-color: var(--deep); box-shadow: inset 0 0 0 1px var(--deep); background: #fbf4ef; }
.choice-card input { width: 18px; height: 18px; grid-row: 1 / span 2; margin-top: 2px; accent-color: var(--deep); }
.choice-card small { color: var(--muted); line-height: 1.55; }
.entry-choice-grid { margin-top: 18px; }
.entry-choice { width: 100%; grid-template-columns: 1fr; color: var(--ink); text-align: left; }
.entry-choice:hover { border-color: var(--deep); box-shadow: inset 0 0 0 1px var(--deep); background: #fbf4ef; }
.inline-control { display: grid !important; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; margin: 0 !important; }
.compact-button { width: auto; padding: 9px 11px; white-space: nowrap; }
.review-toolbar { grid-template-columns: repeat(4, minmax(150px, 1fr)) auto; }
.modal-card { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; padding: 24px; border: 1px solid var(--line); border-radius: 20px; color: var(--ink); background: var(--paper); box-shadow: var(--shadow); }
.modal-card::backdrop { background: rgba(47, 32, 33, .45); }
.modal-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.special-conditions { margin-top: 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: #fbf6f1; }
.special-conditions summary { cursor: pointer; color: var(--deep); font-weight: 800; }
.special-conditions[open] summary { margin-bottom: 14px; }
.flow-note { margin-top: 16px; padding: 14px 16px; border-left: 4px solid var(--deep); border-radius: 0 12px 12px 0; color: #5d484a; background: var(--teal-soft); line-height: 1.65; }
.step-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.confirmation-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.confirmation-grid > div { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.confirmation-grid small, .confirmation-grid strong { display: block; }
.confirmation-grid small { margin-bottom: 5px; color: var(--muted); }
.static-row { cursor: default; }
.static-row:hover { transform: none; }
.muted-status { color: var(--muted); background: #eee7df; }
.list-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: end; margin-bottom: 16px; }
.list-toolbar .search-field span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.case-list { display: grid; gap: 10px; }
.case-row {
  display: grid;
  grid-template-columns: 145px minmax(190px, 1.1fr) minmax(220px, 1.5fr) 90px;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--ink);
  background: var(--paper);
  text-align: left;
  box-shadow: 0 5px 20px rgba(29,48,51,.04);
}
.case-row:hover { border-color: #c8ae96; background: #fffaf6; transform: translateY(-1px); }
.case-row strong, .case-row small { display: block; }
.case-row small { color: var(--muted); }
.case-main small { margin-top: 4px; }
.case-next strong { margin-top: 3px; font-size: 13px; }
.case-status { display: inline-flex; width: fit-content; padding: 5px 9px; border-radius: 999px; color: var(--teal); background: var(--teal-soft); font-size: 12px; font-weight: 800; }
.case-status.urgent { color: var(--danger); background: #fff0ef; }
.empty-inline { display: grid; place-items: center; min-height: 140px; padding: 24px; border: 1px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }
.empty-inline strong, .empty-inline small { display: block; }
.empty-inline small { margin-top: 6px; }
.detail-card { scroll-margin-top: 24px; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.detail-header h3 { margin-bottom: 5px; }
.detail-header p:last-child { color: var(--muted); }
.workflow-banner { display: flex; justify-content: space-between; gap: 18px; margin: 18px 0; padding: 15px 17px; border-radius: 14px; color: white; background: linear-gradient(135deg, var(--deep), var(--teal)); }
.workflow-banner strong, .workflow-banner small { display: block; }
.workflow-banner small { color: rgba(255,255,255,.76); text-align: right; }
.detail-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.detail-grid > div { padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.detail-grid small, .detail-grid strong { display: block; }
.detail-grid small { margin-bottom: 5px; color: var(--muted); }
.timeline { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.timeline h4 { margin: 0 0 12px; }
.timeline-item { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.timeline-item small { color: var(--muted); text-align: right; }
.step-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.step-pill { display: flex; align-items: center; gap: 7px; padding: 9px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); background: white; font-size: 12px; }
.step-pill b { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: #eee9e2; }
.step-pill.done { color: var(--deep); border-color: #c8ae96; background: var(--teal-soft); }
.step-pill.done b { color: white; background: var(--teal); }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.action-panel { margin: 0; padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.action-panel h4 { margin: 0 0 10px; }
.action-panel p { color: var(--muted); font-size: 13px; }
.action-panel summary { cursor: pointer; font-weight: 800; }
.action-panel[open] summary { margin-bottom: 14px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; }
.danger-text { color: var(--danger); }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filter-chip { padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: white; }
.filter-chip.active { color: white; border-color: var(--teal); background: var(--teal); }
.notification-list { display: grid; gap: 12px; }
.notification-item { display: flex; justify-content: space-between; gap: 22px; padding: 18px; }
.notification-item.is-read { opacity: .68; }
.notification-item h3 { margin: 8px 0 5px; }
.notification-item p { margin-bottom: 5px; color: var(--muted); }
.notification-item small { color: var(--muted); }
.notification-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 7px; }
.notification-actions .secondary-button { min-height: 36px; padding: 7px 10px; }
.mini-badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; color: var(--teal); background: var(--teal-soft); font-size: 11px; font-weight: 800; }
.metric-list { display: grid; gap: 10px; }
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 16px; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: white; }
.metric-row strong, .metric-row small { display: block; }
.metric-row small { color: var(--muted); }

.primary-button, .secondary-button {
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 800;
}
.primary-button { border: 1px solid var(--deep); color: white; background: var(--deep); }
.primary-button:hover { background: var(--teal); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: white; }
.section-heading { margin-bottom: 20px; }
.section-heading p:last-child { margin-bottom: 0; color: var(--muted); }
.account-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; align-items: start; }
.account-list-panel { padding: 16px; }
.search-field span, .field span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.account-list { display: grid; gap: 8px; margin-top: 14px; max-height: 68vh; overflow: auto; }
.account-item {
  width: 100%;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}
.account-item:hover, .account-item.active { border-color: #c8ae96; background: var(--teal-soft); }
.account-item strong, .account-item small { display: block; }
.account-item small { margin-top: 3px; color: var(--muted); overflow-wrap: anywhere; }
.account-item .mini-badge { display: inline-block; margin-top: 7px; margin-right: 5px; padding: 2px 7px; border-radius: 999px; color: var(--teal); background: white; font-size: 11px; font-weight: 800; }
.account-editor { padding: 24px; }
.editor-header { display: flex; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.editor-header .status-chip { color: var(--deep); border-color: #c7d8d6; background: var(--teal-soft); }
.field { display: block; margin-bottom: 14px; }
.toggle-field { display: flex; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.toggle-field input { width: 18px; height: 18px; margin-top: 2px; }
.toggle-field strong, .toggle-field small { display: block; }
.toggle-field small { margin-top: 3px; color: var(--muted); }
.permission-intro { margin: 24px 0 12px; }
.permission-intro strong, .permission-intro small { display: block; }
.permission-intro small { margin-top: 5px; color: var(--muted); }
.permission-groups { display: grid; gap: 14px; }
.permission-group { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.permission-group h4 { margin: 0 0 10px; }
.role-function-list { margin: 12px 0 0; padding-left: 20px; color: var(--ink); }
.role-function-list li + li { margin-top: 7px; }
.permission-option { display: flex; gap: 10px; padding: 9px 0; }
.permission-option + .permission-option { border-top: 1px dashed var(--line); }
.permission-option input { width: 18px; height: 18px; margin-top: 2px; }
.permission-option strong, .permission-option small { display: block; }
.permission-option small { margin-top: 3px; color: var(--muted); }
.permission-option.is-disabled { opacity: .5; }
.editor-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.account-empty { min-height: 300px; display: grid; place-content: center; padding: 30px; text-align: center; color: var(--muted); }
.account-empty p { margin-bottom: 0; }
.toast { position: fixed; right: 24px; top: 24px; z-index: 10; max-width: 420px; padding: 13px 16px; border-radius: 12px; color: white; background: var(--deep); box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px; }
  .navigation { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sidebar-user { display: none; }
  .account-layout { grid-template-columns: 1fr; }
  .account-list { max-height: 250px; }
  .case-row { grid-template-columns: 125px minmax(0, 1fr); }
  .case-next, .case-due { grid-column: 2; }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-grid { grid-template-columns: 1fr; }
  .review-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .workspace { padding: 22px 16px 40px; }
  .topbar, .section-heading, .hero-card { align-items: stretch; flex-direction: column; }
  .summary-grid { grid-template-columns: 1fr; }
  .navigation { grid-template-columns: 1fr 1fr; }
  .view-switcher-wrap { width: 100%; }
  .account-editor { padding: 18px; }
  .login-actions { align-items: stretch; flex-direction: column; }
  .form-grid, .detail-grid, .step-row, .metric-row, .registration-stepper, .choice-grid, .confirmation-grid { grid-template-columns: 1fr; }
  .full-span { grid-column: auto; }
  .list-toolbar { grid-template-columns: 1fr; }
  .review-toolbar, .inline-control { grid-template-columns: 1fr; }
  .case-row { grid-template-columns: 1fr; }
  .case-next, .case-due { grid-column: auto; }
  .detail-header, .workflow-banner, .notification-item { align-items: stretch; flex-direction: column; }
  .workflow-banner small, .timeline-item small { text-align: left; }
  .notification-actions { justify-content: flex-start; }
}
