:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1c2420;
  --text-dim: #6b7570;
  --border: #e2ddd0;
  --green: #1e7a4e;
  --green-dark: #165c3b;
  --green-tint: #e4f2ea;
  --red: #c63e34;
  --red-dark: #a5322a;
  --danger: #c63e34;
  --danger-tint: #fbe9e7;
  --radius: 14px;
  --shell-max: 640px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10150f;
    --surface: #181f18;
    --surface-2: #202920;
    --text: #f1f4ef;
    --text-dim: #9fac9d;
    --border: #2b342a;
    --green: #3fb87e;
    --green-dark: #2f9968;
    --green-tint: #17332595;
    --red: #e06a5c;
    --red-dark: #c6544a;
    --danger: #e06a5c;
    --danger-tint: #3a1f1c;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

a { color: var(--green-dark); }

.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  text-align: center;
}

#app {
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(64px + var(--safe-bottom));
}

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  gap: 12px;
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
}

.topbar .brand {
  display: flex;
  align-items: center;
}

.topbar .brand img {
  height: 30px;
  width: auto;
  display: block;
}

.topbar .who {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-dim);
}

.icon-btn {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ---------- Bottom nav ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  max-width: var(--shell-max);
  margin: 0 auto;
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.tabbar a {
  flex: 1;
  text-align: center;
  padding: 10px 0 8px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.tabbar a.active {
  color: var(--green-dark);
}

.tabbar svg { width: 22px; height: 22px; }

/* ---------- Generic layout ---------- */

main {
  flex: 1;
  padding: 0 16px 24px;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 20px 2px 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.empty {
  color: var(--text-dim);
  padding: 32px 8px;
  text-align: center;
  font-size: 15px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--green);
  color: #fff;
}

.btn:active { background: var(--green-dark); }

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn.danger {
  background: var(--danger-tint);
  color: var(--danger);
}

.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-fab {
  position: fixed;
  right: max(16px, calc((100vw - var(--shell-max)) / 2 + 16px));
  bottom: calc(80px + var(--safe-bottom));
  z-index: 41;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="tel"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.field textarea { resize: vertical; min-height: 64px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: -6px;
  margin-bottom: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 10px;
}

/* ---------- Auth ---------- */

.auth-shell {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 0 20px;
  text-align: center;
}

.auth-shell .logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  margin: 0 auto 16px;
}

.auth-shell h1 { margin: 0 0 4px; }
.auth-shell p.sub { color: var(--text-dim); margin: 0 0 24px; }

.tabs-toggle {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 20px;
}

.tabs-toggle button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  border-radius: 8px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
}

.tabs-toggle button.active {
  background: var(--surface);
  color: var(--text);
}

/* ---------- Checklist list ---------- */

.checklist-card {
  display: block;
  text-decoration: none;
  color: inherit;
}

.checklist-card .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.checklist-card h3 { margin: 0; font-size: 16px; }

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}

.badge.done { background: var(--green-tint); color: var(--green-dark); }

.progress-track {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  margin-top: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
}

.checklist-card .meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ---------- Checklist items ---------- */

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}

.item-main {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.item-main input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
  flex-shrink: 0;
}

.item-main span {
  font-size: 15px;
}

.item.done .item-main span {
  color: var(--text-dim);
  text-decoration: line-through;
}

.item-note {
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
}

.item-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  min-height: 14px;
}

/* ---------- Reports / history ---------- */

.report-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.report-row .left h4 { margin: 0 0 3px; font-size: 15px; }
.report-row .left p { margin: 0; font-size: 12px; color: var(--text-dim); }
.report-row .chev { color: var(--text-dim); }

/* ---------- Tasks ---------- */

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
}

.task-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.task-top input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin-top: 1px;
  accent-color: var(--green);
  flex-shrink: 0;
}

.task-title {
  flex: 1;
  font-size: 15px;
  border: none;
  background: transparent;
  padding: 0;
}

.task.done .task-title {
  color: var(--text-dim);
  text-decoration: line-through;
}

.task-del {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
}

.task-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  margin-left: 34px;
}

/* ---------- New checklist form ---------- */

.item-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.item-input-row input { flex: 1; }

.item-input-row button {
  border: none;
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 8px;
  width: 38px;
  cursor: pointer;
}

.add-item-link {
  background: none;
  border: none;
  color: var(--green-dark);
  font-weight: 600;
  padding: 6px 0;
  cursor: pointer;
}
