:root {
  --ink: #161513;
  --muted: #6b655c;
  --paper: #f4efe6;
  --card: #fffdf8;
  --line: #ddd6c8;
  --line-strong: #c9c0ae;
  --accent: #161513;
  --pay: #0f6b3e;
  --pay-soft: #e5f4eb;
  --warn: #9a3412;
  --danger: #9f1239;
  --shadow: 0 10px 30px rgba(22, 21, 19, 0.08);
  --sans: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); }
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-logo { width: 72px; height: 48px; object-fit: cover; object-position: 50% 18%; margin-bottom: 12px; }
.login-card h1 { margin-bottom: 8px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.login-error { color: var(--danger); font-weight: 600; }
body { min-height: 100vh; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; }
.hidden { display: none !important; }

.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 22px;
  background: #111;
  color: #f7f3ea;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.logo {
  width: 54px;
  height: 36px;
  object-fit: cover;
  object-position: 50% 18%;
  background: #fff;
  border-radius: 4px;
}
.brand strong { display: block; font-size: 15px; letter-spacing: 0.04em; text-transform: uppercase; }
.brand span { display: block; color: #cfc6b6; font-size: 12px; margin-top: 2px; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab, .ghost, .primary, .icon-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  background: transparent;
}
.tab { color: #d9d1c3; }
.tab.on, .tab:hover { background: #2a2a28; color: #fff; }
.top-actions { margin-left: auto; }
.access-bar {
  margin: 0;
  padding: 8px 22px;
  background: #1c1b19;
  color: #d9d1c3;
  font-size: 12px;
}
.access-bar a { color: #fff; }
.top .ghost { color: #d9d1c3; border-color: #3a3a38; text-decoration: none; display: inline-block; }
.top .ghost:hover { background: #2a2a28; color: #fff; }

.view { padding: 18px 22px 48px; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 18px;
}
.week-nav { display: flex; align-items: center; gap: 10px; }
.week-copy label, .site-fields label, form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.week-copy p { margin: 4px 0 0; font-size: 13px; color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 500; }
.site-fields { display: flex; gap: 12px; flex: 1; min-width: 280px; }
.site-fields label { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-strong);
  background: var(--card);
  font-size: 22px;
  line-height: 1;
}
.ghost { border-color: var(--line-strong); background: var(--card); }
.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.primary:hover { background: #2b2926; }
.danger { color: var(--danger); }
.small { padding: 6px 10px; font-size: 13px; margin-top: 8px; }
.check { flex-direction: row !important; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--ink); font-size: 14px; }
.check input { width: auto; }

input, textarea {
  border: 1px solid var(--line-strong);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: #111; box-shadow: 0 0 0 3px rgba(22,21,19,0.08); }
textarea { resize: vertical; }
select {
  border: 1px solid var(--line-strong);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
  width: 100%;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.kicker { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; }
.pay-total { margin: 4px 0 0; font-family: var(--display); font-size: 48px; color: var(--pay); line-height: 1; }
.hero-sub { margin: 8px 0 0; color: var(--muted); }
.round-picker { margin-top: 16px; }
.round-picker > span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}
.round-options { display: flex; gap: 8px; flex-wrap: wrap; }
.round-options button {
  min-width: 64px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  border-radius: 999px;
  font-weight: 700;
}
.round-options button.on,
.round-options button:hover {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.stats { display: grid; grid-template-columns: repeat(5, minmax(90px, 1fr)); gap: 12px; margin: 0; min-width: 420px; }
.stats div { background: var(--paper); border-radius: 10px; padding: 10px 12px; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stats dd { margin: 4px 0 0; font-weight: 700; font-size: 16px; }

.sheet-wrap { overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.sheet { width: 100%; border-collapse: collapse; min-width: 860px; }
.sheet th, .sheet td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; font-size: 13px; vertical-align: top; }
.sheet th { background: #111; color: #f4efe6; font-weight: 600; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; position: sticky; top: 0; }
.sheet th.pay { color: #b7ebc8; }
.sheet .name { min-width: 160px; }
.sheet .num, .sheet .day { text-align: right; }
.sheet td.num { font-variant-numeric: tabular-nums; padding-top: 14px; }
.sheet .person { font-weight: 700; }
.sheet .role { color: var(--muted); font-size: 12px; }
.sheet input.cell, .sheet input.rate, .sheet input.hours {
  width: 88px;
  text-align: right;
  padding: 6px 7px;
  border-radius: 6px;
}
.sheet input.rate { width: 88px; }
.sheet input.hours { width: 110px; font-weight: 700; font-size: 15px; }
.sheet .hours-hint { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; text-align: right; }
.sheet .bad input { border-color: var(--danger); background: #fff1f2; }
.sheet .pay-cell { font-weight: 800; color: var(--pay); font-size: 15px; }
.sheet .deduct-btn {
  width: 100%;
  text-align: right;
  border: 1px dashed var(--line-strong);
  background: transparent;
  border-radius: 6px;
  padding: 6px 8px;
}
.sheet .deduct-btn:hover { background: var(--paper); }
.hint { padding: 12px 16px; color: var(--muted); font-size: 13px; margin: 0; }
.hint code { background: var(--paper); padding: 1px 5px; border-radius: 4px; }

.people-grid, .history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card, .history-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: left;
}
.card h3, .history-item h3 { font-size: 20px; }
.meta { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.rate-pill { display: inline-block; background: var(--pay-soft); color: var(--pay); font-weight: 700; padding: 3px 8px; border-radius: 999px; font-size: 12px; margin-right: 6px; }
.person-history { margin-top: 8px; }
.person-pay-total { font-family: var(--display); font-size: 28px; color: var(--pay); margin: 4px 0 10px; }
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th, .history-table td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.history-table th:last-child, .history-table td:last-child { text-align: right; }
.history-table button.week-link {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
}
.inactive { opacity: 0.6; }
.history-item { width: 100%; cursor: pointer; }
.history-item:hover { border-color: #111; }
.history-item .pay { color: var(--pay); font-weight: 800; font-size: 22px; margin-top: 8px; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(640px, 96vw);
  background: var(--card);
  box-shadow: var(--shadow);
}
dialog.site-dialog { width: min(760px, 96vw); }
.addr-wrap { position: relative; }
.addr-suggest {
  position: absolute;
  left: 0; right: 0; top: 100%;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  z-index: 30;
  max-height: 220px;
  overflow: auto;
  box-shadow: var(--shadow);
}
.addr-suggest button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  font-size: 13px;
}
.addr-suggest button:hover { background: var(--paper); }
.fence-toggle { display: flex; gap: 8px; }
.fence-toggle .on { background: var(--ink); color: #fff; border-color: var(--ink); }
.site-map { height: 280px; border-radius: 12px; border: 1px solid var(--line); margin: 8px 0; }
.map-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#radius-wrap { flex-direction: column; }
#radius-label { font-weight: 700; }
dialog::backdrop { background: rgba(22, 21, 19, 0.45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: 80vh; overflow: auto; }
dialog h2 { font-size: 26px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.deduct-editor { display: flex; flex-direction: column; gap: 8px; }
.deduct-row { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; }
menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 8px 0 0; }
.muted { color: var(--muted); margin: 0; }
.preview {
  background: var(--paper);
  border-radius: 10px;
  padding: 12px;
  max-height: 240px;
  overflow: auto;
  font-size: 12px;
  white-space: pre-wrap;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #111;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: 360px;
}

@media (max-width: 900px) {
  .top { flex-wrap: wrap; }
  .hero, .toolbar { flex-direction: column; align-items: stretch; }
  .stats { min-width: 0; grid-template-columns: repeat(2, 1fr); }
  .pay-total { font-size: 36px; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (display-mode: standalone) {
  .access-bar { display: none; }
  .top { padding-top: calc(12px + env(safe-area-inset-top)); }
}

@media print {
  .top, .toolbar, .hint, .toast, dialog { display: none !important; }
  body { background: #fff; }
  .hero, .sheet-wrap { box-shadow: none; border-color: #ccc; }
  .view { padding: 0; }
  .sheet { min-width: 0; }
}
