:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #17201c;
  --muted: #65706b;
  --line: #d9dfd8;
  --accent: #126a59;
  --accent-dark: #0d4d42;
  --warn: #9d5b12;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  min-height: 42px;
  padding: 0 18px;
  cursor: pointer;
}

button:hover { background: var(--accent-dark); }
button.ghost { background: #e9eee9; color: var(--ink); }

.app { min-height: 100vh; }
.hidden { display: none !important; }

.dashboard, .work { padding: 28px; }

.brand p, .topbar p {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
}

.brand h1, .topbar h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 1;
  letter-spacing: 0;
}

.loginBox {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  gap: 16px;
  box-shadow: 0 12px 38px rgba(30, 42, 36, .08);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  min-width: 0;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

textarea { min-height: 92px; resize: vertical; }

.error { color: #b32727; min-height: 20px; margin: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.topbar h1 { font-size: 34px; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#activeCity {
  color: var(--muted);
  font-weight: 700;
}
#saveState { color: var(--muted); min-width: 120px; text-align: right; }

.summary {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
  margin-bottom: 22px;
}

.summary h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.summaryGrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-height: 96px;
}

.metric strong {
  display: block;
  margin-bottom: 12px;
  line-height: 1.2;
}

.metric span {
  display: inline-flex;
  min-width: 86px;
  color: var(--muted);
}

.form {
  display: grid;
  gap: 18px;
}

.group {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.group h2 {
  margin: 0;
  font-size: 20px;
}

.groupTitle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.groupTotals {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.groupTotals span {
  display: grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  align-items: center;
  min-width: 58px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7faf7;
  padding: 5px 8px;
  white-space: nowrap;
}

.groupTotals em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  line-height: 1.1;
}

.groupTotals b {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.1;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.field {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field small {
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.checks {
  display: grid;
  gap: 8px;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 500;
}

.checks input {
  width: 18px;
  height: 18px;
}

.choiceInput {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(0, .85fr);
  gap: 8px;
  max-width: 100%;
  min-width: 0;
}

.tableSection {
  display: grid;
  gap: 12px;
}

.tableTools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tableTools h2 {
  margin: 0;
  font-size: 20px;
}

.tableTools input {
  max-width: 360px;
}

.tableWrap {
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

th, td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  max-width: 240px;
  min-width: 120px;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  white-space: pre-wrap;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #edf2ed;
  color: var(--ink);
  font-weight: 750;
}

.groupHeaderRow th {
  background: #e5ede7;
  min-width: 180px;
}

.tableGroupTitle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: max-content;
}

.groupHeaderRow strong {
  display: block;
  margin: 0;
}

.groupHeaderRow .groupTotals {
  display: flex;
  gap: 5px;
}

.groupHeaderRow .groupTotals span {
  min-width: 50px;
  min-height: 38px;
  background: #f7faf7;
  padding: 3px 6px;
}

.groupHeaderRow .groupTotals b {
  font-size: 14px;
}

thead th span {
  display: block;
  color: var(--accent);
  font-size: 11px;
  margin-bottom: 4px;
}

.stickyCol {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 170px;
  background: #f9fbf9;
}

thead .stickyCol {
  z-index: 4;
  background: #e5ede7;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start end;
  padding: 78px 28px 28px;
  background: rgba(17, 24, 20, .28);
}

.modalPanel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(20, 30, 26, .22);
}

.modalHead {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 0;
}

.modalHead p {
  margin: 0 0 4px;
  color: var(--accent);
  font-weight: 700;
}

.modalHead h2 {
  margin: 0;
  font-size: 22px;
}

.modalPanel .loginBox {
  border: 0;
  box-shadow: none;
}

.iconButton {
  min-width: 36px;
  width: 36px;
  min-height: 36px;
  padding: 0;
  background: #e9eee9;
  color: var(--ink);
}

@media (max-width: 760px) {
  .dashboard, .work { padding: 18px; }
  .topbar { display: grid; }
  .actions { width: 100%; }
  .actions button { flex: 1; }
  #saveState { width: 100%; text-align: left; }
  .tableTools { align-items: stretch; flex-direction: column; }
  .tableTools input { max-width: none; }
  .modal { padding: 70px 14px 14px; }
  .groupTitle { align-items: flex-start; flex-direction: column; }
  .choiceInput { grid-template-columns: 1fr; }
}
