:root {
  --color-bg: oklch(0.97 0.003 90);
  --color-surface: oklch(1 0 0);
  --color-text: oklch(0.22 0.01 260);
  --color-muted: oklch(0.5 0.01 260);
  --color-muted-2: oklch(0.55 0.01 260);
  --color-border: oklch(0.9 0.005 90);
  --color-border-hover: oklch(0.7 0.01 260);
  --color-divider: oklch(0.93 0.005 90);

  --color-dark: oklch(0.25 0.02 260);
  --color-on-dark: oklch(0.98 0.005 90);

  --color-amber: oklch(0.4 0.13 75);
  --color-amber-dot: oklch(0.6 0.14 75);
  --color-amber-bg: oklch(0.97 0.03 75);
  --color-amber-border: oklch(0.78 0.1 75);
  --color-amber-label: oklch(0.45 0.1 75);

  --color-green: oklch(0.6 0.14 145);
  --color-gray-dot: oklch(0.75 0.01 90);
  --color-danger: oklch(0.5 0.13 25);
  --color-link: oklch(0.55 0.14 250);
  --color-link-hover: oklch(0.45 0.16 250);

  --color-overlay: oklch(0.15 0.01 260 / 0.45);
  --color-topbar: oklch(0.99 0.002 90 / 0.92);

  --shadow-card-hover: 0 2px 10px oklch(0.2 0.02 260 / 0.06);
  --shadow-menu: 0 6px 20px oklch(0.2 0.02 260 / 0.12);

  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Helvetica, Arial, sans-serif;
}

* , *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }

html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: contain;
}
button, input { font-family: inherit; }
button { touch-action: manipulation; }
a { color: var(--color-link); text-decoration: none; }
a:hover { color: var(--color-link-hover); }

@keyframes viewFadeIn { from { opacity: 0; } to { opacity: 1; } }

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

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* — topbar — */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--color-topbar);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--color-dark);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-mark span {
  width: 14px; height: 14px; border: 2px solid var(--color-amber-dot);
  border-bottom: none; border-right: none; transform: rotate(45deg);
}
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.back-btn {
  display: flex; align-items: center; gap: 6px; background: none; border: none;
  font-size: 15px; font-weight: 600; color: var(--color-text); cursor: pointer;
  padding: 10px 6px; min-height: 44px; margin: -10px -6px;
  touch-action: manipulation; transition: transform 100ms ease, opacity 150ms ease;
}
.back-btn:active { transform: scale(0.96); opacity: 0.7; }
.back-btn .chevron { font-size: 18px; line-height: 1; }

.week-nav { display: flex; align-items: center; gap: 10px; }
.week-label { font-size: 13px; color: var(--color-muted); font-weight: 500; white-space: nowrap; }
.week-nav-btns { display: flex; align-items: center; gap: 6px; }
.week-btn {
  width: 44px; height: 44px; border-radius: 9px; border: 1px solid var(--color-border);
  background: var(--color-surface); cursor: pointer; font-size: 16px; color: var(--color-muted-2);
  touch-action: manipulation; transition: transform 100ms ease, opacity 150ms ease;
}
.week-btn:active:not(:disabled) { transform: scale(0.92); }
.week-btn:disabled { opacity: 0.4; cursor: default; }

/* — buttons — */
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 6px; background: var(--color-dark);
  color: var(--color-on-dark); border: none; border-radius: 9px; padding: 10px 16px; min-height: 44px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  touch-action: manipulation; transition: transform 100ms ease, opacity 150ms ease;
}
.btn-primary:active { transform: scale(0.97); opacity: 0.9; }
.btn-secondary {
  display: flex; align-items: center; justify-content: center; gap: 6px; background: none;
  border: 1px solid var(--color-border-hover); color: var(--color-dark); border-radius: 8px;
  padding: 7px 14px; min-height: 44px; font-size: 13px; font-weight: 600; cursor: pointer;
  touch-action: manipulation; transition: transform 100ms ease, opacity 150ms ease;
}
.btn-secondary:active { transform: scale(0.97); opacity: 0.8; }
.btn-plus { font-size: 16px; line-height: 1; }

/* — main containers — */
.view-list {
  max-width: 1100px; margin: 0 auto; padding: 28px 20px calc(80px + env(safe-area-inset-bottom)); width: 100%;
  animation: viewFadeIn 180ms ease;
}
.view-detail {
  max-width: 900px; margin: 0 auto; padding: 24px 20px calc(100px + env(safe-area-inset-bottom)); width: 100%;
  animation: viewFadeIn 180ms ease;
}

