/* Pay-slip world: security-tint paper, navy ink, carbon-copy blue, one red for the payable total. */
:root {
  --paper: #FBFBF7;
  --sheet: #FFFFFF;
  --tint: #DCEBDD;
  --ink: #1F2A44;
  --ink-soft: #46526E;
  --blue: #2B4C9B;
  --blue-wash: #E4EAF6;
  --rule: #C4CFE3;
  --red: #B8322A;
  --red-wash: #F8E7E4;
  --space: 8px;
  --font-body: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-brand: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  --font-num: "Red Hat Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --dots: radial-gradient(rgba(43, 76, 155, .24) 1px, transparent 1.3px);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scrollbar-color: var(--blue) var(--paper); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.6 var(--font-body);
  caret-color: var(--blue);
  accent-color: var(--blue);
}
::selection { background: var(--blue); color: #fff; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
h1, p, ul, fieldset, legend, table { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* Masthead */
.masthead {
  background: var(--tint) var(--dots) 0 0 / 6px 6px;
  border-bottom: 1.5px solid var(--ink);
  padding: calc(var(--space) * 2.5) calc(var(--space) * 2) 0;
}
.masthead-row, .tabs, main, .colophon { max-width: 1040px; margin-inline: auto; }
.brand { font: 900 1.5rem/1.2 var(--font-brand); letter-spacing: .02em; }
.min-wage { margin-top: 2px; font-size: .8125rem; font-weight: 500; color: var(--blue); }

.tabs {
  display: flex;
  gap: calc(var(--space) * 2.5);
  margin-top: calc(var(--space) * 2);
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs [role="tab"] {
  flex: none;
  min-height: 44px;
  padding: 0 2px;
  border: 0;
  border-bottom: 4px solid transparent;
  background: none;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  scroll-snap-align: center;
}
.tabs [role="tab"]:hover { color: var(--blue); }
.tabs [role="tab"][aria-selected="true"] { color: var(--blue); font-weight: 700; border-bottom-color: var(--blue); }
.tabs [role="tab"]:focus-visible { outline-offset: -3px; }

/* Calculator layout */
main { padding: calc(var(--space) * 2.5) calc(var(--space) * 2) calc(var(--space) * 3); }
.calc { display: grid; gap: calc(var(--space) * 3); align-items: start; }
.inputs { display: grid; gap: calc(var(--space) * 2.25); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: calc(var(--space) * 2); }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; min-width: 0; }
.field > label, legend { font-size: .8125rem; font-weight: 500; color: var(--blue); }
.hint { font-size: .8125rem; color: var(--ink-soft); line-height: 1.5; margin-top: 4px; }

.control {
  display: flex;
  align-items: center;
  gap: var(--space);
  min-height: 48px;
  border-bottom: 1.5px solid var(--ink);
  background: transparent;
  transition: border-color .15s, box-shadow .15s;
}
.control:focus-within { border-bottom-color: var(--blue); box-shadow: 0 1.5px 0 var(--blue); }
.control input {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 46px;
  border: 0;
  padding: 0;
  background: none;
  font: 400 1.125rem/1 var(--font-num);
  font-variant-numeric: tabular-nums;
  outline: none;
}
.control input::placeholder { color: #5A6580; font-family: var(--font-body); font-size: .9375rem; }
.control input[type="date"] { font-size: 1rem; }
.unit { font-size: .8125rem; color: var(--ink-soft); white-space: nowrap; }

/* Segmented choice (radios) */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1.5px solid var(--blue); border-radius: 4px; overflow: hidden; }
.segmented legend { float: left; width: 100%; padding-bottom: 6px; }
.segmented { position: relative; margin-top: 26px; overflow: visible; }
.segmented legend { position: absolute; top: -26px; left: 0; float: none; }
.segmented label { position: relative; display: grid; place-items: center; min-height: 44px; cursor: pointer; }
.segmented label + label { border-left: 1.5px solid var(--blue); }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented span { font-size: .9375rem; font-weight: 500; color: var(--blue); }
.segmented label:has(input:checked) { background: var(--blue); }
.segmented label:has(input:checked) span { color: #fff; font-weight: 700; }
.segmented label:hover:not(:has(input:checked)) { background: var(--blue-wash); }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; z-index: 1; }

.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: .9375rem; }
.check input { width: 20px; height: 20px; margin: 0; flex: none; }

.optional { border-top: 1px dashed var(--rule); padding-top: calc(var(--space) * 2); }
.optional legend { float: left; width: 100%; margin-bottom: var(--space); }
.optional .field-row { clear: both; }

/* Overtime entries */
.entries { display: grid; gap: var(--space); }
.entries legend { float: left; width: 100%; }
.entries > [data-entries] { clear: both; display: grid; gap: var(--space); }
.entry { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 44px; gap: calc(var(--space) * 1.5); align-items: end; }
.entry select {
  height: 48px;
  width: 100%;
  border: 0;
  border-bottom: 1.5px solid var(--ink);
  border-radius: 0;
  background: transparent;
  padding: 0 22px 0 0;
  font-size: 1rem;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(-45deg, transparent 50%, var(--ink) 50%);
  background-size: 6px 6px;
  background-position: right 9px center, right 3px center;
  background-repeat: no-repeat;
  cursor: pointer;
}
.entry select:focus-visible { outline-offset: 0; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 4px; background: none; color: var(--ink-soft); cursor: pointer; }
.icon svg { width: 14px; height: 14px; }
.icon:hover { background: var(--red-wash); color: var(--red); }
.entry:only-child .icon { visibility: hidden; }
.ghost {
  justify-self: start;
  min-height: 44px;
  padding: 0 calc(var(--space) * 2);
  border: 1.5px solid var(--blue);
  border-radius: 4px;
  background: none;
  color: var(--blue);
  font-weight: 700;
  font-size: .9375rem;
  cursor: pointer;
}
.ghost:hover { background: var(--blue-wash); }
.ghost:active { background: var(--blue); color: #fff; }

/* Result slip */
.result { border: 1.5px solid var(--ink); background: var(--sheet); }
.result.is-empty .route-value, .result.is-empty .route-to .route-value { color: var(--ink-soft); }
.result-empty, .result-error { padding: calc(var(--space) * 2.5) calc(var(--space) * 1.5); font-size: .9375rem; color: var(--ink-soft); }
.result-error { color: var(--red); font-weight: 500; }
.result-error::before { content: "請修正："; font-weight: 700; }

.slip-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space);
  margin: 0;
  padding: 7px calc(var(--space) * 1.5);
  border-bottom: 1px solid var(--ink);
  font-size: .8125rem;
  line-height: 1.4;
}
.slip-name { font: 900 .9375rem/1.4 var(--font-brand); }
.slip-article { font-weight: 500; color: var(--blue); text-align: right; }
.control:has(input[aria-invalid="true"]) { border-bottom-color: var(--red); box-shadow: 0 1.5px 0 var(--red); }

