:root { font: 16px/1.5 system-ui, sans-serif; color: #192932; background: #f1f5f6; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
header { background: #12343b; color: white; padding: 1rem max(1.25rem, calc((100% - 70rem) / 2)); font-weight: 650; }
main { max-width: 73rem; margin: auto; padding: 2rem 1.25rem; }
h1 { margin: 0; font-size: 1.75rem; }
.heading, .actions, .filters { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; }
.heading { justify-content: space-between; margin-bottom: 1rem; }
.panel, #invite-box { background: white; border: 1px solid #d6e1e3; border-radius: .8rem; padding: 1.25rem; }
#invite-box { margin-bottom: 1rem; }
#editor { max-width: 54rem; margin-inline: auto; }
form, fieldset { margin-top: 1rem; }
fieldset { padding: 1rem; border: 1px solid #d6e1e3; border-radius: .5rem; }
.fields { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
fieldset > label { margin-top: 1rem; }
label { display: block; font-weight: 550; }
input, textarea, select, button { font: inherit; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; border: 1px solid #82969e; border-radius: .45rem; padding: .55rem .7rem; background: white; color: inherit; }
button { border: 1px solid #176256; border-radius: .45rem; padding: .55rem .9rem; color: white; background: #176256; cursor: pointer; }
button:disabled { opacity: .6; cursor: wait; }
button.secondary { background: white; color: #13594f; }
form .actions { margin-top: 1.25rem; }
.filters label:first-child { flex: 1 1 15rem; }
.table-wrap { overflow: auto; margin-top: 1rem; }
table { width: 100%; min-width: 48rem; border-collapse: collapse; text-align: left; }
th, td { padding: .75rem .6rem; border-bottom: 1px solid #e0e8e9; }
th { background: #edf3f4; }
small { display: block; font-size: .875rem; color: #526871; }
#message { color: #125a50; max-width: 54rem; margin-inline: auto; }
#message.error { color: #a02337; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.summary > div { background: white; border: 1px solid #d6e1e3; border-radius: .7rem; padding: .75rem 1rem; }
.summary strong { display: block; color: #13594f; font-size: 1.6rem; }
.source-options { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-bottom: 1rem; }
.source-options input { display: inline; width: auto; margin: 0 .2rem 0 0; }
table { min-width: 64rem; }
.with-sidebar {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  min-height: 0;
}
.with-sidebar main { width: 100%; min-width: 0; max-width: none; margin: 0; }
#sidebar { background: #fff; border-right: 1px solid #d6e1e3; padding: 1.5rem .75rem; }
#navigation { display: grid; gap: .35rem; }
#navigation a { color: #13594f; padding: .7rem .8rem; border-radius: .45rem; text-decoration: none; }
#navigation a:hover { background: #edf3f4; }
#navigation a[aria-current="page"] { background: #dceee9; font-weight: 650; }
#menu-toggle { display: none; }
@media (min-width: 48.001rem) {
  body:has(.with-sidebar) {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    overflow: hidden;
  }
  .with-sidebar > #sidebar, .with-sidebar > main {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
  }
}
@media (max-width: 48rem) {
  .with-sidebar { grid-template-columns: minmax(0, 1fr); }
  #sidebar { padding: .65rem 1.25rem; border-right: 0; border-bottom: 1px solid #d6e1e3; }
  #navigation { margin-top: .5rem; max-height: 45dvh; overflow-y: auto; }
  #menu-toggle { display: inline-block; }
  #menu-toggle[aria-expanded="false"] + #navigation { display: none; }
}
#invoice-editor { max-width: 54rem; margin-inline: auto; }
#invoice-page table { min-width: 46rem; }
[aria-invalid="true"] { border-color: #a02337; }
.field-error { display: block; color: #a02337; font-size: .875rem; margin-top: .25rem; }
header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem; }
.narrow-panel { max-width: 44rem; margin-inline: auto; }
#login-page { max-width: 28rem; }
#login-form label + label { margin-top: 1rem; }
#staff-page table { min-width: 32rem; }
#billing-tracks { margin-bottom: 1rem; }
#billing-tracks h2 { margin: 0; font-size: 1.125rem; }
#billing-track-status, #billing-track-ranges { margin-block: .5rem 0; }
button.danger { background: #a02337; border-color: #a02337; color: white; }
td button + button { margin-left: .35rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.inline-form input { min-width: 10rem; }
.allowance-row td { background: #f6f8f8; }
.allowance-line { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .25rem 0; }
td button { white-space: nowrap; }
#invoice-rows td:last-child { white-space: nowrap; }
#invoice-rows td:last-child button { display: block; width: 100%; margin: 0 0 .35rem; }
#invoice-rows td:last-child button + button { margin-left: 0; }
.allowance-row td:last-child button { display: inline-block; width: auto; }
.allowance-line button { display: inline-block; width: auto; margin: 0; }
.allowance-row td:last-child { white-space: normal; }
.allowance-row td > * { position: sticky; left: .75rem; max-width: min(40rem, calc(100vw - 4rem)); }
.allowance-line { flex-direction: column; align-items: flex-start; border-bottom: 1px solid #dde5e6; padding: .5rem 0; }
.allowance-line > div { display: flex; gap: .35rem; }
.warning { color: #a02337; font-weight: 600; }
#overview-results table { min-width: 0; }

/* ───── 仿 INVWeb 介面：靛藍標題列、左側圖示選單（膠囊選取）、圓角按鈕、米黃淺色／深色模式 ───── */
:root {
  --bg: #fbf6ea; --surface: #fffbf2; --surface-2: #f2ead8; --line: #e2d7bf; --text: #1b1b21; --muted: #5d5e66;
  --primary: #3f51b5; --on-primary: #fff; --primary-soft: #dfe0ff; --on-primary-soft: #000f5c;
  --bar: #303f9f; --danger: #ba1a1a; --ok: #2e7d32; --chip: #e7e0ec;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121318; --surface: #1b1b21; --surface-2: #292a2f; --line: #45464f; --text: #e4e1e9; --muted: #c6c5d0;
    --primary: #bac3ff; --on-primary: #08218a; --primary-soft: #2f3a73; --on-primary-soft: #dfe0ff;
    --bar: #303f9f; --danger: #ffb4ab; --ok: #81c784; --chip: #303038;
    color-scheme: dark;
  }
}
:root { color: var(--text); background: var(--bg); font-family: "Noto Sans TC", "PingFang TC", system-ui, sans-serif; }
body { background: var(--bg); color: var(--text); }
header { background: var(--bar); color: #fff; padding: .7rem 1rem; font-weight: 600; }
header .brand { font-size: 1.05rem; font-weight: 700; letter-spacing: .02em; }
header #session-user { color: #fff; }
header button.secondary { background: transparent; color: #fff; border-color: transparent; }
header button.secondary:hover { background: rgb(255 255 255 / .12); }
h1 { font-size: 1.5rem; font-weight: 700; }
.panel, #invite-box, .summary > div, fieldset { background: var(--surface); border-color: var(--line); }
small, .muted { color: var(--muted); }
input, select, textarea { background: var(--surface); color: var(--text); border-color: var(--line); border-radius: .3rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
button { background: var(--primary-soft); color: var(--on-primary-soft); border: 1px solid transparent; border-radius: 999px; padding: .5rem 1.15rem; font-weight: 500; }
button:hover { filter: brightness(1.06); }
button.secondary { background: transparent; color: var(--primary); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: transparent; }
button.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
form .actions button[type="submit"], #add, #invoice-add, #staff-add { background: var(--primary); color: var(--on-primary); }
th { background: transparent; color: var(--text); font-weight: 700; border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid var(--line); }
tbody tr:hover td { background: color-mix(in srgb, var(--primary) 6%, transparent); }
.allowance-row td { background: var(--surface-2); }
.summary strong { color: var(--primary); }
#message { color: var(--ok); }
#message.error, .warning, .field-error { color: var(--danger); }
[aria-invalid="true"] { border-color: var(--danger); }

/* 左側選單：像 INVWeb 的 NavigationRail（圖示在上、文字在下，選取時圖示有膠囊底色） */
.with-sidebar { grid-template-columns: 6.5rem minmax(0, 1fr); }
#sidebar { background: var(--bg); border-right: 1px solid var(--line); padding: .75rem .25rem; }
#navigation { gap: .15rem; }
#navigation a { display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .45rem .25rem .55rem;
  color: var(--text); font-size: .78rem; font-weight: 600; text-align: center; border-radius: .6rem; }
#navigation a:hover { background: transparent; }
#navigation .nav-icon { display: grid; place-items: center; width: 3.5rem; height: 2rem; border-radius: 999px; transition: background .15s; }
#navigation .nav-icon svg { width: 1.45rem; height: 1.45rem; fill: currentColor; }
#navigation a:hover .nav-icon { background: color-mix(in srgb, var(--text) 8%, transparent); }
#navigation a[aria-current="page"] { background: transparent; font-weight: 700; }
#navigation a[aria-current="page"] .nav-icon { background: var(--primary-soft); color: var(--on-primary-soft); }
@media (max-width: 48rem) {
  .with-sidebar { grid-template-columns: minmax(0, 1fr); }
  #sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: .5rem 1rem; }
  #navigation { grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)); }
}
header .brand { display: inline-flex; align-items: center; gap: .55rem; color: #fff; text-decoration: none; }
header .brand-logo { width: 28px; height: 28px; border-radius: 7px; box-shadow: 0 0 0 1px rgb(255 255 255 / .25); }
