:root {
  --brand: #2864f0;
  --brand-dark: #1b4fd0;
  --brand-soft: #e8efff;
  --sidebar-bg: #f5f9ff;
  --nav-active-bg: #ffffff;
  --topbar: #ecf3ff;
  --bg: #ffffff;
  --card: #ffffff;
  --ink: #1f2a44;
  --muted: #6b7488;
  --line: #e3e7ee;
  --danger: #e03131;
  --ok: #2f9e44;
  --orange: #f08c00;
  --sidebar-w: 224px;
  --topbar-h: 52px;

  /* one consistent type scale used everywhere */
  --fs-xs: 12px;   /* section labels, chips, table headers */
  --fs-sm: 13px;   /* hints, form labels, in-table controls */
  --fs-base: 14px; /* body, nav, inputs, buttons, table cells */
  --fs-md: 16px;   /* h3, top-bar title, totals */
  --fs-lg: 20px;   /* h2 */
  --fs-xl: 24px;   /* h1 */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* Typewriter/monospace for Latin, digits and symbols; CJK falls through to
     the proportional TC/JP fonts (they have no glyphs in the mono fonts). */
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    "PingFang TC", "Hiragino Sans", "Noto Sans TC", "Yu Gothic", monospace;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  font-size: var(--fs-base);
  line-height: 1.5;
}

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.4rem;
  background: var(--topbar);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: var(--fs-md); font-weight: 700; letter-spacing: .02em; color: var(--ink); }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7em;
  height: 1.7em;
  margin-right: .5rem;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 800;
  vertical-align: middle;
}
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.topbar-right .who {
  font-size: var(--fs-xs);
  background: #eef1f5;
  color: var(--muted);
  padding: .18rem .6rem;
  border-radius: 999px;
}
.topbar-right a { color: var(--brand); text-decoration: none; font-size: var(--fs-sm); font-weight: 600; }
.topbar-right a:hover { color: var(--brand-dark); }
.topbar-right form { margin: 0; }
.topbar-right .ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: .35rem .85rem;
  font-size: var(--fs-sm);
  font-weight: 600;
}
.topbar-right .ghost:hover { background: #ffffff; border-color: #cfd6e0; }

/* ---- layout ---- */
.layout { display: flex; align-items: stretch; }
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  min-height: calc(100vh - var(--topbar-h));
  padding: .8rem 0;
}
.sidebar nav { display: flex; flex-direction: column; }
.nav-section {
  padding: .9rem 1.2rem .25rem;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .08em;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1.2rem;
  color: var(--ink);
  text-decoration: none;
  font-size: var(--fs-base);
  font-weight: 600;
  border-left: 3px solid transparent;
}
.nav-item .ico {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--brand);
}
.nav-item:hover { background: #f3f6fc; }
.nav-item:hover .ico,
.nav-item.active .ico { color: var(--brand); }
.nav-item.active {
  background: var(--nav-active-bg);
  border-left-color: transparent;
  color: var(--ink);
}
/* freee-style count badge (orange pill) for wherever a count is shown */
.count-badge {
  display: inline-block;
  background: var(--orange);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 2px 9px;
  border-radius: 11px;
  line-height: 1.4;
}

main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 1.6rem 2rem;
  max-width: 1180px;
}
main.transactions-page { max-width: none; }

/* ---- headings ---- */
h1 { font-size: var(--fs-xl); font-weight: 700; margin: .2rem 0 1rem; }
h2 { font-size: var(--fs-lg); font-weight: 700; color: var(--ink); margin: .2rem 0 1.1rem; }
h3 { font-size: var(--fs-md); font-weight: 700; color: var(--ink); margin: 0 0 .2rem; }

/* ---- cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.25rem 1.3rem;
  margin: 1rem 0;
  max-width: 640px;
  display: grid;
  gap: .8rem;
  box-shadow: 0 1px 2px rgba(20,30,60,.04);
}
.hint { color: var(--muted); font-size: var(--fs-sm); line-height: 1.5; margin: 0; }

/* ---- forms ---- */
label { display: grid; gap: .3rem; color: var(--ink); font-weight: 600; font-size: var(--fs-sm); }
input, select, textarea {
  padding: .55rem .65rem;
  border: 1px solid #cfd6e0;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: var(--fs-base);
  font-family: inherit;
  font-variant-numeric: inherit;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(40,100,240,.15);
}

