:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --soft: #eef6f2;
  --text: #173f3b;
  --muted: #657772;
  --line: #d8e2df;
  --primary: #176b5b;
  --primary-pressed: #115346;
  --danger: #b83a2f;
  --danger-soft: #fbe8e5;
  --early: #fff2c7;
  --middle: #dceef7;
  --late: #ede3f7;
  --off: #eef1f0;
  --shadow: 0 8px 28px rgba(24, 59, 58, 0.12);
  --radius: 6px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select { font: inherit; letter-spacing: 0; }

button,
input[type="date"],
input[type="month"],
input[type="text"],
select { min-height: var(--tap); }

button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(23, 107, 91, 0.24);
  outline-offset: 1px;
}

a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.app-shell,
.snapshot-sheet {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--surface);
}

.app-shell > main {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 12px;
  color: #ffffff;
  background: var(--primary);
}

.app-header h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
}

.app-header p {
  margin: 2px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
}

.back-link,
.header-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  color: var(--primary);
  background: #ffffff;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
}

.date-toolbar {
  display: grid;
  grid-template-columns: var(--tap) minmax(0, 1fr) var(--tap);
  gap: 8px;
  padding: 11px 12px 9px;
  border-bottom: 1px solid var(--line);
}

.date-step,
.btn,
.icon-btn,
.nav-link,
.history-open,
.history-clear {
  border: 0;
  border-radius: var(--radius);
}

.date-step {
  padding: 0;
  color: var(--text);
  background: var(--soft);
  font-size: 25px;
  line-height: 1;
}

.form-control {
  width: 100%;
  min-width: 0;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.date-input,
.month-input { text-align: center; font-weight: 600; }

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--soft);
  border-bottom: 1px solid var(--line);
}

.metric { padding: 9px 7px; text-align: center; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 12px;
  color: var(--text);
  background: var(--soft);
  font-weight: 600;
  text-align: center;
}

.btn-primary { color: #ffffff; background: var(--primary); }
.btn-primary:active { background: var(--primary-pressed); }
.btn-danger { color: var(--danger); background: var(--danger-soft); }
.btn[disabled] { color: #9aa6a3; background: #f1f3f2; cursor: default; }
.btn-block { width: 100%; }

.search-row,
.add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 7px 12px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}

.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; }

.schedule-row {
  padding: 9px 11px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.schedule-row.early { background: var(--early); }
.schedule-row.middle { background: var(--middle); }
.schedule-row.late { background: var(--late); }
.schedule-row.is-filtered,
.schedule-row.is-inactive { display: none; }

.row-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 7px;
  align-items: center;
  margin-bottom: 7px;
}

.employee-name { overflow-wrap: anywhere; font-size: 16px; font-weight: 600; }
.hours { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.hours.error { color: var(--danger); }

.row-clear {
  min-height: 34px;
  padding: 0 9px;
  color: var(--danger);
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(184, 58, 47, 0.28);
  border-radius: var(--radius);
  font-size: 12px;
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.field-label { display: grid; gap: 3px; min-width: 0; color: var(--muted); font-size: 11px; }
.field-label.note { grid-column: 1 / -1; }
.field-label .form-control { padding: 0 7px; background: rgba(255, 255, 255, 0.78); font-size: 14px; }

.section-header { padding: 17px 13px 10px; border-bottom: 1px solid var(--line); }
.section-header h2 { margin: 0; font-size: 19px; font-weight: 600; }
.section-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.person-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 7px;
  align-items: center;
  min-height: 58px;
  padding: 7px 11px;
  border-bottom: 1px solid var(--line);
}

.person-row.disabled { color: var(--muted); }
.person-main strong { display: block; overflow-wrap: anywhere; font-weight: 600; }
.person-main span { display: block; margin-top: 1px; color: var(--muted); font-size: 12px; }
.person-row .btn { min-height: 36px; padding: 0 9px; font-size: 12px; }

.month-filter { padding: 12px; background: var(--soft); border-bottom: 1px solid var(--line); }
.month-filter .form-control { background: var(--surface); }

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  min-height: 70px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line);
}

