:root {
  --ink: #25312d;
  --muted: #6d7974;
  --line: #dce4df;
  --paper: #f6f8f5;
  --white: #ffffff;
  --green: #315f52;
  --green-dark: #24493f;
  --green-soft: #e4eee9;
  --gold: #b68a43;
  --gold-soft: #f4ead8;
  --red: #a34a43;
  --red-soft: #f8e7e4;
  --blue: #3f7390;
  --blue-soft: #e7f1f5;
  --shadow: 0 18px 45px rgba(37, 49, 45, .08);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { background: var(--green-dark); color: white; padding: 28px 20px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); border-radius: 50%; font-family: serif; font-size: 22px; }
.brand strong { display: block; letter-spacing: .08em; }
.brand small { display: block; color: rgba(255,255,255,.62); margin-top: 3px; }
nav { display: grid; gap: 7px; }
.nav-item { width: 100%; border: 0; color: rgba(255,255,255,.72); background: transparent; border-radius: 12px; padding: 12px; display: flex; align-items: center; gap: 11px; text-align: left; }
.nav-item span { width: 27px; height: 27px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.24); border-radius: 8px; font-size: 12px; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.11); color: white; }
.sidebar-note { margin-top: auto; border-top: 1px solid rgba(255,255,255,.15); padding: 20px 8px 0; }
.sidebar-note strong { color: #f5dcad; font-size: 14px; }
.sidebar-note p { color: rgba(255,255,255,.62); font-size: 12px; line-height: 1.65; }

main { min-width: 0; }
.topbar { min-height: 102px; background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line); padding: 22px 34px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 10; backdrop-filter: blur(12px); }
.eyebrow { color: var(--gold); text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 800; margin: 0 0 4px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 25px; margin-bottom: 0; font-weight: 720; }
h2 { font-size: 21px; margin-bottom: 0; }
h3 { font-size: 16px; }
.actor-switcher { display: grid; gap: 5px; min-width: 190px; }
.actor-switcher label { font-size: 11px; color: var(--muted); }
.actor-switcher select { border: 1px solid var(--line); background: var(--white); border-radius: 10px; padding: 9px 12px; }
.content { padding: 28px 34px 60px; max-width: 1500px; margin: 0 auto; }
.notice { margin: 18px 34px 0; padding: 12px 16px; border-radius: 10px; background: var(--green-soft); color: var(--green-dark); }
.notice.error { background: var(--red-soft); color: var(--red); }
.hidden { display: none !important; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.toolbar-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.scope-summary { color: var(--muted); font-size: 12px; margin-right: auto; }
.date-control { display: flex; align-items: center; border: 1px solid var(--line); background: white; border-radius: 12px; padding: 4px; }
.date-control input { border: 0; padding: 7px 9px; color: var(--ink); }
.date-control button { border: 0; background: transparent; padding: 7px 10px; color: var(--green); }
.button { border: 1px solid transparent; border-radius: 10px; padding: 9px 14px; font-weight: 650; }
.button.primary { background: var(--green); color: white; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: var(--gold-soft); color: #745423; }
.button.ghost { border-color: var(--line); background: white; color: var(--ink); }
.button.danger { background: var(--red-soft); color: var(--red); }
.button.small { padding: 6px 10px; font-size: 12px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: white; border: 1px solid var(--line); border-radius: 14px; padding: 17px; }
.stat strong { display: block; font-size: 25px; }
.stat span { color: var(--muted); font-size: 12px; }
.status-stat { position: relative; overflow: hidden; }
.status-stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; }
.status-stat.upcoming::before { background: var(--gold); }
.status-stat.in-progress::before { background: var(--blue); }
.status-stat.completed::before { background: var(--green); }
.status-stat.cancelled::before { background: var(--red); }

.panel { background: white; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.panel-head h2, .panel-head h3 { margin-bottom: 0; }
.panel-body { padding: 20px; }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty strong { display: block; color: var(--ink); margin-bottom: 8px; }

.task-list { display: grid; }
.task-card { display: grid; grid-template-columns: 100px minmax(320px, 1fr) minmax(250px, 360px) 92px; gap: 24px; align-items: center; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.task-card:last-child { border-bottom: 0; }
.task-card { position: relative; border-left: 5px solid transparent; }
.task-card.status-upcoming { border-left-color: var(--gold); background: linear-gradient(90deg, rgba(244,234,216,.64), white 28%); }
.task-card.status-in-progress { border-left-color: var(--blue); background: linear-gradient(90deg, rgba(231,241,245,.9), white 32%); }
.task-card.status-completed { border-left-color: var(--green); background: linear-gradient(90deg, rgba(228,238,233,.78), white 28%); }
.task-card.status-cancelled { border-left-color: var(--red); opacity: .58; background: #fafafa; }
.time { color: var(--green); font-weight: 850; font-size: 20px; letter-spacing: .01em; }
.time small { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 750; margin-top: 5px; }
.time small i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-upcoming .time small { color: #9b6c24; }
.status-in-progress .time small { color: var(--blue); }
.status-completed .time small { color: var(--green); }
.status-cancelled .time small { color: var(--red); }
.task-main h3 { margin: 0 0 9px; font-size: 20px; line-height: 1.3; }
.task-main .case-link { color: #946b2d; font-size: 14px; font-weight: 800; margin-bottom: 7px; display: block; }
.task-location { display: flex; align-items: baseline; gap: 8px; font-size: 14px; }
.task-location > span, .task-field-label { color: var(--muted); font-size: 12px; font-weight: 750; }
.task-location strong { font-size: 15px; }
.task-instruction { color: var(--muted); margin: 7px 0 0; font-size: 14px; line-height: 1.55; }
.assignment-block { min-width: 0; }
.task-field-label { display: block; margin-bottom: 8px; }
.assignment-stack { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 7px 11px; background: var(--green-soft); color: var(--green-dark); font-size: 13px; font-weight: 800; }
.chip.vendor { background: var(--gold-soft); color: #745423; }
.chip.muted { background: #edf0ee; color: var(--muted); text-decoration: line-through; }
.chip.reported { background: #e8edf7; color: #3f5e8b; text-decoration: none; }
.chip.completed { background: #dceddf; color: #23613d; text-decoration: none; }
.task-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; max-width: 260px; }
.task-action-menu { position: relative; }
.task-action-menu summary { list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: 9px; background: white; padding: 9px 13px; font-size: 14px; font-weight: 800; }
.task-action-menu summary::-webkit-details-marker { display: none; }
.task-action-menu[open] summary { border-color: #a9beb5; }
.task-action-menu > div { position: absolute; z-index: 20; right: 0; top: calc(100% + 6px); min-width: 145px; padding: 6px; border: 1px solid var(--line); border-radius: 11px; background: white; box-shadow: 0 14px 36px rgba(37,49,45,.16); display: grid; }
.menu-action { border: 0; background: transparent; text-align: left; padding: 9px 10px; border-radius: 7px; color: var(--ink); font-weight: 650; white-space: nowrap; }
.menu-action:hover { background: var(--green-soft); }
.menu-action.danger-text { color: var(--red); }
.status-legend { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.legend { font-size: 12px; font-weight: 750; padding: 5px 9px; border-radius: 999px; }
.legend.upcoming { color: #845e24; background: var(--gold-soft); }
.legend.in-progress { color: #315f77; background: var(--blue-soft); }
.completed-archive { margin-top: 16px; box-shadow: none; }
.completed-archive summary { list-style: none; cursor: pointer; padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--green-dark); }
.completed-archive summary::-webkit-details-marker { display: none; }
.completed-archive summary span { display: grid; gap: 4px; }
.completed-archive summary small { color: var(--muted); font-weight: 400; }
.completed-archive summary b { padding: 5px 9px; border-radius: 999px; background: var(--green-soft); font-size: 12px; }
.cancelled-archive summary { color: var(--red); }
.cancelled-archive summary b { background: var(--red-soft); }

.case-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.case-card { text-align: left; background: white; border: 1px solid var(--line); border-radius: 15px; padding: 18px; box-shadow: 0 8px 24px rgba(37,49,45,.04); }
.case-card:hover { border-color: #a9beb5; transform: translateY(-1px); }
.case-card .case-no { color: var(--gold); font-weight: 800; font-size: 12px; }
.case-card h3 { font-size: 18px; margin: 10px 0 4px; }
.case-card p { color: var(--muted); font-size: 13px; min-height: 20px; }
.case-meta { display: flex; gap: 12px; padding-top: 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

.case-detail { display: grid; gap: 18px; }
.case-summary { display: grid; grid-template-columns: 1fr auto; gap: 20px; }
.case-summary dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 18px 0 0; }
dt { color: var(--muted); font-size: 11px; margin-bottom: 5px; }
dd { margin: 0; }
.timeline { display: grid; gap: 12px; }
.timeline-item { border-left: 3px solid var(--gold); padding: 2px 0 2px 15px; display: grid; grid-template-columns: 120px 1fr auto; gap: 15px; align-items: start; }
.timeline-item .date { color: var(--green); font-weight: 800; }
.timeline-item p { color: var(--muted); margin: 4px 0 0; font-size: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-size: 11px; letter-spacing: .04em; background: #fafbfa; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.wrap { white-space: normal; min-width: 160px; }

.principles { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.principle { padding: 22px; background: white; border: 1px solid var(--line); border-radius: 15px; }
.principle strong { display: block; margin-bottom: 8px; }
.principle p { color: var(--muted); line-height: 1.7; margin: 0; }
.month-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.employee-total { background: white; border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.employee-total strong { display: block; font-size: 17px; margin-bottom: 5px; }
.employee-total span { color: var(--muted); font-size: 12px; }
.employee-total b { display: block; margin-top: 9px; color: var(--green); font-size: 13px; }
.employee-total-button { appearance: none; width: 100%; color: inherit; font: inherit; text-align: left; cursor: pointer; transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease; }
.employee-total-button:hover { transform: translateY(-2px); border-color: var(--gold); box-shadow: 0 10px 24px rgba(24, 55, 48, .08); }
.employee-total-button:focus-visible { outline: 3px solid rgba(188, 134, 43, .28); outline-offset: 2px; }
.employee-total-button.active { border-color: var(--green); box-shadow: inset 4px 0 0 var(--green); }
.employee-total-button em { display: block; margin-top: 12px; color: var(--gold); font-size: 12px; font-style: normal; font-weight: 800; }
.ledger-focus { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 18px 0; padding: 16px 18px; border: 1px solid #cbded6; border-radius: 14px; background: #eef6f2; }
.ledger-focus span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.ledger-focus strong { font-size: 18px; }
.month-note { padding: 12px 15px; border-radius: 12px; background: var(--gold-soft); color: #745423; font-size: 13px; }
.change-warning { width: 100%; margin-top: 12px; border: 1px solid #e2bd82; background: #fff8ec; border-radius: 12px; padding: 13px 15px; color: #745423; text-align: left; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.change-warning span { font-size: 12px; }
.change-count { display: flex; align-items: baseline; gap: 8px; color: var(--red); }
.change-count strong { font-size: 25px; }
.change-count span { font-size: 12px; }
.change-list { display: grid; }
.change-row { display: grid; grid-template-columns: 105px minmax(260px, 1fr) 110px auto; gap: 16px; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--line); border-left: 5px solid var(--green); }
.change-row:last-child { border-bottom: 0; }
.change-row.pending { border-left-color: var(--gold); background: linear-gradient(90deg, rgba(244,234,216,.6), white 28%); }
.change-row.reviewed { opacity: .72; }
.change-date { display: grid; gap: 3px; }
.change-date span { color: var(--muted); font-size: 12px; }
.change-main { display: grid; gap: 4px; }
.change-main p { margin: 0; color: var(--muted); font-size: 12px; }
.change-status { justify-self: start; border-radius: 999px; padding: 5px 9px; background: var(--gold-soft); color: #745423; font-size: 11px; font-weight: 750; }
.change-row.reviewed .change-status { background: var(--green-soft); color: var(--green-dark); }
.price-field { display: flex; align-items: center; gap: 5px; min-width: 135px; font-weight: 700; }
.price-field span { margin: 0; font-size: 13px; color: var(--ink); }
.price-field input { width: 105px; padding: 7px 8px; }
.amount-cell { color: var(--green-dark); font-weight: 750; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(620px, calc(100vw - 28px)); box-shadow: 0 28px 100px rgba(20,30,26,.28); color: var(--ink); }
#task-dialog { width: min(780px, calc(100vw - 28px)); }
dialog::backdrop { background: rgba(24,34,30,.55); backdrop-filter: blur(2px); }
dialog form { padding: 24px; display: grid; gap: 15px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; }
.icon-button { border: 0; background: #eef2ef; border-radius: 50%; width: 32px; height: 32px; font-size: 21px; color: var(--muted); }
.form-hint { background: var(--green-soft); color: var(--green-dark); padding: 11px 13px; border-radius: 10px; font-size: 12px; line-height: 1.55; margin: 0; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
label span { color: var(--muted); font-size: 10px; font-weight: 500; margin-left: 5px; }
fieldset { border: 1px solid #ccd7d1; border-radius: 11px; padding: 12px; margin: 0; }
legend { padding: 0 5px; font-size: 13px; font-weight: 700; }
legend span { color: var(--muted); font-size: 10px; font-weight: 500; margin-left: 5px; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.check-option { display: flex; align-items: center; gap: 8px; padding: 9px; border-radius: 9px; background: #f7f9f7; font-weight: 600; }
.check-option input { width: auto; margin: 0; }
.assignee-picker { padding: 16px; }
.assignee-picker-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.assignee-picker-columns section { min-width: 0; }
.assignee-picker-columns h3 { margin: 0 0 9px; font-size: 15px; }
.assignee-check-list { display: grid; gap: 7px; }
.assignee-check { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: #f9fbfa; cursor: pointer; }
.assignee-check:hover { border-color: #9fb8ae; background: var(--green-soft); }
.assignee-check input { width: 18px; height: 18px; margin: 0; flex: 0 0 auto; accent-color: var(--green); }
.assignee-check span { display: grid; gap: 1px; margin: 0; color: var(--ink); }
.assignee-check strong { font-size: 14px; }
.assignee-check small { color: var(--muted); font-size: 11px; }
.assignee-empty { color: var(--muted); font-size: 13px; margin: 0; padding: 10px; }
input, select, textarea { width: 100%; border: 1px solid #ccd7d1; border-radius: 10px; padding: 10px 11px; background: white; color: var(--ink); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(49,95,82,.12); border-color: var(--green); }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 5px; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding: 20px 12px; }
  .brand { padding: 0 8px 24px; justify-content: center; }
  .brand div, .nav-item:not(.active) { font-size: 0; }
  .nav-item { justify-content: center; font-size: 0; }
  .nav-item span { font-size: 12px; }
  .sidebar-note { display: none; }
  .task-card { grid-template-columns: 65px 1fr; }
  .assignment-block, .task-actions { grid-column: 2; justify-content: flex-start; }
  .case-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .month-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 30; bottom: 0; top: auto; width: 100%; height: 64px; padding: 7px 10px; }
  .brand, .sidebar-note { display: none; }
  nav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
  .nav-item, .nav-item:not(.active) { display: grid; justify-items: center; padding: 4px; font-size: 9px; gap: 2px; }
  .nav-item span { width: 25px; height: 25px; }
  .topbar { padding: 16px 18px; min-height: 86px; }
  .topbar h1 { font-size: 20px; }
  .actor-switcher { min-width: 145px; }
  .content { padding: 20px 15px 92px; }
  .notice { margin: 12px 15px 0; }
  .stats, .case-grid, .principles, .month-summary, .check-grid { grid-template-columns: 1fr; }
  .task-card { grid-template-columns: 55px 1fr; gap: 10px; padding: 15px; }
  .case-summary, .case-summary dl, .two-cols, .assignee-picker-columns { grid-template-columns: 1fr; }
  .timeline-item { grid-template-columns: 90px 1fr; }
  .timeline-item .button { grid-column: 2; justify-self: start; }
  .change-row { grid-template-columns: 82px 1fr; gap: 9px; padding: 14px; }
  .change-status, .change-row .button { grid-column: 2; }
  .change-warning { align-items: flex-start; flex-direction: column; }
}

/* LINE 綁定 */
.line-table td { vertical-align: middle; }
.line-who, .line-user { display: flex; align-items: center; gap: 10px; }
.line-who div, .line-user div { display: flex; flex-direction: column; min-width: 0; }
.line-who span, .line-user span { color: var(--muted); font-size: 12px; }
.line-user { padding: 12px 20px; border-bottom: 1px solid var(--line); }
.line-user:last-child { border-bottom: 0; }
.line-user div { flex: 1; }
.line-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; background: var(--green-soft); }
.line-avatar.placeholder { display: inline-flex; align-items: center; justify-content: center; color: var(--green-dark); font-weight: 800; font-size: 14px; }
.bind-code { display: flex; flex-direction: column; gap: 2px; }
.bind-code code { font-size: 22px; font-weight: 800; letter-spacing: 0.18em; color: var(--green-dark); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.bind-code span { color: var(--muted); font-size: 12px; }
.code-mini { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; letter-spacing: 0.1em; min-width: 72px; }
.bind-tag { display: inline-block; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.bind-tag.formal, .bind-tag.code-used { background: var(--green-soft); color: var(--green-dark); }
.bind-tag.demo, .bind-tag.code-active { background: var(--gold-soft); color: #745423; }
.bind-tag.none, .bind-tag.code-revoked, .bind-tag.code-expired { background: var(--paper); color: var(--muted); }
.line-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.line-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
@media (max-width: 860px) { .line-columns { grid-template-columns: 1fr; } .line-actions { justify-content: flex-start; } }
