/* ============================================================
   SiteOps — mobile-first field operations app
   ============================================================ */
:root {
  --navy: #0e2530;
  --navy-2: #16333f;
  --ink: #18242e;
  --muted: #5c6f7d;
  --line: #e3e9ee;
  --bg: #f2f5f7;
  --surface: #ffffff;
  --brand: #0e7490;
  --brand-soft: #e0f2f6;
  --accent: #f59e0b;
  --accent-ink: #7c4a03;
  --green: #15803d;
  --green-soft: #e3f4e8;
  --red: #b91c1c;
  --red-soft: #fdeaea;
  --gray-soft: #eef1f4;
  --shadow: 0 1px 2px rgba(14, 37, 48, .07), 0 4px 14px rgba(14, 37, 48, .06);
  --radius: 12px;
  --topbar-h: 58px;
  --bottomnav-h: 62px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15.5px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 1rem; color: var(--ink);
}
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--navy); color: #eaf2f5;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 1.06rem; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.brand-mark svg { width: 24px; height: 24px; display: block; color: var(--accent); }
.brand-name span { color: var(--accent); }
.topnav { display: none; align-items: center; gap: 4px; margin-left: 10px; flex: 1; }
.topnav a {
  color: #c9d7de; padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: .92rem;
}
.topnav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.topnav a.active { background: rgba(245,158,11,.16); color: var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.role-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(255,255,255,.12); color: #cfe3ea;
}
.role-chip.gc { background: #3b2a05; color: var(--accent); }
.icon-btn {
  background: transparent; border: 0; color: #cfe3ea; border-radius: 8px;
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.user-menu { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 46px; z-index: 60;
  background: var(--surface); color: var(--ink);
  border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.2); border: 1px solid var(--line);
  min-width: 240px; overflow: hidden;
}
.dropdown-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.dropdown-head span { color: var(--muted); font-size: .8rem; }
.dropdown .role-chip { align-self: flex-start; margin-top: 6px; background: var(--gray-soft); color: var(--muted); }
.dropdown-item { display: block; width: 100%; text-align: left; padding: 12px 16px; border: 0; background: none; font-size: .95rem; }
.dropdown-item:hover { background: var(--gray-soft); }
.dropdown-item.danger { color: var(--red); }

.content {
  max-width: 1040px; margin: 0 auto;
  padding: 16px 14px calc(var(--bottomnav-h) + 26px);
}
@media (min-width: 900px) {
  .content { padding: 22px 20px 40px; }
}

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: var(--bottomnav-h);
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); font-size: .68rem; font-weight: 600;
}
.bottomnav svg { width: 22px; height: 22px; }
.bottomnav a.active { color: var(--brand); }
.bottomnav a span.fab-lbl { display: none; }
@media (min-width: 900px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
}