.list-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.list-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.list-subtitle { font-size: 14px; color: var(--color-muted); margin-top: 4px; }

/* — site grid/cards — */
.site-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px;
}
.site-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 14px;
  padding: 20px; cursor: pointer; touch-action: manipulation;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 100ms ease;
}
.site-card:hover { border-color: var(--color-border-hover); box-shadow: var(--shadow-card-hover); }
.site-card:active { transform: scale(0.985); border-color: var(--color-border-hover); }
.site-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.site-code { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; min-width: 0; overflow-wrap: break-word; }
.site-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.site-name { font-size: 13px; color: var(--color-muted); margin-bottom: 2px; min-height: 16px; overflow-wrap: break-word; }
.site-workers { display: flex; align-items: baseline; gap: 6px; margin-top: 16px; }
.site-worker-count { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.site-worker-label { font-size: 13px; color: var(--color-muted); }
.site-total-row {
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--color-divider);
  display: flex; align-items: center; justify-content: space-between;
}
.site-total-label { font-size: 12px; color: var(--color-muted); }
.site-total-value { font-size: 16px; font-weight: 700; color: var(--color-amber); }

/* — detail header — */
.detail-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 14px;
}
.detail-code { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; overflow-wrap: break-word; }
.detail-name { font-size: 14px; color: var(--color-muted); margin-top: 2px; overflow-wrap: break-word; }
.detail-header-right { display: flex; align-items: flex-start; gap: 8px; }
.detail-total-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 12px;
  padding: 12px 18px; text-align: right;
}
.detail-total-label {
  font-size: 11px; color: var(--color-muted); text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 600;
}
.detail-total-value { font-size: 24px; font-weight: 700; color: var(--color-amber); margin-top: 2px; }

.section-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.section-label {
  font-size: 13px; font-weight: 600; color: var(--color-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* — worker rows — */
.worker-list { display: flex; flex-direction: column; gap: 10px; }
.worker-card {
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 14px; padding: 16px;
  transition: opacity 180ms ease, transform 180ms ease;
}
.worker-card-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px;
  flex-wrap: wrap;
}
.worker-name { font-size: 15px; font-weight: 600; overflow-wrap: break-word; }
.worker-rate { font-size: 12px; color: var(--color-muted); margin-top: 1px; display: flex; align-items: center; gap: 4px; }
.worker-rate-input {
  width: 72px; padding: 8px 6px; border-radius: 6px; border: 1px solid transparent;
  font-size: 13px; color: var(--color-muted); background: transparent; text-align: right; min-height: 36px;
}
.worker-rate-input:hover, .worker-rate-input:focus {
  border-color: var(--color-border); background: var(--color-surface); outline: none; color: var(--color-text);
}
.worker-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.worker-total { text-align: right; }
.worker-total-label { font-size: 11px; color: var(--color-muted); }
.worker-total-value { font-size: 17px; font-weight: 700; }

.menu-wrap { position: relative; }
.menu-btn {
  width: 44px; height: 44px; border-radius: 9px; border: 1px solid var(--color-border);
  background: var(--color-surface); cursor: pointer; font-size: 17px; color: var(--color-muted-2);
  touch-action: manipulation; transition: transform 100ms ease;
}
.menu-btn:active { transform: scale(0.92); }
.menu-dropdown {
  position: absolute; right: 0; top: 48px; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: 10px; box-shadow: var(--shadow-menu);
  z-index: 10; min-width: 190px; overflow: hidden;
  opacity: 0; transform: translateY(-6px) scale(0.98); pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.menu-dropdown.is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.menu-section-label {
  padding: 8px 14px; font-size: 11px; font-weight: 600; color: var(--color-muted);
  text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--color-divider);
}
.menu-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 12px 14px; min-height: 44px; font-size: 14px; cursor: pointer; color: var(--color-dark);
  touch-action: manipulation; transition: background-color 100ms ease;
}
.menu-item:hover { background: var(--color-bg); }
.menu-item:active { background: var(--color-divider); }
.menu-item-danger {
  color: var(--color-danger); border-top: 1px solid var(--color-divider);
}

