:root {
  color-scheme: light dark;
  --bg: oklch(0.985 0.004 210);
  --surface: oklch(1 0 0);
  --surface-muted: oklch(0.958 0.009 210);
  --ink: oklch(0.205 0.026 218);
  --muted: oklch(0.48 0.03 218);
  --faint: oklch(0.69 0.02 218);
  --line: oklch(0.89 0.012 210);
  --primary: oklch(0.55 0.091 210);
  --primary-strong: oklch(0.45 0.11 210);
  --primary-soft: oklch(0.94 0.034 210);
  --primary-softer: oklch(0.97 0.018 210);
  --accent: oklch(0.72 0.14 65);
  --danger: oklch(0.52 0.18 25);
  --focus: oklch(0.64 0.13 210);
  --backdrop: oklch(0.12 0.02 218 / 0.46);
  --shadow: oklch(0.2 0.03 218 / 0.12);
  --z-sticky: 10;
  --z-backdrop: 20;
  --z-modal: 30;
  --z-toast: 40;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

/* 移动端点日期时不触发双击缩放（保留双指捏合与滚动） */
html,
body,
button,
input,
a {
  touch-action: manipulation;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
}

button {
  color: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  width: min(100%, 640px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px calc(92px + env(safe-area-inset-bottom));
  background: var(--surface);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  margin-bottom: 14px;
}

.brand {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 720;
  letter-spacing: -0.015em;
}

.save-state {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.icon-button:hover {
  background: var(--surface-muted);
}

.icon-button:active {
  background: var(--line);
}

.summary {
  padding: 17px 18px 14px;
  border-radius: 14px;
  background: var(--primary-soft);
}

.summary-primary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}

.summary-label {
  display: block;
  margin-bottom: 5px;
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 650;
}

.summary strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 1.75rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.summary strong small {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0;
}

.income-block {
  text-align: right;
}

.summary-extra {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
}

.summary-meta {
  margin: 12px 0 0;
  padding-top: 10px;
  color: var(--primary-strong);
  border-top: 1px solid color-mix(in oklch, var(--primary) 24%, transparent);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.calendar {
  margin-top: 12px;
}

.month-nav {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 4px;
  align-items: center;
  min-height: 58px;
}

.month-heading {
  display: flex;
  min-height: 48px;
  padding: 4px 12px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border: 0;
  border-radius: 10px;
  background: transparent;
}

.month-heading:hover {
  background: var(--surface-muted);
}

.month-heading span {
  font-size: 1rem;
  font-weight: 720;
  letter-spacing: -0.01em;
}

.month-heading small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.68rem;
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(44px, 1fr));
}

.weekday-row span {
  display: grid;
  min-height: 27px;
  place-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
}

.calendar-grid {
  gap: 2px 0;
}

.day-cell {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 52px;
  padding: 6px 2px 4px;
  align-items: center;
  justify-content: flex-start;
  flex-direction: column;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-variant-numeric: tabular-nums;
}

.day-cell:hover {
  background: var(--surface-muted);
}

.day-cell:active {
  background: var(--line);
  transform: scale(0.97);
}

.day-number {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 50%;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1;
}

.day-hours {
  min-height: 14px;
  margin-top: 1px;
  color: var(--primary-strong);
  font-size: 0.67rem;
  font-weight: 720;
  line-height: 1;
}

.outside-month {
  color: var(--faint);
}

.outside-month .day-hours {
  color: var(--faint);
}

.today .day-number {
  box-shadow: inset 0 0 0 1.5px var(--primary);
  color: var(--primary-strong);
}

.recorded {
  background: var(--primary-softer);
}

.recorded.standard-shift .day-number {
  color: var(--surface);
  background: var(--primary);
}

.recorded.long-shift .day-number {
  color: var(--surface);
  background: var(--accent);
}

.recorded.long-shift .day-hours {
  color: oklch(0.42 0.12 55);
}

.recorded.short-shift .day-number {
  color: var(--ink);
  background: var(--line);
}

.day-cell.rest {
  background: var(--line);
}

.day-cell.rest .day-number {
  color: var(--muted);
  font-weight: 600;
}

.day-cell.rest .day-hours {
  color: var(--muted);
  font-weight: 700;
}

.calendar-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  text-align: center;
}

.bottom-action {
  position: fixed;
  z-index: var(--z-sticky);
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  background: color-mix(in oklch, var(--surface) 94%, transparent);
  border-top: 1px solid var(--line);
}

.primary-button,
.secondary-button,
.danger-text-button {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  font-weight: 700;
  transition: background 180ms cubic-bezier(0.25, 1, 0.5, 1), transform 180ms cubic-bezier(0.25, 1, 0.5, 1);
}

