:root {
  --paper: #ebebeb;
  --surface: #fff;
  --ink: #2d3436;
  --muted: #636e72;
  --line: #e2dcda;
  --sidebar: #faf7f6;
  --accent: #786461;
  --accent-hover: #675451;
  --soft: #f1ebe9;
  --nav-active: #e9dfdd;
  --danger: #9b352b;
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans TC", "PingFang HK", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  font-size: 15px;
}
*,*::before,*::after{box-sizing:border-box}
body{margin:0;min-width:280px}
a{color:var(--accent);text-underline-offset:.2em;text-decoration-thickness:1px}
a:hover{text-decoration:underline}
a:focus-visible,button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible,summary:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
p,h1,h2,h3,dl{margin:0}
h1{font-size:clamp(1.85rem,4vw,2.85rem);line-height:1.14;letter-spacing:-.04em;overflow-wrap:anywhere}
h2{font-size:1.13rem;line-height:1.35;letter-spacing:-.025em}
h2 small{font-size:.77rem;font-weight:500;margin-left:.5rem}
p.muted,.page-head p,.hero p{margin-top:.34rem}
small{font-size:.79rem}
strong,.strong{font-weight:750}
.muted{color:var(--muted)}
.nowrap,.num{white-space:nowrap}
.num{text-align:right;font-variant-numeric:tabular-nums}
.skip{position:absolute;z-index:9;top:-10rem;left:.75rem;background:var(--surface);padding:.55rem .8rem;border-radius:.5rem}
.skip:focus{top:.75rem}
.app{display:grid;grid-template-columns:260px minmax(0,1fr);min-height:100dvh}
.sidebar{background:var(--sidebar);color:var(--ink);border-right:1px solid var(--line);display:flex;flex-direction:column;gap:1.35rem;padding:1.55rem 1rem 1rem;position:sticky;top:0;height:100dvh;overflow:auto}
.brand{display:inline-flex;align-items:center;gap:.67rem;color:inherit;text-decoration:none;font-size:1.22rem;line-height:1.12;font-weight:780;letter-spacing:-.03em}
.brand:hover{text-decoration:none}
.brand img{flex:none}.brand small{display:block;margin-top:.19rem;color:var(--accent);font-size:.75rem;letter-spacing:.02em;font-weight:600}
.sidebar .brand{margin:.3rem .47rem;color:var(--accent);font-size:1rem}
.sidebar nav{display:grid;gap:.22rem}
.nav-label{margin:.72rem .65rem .25rem;color:var(--accent);letter-spacing:.12em;font-weight:650;font-size:.72rem}
.sidebar nav a{display:flex;align-items:center;gap:.63rem;border-radius:.65rem;padding:.62rem .66rem;color:var(--ink);text-decoration:none;font-weight:560;white-space:nowrap}
.sidebar nav a span{width:1.15rem;color:var(--accent);text-align:center;font-size:1.07rem}
.sidebar nav a:hover,.sidebar nav a[aria-current]{background:var(--nav-active);color:var(--accent)}
.sidebar nav a[aria-current]{font-weight:750}
.identity{margin-top:auto;display:flex;align-items:center;gap:.55rem;background:var(--soft);border:1px solid var(--line);border-radius:.8rem;padding:.65rem}
.avatar{background:var(--accent);color:#fff;display:grid;place-items:center;width:2rem;height:2rem;flex:none;border-radius:50%;font-size:.87rem;font-weight:800}
.who{min-width:0;flex:1;line-height:1.25}.who strong{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:.82rem}.who small{color:var(--muted);font-size:.71rem}
.signout{color:var(--accent);background:#fff;border:1px solid #cfc5c2;border-radius:.45rem;padding:.32rem .47rem;font-size:.74rem;white-space:nowrap}
.content{width:100%;min-width:0;margin:0;padding:28px 24px}
footer{font-size:.72rem;color:var(--muted);letter-spacing:.07em;margin:1.7rem 0 0}footer span{padding:0 .25rem}
.hero,.page-head{display:flex;align-items:flex-end;justify-content:space-between;gap:1rem;margin-bottom:1.65rem}
.hero{background:var(--sidebar);border:1px solid var(--line);color:var(--ink);padding:clamp(1.35rem,3vw,2.45rem);border-radius:.9rem;min-height:150px}
.hero p{color:var(--muted)}.hero h1{margin-top:.38rem}
.eyebrow{font-size:.74rem;font-weight:780;letter-spacing:.12em;color:var(--accent)}
.eyebrow i{display:inline-block;background:#ac9e9c;width:.47rem;height:.47rem;border-radius:50%;margin:0 .17rem .08rem 0}
.page-head{min-height:94px}.page-head h1{margin-top:.25rem}.page-head p{color:var(--muted)}
.section-head,.panel-head,.detail-head{display:flex;align-items:center;justify-content:space-between;gap:.85rem}
.section-head{margin:0 0 .7rem}.section-head p,.panel-head p{font-size:.84rem}
.month-picker,.actions{display:flex;gap:.52rem;align-items:center;flex-wrap:wrap}
.month-picker label{margin:0;font-size:.78rem}.month-picker input{width:auto;font-size:.83rem;min-height:2.14rem}
.button,button{font:inherit;cursor:pointer}
.button{display:inline-flex;align-items:center;justify-content:center;gap:.45rem;min-height:2.56rem;padding:.55rem .84rem;line-height:1.25;border:1px solid #cfc5c2;border-radius:.61rem;background:#fff;color:var(--accent);text-decoration:none;font-weight:680;white-space:nowrap}
.button:hover{background:var(--soft);text-decoration:none}.button.primary{color:#fff;background:var(--accent);border-color:var(--accent)}.button.primary:hover{background:var(--accent-hover);border-color:var(--accent-hover)}
.button.small{min-height:2.1rem;padding:.38rem .68rem;font-size:.82rem}
.metrics{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:.72rem;margin-bottom:1.45rem}
.metric{min-width:0;background:var(--surface);border:1px solid var(--line);border-radius:.86rem;box-shadow:0 2px 8px #5243400a}
.metric a{display:block;min-height:100%;color:inherit;padding:.85rem .9rem;text-decoration:none;border-radius:inherit}
.metric a:hover{background:var(--sidebar)}
.metric-top{display:flex;align-items:center;justify-content:space-between;gap:.25rem;color:var(--ink);font-weight:690;font-size:.86rem}
.metric-icon{display:grid;place-items:center;width:1.65rem;height:1.65rem;flex:none;border-radius:.55rem;color:var(--accent);background:var(--soft)}
.metric.out .metric-icon{background:#e7eff8;color:#305b82}.metric.due .metric-icon{background:#f9f1e0;color:#77531c}
.metric-value{font-size:clamp(.98rem,1.9vw,1.52rem);font-weight:785;font-variant-numeric:tabular-nums;letter-spacing:-.035em;overflow-wrap:anywhere;line-height:1.22;margin:.62rem 0 .22rem}
.metric-value small{font-size:.68rem;letter-spacing:.035em;color:var(--muted)}
.panel{min-width:0;background:var(--surface);border:1px solid var(--line);border-radius:.88rem;margin-bottom:1.13rem;box-shadow:0 2px 8px #5243400a}
.panel-head,.panel-body,.filter,.totals{padding:1rem 1.15rem}
.panel-head a{font-size:.87rem}
.table-wrap{overflow-x:auto;max-width:100%}
table{width:100%;border-collapse:collapse;text-align:left;font-size:.88rem}
th,td{padding:.66rem .85rem;border-bottom:1px solid #eee9e8;vertical-align:top}
tr:last-child td{border-bottom:0}th:first-child,td:first-child{padding-left:1.15rem}th:last-child,td:last-child{padding-right:1.15rem}
th{background:#f4f0ef;color:#4c4442;font-size:.75rem;font-weight:720;white-space:nowrap}
td a{font-weight:670}.row-sub{display:block;color:var(--muted);font-weight:480;margin-top:.1rem;overflow-wrap:anywhere}
.empty{text-align:center;color:var(--muted);padding:2.4rem 1rem!important}.empty strong{color:var(--ink)}
.pill{display:inline-flex;align-items:center;padding:.19rem .46rem;line-height:1.32;white-space:nowrap;border-radius:10rem;font-size:.73rem;font-weight:690}
.pill.pending{background:#fff0d5;color:#6c4b17}.pill.settled{background:#e4f5e6;color:#225a37}.pill.void{background:#fbe9e8;color:#8b3330}
label{display:block;color:#514946;font-size:.83rem;font-weight:680;margin-bottom:.25rem}
input:not([type=checkbox]):not([type=hidden]),select,textarea{font:inherit;color:var(--ink);background:#fff;border:1px solid #ddd7d5;border-radius:.5rem;min-height:2.49rem;padding:.4rem .55rem;width:100%;min-width:0}
input[type=checkbox]{accent-color:var(--accent);width:1rem;height:1rem;margin:.2rem .28rem}
input[type=file]{font-size:.82rem!important;padding:.37rem!important}
input[type=month]::-webkit-calendar-picker-indicator,input[type=date]::-webkit-calendar-picker-indicator{cursor:pointer}
textarea{resize:vertical}
.filter-grid,.form-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:.8rem .95rem;margin-bottom:.86rem}
.form-grid{grid-template-columns:repeat(2,minmax(0,1fr));margin:.9rem 0 0}
.form-grid [data-field=notes],.form-grid [data-field=documents]{grid-column:1/-1}
.field small{display:block;margin-top:.2rem}
.inline-person {
  margin-top: .5rem;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--sidebar);
}
.inline-person summary { color: var(--accent); font-size: .85rem; }
.inline-person label { margin-top: .6rem; }
.inline-person small { margin-top: .45rem; }
.errorlist{padding:.1rem 0 0 1rem;color:var(--danger);font-size:.84rem}
.invalid input,.invalid select{border-color:var(--danger)!important}
.required,.danger summary{color:var(--danger)}
.notice{border-radius:.6rem;padding:.6rem .8rem;margin:0 0 1rem;background:#e4f4e7;color:#265c39;border:1px solid #d5ead9}
.notice.error{background:#fff0ef;color:#8b3330;border-color:#efcecc}
.totals-grid{display:flex;flex-wrap:wrap;gap:.5rem;margin-top:.7rem}
.totals-grid div{display:flex;flex-wrap:wrap;align-items:center;gap:.45rem;border-radius:.52rem;background:var(--soft);padding:.43rem .63rem;font-size:.83rem}
.totals-grid small{color:var(--muted)}
.pager{display:flex;gap:.65rem;justify-content:flex-end;align-items:center;padding:.8rem 1rem;border-top:1px solid var(--line);font-size:.8rem}
.back{display:inline-block;margin-bottom:.35rem;font-weight:680;font-size:.86rem}
.setup-tip{margin:0 0 .85rem;font-size:.85rem;color:var(--muted)}.setup-tip a{margin-inline:.2rem}
.record-form{width:100%;min-width:0}
.allocation-list{border-top:1px solid var(--line);padding:0 1.15rem}
.allocation{display:grid;grid-template-columns:minmax(0,1fr) minmax(130px,220px);align-items:center;gap:1rem;padding:.8rem 0;border-bottom:1px solid var(--line)}
.allocation:last-child{border-bottom:0}
.detail-grid{display:grid;grid-template-columns:1fr 1fr;gap:1rem}
.details{display:grid;grid-template-columns:minmax(90px,auto) minmax(0,1fr);gap:.48rem 1rem;margin-top:.8rem;font-size:.9rem}
.details dt{color:var(--muted)}.details dd{margin:0;overflow-wrap:anywhere}.multiline{white-space:pre-wrap}
.files{list-style:none;padding:0;margin:.65rem 0 1rem}.files li{padding:.4rem 0;overflow-wrap:anywhere}.download{margin-left:.55rem;font-size:.75rem;font-weight:550}.file-line+.file-line{margin-top:.23rem}
.upload{border-top:1px solid var(--line);padding-top:.78rem}.upload button,.danger button{margin-top:.65rem}
.danger summary,summary{cursor:pointer;font-weight:680}.danger .muted{margin:.65rem 0}
.danger-button{color:var(--danger);border-color:#dfb3b1}.danger-button:hover{background:#fce9e8}
.credit{color:#227447}
pre{font-size:.79rem;white-space:pre-wrap;overflow-wrap:anywhere}
.login {
  display: grid;
  place-items: center;
  padding: 54px 20px max(36px, env(safe-area-inset-bottom));
  color: #302d2d;
  background: #d9d5d5;
  min-height: 100dvh;
}
.login-shell {
  width: min(100%, 448px);
  min-width: 0;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 46px;
}
.login-brand-mark { width: 126px; height: 126px; overflow: hidden; border-radius: 50%; }
.login-brand strong {
  margin-top: 2px;
  color: #666363;
  font: 700 24px/1.55 Arial, sans-serif;
  letter-spacing: -.03em;
}
.login-brand img { display: block; width: 100%; height: 100%; object-fit: contain; border-radius: 50%; }
.login-card {
  width: 100%;
  padding: 25px 48px 36px;
  background: var(--surface);
  border: 1px solid #e2e5e7;
  border-radius: 15px;
  box-shadow: 0 26px 58px #352f2f2b;
}
.login-card h1 { margin: 0 0 30px; text-align: center; font-size: 20px; line-height: 1.4; font-weight: 700; letter-spacing: .03em; }
.login-fields label { margin: 0 0 9px; font-size: 14px; font-weight: 600; color: inherit; }
.login-input {
  height: 40px;
  display: flex;
  align-items: center;
  margin-bottom: 28px;
  border: 1px solid #d6dadd;
  border-radius: 5px;
  background: #f3f3f3;
}
.login-input:focus-within { border-color: #b5a6a4; background: #fff; box-shadow: 0 0 0 3px #b5a6a429; }
.login-input svg { width: 19px; height: 19px; flex: none; margin: 0 14px 0 17px; color: #b5a6a4; }
.login-input input:not([type=hidden]) {
  height: 100%;
  min-height: 0;
  padding: 0 13px 0 0;
  border: 0;
  outline: 0;
  border-radius: inherit;
  color: #3d3939;
  background: transparent;
  font-size: 16px;
}
.login-input input::placeholder { color: #9d9999; }
.login-fields .button, .logout-current .button { width: 100%; min-height: 40px; }
.login-fields .button { margin-top: -4px; border: 0; border-radius: 4px; background: #b4a6a4; color: #fff; font-size: 16px; font-weight: 600; }
.login-fields .button:hover { background: #a29492; box-shadow: 0 7px 18px #63565429; }
.logout-current { margin-top: .75rem; }
.login-note { margin: 23px 0 0; color: #999696; text-align: center; font-size: 12px; }
.login-shell footer { text-align: center; margin-top: 49px; color: #999696; font: 12px/1.55 Arial, sans-serif; letter-spacing: .04em; }
@media (max-width: 520px) {
  .login { align-items: start; padding-top: 38px; }
  .login-brand { margin-bottom: 30px; }
  .login-brand-mark { width: 104px; height: 104px; }
  .login-brand strong { font-size: 21px; }
  .login-card { padding: 25px 26px 30px; border-radius: 13px; }
  .login-input { height: 48px; }
  .login-fields .button, .logout-current .button { min-height: 48px; }
  .login-shell footer { margin-top: 34px; }
}
[hidden]{display:none!important}
@media(max-width:1160px){.metrics{grid-template-columns:repeat(3,minmax(0,1fr))}.hero,.page-head{align-items:flex-start}.hero .actions,.page-head .actions{justify-content:flex-end}}
@media(max-width:850px){.app{display:block}.sidebar{position:static;height:auto;overflow:visible;display:grid;grid-template-columns:minmax(0,1fr) auto;gap:.65rem;padding:.7rem .85rem}.sidebar .brand{margin:0}.sidebar nav{grid-row:2;grid-column:1/-1;display:flex;overflow-x:auto;gap:.12rem;padding:.13rem 0}.sidebar nav a{padding:.4rem .55rem;font-size:.82rem}.nav-label{display:none}.identity{grid-row:1;grid-column:2;padding:.3rem .45rem;margin:0}.who{max-width:7rem}.filter-grid{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media(max-width:600px){.hero,.page-head,.section-head{align-items:flex-start;flex-direction:column}.hero .actions,.page-head .actions{justify-content:flex-start}.hero{min-height:unset}.page-head{min-height:unset}.content{padding:1rem}.metrics{grid-template-columns:repeat(2,minmax(0,1fr));gap:.55rem}.metric-value{font-size:1.19rem}.filter-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.form-grid,.detail-grid{grid-template-columns:minmax(0,1fr)}.panel-head,.panel-body,.filter,.totals{padding:.82rem}.detail-grid{gap:0}.month-picker{flex-wrap:nowrap}.allocation-list{padding:0 .8rem}.allocation{gap:.55rem}}

@media (max-width: 360px) {
  .identity .avatar, .identity .who { display: none; }
}

/* The calendar stays in the viewport, including inside long mobile forms. */
.date-control {
  display: flex;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  border: 1px solid #ddd7d5;
  border-radius: .5rem;
  background: var(--surface);
}
.date-control input:not([type=hidden]) {
  flex: 1;
  width: 0;
  min-width: 0;
  border: 0;
  min-height: 44px;
  font-variant-numeric: tabular-nums;
  background: transparent;
}
.calendar-toggle, .calendar-close, .calendar-previous, .calendar-next {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: .45rem;
  background: var(--soft);
  color: var(--accent);
  touch-action: manipulation;
}
.calendar-toggle { border-radius: 0 .45rem .45rem 0; }
.calendar-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.calendar-open { overflow: hidden; }
.calendar-dialog {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  width: min(420px, calc(100vw - 16px));
  max-width: calc(100vw - 16px);
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 16px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 70px #30252540;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.calendar-dialog::backdrop { background: #302a2880; }
.calendar-shell { padding: 12px; }
.calendar-heading, .calendar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  background: var(--surface);
}
.calendar-heading { position: sticky; top: 0; z-index: 1; padding-bottom: 10px; }
.calendar-heading h2 { font-size: 1rem; }
.calendar-close { font-size: 1.7rem; }
.calendar-navigation { display: grid; grid-template-columns: 44px minmax(70px, 1fr) minmax(70px, 1fr) 44px; gap: 6px; align-items: end; }
.calendar-dialog.month-only .calendar-navigation { grid-template-columns: 44px minmax(90px, 1fr) 44px; }
.calendar-navigation label { min-width: 0; margin: 0; font-size: .8rem; }
.calendar-navigation input, .calendar-navigation select { min-height: 44px; font-size: 16px; }
.calendar-period { margin: 10px 0 8px; font-weight: 700; font-size: .9rem; text-align: center; }
.calendar-weekdays, .calendar-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.calendar-weekdays { color: var(--muted); text-align: center; font-size: .8rem; margin-bottom: 4px; }
.calendar-days button, .calendar-months button {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: .5rem;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
}
.calendar-days button:hover, .calendar-months button:hover { background: var(--soft); }
.calendar-dialog button.is-today { border-color: var(--accent); }
.calendar-dialog button.is-selected { background: var(--accent); color: #fff; }
.calendar-dialog button:disabled { opacity: .35; cursor: default; }
.calendar-months { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.calendar-months button { min-height: 48px; border-color: var(--line); }
.calendar-footer { position: sticky; bottom: 0; justify-content: flex-end; padding-top: 12px; font-size: .85rem; }
.calendar-footer .button { min-height: 44px; }
.month-picker .date-control { width: 170px; }
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-width: 850px) {
  .sidebar { border-bottom: 1px solid var(--line); }
  .sidebar nav a { min-height: 44px; }
  .sidebar .brand { min-width: 0; }
  .signout { min-height: 44px; min-width: 44px; }
}

@media (max-width: 600px) {
  input:not([type=checkbox]):not([type=hidden]), select, textarea { min-height: 44px; font-size: 16px; }
  .button, .button.small { min-height: 44px; max-width: 100%; }
  .panel-head, .detail-head, .pager { flex-wrap: wrap; }
  .page-head .actions, .hero .actions { width: 100%; }
  .month-picker { display: grid; grid-template-columns: minmax(0, 1fr) auto; width: 100%; gap: 8px; }
  .month-picker label { grid-column: 1 / -1; }
  .month-picker .date-control { width: 100%; }
  .sidebar .brand { gap: .5rem; font-size: .95rem; }
  .sidebar .brand small { font-size: .68rem; }
  .sidebar .brand img { width: 36px; height: 36px; }
  .identity .who { max-width: 5rem; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .table-wrap::before { content: "左右滑動查看完整明細"; display: block; padding: .5rem .8rem; color: var(--muted); font-size: .75rem; }
}

@media (max-width: 480px) {
  .filter-grid, .allocation { grid-template-columns: minmax(0, 1fr); }
  .identity .who { display: none; }
  .sidebar { gap: .5rem; padding-inline: .7rem; }
}

@media (max-width: 360px) {
  .calendar-shell { padding: 8px; }
  .calendar-weekdays, .calendar-days { gap: 2px; }
}
