/* AgriTurf employee portal */

:root {
  --green-dark: #1a3c2a;
  --green: #2d6a4f;
  --green-mid: #40916c;
  --green-soft: #d8f3dc;
  --earth: #6b4f3a;
  --sand: #f4f1ea;
  --sand-deep: #e8e2d6;
  --ink: #1c1c1c;
  --muted: #5a5a5a;
  --line: #cfc8b8;
  --white: #ffffff;
  --warn: #8a5a00;
  --danger: #8b1a1a;
  --ok: #1b4332;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --max: 1180px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--sand);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

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

/* ---- Login / setup ---- */

body.login-page {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--green-dark) 0%, var(--green) 45%, #3d5a40 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  padding: 1.75rem 1.5rem;
}

.login-card .brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.login-card .brand img {
  height: 44px;
  width: auto;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.3rem;
  color: var(--green-dark);
}

.login-card .sub {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--green-dark);
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  margin-bottom: 0.95rem;
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--green-mid);
  outline-offset: 1px;
}

.btn,
button.btn {
  display: inline-block;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--green);
  color: var(--white);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover,
button.btn:hover {
  background: var(--green-dark);
  text-decoration: none;
}

.btn:disabled,
button.btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn-block {
  width: 100%;
}

.btn-secondary {
  background: transparent;
  color: var(--green-dark);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: var(--sand);
  color: var(--green-dark);
}

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

.btn-danger:hover {
  background: #6a1212;
}

.login-error,
.flash-error,
.flash-ok {
  display: none;
  margin: 0 0 0.9rem;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.login-error,
.flash-error {
  background: #fde8e8;
  color: var(--danger);
}

.flash-ok {
  background: var(--green-soft);
  color: var(--ok);
}

.login-error.show,
.flash-error.show,
.flash-ok.show {
  display: block;
}

.login-note {
  margin: 1rem 0 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--sand-deep);
  font-size: 0.8rem;
  color: var(--muted);
}

.login-note a {
  font-weight: 600;
}

/* ---- Chrome ---- */

.site-header {
  background: var(--green-dark);
  color: var(--white);
  border-bottom: 3px solid var(--green-mid);
}

.site-header .inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--white);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-link:hover {
  text-decoration: none;
  opacity: 0.95;
}

.brand-link img {
  height: 38px;
  width: auto;
  background: var(--white);
  border-radius: 4px;
  padding: 2px;
}

.user-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.role-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--earth);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.role-pill.admin {
  background: var(--green);
}

.role-pill.manager {
  background: #3d5a40;
}

.user-bar button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: var(--white);
  border-radius: 4px;
  padding: 0.25rem 0.55rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.user-bar button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.site-nav {
  background: var(--green);
}

.site-nav ul {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 0.5rem;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0;
}

.site-nav a {
  display: block;
  padding: 0.65rem 0.9rem;
  color: var(--white);
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  border-bottom: 3px solid transparent;
}

.site-nav a:hover {
  background: rgba(0, 0, 0, 0.12);
  text-decoration: none;
}

.site-nav a.active {
  border-bottom-color: #b7e4c7;
  background: rgba(0, 0, 0, 0.15);
}

.nav-admin {
  display: none;
}

body.role-admin .nav-admin {
  display: list-item;
}

main {
  flex: 1;
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
}

.page-title {
  margin: 0 0 0.35rem;
  font-size: 1.55rem;
  color: var(--green-dark);
}

.lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
  max-width: 42rem;
}

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1rem;
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 1.15rem;
  color: var(--green-dark);
}

.panel p {
  margin: 0 0 0.65rem;
}

.panel p:last-child {
  margin-bottom: 0;
}

.placeholder-note {
  margin: 0;
  padding: 0.85rem 1rem;
  background: var(--green-soft);
  border-left: 4px solid var(--green-mid);
  border-radius: 0 6px 6px 0;
  color: var(--ink);
  font-size: 0.95rem;
}

