:root {
  --green: #2f5233;
  --green-light: #4d7c4d;
  --amber: #c98a2b;
  --red: #b3452c;
  --bg: #f6f4ef;
  --card-bg: #ffffff;
  --text: #23291f;
  --muted: #6b7160;
  --border: #ddd6c6;
}

* { box-sizing: border-box; }

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

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: var(--green);
  color: white;
  padding: 0.75rem 1rem;
}

.app-header h1 {
  font-size: 1.15rem;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-bar {
  font-size: 0.8rem;
  opacity: 0.85;
}

select, input, textarea, button {
  font: inherit;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* A utility class has to beat whatever display value the component sets, and .hidden is
   declared before most of them -- without !important, any later `display: flex` wins on
   source order and the element stays on screen. */
.hidden { display: none !important; }

.current-user {
  font-size: 0.85rem;
  font-weight: 600;
}

.secondary-btn {
  background: transparent;
  color: white;
  border-color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  white-space: nowrap;
}

.auth-screen, .pending-screen {
  max-width: 380px;
  margin: 3rem auto;
  padding: 1.5rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-form h2 {
  margin: 0 0 0.4rem;
}

.auth-form button[type="submit"] {
  background: var(--green);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.auth-error {
  color: var(--red);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 0;
}

.pending-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.75rem;
}

.pending-actions button {
  cursor: pointer;
}

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

#crew-panel {
  background: #fffaf0;
  border-color: var(--amber);
}

#crew-panel > details > summary {
  color: var(--amber);
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stacked-form h3 {
  margin: 0.75rem 0 0;
  font-size: 0.95rem;
}

#add-employee-form button[type="submit"] {
  align-self: flex-start;
  background: var(--amber);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  border: none;
}

.feedback {
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

.feedback.error {
  color: var(--red);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

#add-job-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

/* Selects and date inputs carry an intrinsic minimum width that's wider than half a
   phone screen, which pushed the right-hand column off the edge. Grid children default
   to min-width:auto, so they have to be told they're allowed to shrink. */
.form-row > * {
  min-width: 0;
  width: 100%;
}

#add-job-form textarea {
  min-height: 4.5rem;
  resize: vertical;
  font: inherit;
}

#add-job-form input[type="text"] {
  width: 100%;
}

#add-job-form button {
  align-self: flex-start;
  background: var(--green);
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  font-weight: 600;
}

.filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filters button {
  white-space: nowrap;
  flex: 0 0 auto;
}

.filters button {
  background: white;
  cursor: pointer;
}

.filters button.active {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.job-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem;
}

.job-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 6px solid var(--green-light);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.job-card.pinned {
  border-left-color: var(--amber);
  background: #fffaf0;
}

.job-card.overdue {
  border-left-color: var(--red);
}

.job-card.done {
  opacity: 0.55;
}

