:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e2e4e9;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success-bg: #ecfdf3;
  --success-text: #027a48;
  --error-bg: #fef3f2;
  --error-text: #b42318;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --radius: 10px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 14px 72px;
}

h1 { font-size: 1.35rem; margin: 28px 0 12px; }
h1:first-of-type { margin-top: 8px; }
h2 { font-size: 1.05rem; margin: 22px 0 8px; }

a { color: var(--primary); text-decoration: none; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar span { font-weight: 600; }

/* ---------- Auth pages ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.auth-card {
  background: var(--card);
  padding: 28px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 360px;
}
.auth-card h1 { font-size: 1.2rem; text-align: center; margin: 0 0 20px; }

/* ---------- Form controls ---------- */
label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 14px;
}

input, select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px; /* keeps iOS from zooming on focus */
  background: #fff;
  color: var(--text);
  min-height: 44px;
}

button {
  width: 100%;
  min-height: 46px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--primary-dark); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 18px;
}
.checkbox-row input { width: auto; margin: 0; min-height: 0; }

/* ---------- Messages / badges ---------- */
.success { background: var(--success-bg); color: var(--success-text); padding: 11px 14px; border-radius: 8px; font-size: 0.9rem; }
.error   { background: var(--error-bg);   color: var(--error-text);   padding: 11px 14px; border-radius: 8px; font-size: 0.9rem; }
.muted { color: var(--muted); }

.site-badge { font-size: 0.95rem; margin: 4px 0 16px; }
.site-badge.muted { color: var(--muted); }

.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary-dark);
  vertical-align: middle;
}
.tag-off { background: #f3f4f6; color: var(--muted); }

/* ---------- Cards / forms ---------- */
.entry-form, .range-form, .inline-form, .stack-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 22px;
}
.stack-form { margin-top: 12px; }

.hours-line { margin: 4px 0 14px; font-size: 0.95rem; color: var(--muted); }

.role-choice { font-size: 0.85rem; margin-bottom: 14px; }
.role-choice .field-label { display: block; color: var(--muted); margin-bottom: 6px; }
.role-options { display: flex; gap: 18px; }
.role-options label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 0.95rem; color: var(--text); }
.role-options input { width: auto; margin: 0; min-height: 0; }

/* ---------- Tables (always wrapped in .table-wrap) ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 8px; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 0.92rem; white-space: nowrap; }
th { background: #fafafa; color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
.total-row td { font-weight: 700; background: #fafafa; }

.worker-heading { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Worker management cards ---------- */
.worker-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.worker-card.is-off { opacity: 0.7; }
.worker-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.worker-card-head .muted { font-size: 0.85rem; }

.card-line { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 12px; }
.card-line:last-child { margin-bottom: 0; }
.card-line label { flex: 1; margin-bottom: 0; }
.btn-small { width: auto; min-height: 44px; padding: 10px 16px; font-size: 0.9rem; white-space: nowrap; }
.btn-danger { width: auto; min-height: 44px; padding: 10px 16px; font-size: 0.9rem; background: var(--danger); white-space: nowrap; }
.btn-danger:hover { background: var(--danger-dark); }

.add-worker { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--border); }

.pw-change { margin-top: 28px; }
.pw-change > summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: 6px 0; }

.row-actions { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.inline-delete { display: inline; margin: 0; padding: 0; border: none; background: none; }

/* ---------- Larger screens: let forms breathe into columns ---------- */
@media (min-width: 620px) {
  main { padding: 24px 16px 72px; }
  h1 { font-size: 1.5rem; }

  .entry-form, .range-form, .inline-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    align-items: end;
  }
  .entry-form label, .range-form label, .inline-form label { margin-bottom: 0; }
  .entry-form .hours-line { grid-column: 1 / -1; margin: 0; }
  .role-choice { grid-column: 1 / -1; }
  .entry-form button, .range-form button, .inline-form button { width: auto; padding: 12px 22px; }

  .stack-form { max-width: 360px; }
  .stack-form button { width: auto; padding: 12px 22px; }
}