.route {
  display: grid;
  grid-template-columns: minmax(0, auto) 28px minmax(0, 1fr);
  align-items: end;
  gap: var(--space);
  padding: calc(var(--space) * 1.5) calc(var(--space) * 1.5) calc(var(--space) * 1.25);
  background: var(--tint) var(--dots) 0 0 / 6px 6px;
  border-bottom: 1.5px solid var(--ink);
}
.route-label { display: block; font-size: .75rem; font-weight: 500; color: var(--blue); }
.route-value { display: block; font-size: 1rem; line-height: 1.3; overflow-wrap: anywhere; }
.route-unit { font-size: .75rem; margin-left: 3px; color: var(--ink-soft); }
.route-arrow { width: 28px; height: 12px; margin-bottom: 7px; color: var(--ink); }
.route-to { text-align: right; }
.route-to .route-value { font-size: 2rem; font-weight: 600; line-height: 1.1; color: var(--red); }
.route-to .route-unit { font-size: .875rem; color: var(--ink); }

.lines { width: 100%; border-collapse: collapse; font-size: .875rem; }
.lines th, .lines td { padding: 9px calc(var(--space) * 1.5); vertical-align: top; text-align: right; border-top: 1px solid var(--rule); }
.lines tbody tr:first-child > * { border-top: 0; }
.lines th { text-align: left; font-weight: 500; }
.line-label { display: block; }
.line-basis { display: block; font-size: .75rem; font-weight: 400; color: var(--blue); }
.line-formula { color: var(--ink-soft); font-size: .8125rem; white-space: nowrap; }
.line-amount { white-space: nowrap; font-weight: 600; }
.lines tbody tr { transition: background-color .5s cubic-bezier(.16, 1, .3, 1); }
.lines thead { display: none; }
.lines tbody tr.changed { background: var(--blue-wash); box-shadow: inset 0 1px 0 var(--blue), inset 0 -1px 0 var(--blue); }
.lines tbody tr.changed .line-amount { color: var(--blue); }
.lines tbody tr.changed .line-amount::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  background: var(--blue);
  vertical-align: 1px;
}
.lines tfoot th, .lines tfoot td { border-top: 4px double var(--ink); font-weight: 700; font-size: .9375rem; padding-block: 11px; }