.unavailable {
  background: var(--sand);
  border-left-color: var(--earth);
  color: var(--muted);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.simple,
table.week,
table.admin {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table.simple th,
table.simple td,
table.admin th,
table.admin td,
table.week th,
table.week td {
  text-align: left;
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--sand-deep);
  vertical-align: top;
}

table.week th,
table.week td {
  border: 1px solid var(--sand-deep);
  padding: 0.55rem 0.6rem;
  min-width: 8.5rem;
}

table.simple th,
table.admin th,
table.week th {
  background: var(--sand);
  color: var(--green-dark);
  font-weight: 600;
}

table.week th .date {
  display: block;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.8rem;
}

table.week td.label,
table.week th.item {
  position: sticky;
  left: 0;
  background: #faf8f3;
  min-width: 8rem;
  max-width: 10rem;
  font-weight: 600;
  color: var(--green-dark);
  z-index: 1;
}

table.week th.item {
  background: var(--sand);
  z-index: 2;
}

table.week td {
  white-space: pre-wrap;
  font-size: 0.88rem;
}

table.simple tbody tr:hover,
table.admin tbody tr:hover {
  background: #faf8f3;
}

table.simple td.muted {
  color: var(--muted);
  font-style: italic;
}

.notes-box {
  margin-top: 0.85rem;
  padding: 0.85rem 1rem;
  background: #faf8f3;
  border: 1px solid var(--sand-deep);
  border-radius: 6px;
}

.notes-box h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: var(--green-dark);
}

.notes-box .body {
  white-space: pre-wrap;
  font-size: 0.9rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
  margin-top: 0.5rem;
}

.card-link {
  display: block;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.card-link:hover {
  border-color: var(--green-mid);
  text-decoration: none;
}

.card-link strong {
  display: block;
  color: var(--green-dark);
  margin-bottom: 0.25rem;
}

.card-link span {
  font-size: 0.88rem;
  color: var(--muted);
}

.admin-only {
  display: none;
}

body.role-admin .admin-only {
  display: block;
}

.week-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1rem;
}

.week-tabs button {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  color: var(--green-dark);
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}

.form-row .field {
  min-width: 0;
}

.form-row .field.grow {
  grid-column: span 1;
}

.code-box {
  display: none;
  margin: 0.75rem 0 0;
  padding: 0.85rem 1rem;
  background: #fff8e1;
  border: 1px solid #e6d28a;
  border-radius: 6px;
}

.code-box.show {
  display: block;
}