.history-info strong { display: block; font-weight: 600; }
.history-info span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.history-actions { display: grid; grid-template-columns: auto auto; gap: 6px; }
.history-open,
.history-clear { min-height: 38px; padding: 0 10px; font-size: 12px; font-weight: 600; }
.history-open { color: #ffffff; background: var(--primary); }
.history-clear { color: var(--danger); background: var(--danger-soft); }

.settings-section { border-bottom: 8px solid var(--bg); }
.settings-section h2 { margin: 0; padding: 14px 12px 8px; font-size: 17px; font-weight: 600; }
.settings-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 12px 15px; }
.settings-actions .wide { grid-column: 1 / -1; }
.settings-note { margin: 0; padding: 0 12px 14px; color: var(--muted); font-size: 12px; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 480px);
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid var(--line);
  box-shadow: 0 -5px 18px rgba(24, 59, 58, 0.1);
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
}

.nav-link.active {
  color: var(--primary);
  background: var(--soft);
  box-shadow: inset 0 3px 0 var(--primary);
}

.empty { padding: 42px 18px; color: var(--muted); text-align: center; }

body[data-page="history"] #historyList .empty {
  display: grid;
  min-height: 160px;
  margin: 12px;
  padding: 24px 18px;
  place-items: center;
  background: var(--soft);
  border-radius: var(--radius);
}

dialog {
  width: calc(100% - 30px);
  max-width: 420px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(10, 33, 30, 0.48); }
.dialog-body { padding: 17px 15px; }
.dialog-body h3 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.dialog-body p { margin: 0 0 13px; color: var(--muted); }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100% - 34px);
  padding: 9px 13px;
  color: #ffffff;
  background: var(--text);
  border-radius: var(--radius);
  transform: translateX(-50%);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.snapshot-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
}

.snapshot-header { padding: 17px 12px 13px; color: #ffffff; background: var(--primary); text-align: center; }
.snapshot-header h1 { margin: 0; font-size: 22px; font-weight: 600; }
.snapshot-header p { margin: 3px 0 0; color: rgba(255, 255, 255, 0.86); font-size: 13px; }
.snapshot-summary { display: grid; grid-template-columns: 1fr 1fr; background: var(--soft); border-bottom: 1px solid var(--line); }
.snapshot-summary div { padding: 8px; text-align: center; }
.snapshot-summary div + div { border-left: 1px solid var(--line); }
.snapshot-summary span { display: block; color: var(--muted); font-size: 11px; }
.snapshot-summary strong { display: block; font-size: 16px; font-weight: 600; }

.snapshot-grid,
.snapshot-row {
  display: grid;
  grid-template-columns: minmax(64px, 0.9fr) 92px 48px minmax(66px, 1.1fr);
  gap: 6px;
  align-items: center;
}

.snapshot-grid { padding: 8px 10px; color: #ffffff; background: var(--primary); font-size: 12px; font-weight: 600; text-align: center; }
.snapshot-row { min-height: 30px; padding: 3px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.snapshot-row.early { background: var(--early); }
.snapshot-row.middle { background: var(--middle); }
.snapshot-row.late { background: var(--late); }
.snapshot-name { overflow-wrap: anywhere; font-weight: 600; }
.snapshot-time,
.snapshot-hours { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.snapshot-note { overflow-wrap: anywhere; }
.snapshot-footer { padding: 10px; color: var(--muted); text-align: center; font-size: 11px; }

body.clean-snapshot .snapshot-tools { display: none; }

@media (max-width: 350px) {
  .app-header { padding-inline: 10px; }
  .action-grid { gap: 4px; padding-inline: 7px; }
  .action-grid .btn { padding-inline: 5px; font-size: 12px; }
  .fields-grid { gap: 5px; }
  .field-label .form-control { padding-inline: 5px; font-size: 13px; }
  .snapshot-grid,
  .snapshot-row {
    grid-template-columns: minmax(57px, 0.9fr) 82px 43px minmax(56px, 1fr);
    gap: 4px;
    padding-inline: 7px;
    font-size: 12px;
  }
}

@media print {
  .snapshot-tools { display: none !important; }
  .snapshot-sheet { max-width: none; }
}
