* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

:root {
  --red: #db4c3f;
  --gold: #b8860b;
  --border: #eaeaea;
  --text: #202020;
  --muted: #808080;
  --bg: #fafafa;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #fff;
  overscroll-behavior-y: contain;
}

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

/* ---- login ---- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.brand { color: var(--gold); font-weight: 800; font-size: 26px; text-align: center; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 8px; }

.login-card input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
}
.login-card input:focus { outline: none; border-color: var(--gold); }

.login-error { color: var(--red); font-size: 13px; text-align: center; }
.login-toggle { text-align: center; font-size: 13px; color: var(--muted); }
.login-toggle a { color: var(--gold); }

/* ---- app shell ---- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 8px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}

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

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text);
}
.icon-btn.small { font-size: 15px; padding: 2px 8px; }

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.search-icon { font-size: 14px; opacity: 0.6; }
#searchInput {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 15px;
}
#searchInput:focus { outline: none; border-color: var(--gold); }

.offline-banner {
  background: #fff3cd;
  color: #7a5c00;
  font-size: 12px;
  text-align: center;
  padding: 6px;
}

.reminder-banner {
  display: block;
  width: 100%;
  background: #fff8e6;
  color: var(--gold);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 8px;
  border: none;
  border-bottom: 1px solid #f0e0b0;
}

.task-list { flex: 1; padding: 6px 12px 90px; overflow-y: auto; }

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 16px 4px 6px;
}

.task-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}

.task-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #ccc;
  background: none;
  flex-shrink: 0;
  margin-top: 2px;
}
.task-check.p1 { border-color: var(--red); }
.task-check.p2 { border-color: #ff9933; }
.task-check.p3 { border-color: #4073ff; }
.task-check.completed { background: #ccc; }

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 16px; line-height: 1.4; }
.task-row.completed .task-title { text-decoration: line-through; color: var(--muted); }

.task-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.task-due { font-size: 13px; color: var(--muted); padding: 2px 7px; background: #f0f0f0; border-radius: 4px; }
.task-due.overdue { color: var(--red); background: #fbe1de; }
.color-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 10px; color: #fff; }
.task-photo-thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; }

.empty-state { color: var(--muted); font-size: 13px; padding: 30px 8px; text-align: center; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  font-size: 28px;
  border: none;
  box-shadow: 0 4px 14px rgba(184,134,11,0.4);
  z-index: 15;
}

/* ---- drawer ---- */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 30;
}
.drawer-overlay[hidden] { display: none; }

.drawer {
  width: 82vw;
  max-width: 300px;
  height: 100%;
  background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 14px 16px;
  overflow-y: auto;
}

.drawer-brand { text-align: left; margin-bottom: 14px; }

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 8px;
  border-radius: 6px;
  font-size: 15px;
  color: var(--text);
}
.nav-item.active { background: #f7ecd0; color: var(--gold); font-weight: 600; }

.drawer-section { margin-top: 16px; }
.drawer-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  padding: 4px 8px;
}

.entity-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 8px;
  border-radius: 6px;
  font-size: 15px;
}
.entity-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-item .count { color: var(--muted); font-size: 12px; }
.entity-item .edit-dot { color: var(--muted); font-size: 14px; padding: 2px 6px; }

/* ---- sheets (full screen task editor etc) ---- */

.sheet {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.sheet[hidden] { display: none; }

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 8px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.text-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-weight: 700;
  font-size: 15px;
  padding: 8px 12px;
}

.sheet-body { flex: 1; overflow-y: auto; padding: 14px 16px calc(30px + env(safe-area-inset-bottom)); }

.title-input {
  width: 100%;
  font-size: 18px;
  font-weight: 600;
  border: none;
  outline: none;
  padding: 8px 2px;
  margin-bottom: 4px;
}

.notes-input {
  width: 100%;
  min-height: 60px;
  border: none;
  outline: none;
  resize: vertical;
  font-size: 15px;
  padding: 4px 2px;
  color: var(--muted);
  margin-bottom: 12px;
}

.photo-section { margin-bottom: 16px; }
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.photo-item { position: relative; width: 64px; }
.photo-item img { width: 64px; height: 54px; object-fit: cover; border-radius: 6px; display: block; }
.photo-item .remove-x {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: #fff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  border: 2px solid #fff;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  z-index: 2;
}
.photo-caption-input {
  width: 100%;
  margin-top: 4px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
}
.photo-gps-link {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--gold);
  text-decoration: none;
}

.photo-add-btn {
  display: inline-block;
  padding: 9px 14px;
  border: 1px dashed var(--gold);
  border-radius: 8px;
  font-size: 14px;
  color: var(--gold);
  font-weight: 600;
}
.photo-count { color: var(--muted); font-weight: 400; }
.photo-paste-hint { margin-left: 8px; font-size: 12px; color: var(--muted); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field select, .field input[type="date"], .field input[type="time"] {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
}
.field.two-col { display: flex; gap: 10px; }
.field.two-col > div { flex: 1; }

.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
}
.swatch.selected { border-color: #202020; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.label-toggle {
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 13px;
  color: #fff;
}
.label-toggle.off { opacity: 0.35; }

.primary-btn {
  background: var(--gold);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}
.full-width { width: 100%; }

.danger-btn {
  background: none;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 20px;
}

.listing-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 6px;
}
.listing-field-checks { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); padding: 4px 0; }
.listing-photo-checks { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.listing-photo-check { position: relative; width: 60px; }
.listing-photo-check img { width: 60px; height: 48px; object-fit: cover; border-radius: 6px; display: block; }
.listing-photo-check input {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
}
.listing-btn {
  background: var(--gold);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  margin-top: 4px;
}
.listing-btn:hover { background: #96700a; }

.small-sheet .sheet-body { max-width: 400px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #202020;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 60;
  max-width: 85vw;
  text-align: center;
}
.toast[hidden] { display: none; }