/* ---- buttons ---- */
button {
  padding: .5rem 1rem;
  border: 1px solid var(--brand);
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: var(--fs-base);
  cursor: pointer;
}
button:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button.primary { background: var(--brand); }
button.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---- tables ---- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin: .4rem 0 1.2rem;
  box-shadow: 0 1px 2px rgba(20,30,60,.04);
}
th, td {
  padding: .65rem .8rem;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-base);
}
th {
  background: #f5f7fb;
  color: var(--muted);
  font-weight: 700;
  font-size: var(--fs-xs);
  text-align: left;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f9fbfe; }
td.num, .num { text-align: right; font-variant-numeric: tabular-nums; }
th.ctr, td.ctr { text-align: center; }
.ctr-table th, .ctr-table td { text-align: center; vertical-align: middle; }
.transactions-table-wrap { max-width: 100%; overflow-x: auto; }
.transactions-table th, .transactions-table td { white-space: nowrap; }
table input, table select, table button { font-size: var(--fs-sm); }
table input, table select { padding: .35rem .45rem; }
table button { padding: .35rem .7rem; margin: 2px 3px 2px 0; }

/* action column: a neat, equal-width vertical stack of buttons */
.cell-actions {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  justify-content: center;
}
.cell-actions form { display: flex; margin: 0; }
.cell-actions button { margin: 0; }

/* month-close component breakdown */
table.components th { width: 60%; }
table.components tr.total th,
table.components tr.total td {
  font-weight: 800;
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-size: var(--fs-md);
}

.actions, .inline {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 1rem;
}
.inline label { font-size: var(--fs-sm); }
.inline input:not([type="hidden"]),
.inline select,
.inline button {
  height: 40px;
}

a { color: var(--brand); }

/* login page is standalone (no sidebar) */
body > main:only-child,
main.auth { max-width: 420px; margin: 3rem auto; }

/* ---- mobile: move the nav to the top, single column ---- */
@media (max-width: 720px) {
  .topbar { padding: 0 1rem; }
  .brand { font-size: var(--fs-base); }
  .topbar-right { gap: .55rem; }
  .topbar-right a, .topbar-right .who { font-size: var(--fs-xs); }

  /* sidebar becomes a horizontal, scrollable bar pinned under the top bar */
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0;
    position: sticky;
    top: var(--topbar-h);
    z-index: 15;
    background: #fff;
  }
  .sidebar nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: .15rem;
    padding: 0 .5rem;
  }
  .nav-section { display: none; }            /* group labels off on mobile */
  .nav-item {
    flex: 0 0 auto;
    border-left: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    padding: .6rem .7rem;
    white-space: nowrap;
  }
  .nav-item.active {
    border-left: 0;
    border-bottom-color: var(--brand);
  }

  main { padding: 1rem; max-width: 100%; }
  .card { max-width: 100%; }

  /* wide tables scroll sideways instead of squeezing the page */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---- 獎金提撥：先比較摘要，再分開核對採購與貨運 ---- */