.warnings, .notes { list-style: none; padding: calc(var(--space) * 1.5); font-size: .8125rem; line-height: 1.6; border-top: 1px solid var(--rule); display: grid; gap: 6px; }
.warnings { background: var(--blue-wash); color: var(--ink); font-weight: 500; border-top: 1.5px solid var(--blue); }
.notes { color: var(--ink-soft); }
.notes li { padding-left: 14px; position: relative; }
.notes li::before { content: ""; position: absolute; left: 2px; top: .7em; width: 5px; height: 1.5px; background: var(--blue); }

.colophon { padding: 0 calc(var(--space) * 2) calc(var(--space) * 4); font-size: .75rem; line-height: 1.7; color: var(--ink-soft); display: grid; gap: 4px; }

/* Narrow phones: stack formula under the label so amounts never wrap */
@media (max-width: 479px) {
  .lines tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; }
  .lines tbody th { grid-column: 1; grid-row: 1; padding-bottom: 0; }
  .lines tbody .line-formula { grid-column: 1; grid-row: 2; text-align: left; border-top: 0; padding-top: 2px; white-space: normal; }
  .lines tbody .line-formula:empty { display: none; }
  .lines tbody .line-amount { grid-column: 2; grid-row: 1 / span 2; align-self: center; border-top: 0; }
  .lines tbody tr { border-top: 1px solid var(--rule); }
  .lines tbody tr:first-child { border-top: 0; }
  .lines tbody th { border-top: 0; }
  .lines tfoot th { grid-column: 1; }
}

/* Pinned payable figure for phones */
.peek {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: var(--space);
  min-height: 56px;
  padding: 10px calc(var(--space) * 2) calc(10px + env(safe-area-inset-bottom));
  background: var(--tint) var(--dots) 0 0 / 6px 6px;
  border-top: 1.5px solid var(--ink);
  color: var(--ink);
  text-decoration: none;
  transition: transform .25s cubic-bezier(.16, 1, .3, 1);
}
.peek.is-covered { transform: translateY(110%); }
.peek-label { font-size: .8125rem; font-weight: 500; color: var(--blue); margin-right: auto; }
.peek-value { font-size: 1.5rem; font-weight: 600; line-height: 1.2; color: var(--red); }
.peek-unit { font-size: .8125rem; }
.has-peek .colophon { padding-bottom: calc(var(--space) * 11); }

@media (min-width: 480px) {
  .lines thead { display: table-header-group; }
  .lines thead th { font-size: .75rem; font-weight: 500; color: var(--blue); padding-block: 7px 3px; border-top: 0; text-align: right; }
  .lines thead th:first-child { text-align: left; width: 46%; }
  .lines tbody tr:first-child > * { border-top: 1px solid var(--rule); }
}

@media (min-width: 860px) {
  .peek { display: none; }
  .has-peek .colophon { padding-bottom: calc(var(--space) * 4); }
  .masthead { padding-inline: calc(var(--space) * 4); }
  .masthead-row { display: flex; align-items: baseline; justify-content: space-between; gap: calc(var(--space) * 3); }
  .brand { font-size: 1.75rem; }
  main { padding: calc(var(--space) * 5) calc(var(--space) * 4); }
  .calc { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: calc(var(--space) * 6); }
  .result { position: sticky; top: calc(var(--space) * 3); }
  .route-to .route-value { font-size: 2.5rem; }
  .colophon { padding-inline: calc(var(--space) * 4); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