/* ---------- Generic UI ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card, .stack > * + * { margin-top: 14px; }
.card-pad { padding: 16px; }
.section-title {
  display: flex; align-items: center; gap: 10px; margin: 6px 0 10px;
}
.section-title h2 { margin: 0; font-size: .95rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 11px 16px; font-size: .95rem; font-weight: 700;
  background: var(--gray-soft); color: var(--ink);
  transition: filter .12s ease, transform .05s ease;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-accent { background: var(--accent); color: #221500; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--brand); border-color: var(--line); }
.btn-danger-ghost { background: transparent; color: var(--red); border-color: #f3c2c2; }
.btn-sm { padding: 6px 11px; font-size: .84rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .grow { flex: 1; }

.input, select.input, textarea.input {
  width: 100%; padding: 11px 12px; border: 1px solid #cfd9e0; border-radius: 10px;
  background: #fff; outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,116,144,.14); }
textarea.input { min-height: 92px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .82rem; font-weight: 700; color: var(--muted); margin-bottom: 5px; letter-spacing: .2px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 4px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .72rem; font-weight: 800; letter-spacing: .5px; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px;
}
.badge-draft { background: #f3ede0; color: #8a6a1a; }
.badge-sent { background: #e0eef5; color: #0e5c7a; }
.badge-answered { background: var(--green-soft); color: var(--green); }
.badge-closed { background: var(--gray-soft); color: var(--muted); }
.badge-submitted { background: var(--green-soft); color: var(--green); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-draft { background: #caa53d; }
.dot-submitted { background: var(--green); }

.empty {
  text-align: center; padding: 44px 18px; color: var(--muted);
}
.empty svg { width: 46px; height: 46px; opacity: .35; margin-bottom: 10px; }

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: #f7fafb; }
.tnum { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.bold { font-weight: 700; }
.nowrap { white-space: nowrap; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background:
    radial-gradient(900px 500px at 85% -10%, rgba(245,158,11,.12), transparent 60%),
    linear-gradient(160deg, #0e2530 0%, #102d3c 60%, #123a4a 100%);
}
.login-card { width: 100%; max-width: 400px; }
.login-brand { display: flex; align-items: center; gap: 12px; color: #fff; margin: 0 4px 22px; font-size: 1.5rem; font-weight: 800; }
.login-brand svg { width: 40px; height: 40px; }
.login-card .card { padding: 26px 24px; }
.login-title { font-size: 1.15rem; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: .88rem; margin-bottom: 18px; }
.demo-note {
  margin-top: 18px; font-size: .76rem; color: var(--muted);
  background: var(--gray-soft); border-radius: 10px; padding: 10px 12px;
}
.demo-note code { font-weight: 700; color: var(--ink); }

/* ---------- Dashboard ---------- */
.hero {
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #eaf2f5; border-radius: var(--radius); padding: 18px 18px 14px;
  margin-bottom: 16px;
}
.hero h1 { font-size: 1.25rem; color: #fff; }
.hero .sub { color: #9fc2cd; font-size: .86rem; }
.hero .accent-line { color: var(--accent); font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.stat .num { font-size: 1.5rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat .lbl { font-size: .76rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; margin-top: 2px; }
.stat.warn .num { color: var(--accent-ink); }
.stat-cta { grid-column: 1 / -1; }

.log-item { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); color: inherit; }
.log-item:hover { background: #f7fafb; text-decoration: none; }
.log-item:last-child { border-bottom: 0; }
.log-item .row1 { display: flex; align-items: center; gap: 10px; }
.log-item .date-badge {
  background: var(--navy); color: #fff; border-radius: 10px; padding: 6px 4px;
  text-align: center; min-width: 52px; line-height: 1.05; flex: none;
}
.log-item .date-badge b { display: block; font-size: 1.05rem; }
.log-item .date-badge span { font-size: .62rem; text-transform: uppercase; opacity: .85; letter-spacing: .6px; }
.log-item .titles { flex: 1; min-width: 0; }
.log-item .titles .pname { font-weight: 700; color: var(--ink); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-item .titles .meta { color: var(--muted); font-size: .8rem; }
.chev { color: #b8c6cf; flex: none; }

/* ---------- Projects / lists ---------- */
.project-card { padding: 14px 16px; display: block; color: inherit; }
.project-card:hover { text-decoration: none; box-shadow: 0 2px 10px rgba(14,37,48,.1); }
.project-card .p-top { display: flex; align-items: flex-start; gap: 10px; }
.project-card .p-name { font-weight: 700; font-size: 1.02rem; flex: 1; }
.project-card .p-meta { color: var(--muted); font-size: .84rem; margin-top: 5px; line-height: 1.5; }
.project-card .p-meta svg { width: 14px; height: 14px; vertical-align: -2px; margin-right: 3px; }
.status-badge { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; padding: 2px 8px; border-radius: 999px; flex: none; }
.status-active { background: var(--green-soft); color: var(--green); }
.status-on_hold { background: #fdf0d7; color: #92600a; }
.status-completed { background: var(--gray-soft); color: var(--muted); }

.detail-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.detail-head h1 { margin: 0; }
.back-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--line); color: var(--ink); flex: none;
}
.back-btn svg { width: 20px; height: 20px; }

.attr-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
.attr { }
.attr .k { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.attr .v { font-size: .95rem; margin-top: 1px; word-break: break-word; }
@media (max-width: 560px) { .attr-grid { grid-template-columns: 1fr; } }

.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.contact-list { display: flex; flex-direction: column; gap: 8px; }
.contact-row {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--line); background: #fbfcfd;
  border-radius: 10px; padding: 8px 10px;
}
.contact-row .icon-btn { width: 30px; height: 30px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--gray-soft); border-radius: 999px; padding: 4px 11px; font-size: .83rem;
}
.chip.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---------- Forms & repeaters ---------- */
.repeater { border: 1px dashed #cbd6dd; border-radius: 12px; padding: 10px; margin-bottom: 10px; background: #fbfcfd; }
.repeater .r-grid { display: grid; gap: 8px; }
.repeater .r-grid.crew-grid { grid-template-columns: 1fr 84px; }
.repeater .r-grid.eq-grid { grid-template-columns: 1fr 90px 1fr; }
.repeater .r-grid.del-grid { grid-template-columns: 1fr 70px 80px; }
@media (max-width: 560px) {
  .repeater .r-grid.crew-grid { grid-template-columns: 1fr 84px; }
  .repeater .r-grid.eq-grid, .repeater .r-grid.del-grid { grid-template-columns: 1fr 1fr; }
}
.repeater .r-actions { display: flex; justify-content: flex-end; margin-top: 6px; }
.repeater .input { padding: 8px 10px; }
.repeater textarea.input { min-height: 46px; }
.add-row-btn { display: flex; align-items: center; gap: 6px; color: var(--brand); font-weight: 700; font-size: .86rem; background: none; border: 0; padding: 6px 2px; }
.add-row-btn svg { width: 18px; height: 18px; }

.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .btn { flex: 1; }
@media (min-width: 560px) { .form-actions .btn { flex: 0 1 auto; min-width: 150px; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 22, 30, .5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; animation: fade .15s ease;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; padding: 20px; } }
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); width: 100%; max-width: 460px;
  border-radius: 18px 18px 0 0; padding: 20px 18px 16px;
  animation: rise .18s ease;
  max-height: 86vh; overflow: auto;
}
@media (min-width: 640px) { .modal { border-radius: 16px; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
.modal h3 { font-size: 1.05rem; }
.modal p { color: var(--muted); }
.modal .btn-row { margin-top: 16px; }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 12px;
  font-size: .92rem; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.3);
  animation: toastIn .18s ease;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes toastIn { from { transform: translateY(-10px); opacity: 0; } }

/* ---------- Skeleton / busy ---------- */
.busy {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 40px; color: var(--muted); font-weight: 600;
}
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Daily log view / report ---------- */
.weather-line { display: flex; flex-wrap: wrap; gap: 8px; }
.wchip { background: var(--gray-soft); border-radius: 10px; padding: 8px 12px; font-size: .9rem; display: inline-flex; align-items: center; gap: 7px; }
.wchip svg { width: 16px; height: 16px; opacity: .7; }

.report-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.seg-block { white-space: pre-wrap; word-break: break-word; }
.kv { display: flex; gap: 8px; font-size: .9rem; padding: 3px 0; }
.kv .k { color: var(--muted); min-width: 96px; flex: none; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--bottomnav-h) + 16px);
  z-index: 45; width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: #221500; border: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(0,0,0,.28);
}
.fab svg { width: 26px; height: 26px; }
@media (min-width: 900px) { .fab { bottom: 24px; } }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters .input { width: auto; padding: 8px 10px; font-size: .9rem; }
.filters select.input { max-width: 220px; }

.search-inline { position: relative; flex: 1; min-width: 160px; }
.search-inline input { padding-left: 32px; }
.search-inline svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }

/* ---------- Site photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo-card { margin: 0; position: relative; }
.photo-card img {
  width: 100%; height: 128px; object-fit: cover; border-radius: 10px;
  display: block; border: 1px solid var(--line); background: var(--gray-soft);
  cursor: zoom-in;
}
.photo-card figcaption {
  font-size: .78rem; color: var(--muted); padding: 5px 2px 0; word-break: break-word;
}
.photo-actions { display: flex; gap: 6px; margin-top: 6px; }
.photo-actions .cap-input { padding: 6px 9px; font-size: .84rem; border-radius: 8px; flex: 1; min-width: 0; }
.photo-actions .icon-btn { width: 34px; height: 34px; flex: none; color: var(--red); border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.photo-add { margin-top: 12px; border-style: dashed; cursor: pointer; }
.photo-add svg { width: 20px; height: 20px; }
@media print {
  .photo-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .photo-card { break-inside: avoid; }
  .photo-card img { height: auto; max-height: 190px; cursor: default; }
  .photo-actions, .photo-add { display: none !important; }
}

/* ---------- Print ---------- */
.print-doc { display: none; }
.print-only { display: none; }
@media print {
  body { background: #fff; font-size: 11.5px; }
  .no-print, .fab, .bottomnav, #toast-root, #modal-root { display: none !important; }
  .print-only { display: block; }
  .print-only.report-head, .sig-row { display: flex; justify-content: space-between; gap: 10px; }
  .shell { min-height: 0; }
  .content { max-width: none; padding: 0; }
  .topbar { display: none !important; }
  .card { box-shadow: none; border-color: #bbb; }
  .print-doc { display: block; }
  .table td, .table th { padding: 4px 6px; }
  a { color: inherit; }
}