.bonus-page-hint { margin-bottom: .8rem; }
.bonus-summary-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.bonus-summary-table {
  min-width: 880px;
  margin-top: 0;
}
.bonus-summary-table th.num,
.bonus-summary-table td.num { text-align: right; }
.bonus-summary-table .bonus-detail-column { width: 78px; }
.bonus-summary-table .bonus-person { font-weight: 700; }
.bonus-summary-table .bonus-month { white-space: nowrap; }
.bonus-currency {
  display: block;
  font-size: 10px;
  font-weight: 600;
}
.bonus-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  min-width: 62px;
  padding: .32rem .55rem;
  margin: 0;
  border-color: #cfd8ee;
  background: #fff;
  color: var(--brand-dark);
  font-size: var(--fs-xs);
}
.bonus-toggle:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.bonus-toggle:focus-visible,
.bonus-summary-wrap:focus-visible,
.bonus-shipping-scroll:focus-visible {
  outline: 3px solid rgba(40,100,240,.24);
  outline-offset: 2px;
}
.bonus-summary-amount {
  min-width: 128px;
  white-space: nowrap;
}
.bonus-summary-amount strong {
  display: block;
  font-size: var(--fs-md);
}
.bonus-summary-amount small {
  display: block;
  margin-top: .1rem;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 500;
}
.bonus-summary-total strong { color: var(--brand-dark); }
.bonus-none { color: var(--muted); font-size: var(--fs-md); }
.bonus-detail > td {
  padding: 1rem;
  background: #f6f8fc;
  text-align: left;
}
.bonus-detail:hover > td { background: #f6f8fc; }
.bonus-detail-panel {
  display: grid;
  gap: 1rem;
}
.bonus-detail-card {
  min-width: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(20,30,60,.03);
}
.bonus-detail-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .8rem;
}
.bonus-detail-section-head h3 { margin: 0 0 .2rem; }
.bonus-section-total {
  flex: 0 0 auto;
  min-width: 150px;
  text-align: right;
}
.bonus-section-total > span {
  display: block;
  color: var(--muted);
  font-size: var(--fs-xs);
}
.bonus-section-total strong {
  color: var(--brand-dark);
  font-size: var(--fs-lg);
}
.bonus-section-total small { color: var(--muted); font-size: var(--fs-xs); }
.bonus-count-chip {
  display: inline-block;
  margin-left: .35rem;
  padding: .08rem .45rem;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: var(--fs-xs);
  vertical-align: .1rem;
}
.bonus-procurement-breakdown {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .65rem;
}
.bonus-procurement-source {
  min-width: 0;
  padding: .7rem .75rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f9fbfe;
}
.bonus-procurement-source span,
.bonus-calculation-step span {
  display: block;
  color: var(--muted);
  font-size: var(--fs-xs);
}
.bonus-procurement-source strong {
  display: block;
  margin-top: .18rem;
  white-space: nowrap;
  font-size: var(--fs-md);
  text-align: right;
}
.bonus-procurement-deduction strong { color: #b45309; }
.bonus-procurement-calculation {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .7rem;
  margin-top: .8rem;
  padding: .8rem;
  border-radius: 7px;
  background: var(--brand-soft);
}
.bonus-calculation-step { text-align: right; }
.bonus-calculation-step strong { font-size: var(--fs-md); }
.bonus-calculation-step small { color: var(--muted); font-size: var(--fs-xs); }
.bonus-calculation-arrow,
.bonus-calculation-formula {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 700;
}
.bonus-calculation-result strong {
  color: var(--brand-dark);
  font-size: var(--fs-lg);
}
.bonus-detail-empty {
  margin: 0;
  padding: .8rem;
  border-radius: 7px;
  background: #f9fbfe;
  color: var(--muted);
  font-size: var(--fs-sm);
}
.bonus-shipping-scroll {
  max-height: min(52vh, 32rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.bonus-shipping-table {
  min-width: 650px;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}
.bonus-shipping-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f5f7fb;
  font-size: var(--fs-xs);
}
.bonus-shipping-table td { font-size: var(--fs-sm); }
.bonus-shipping-table th.num,
.bonus-shipping-table td.num { text-align: right; }
.bonus-shipping-table td { white-space: nowrap; }
.bonus-shipping-weight small {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

@media (max-width: 720px) {
  /* Let dedicated wrappers own scrolling; the global mobile table rule would
     otherwise create a second scrollbar inside each bonus section. */
  .bonus-summary-table,
  .bonus-shipping-table {
    display: table;
    overflow: visible;
  }
  .bonus-procurement-breakdown { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bonus-detail-section-head { align-items: flex-start; }
  .bonus-procurement-calculation {
    align-items: flex-end;
    flex-wrap: wrap;
  }
}

/* 業務首頁：自己的預估獎金 */
.bonus-panel .bonus-total {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--brand-dark);
  margin: .2rem 0 .35rem;
  font-variant-numeric: tabular-nums;
}
.bonus-panel .bonus-total small { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); }
.disclosure-link { color: var(--muted); text-decoration: none; font-size: var(--fs-sm); }
.disclosure-link:hover { color: var(--brand-dark); }