.primary-button {
  display: inline-flex;
  min-width: min(100%, 280px);
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--surface);
  border: 0;
  background: var(--primary-strong);
}

.primary-button:hover {
  background: oklch(0.4 0.11 210);
}

.primary-button:active,
.secondary-button:active {
  transform: scale(0.98);
}

.secondary-button {
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--surface);
}

.secondary-button:hover {
  background: var(--surface-muted);
}

.danger-text-button {
  color: var(--danger);
  border: 0;
  background: transparent;
}

.danger-text-button:hover {
  background: color-mix(in oklch, var(--danger) 8%, transparent);
}

.full-width {
  width: 100%;
  min-width: 0;
}

dialog {
  color: var(--ink);
}

dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}

.sheet {
  width: min(calc(100% - 24px), 520px);
  max-height: min(86dvh, 720px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 8px var(--shadow);
  overflow: auto;
}

.sheet[open],
.message-dialog[open] {
  animation: dialog-in 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet form,
.message-dialog > div {
  padding: 8px 20px 20px;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 3px auto 9px;
  border-radius: 99px;
  background: var(--line);
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.dialog-kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.75rem;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 14px 0 7px;
  font-size: 0.82rem;
  font-weight: 700;
}

.field-label span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
}

.number-control {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  min-height: 58px;
  border-radius: 12px;
  background: var(--surface-muted);
}

.number-control > button {
  border: 0;
  background: transparent;
  font-size: 1.3rem;
}

.number-control > button:hover {
  color: var(--primary-strong);
  background: var(--line);
}

.number-input-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.number-input-wrap input {
  width: 74px;
  padding: 0;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 1.55rem;
  font-weight: 750;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.number-input-wrap span {
  color: var(--muted);
  font-size: 0.8rem;
}

.quick-hours {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.quick-hours button {
  min-height: 44px;
  color: var(--primary-strong);
  border: 0;
  border-radius: 10px;
  background: var(--primary-soft);
  font-size: 0.8rem;
  font-weight: 700;
}

.quick-hours button:hover {
  background: color-mix(in oklch, var(--primary-soft) 78%, var(--primary));
}

.text-input,
.currency-input {
  width: 100%;
  min-height: 48px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}

.text-input {
  padding: 0 13px;
}

.text-input::placeholder {
  color: var(--muted);
}

.entry-preview {
  margin: 13px 0 0;
  color: var(--primary-strong);
  font-size: 0.82rem;
  font-weight: 650;
}

.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.dialog-actions .primary-button {
  min-width: 148px;
}

.settings-section {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.settings-section h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.settings-section p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.55;
}

.currency-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 0 13px;
}

.currency-input span {
  color: var(--muted);
  font-size: 0.78rem;
}

.currency-input input {
  min-width: 0;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
  font-weight: 700;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.message-dialog {
  width: min(calc(100% - 32px), 420px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 8px var(--shadow);
}

.message-dialog > div {
  padding-top: 18px;
}

.message-dialog p,
.message-dialog ol {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

.message-dialog ol {
  padding-left: 1.4rem;
}

.message-dialog .primary-button {
  margin-top: 14px;
}

.toast {
  position: fixed;
  z-index: var(--z-toast);
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 50%;
  max-width: min(calc(100% - 32px), 440px);
  padding: 10px 15px;
  color: var(--surface);
  border-radius: 10px;
  background: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
  font-size: 0.82rem;
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 600px) {
  .sheet {
    width: 100%;
    max-width: none;
    max-height: 88dvh;
    margin: auto 0 0;
    border-radius: 16px 16px 0 0;
  }

  .sheet form {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 360px) {
  .app-shell {
    padding-right: 6px;
    padding-left: 6px;
  }
}

@media (min-width: 641px) {
  body {
    padding: 24px 0;
  }

  .app-shell {
    min-height: calc(100dvh - 48px);
    border-radius: 16px;
  }

  .bottom-action {
    width: 640px;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 0 0 16px 16px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.12 0.012 218);
    --surface: oklch(0.17 0.018 218);
    --surface-muted: oklch(0.215 0.02 218);
    --ink: oklch(0.94 0.012 210);
    --muted: oklch(0.72 0.025 210);
    --faint: oklch(0.49 0.02 218);
    --line: oklch(0.29 0.022 218);
    --primary: oklch(0.68 0.092 210);
    --primary-strong: oklch(0.78 0.082 210);
    --primary-soft: oklch(0.25 0.042 210);
    --primary-softer: oklch(0.215 0.028 210);
    --accent: oklch(0.76 0.13 65);
    --danger: oklch(0.7 0.16 25);
    --focus: oklch(0.76 0.12 210);
    --shadow: oklch(0.03 0 0 / 0.5);
  }

  .recorded.long-shift .day-hours {
    color: var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
