:root {
  --bg: #f1f2f0;
  --surface: #ffffff;
  --surface-muted: #f5f6f5;
  --ink: #1f2429;
  --muted: #626b70;
  --accent: #3f6b63;
  --accent-hover: #325550;
  --danger: #9c4a3a;
  --danger-hover: #82392b;
  --line: #dde1df;
  --shadow: 0 1px 2px rgba(15, 23, 27, 0.04), 0 4px 10px rgba(15, 23, 27, 0.05);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-weight: 600;
}

h1 {
  margin: 4px 0 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 70ch;
  line-height: 1.6;
}

/* Auth */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-grid {
  display: grid;
  grid-template-columns: minmax(0, 420px);
  gap: 18px;
  align-items: stretch;
  justify-content: center;
}

.auth-grid #setupCard:not([hidden]) {
  grid-column: span 1;
}

.auth-grid:has(#setupCard:not([hidden])) {
  grid-template-columns: repeat(2, minmax(0, 320px));
}

.auth-grid h2 {
  margin-top: 10px;
}

.stack-form,
.employee-form {
  display: grid;
  gap: 12px;
}

.employee-form {
  grid-template-columns: 1.2fr 1.2fr 1.1fr auto;
  align-items: end;
}

.employee-form > * {
  min-width: 0;
  width: 100%;
}

/* App shell */

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  font-weight: 500;
  padding: 10px 12px;
}

.nav-item:hover {
  background: var(--surface-muted);
  color: var(--ink);
  border-color: transparent;
}

.nav-item.active {
  background: var(--surface-muted);
  color: var(--accent);
  font-weight: 600;
  border-color: var(--line);
}

.user-panel {
  margin-top: auto;
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.user-panel strong {
  font-size: 1.02rem;
}

.user-panel span,
.form-help {
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.user-panel button {
  margin-top: 4px;
  padding: 8px 12px;
  background: var(--ink);
  border-color: var(--ink);
}

.user-panel button:hover {
  background: #000;
  border-color: #000;
}

.content {
  padding: 28px 32px 44px;
  display: grid;
  gap: 18px;
  align-content: start;
  min-width: 0;
  max-width: 1180px;
}

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

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  flex-wrap: wrap;
}

.page-head h2 {
  font-size: 1.4rem;
}

.page-head-controls {
  display: flex;
  align-items: end;
  gap: 16px;
  flex-wrap: wrap;
}

.week-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.week-nav button {
  padding: 8px 10px;
  background: var(--surface-muted);
  color: var(--ink);
  border-color: var(--line);
}

.week-nav button:hover {
  background: var(--line);
}

/* Shared form controls */

.inline-form,
.entry-form {
  display: grid;
  gap: 10px;
}

.inline-form {
  grid-template-columns: 1fr auto;
}

.entry-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.entry-form .full {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 500;
  color: var(--ink);
  font-size: 0.92rem;
}

input,
select,
button {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 10px 12px;
  font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input::placeholder {
  color: #8a9297;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(63, 107, 99, 0.14);
}

button {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.secondary-button {
  margin-top: 14px;
  width: 100%;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
}

.secondary-button:hover {
  background: var(--surface-muted);
  border-color: var(--line);
  color: var(--accent-hover);
}

#setupCard {
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.chips {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips li {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px 4px 10px;
  font-size: 0.9rem;
}

.chips button {
  border-radius: 999px;
  width: 20px;
  height: 20px;
  line-height: 1;
  padding: 0;
  font-size: 11px;
  background: var(--muted);
  border-color: var(--muted);
}

.chips button:hover {
  background: var(--ink);
  border-color: var(--ink);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin-bottom: 12px;
}

.section-head p {
  margin: 0;
  color: var(--muted);
}

.report-actions {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.report-actions .secondary-button {
  margin-top: 0;
  width: auto;
  white-space: nowrap;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}

.filters button {
  width: 100%;
  background: var(--surface-muted);
  color: var(--ink);
  border: 1px solid var(--line);
}

.filters button:hover {
  background: var(--line);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpis div {
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.kpis p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpis strong {
  font-size: clamp(1.5rem, 2vw, 2rem);
  line-height: 1.1;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.summary-grid article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-muted);
  padding: 10px 12px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap {
  overflow-x: auto;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  vertical-align: middle;
}

th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

tr:last-child td {
  border-bottom: none;
}

.remove-entry {
  background: var(--danger);
  border-color: var(--danger);
  padding: 6px 8px;
}

.remove-entry:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.empty {
  color: var(--muted);
  font-style: italic;
}

/* Track grid */

.grid-table th:nth-child(n + 4),
.grid-table td.grid-cell,
.grid-table td.row-total {
  text-align: center;
}

.grid-cell {
  padding: 6px;
}

.empty-cell {
  color: var(--muted);
}

.cell-fill {
  display: inline-flex;
  min-width: 48px;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

button.cell-fill {
  background: var(--surface-muted);
  color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer;
}

button.cell-fill:hover {
  background: var(--line);
  border-color: var(--line);
}

span.cell-fill {
  background: transparent;
  color: var(--ink);
  border: none;
  font-weight: 500;
}

.row-total {
  font-weight: 600;
}

.totals-row td {
  font-weight: 700;
  border-top: 2px solid var(--line);
  border-bottom: none;
  text-align: center;
}

.totals-row td:first-child {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.78rem;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px 16px;
    padding: 14px 18px;
  }

  .brand {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .nav {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
  }

  .nav-item {
    white-space: nowrap;
  }

  .user-panel {
    margin-top: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    padding: 0;
    text-align: left;
  }

  .user-panel span {
    display: none;
  }

  .user-panel button {
    margin-top: 0;
  }

  .content {
    padding: 20px 18px 36px;
  }

  .auth-grid,
  .summary-grid,
  .kpis,
  .filters,
  .employee-form,
  .entry-form {
    grid-template-columns: 1fr;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 560px) {
  .card {
    padding: 16px;
  }

  .filters,
  .summary-grid,
  .kpis {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 7px 5px;
    font-size: 0.9rem;
  }
}

@media print {
  .no-print {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 0;
    max-width: 100%;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
  }

  #weeklySummarySection {
    break-inside: avoid;
  }
}