/* — day toggle strip — */
.day-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-toggle {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 0; min-height: 48px;
  border-radius: 9px; border: 1px solid var(--color-border); background: var(--color-bg);
  cursor: pointer; touch-action: manipulation;
  transition: background-color 160ms ease, border-color 160ms ease, transform 100ms ease;
}
.day-toggle.is-present {
  background: var(--color-amber-bg); border-color: var(--color-amber-border);
}
.day-toggle:active:not(:disabled) { transform: scale(0.94); }
.day-toggle:disabled { opacity: 0.45; cursor: default; }
.day-toggle-label {
  font-size: 10px; font-weight: 600; color: var(--color-muted-2);
  text-transform: uppercase; letter-spacing: 0.02em;
  transition: color 160ms ease;
}
.day-toggle.is-present .day-toggle-label { color: var(--color-amber-label); }
.day-toggle-dot {
  width: 18px; height: 18px; border-radius: 5px; background: var(--color-border);
  display: flex; align-items: center; justify-content: center;
  transition: background-color 160ms ease;
}
.day-toggle.is-present .day-toggle-dot { background: var(--color-amber-dot); }
.day-toggle-check {
  width: 8px; height: 5px; border-left: 2px solid white; border-bottom: 2px solid white;
  transform: rotate(-45deg) translateY(-1px) scale(0.5);
  opacity: 0; transition: opacity 150ms ease, transform 150ms ease;
}
.day-toggle.is-present .day-toggle-check {
  opacity: 1; transform: rotate(-45deg) translateY(-1px) scale(1);
}

/* — empty state — */
.empty-state { text-align: center; padding: 60px 20px; color: var(--color-muted-2); }
.empty-state-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.empty-state-body { font-size: 13px; }

/* — error banner — */
.error-banner {
  max-width: 1100px; margin: 16px auto 0; padding: 0 20px;
}
.error-banner-inner {
  background: oklch(0.96 0.04 25); border: 1px solid oklch(0.85 0.08 25);
  color: oklch(0.4 0.13 25); border-radius: 10px; padding: 10px 14px;
  font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.error-dismiss {
  background: none; border: none; color: inherit; cursor: pointer; font-size: 18px; line-height: 1;
  padding: 10px; margin: -10px; flex-shrink: 0; touch-action: manipulation;
}

/* — modals — */
.modal-overlay {
  position: fixed; inset: 0; background: var(--color-overlay); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; transition: opacity 180ms ease;
}
.modal-overlay.is-open { opacity: 1; }
.modal-box {
  background: var(--color-surface); border-radius: 16px; padding: 24px; width: 100%; max-width: 380px;
  transform: scale(0.96) translateY(8px);
  transition: transform 180ms ease;
}
.modal-overlay.is-open .modal-box { transform: scale(1) translateY(0); }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 12px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--color-muted); margin-bottom: 5px; }
.form-input {
  width: 100%; padding: 10px 12px; min-height: 44px; border-radius: 9px; border: 1px solid var(--color-border-hover);
  font-size: 16px; background: var(--color-surface); color: var(--color-text);
  transition: border-color 150ms ease;
}
.form-input:focus { outline: none; border-color: var(--color-dark); }
.form-select { width: 100%; padding: 10px 12px; min-height: 44px; border-radius: 9px; border: 1px solid var(--color-border-hover); font-size: 16px; background: var(--color-surface); color: var(--color-text); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-body-text { font-size: 14px; color: var(--color-muted); line-height: 1.5; margin-bottom: 4px; }
.modal-btn-cancel {
  flex: 1; padding: 11px; min-height: 44px; border-radius: 9px; border: 1px solid var(--color-border-hover);
  background: none; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--color-text);
  touch-action: manipulation; transition: transform 100ms ease, opacity 150ms ease;
}
.modal-btn-cancel:active { transform: scale(0.97); opacity: 0.8; }
.modal-btn-submit {
  flex: 1; padding: 11px; min-height: 44px; border-radius: 9px; border: none; background: var(--color-dark);
  color: white; font-size: 14px; font-weight: 600; cursor: pointer;
  touch-action: manipulation; transition: transform 100ms ease, opacity 150ms ease;
}
.modal-btn-submit:active:not(:disabled) { transform: scale(0.97); opacity: 0.9; }
.modal-btn-submit:disabled { opacity: 0.6; cursor: default; }
.modal-btn-danger { background: var(--color-danger); }

@media (max-width: 640px) {
  .view-list { padding: 20px 14px calc(72px + env(safe-area-inset-bottom)); }
  .view-detail { padding: 16px 12px calc(88px + env(safe-area-inset-bottom)); }
  .list-title { font-size: 22px; }
  .site-grid { gap: 12px; }
  .site-card { padding: 16px; }
  .worker-card { padding: 12px; }
  .day-strip { gap: 4px; }
  .day-toggle-label { font-size: 9px; }
  .day-toggle-dot { width: 20px; height: 20px; }
  .worker-card-top { flex-wrap: wrap; }
  .detail-header { gap: 10px; }
  .detail-header-right { width: 100%; justify-content: space-between; }
  .modal-box { padding: 20px; }
}