.job-top {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.chip {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  font-weight: 600;
}

.pinned-chip { background: var(--amber); color: white; }
.overdue-chip { background: var(--red); color: white; }

.job-card h3 {
  margin: 0.1rem 0;
  font-size: 1.05rem;
}

.job-meta {
  color: var(--muted);
  font-size: 0.85rem;
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.job-notes {
  font-size: 0.9rem;
  margin: 0.4rem 0 0;
  color: var(--text);
}

.job-actions {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.job-actions button {
  background: var(--bg);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
}




/* ---------- ageing / neglect UI ---------- */

/* The add-job form collapses by default so the board itself is what you see first --
   on a phone in the paddock, reading the list matters more than filing new work. */
#add-job-panel > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--green);
  list-style: none;
  padding: 0.2rem 0;
}

#add-job-panel > summary::-webkit-details-marker {
  display: none;
}

#add-job-panel[open] > summary {
  margin-bottom: 0.75rem;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* Standing count of what the crew has been working around. */
.slip-alert {
  background: #fdf3e2;
  border: 1px solid var(--amber);
  border-left: 6px solid var(--amber);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.slip-alert button {
  background: var(--amber);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  margin-left: 0.25rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

.job-card.slipping {
  border-left-color: var(--amber);
}

/* Overdue and pinned outrank "slipping" for the edge colour -- a job can be both, and
   the harder signal should be the one you see. */
.job-card.overdue.slipping {
  border-left-color: var(--red);
}

.job-card.pinned.slipping {
  border-left-color: var(--amber);
}

.chip.importance {
  font-weight: 700;
  color: white;
}

.imp-critical { background: var(--red); }
.imp-high { background: var(--amber); }
.imp-medium { background: var(--green-light); }
.imp-low { background: var(--muted); }

.slipping-chip {
  background: var(--amber);
  color: white;
}

/* Why the job sits where it does. Without this the ordering looks arbitrary. */
.rank-reason {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.5rem 0 0;
  font-style: italic;
}

.assign-inline select {
  font-size: 0.8rem;
  padding: 0.35rem 0.4rem;
  max-width: 10rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

.auth-screen {
  text-align: left;
}

.auth-form label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: -0.3rem;
}

.auth-form input {
  width: 100%;
}

.auth-form input[readonly] {
  background: var(--bg);
  color: var(--muted);
}

.auth-sub,
.auth-note {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.4rem;
  line-height: 1.4;
}

.auth-note:empty {
  margin: 0;
}

.auth-note {
  color: var(--amber);
}

#auth-back {
  font-size: 0.85rem;
  color: var(--green);
  text-align: center;
}

/* ---------- crew admin ---------- */

.crew-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.crew-row {
  display: grid;
  gap: 0.35rem;
  padding: 0.6rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* The name is directly editable -- renaming is a one-tap job, not a dialog. */
.crew-name {
  font-weight: 600;
  width: 100%;
}

.crew-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.crew-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.crew-actions .secondary-btn {
  color: var(--red);
  border-color: var(--border);
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
}

.crew-actions .secondary-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.crew-feedback:empty {
  display: none;
}

.pending-chip {
  background: var(--muted);
  color: white;
}

/* ---------- attachments: photos and map pins ---------- */

.attach-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.map-url-input {
  flex: 1 1 12rem;
  min-width: 0;
  font-size: 0.85rem;
}

.map-link {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--green);
  font-weight: 600;
  text-decoration: none;
}

.photo-strip {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.photo-strip:empty {
  margin-top: 0;
}

.photo-thumb {
  position: relative;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  cursor: pointer;
  line-height: 0;
}

.photo-thumb img {
  width: 76px;
  height: 76px;
  object-fit: cover;
  display: block;
}

.photo-thumb.draft {
  cursor: default;
}

.photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
}

.photo-size {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.55);
  color: white;
  font-size: 0.62rem;
  line-height: 1.4;
  text-align: center;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.1rem;
  cursor: pointer;
}

/* ---------- reactions and comments ---------- */

.reaction-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

.reaction {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.reaction.reacted {
  background: var(--green);
  border-color: var(--green);
  color: white;
  font-weight: 600;
}

.comment-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  width: 100%;
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  padding: 0.6rem 0 0;
  text-align: left;
  font-size: 0.85rem;
  color: var(--green);
  font-weight: 600;
  cursor: pointer;
}

.thread {
  margin-top: 0.5rem;
}

.comment-list {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.comment {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
}

.comment-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.comment p {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.comment-compose {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.comment-compose textarea {
  width: 100%;
  resize: vertical;
  font-size: 0.9rem;
}

[data-action="comment-send"] {
  background: var(--green);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}

.comment-feedback:empty {
  display: none;
}


/* ---------- invites, codes and recovery ---------- */

.auth-links {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.2rem;
  text-align: center;
}

.auth-links a {
  font-size: 0.85rem;
  color: var(--green);
}

/* Codes get typed with gloves on, so give them room and don't let the browser
   second-guess the characters. */
.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.15rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}

.crew-phone {
  width: 100%;
  font-size: 0.85rem;
}

.crew-phone-readout {
  font-size: 0.8rem;
  font-weight: 600;
}

/* The one moment a code is readable. Deliberately loud -- if it's missed, it's gone. */
.code-panel {
  margin-top: 0.75rem;
  padding: 0.9rem 1rem;
  background: var(--card-bg);
  border: 2px solid var(--green);
  border-radius: 10px;
}

.code-panel h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.code-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin: 0.2rem 0;
  color: var(--green);
  user-select: all; /* one tap selects the whole code */
}

.code-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.2rem 0 0;
  line-height: 1.4;
}

.code-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

.code-actions a.attach-btn {
  text-decoration: none;
  color: var(--text);
}

#code-copy {
  background: var(--green);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
  padding: 0.5rem 0.9rem;
}

.code-actions .secondary-btn {
  color: var(--muted);
  border-color: var(--border);
}

.reset-requests {
  margin-bottom: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: #fdf3e2;
  border: 1px solid var(--amber);
  border-radius: 10px;
}

.reset-requests h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.reset-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 0;
  border-top: 1px solid rgba(201, 138, 43, 0.35);
}

.reset-row > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.reset-when {
  font-size: 0.78rem;
  color: var(--muted);
}

.reset-actions {
  display: flex;
  gap: 0.4rem;
}

.reset-approve {
  background: var(--amber);
  color: white;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.45rem 0.8rem;
}

.reset-actions .secondary-btn {
  color: var(--muted);
  border-color: var(--border);
  font-size: 0.85rem;
}

/* ===========================================================================
   KEEP THIS BLOCK LAST.
   Media queries add no specificity, so any rule written below this point wins
   over its desktop override on source order alone -- which is how the crew list
   quietly went back to a single column after new styles were appended. New
   styles go ABOVE here.
   =========================================================================== */

/* Dashboard / wide-screen view: denser multi-column board for a mounted tablet or laptop */
@media (min-width: 900px) {
  .form-row {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
  .job-list {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    align-items: start;
  }
  .app-header h1 {
    font-size: 1.4rem;
  }
  .job-card h3 {
    font-size: 1.15rem;
  }
  /* On a mounted tablet or laptop the crew list reads better as a grid than as one
     very wide row per person. */
  .crew-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    align-items: start;
  }
}