.code-box strong.code {
  display: block;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  margin: 0.35rem 0;
  color: var(--green-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.status {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--sand-deep);
}

.status.active {
  background: var(--green-soft);
  color: var(--ok);
}

.status.invited {
  background: #fff3cd;
  color: var(--warn);
}

.status.disabled {
  background: #fde8e8;
  color: var(--danger);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.row-actions button,
.row-actions select {
  margin: 0;
  font-size: 0.8rem;
  padding: 0.25rem 0.45rem;
}

.row-actions select {
  width: auto;
  margin-bottom: 0;
}

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--sand-deep);
  padding: 0.85rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

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

@media (max-width: 720px) {
  .user-bar {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .site-nav a {
    padding: 0.55rem 0.7rem;
    font-size: 0.88rem;
  }

  .page-title {
    font-size: 1.35rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  table.week {
    font-size: 0.85rem;
  }
}

.brand-tagline {
  font-size: 0.85rem;
  color: var(--muted);
}
.week-title {
  font-size: 1.15rem;
  margin: 0 0 0.6rem;
  color: var(--green-dark);
}
.tight {
  margin: 0;
}
.hint.tight {
  margin: 0;
}

/* Long names and emails wrap instead of pushing the table off-screen (WT-006). */
table.admin { table-layout: fixed; }
table.admin th:nth-child(1), table.admin td:nth-child(1) { width: 22%; }
table.admin th:nth-child(2), table.admin td:nth-child(2) { width: 26%; }
table.admin th:nth-child(3), table.admin td:nth-child(3) { width: 14%; }
table.admin th:nth-child(4), table.admin td:nth-child(4) { width: 14%; }
table.admin td.wrap, table.admin td .cell-text {
  overflow-wrap: anywhere;
  word-break: break-word;
}
table.admin td .cell-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
table.admin select { max-width: 100%; }
.lock-note { color: #9a3b1e; }
.notice-box { display: none; border: 1px solid var(--sand-deep); background: #fff8e6; padding: 0.7rem 0.9rem; border-radius: 6px; margin: 0.6rem 0; }
.notice-box.show { display: block; }
.notice-box p { margin: 0 0 0.5rem; }
@media (max-width: 720px) {
  table.admin { table-layout: auto; min-width: 0; }
  table.admin th:nth-child(n), table.admin td:nth-child(n) { width: auto; }
}

/* ---------- Read-only sections (Action List, Tickets, Projects, Tsumeb latest) ---------- */
.source-line { color: var(--muted, #5a5a5a); font-size: 0.85rem; margin: 0 0 0.6rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.8rem 1.2rem; align-items: center; margin: 0.8rem 0; }
.filters label { display: flex; align-items: center; gap: 0.4rem; font-weight: 600; font-size: 0.9rem; }
.filters select { max-width: 16rem; }
.filters .check { font-weight: 500; }
.filter-count { color: var(--muted, #5a5a5a); font-size: 0.85rem; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data th, table.data td { text-align: left; vertical-align: top; padding: 0.45rem 0.55rem; border: 1px solid var(--sand-deep, #ddd5c4); white-space: pre-line; overflow-wrap: anywhere; }
table.data th { background: var(--sand, #f4f1ea); color: var(--green-dark, #1a3c2a); position: sticky; top: 0; }
table.data td { min-width: 5.5rem; }
table.data { width: max-content; min-width: 100%; }
table.data td.long { min-width: 18rem; max-width: 26rem; }
table.data td .clip { max-height: 9.5em; overflow-y: auto; white-space: pre-line; }
table.data tr.status-closed td { color: #6b6b6b; }
table.data tr.overdue td { background: #fde8e4; }
table.data tr.overdue td:first-child { border-left: 4px solid #b3261e; font-weight: 700; }
table.data tr.critical td:first-child { border-left: 4px solid #b3261e; }
.sample-banner { background: #fff3cd; border: 2px solid #c99a06; color: #5c4400; padding: 0.7rem 1rem; border-radius: 6px; font-weight: 700; margin: 0.5rem 0 0.8rem; }
.project h2 { margin-top: 0.4rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1rem; margin: 0.6rem 0 1rem; font-size: 0.9rem; }
.facts dt { font-weight: 700; color: var(--green-dark, #1a3c2a); }
.facts dd { margin: 0; }
.project-notes { font-size: 0.88rem; background: #faf8f3; border: 1px solid var(--sand-deep, #ddd5c4); padding: 0.6rem 0.8rem; white-space: pre-line; }
.gantt-wrap { overflow-x: auto; border: 1px solid var(--sand-deep, #ddd5c4); background: #fff; margin-bottom: 1rem; }
svg.gantt { display: block; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
svg.gantt .g-axis { font-size: 11px; fill: #5a5a5a; }
svg.gantt .g-axis-strong { font-weight: 700; fill: #1a3c2a; }
svg.gantt .g-grid { stroke: #e3ddd0; stroke-width: 1; }
svg.gantt .g-weekend { fill: #f6f3ec; }
svg.gantt .g-stripe { fill: #fbfaf6; }
svg.gantt .g-label { font-size: 11.5px; fill: #1c1c1c; }
svg.gantt .g-label.crit { fill: #8f1d16; font-weight: 700; }
svg.gantt .g-after { font-size: 10px; fill: #7a7a7a; }
svg.gantt .bar { stroke: rgba(0,0,0,0.25); stroke-width: 1; }
svg.gantt .st-issued { fill: #2d6a4f; }
svg.gantt .st-decided { fill: #52b788; }
svg.gantt .st-open { fill: #e9a23b; }
svg.gantt .st-planned { fill: #7a96b8; }
svg.gantt .bar.crit { stroke: #b3261e; stroke-width: 2.5; }
svg.gantt .dep { fill: none; stroke: #9a948a; stroke-width: 1; opacity: 0.45; }
svg.gantt .dep-head { fill: #9a948a; }
svg.gantt.focus .dep { opacity: 0.12; }
svg.gantt .dep.on { opacity: 1; stroke: #1a3c2a; stroke-width: 2; }
svg.gantt .g-today { stroke: #1565c0; stroke-width: 2; stroke-dasharray: 4 3; }
svg.gantt .g-today-text { fill: #1565c0; font-weight: 700; }
svg.gantt .g-deadline { stroke: #b3261e; stroke-width: 2; }
svg.gantt .g-deadline-text { fill: #b3261e; font-weight: 700; }
.gantt-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.82rem; margin: 0.3rem 0 0.5rem; }
.gantt-legend .sw { display: inline-block; width: 14px; height: 10px; margin-right: 4px; border-radius: 2px; vertical-align: middle; }
.gantt-legend .sw.st-issued { background: #2d6a4f; }
.gantt-legend .sw.st-decided { background: #52b788; }
.gantt-legend .sw.st-open { background: #e9a23b; }
.gantt-legend .sw.st-planned { background: #7a96b8; }
.gantt-legend .sw.crit { background: #fff; border: 2.5px solid #b3261e; }
.rating { padding: 0.1rem 0.45rem; border-radius: 4px; font-weight: 700; }
.rating-high { background: #fde8e4; color: #8f1d16; }
.rating-medium { background: #fff3cd; color: #5c4400; }
.rating-low { background: #e5f3ea; color: #1f5137; }
@media (max-width: 720px) {
  .filters { flex-direction: column; align-items: stretch; }
  .filters label { justify-content: space-between; }
  .facts { grid-template-columns: 1fr; }
  table.data td.long { min-width: 12rem; }
}

/* Hide section links until /api/session lists them for this role (WT-028). */
.nav-section[data-section][hidden],
.card-link[data-section][hidden] {
  display: none !important;
}

/* Ticket Register and Action List: cards instead of wide tables on a phone
   (WT-030, WT-034). */
.ticket-cards, .action-cards { display: none; }
.ticket-card, .action-card {
  border: 1px solid var(--sand-deep, #ddd5c4);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  background: #fff;
}
.ticket-card.overdue, .action-card.overdue {
  background: #fde8e4;
  border-left: 4px solid #b3261e;
}
.ticket-card h3, .action-card h3 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
  color: var(--green-dark, #1a3c2a);
}
.ticket-card .subject, .action-card .subject {
  margin: 0 0 0.65rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.ticket-card dl, .action-card dl {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.25rem 0.8rem;
  margin: 0;
  font-size: 0.88rem;
}
.ticket-card dt, .action-card dt {
  font-weight: 700;
  color: var(--green-dark, #1a3c2a);
}
.ticket-card dd, .action-card dd {
  margin: 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}
@media (max-width: 600px) {
  #section-root[data-section="tickets"] .table-wrap,
  #section-root[data-section="action-list"] .table-wrap { display: none; }
  #section-root[data-section="tickets"] .ticket-cards,
  #section-root[data-section="action-list"] .action-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
}


/* Ticket Register: first-line preview with a native More toggle */
details.long-text { margin: 0; }
details.long-text > summary {
  cursor: pointer;
  list-style: none;
}
details.long-text > summary::-webkit-details-marker,
details.long-text > summary::marker { display: none; }
details.long-text > summary .more {
  margin-left: 0.4em;
  color: var(--green, #2d6a4f);
  font-weight: 600;
  text-decoration: underline;
  white-space: nowrap;
}
details.long-text[open] > summary .preview { display: none; }
details.long-text > .full { white-space: pre-line; margin-top: 0.4em; }

/* Tsumeb: older v11 is collapsed under a summary */
details.older-version {
  background: var(--white, #fff);
  border: 1px solid var(--line, #cfc8b8);
  border-radius: var(--radius, 8px);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1rem;
}
details.older-version > summary {
  cursor: pointer;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--green-dark, #1a3c2a);
}
details.older-version[open] > summary { margin-bottom: 0.55rem; }

.vehicles-block h3 {
  margin: 0.8rem 0 0.45rem;
  font-size: 1rem;
  color: var(--green-dark, #1a3c2a);
}

.import-warnings {
  background: #fff3cd;
  border: 2px solid #c99a06;
  color: #5c4400;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  font-weight: 700;
  margin: 0.4rem 0 0.7rem;
}
.import-badge {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: #fff3cd;
  border: 1px solid #c99a06;
  color: #5c4400;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  vertical-align: middle;
}
.ticket-id-cell { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
table.data tr.import-flag td:first-child { border-left: 4px solid #c99a06; }
.ticket-card.import-flag { border-left: 4px solid #c99a06; }
