/* Ranch Maintenance — field app styles. iPhone-first, app-like. */

:root {
  --green-900: #16301f;
  --green-700: #1f3d2b;
  --green-600: #2f5a3f;
  --green-500: #3d7a54;
  --amber:     #d98324;
  --amber-dk:  #b56a16;

  --bg:        #f4f3ee;
  --surface:   #ffffff;
  --surface-2: #efeee7;
  --ink:       #1c2620;
  --ink-soft:  #5c665e;
  --line:      #dcdbd2;

  --red:    #c43c2f;
  --orange: #e07b1a;
  --yellow: #d8a800;
  --blue:   #2f6fb0;
  --gray:   #8b938b;

  --radius: 14px;
  --tap: 48px;
  --pad: 16px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

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

/* ---- boot / loading ---- */

.boot {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--ink-soft);
}
.boot-spinner, .spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px var(--pad);
  text-align: center;
  color: var(--ink-soft);
}
.center-state .big { font-size: 40px; }

/* ---- top bar ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--green-700);
  color: #fff;
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  min-height: calc(54px + var(--safe-top));
  box-shadow: 0 1px 0 rgba(0,0,0,0.15);
}
.topbar .tb-title {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 4px;
}
.topbar .tb-btn {
  min-width: var(--tap);
  height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  font-family: var(--font);
  cursor: pointer;
}
.topbar .tb-btn:active { opacity: 0.6; }
.topbar .tb-spacer { min-width: var(--tap); }

/* ---- screen body ---- */

.screen {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--pad);
  padding-bottom: calc(96px + var(--safe-bottom));
}
.screen.no-nav { padding-bottom: calc(var(--pad) + var(--safe-bottom)); }

.section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 18px 2px 8px;
}
.section-label:first-child { margin-top: 2px; }

/* ---- cards & rows ---- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
}
.card + .card { margin-top: 10px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px var(--pad);
  min-height: var(--tap);
  background: var(--surface);
  border: none;
  width: 100%;
  text-align: left;
  font-family: var(--font);
  font-size: 16px;
  color: var(--ink);
  cursor: pointer;
}
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--surface-2); }
.row .row-main { flex: 1; min-width: 0; }
.row .row-title {
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .row-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .chevron { color: var(--gray); font-size: 20px; flex: none; }
.row .row-thumb {
  width: 44px; height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}

/* ---- stat tiles (home) ---- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  font-family: var(--font);
  cursor: pointer;
}
.tile:active { background: var(--surface-2); }
.tile .tile-num { font-size: 30px; font-weight: 700; line-height: 1; }
.tile .tile-label { font-size: 13px; color: var(--ink-soft); margin-top: 6px; }
.tile.alert .tile-num { color: var(--red); }

/* ---- buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { opacity: 0.7; }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn-primary {
  background: var(--green-600);
  border-color: var(--green-600);
  color: #fff;
}
.btn-amber {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 56px; font-size: 17px; }

/* ---- forms ---- */

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field .req { color: var(--red); }
.field .hint { font-size: 12px; color: var(--ink-soft); margin-top: 5px; }

input, select, textarea {
  width: 100%;
  font-family: var(--font);
  font-size: 16px; /* 16px keeps iOS from auto-zooming on focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  -webkit-appearance: none;
  appearance: none;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.4; }
select {
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%235c665e' stroke-width='2' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(61,122,84,0.15);
}

/* ---- chips / badges ---- */

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip-crit-1 { background: #f7dcd9; color: var(--red); }
.chip-crit-2 { background: #fae3cf; color: var(--orange); }
.chip-crit-3 { background: #f8efc7; color: var(--amber-dk); }
.chip-crit-4 { background: #d6e6f2; color: var(--blue); }
.chip-crit-5 { background: #e4e6e3; color: var(--ink-soft); }

.chip-status-pending     { background: #e4e6e3; color: var(--ink-soft); }
.chip-status-in-progress { background: #d6e6f2; color: var(--blue); }
.chip-status-done        { background: #d8ecdc; color: var(--green-600); }
.chip-status-overdue     { background: #f7dcd9; color: var(--red); }
.chip-status-deferred    { background: #f8efc7; color: var(--amber-dk); }
.chip-status-blocked     { background: #f7dcd9; color: var(--red); }

/* ---- detail key/value ---- */

.kv { padding: 0; }
.kv-row {
  display: flex;
  gap: 12px;
  padding: 12px var(--pad);
  font-size: 15px;
}
.kv-row + .kv-row { border-top: 1px solid var(--line); }
.kv-row .kv-key { color: var(--ink-soft); flex: none; width: 38%; }
.kv-row .kv-val { flex: 1; font-weight: 500; word-break: break-word; }

.detail-photo {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: block;
  margin-bottom: 14px;
  background: var(--surface-2);
}

/* ---- bottom nav ---- */

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px;
  min-height: 56px;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.bottom-nav button .nav-icon { font-size: 21px; line-height: 1; }
.bottom-nav button.active { color: var(--green-600); }
.bottom-nav button.nav-add .nav-icon {
  background: var(--amber);
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-top: -2px;
}
.bottom-nav button.nav-add { color: var(--amber-dk); }

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

.login-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 32px var(--pad) calc(32px + var(--safe-bottom));
  background: var(--green-700);
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
}
.login-logo {
  width: 84px; height: 84px;
  border-radius: 20px;
  margin-bottom: 18px;
}
.login-wrap h1 { font-size: 22px; margin-bottom: 4px; }
.login-wrap .login-sub { color: #bcd1bf; font-size: 14px; margin-bottom: 30px; }
.login-card {
  background: var(--surface);
  color: var(--ink);
  border-radius: 18px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
}
.login-card input {
  text-align: center;
  letter-spacing: 0.2em;
  font-size: 20px;
}
.login-error {
  color: var(--red);
  font-size: 14px;
  text-align: center;
  margin-top: 12px;
  min-height: 18px;
}

/* ---- toast ---- */

#toast-host {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(76px + var(--safe-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--green-900);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 18px;
  border-radius: 999px;
  max-width: 88%;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  animation: toast-in 0.2s ease;
}
.toast.toast-error { background: var(--red); }
.toast.toast-success { background: var(--green-600); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---- offline banner ---- */

.offline-banner {
  background: var(--amber-dk);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 6px 12px;
}
.offline-banner .pending-count { opacity: 0.85; }

/* ---- misc ---- */

.muted { color: var(--ink-soft); }
.spacer-12 { height: 12px; }
.inline-spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -3px;
}
.photo-preview {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  display: block;
}
.search-input { margin-bottom: 12px; }
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.filter-bar .filter-chip {
  flex: none;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
}
.filter-bar .filter-chip.active {
  background: var(--green-600);
  border-color: var(--green-600);
  color: #fff;
}

/* ---- modal / confirm dialog ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 80;
}
.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 8px;
}
.modal-message {
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  white-space: pre-line;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions .btn { flex: 1; }
