/* ============================================================
   PF Seva Manager — single responsive stylesheet
   Phone-first: base styles target 375px+, desktop at 900px+
   Palette: olive-gold family (matches the project plan)
   ============================================================ */

:root {
  /* cascade palette */
  --page-bg: #f5f5f4;
  --section-bg: #f2f1f0;
  --card-bg: #ebeae8;
  --stripe: #ededeb;
  --header-fill: #4e4732;
  --accent: #92761f;
  --accent-strong: #7a631a;
  --border: #c5bfac;
  --border-soft: #ddd9cc;
  --text: #151513;
  --text-2: #565347;
  --muted: #7e7c74;
  /* semantic (low-sat) */
  --ok: #529067;      --ok-bg: #eaf3ec;
  --warn: #8c7443;    --warn-bg: #f7f1e3;
  --danger: #a25b54;  --danger-bg: #f6eae8;
  --info: #507aa4;    --info-bg: #e9eff6;
  /* layout */
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 3px rgba(21, 21, 19, 0.08), 0 4px 14px rgba(21, 21, 19, 0.06);
  --topbar-h: 56px;
  --bottomnav-h: 62px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--page-bg);
  min-height: 100vh;
  min-height: 100dvh;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; }
a { color: var(--accent-strong); }

/* ---------- lock screen ---------- */
.lock-screen {
  position: fixed; inset: 0; z-index: 200;
  background: linear-gradient(160deg, #f7f6f2, #ebeae4);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.lock-card { text-align: center; width: min(340px, 100%); }
.lock-icon { color: var(--accent); margin-bottom: 10px; }
.lock-card h1 { font-size: 21px; font-weight: 700; color: var(--header-fill); }
.lock-sub { color: var(--muted); font-size: 13.5px; margin: 4px 0 18px; }
.lock-dots { display: flex; gap: 14px; justify-content: center; margin-bottom: 18px; min-height: 14px; }
.lock-dots .dot {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); background: transparent; transition: all .12s;
}
.lock-dots .dot.filled { background: var(--accent); border-color: var(--accent); }
.lock-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; justify-content: center; }
.lock-pad button {
  height: 58px; border-radius: 50%; border: 1.5px solid var(--border-soft);
  background: #fff; font-size: 22px; font-weight: 600; color: var(--text);
  cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.06);
  display: flex; align-items: center; justify-content: center;
}
.lock-pad button:active { background: var(--card-bg); }
.lock-pad button.ghost { border: none; background: none; box-shadow: none; color: var(--muted); }
.lock-err { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 14px; }

/* ---------- app shell ---------- */
.app[hidden] { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(245, 245, 244, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 14px;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 9px; margin-right: auto; }
.brand-logo { width: 30px; height: 30px; border-radius: 7px; }
.brand-name { font-weight: 700; color: var(--header-fill); font-size: 16px; }
.topnav { display: none; gap: 4px; }
.topnav a {
  text-decoration: none; color: var(--text-2); font-weight: 600; font-size: 14px;
  padding: 7px 13px; border-radius: 8px;
}
.topnav a.active { background: var(--card-bg); color: var(--header-fill); }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none;
  background: transparent; color: var(--text-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  position: relative;
}
.icon-btn:hover { background: var(--card-bg); }
.sync-dot {
  position: absolute; top: 7px; right: 7px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}

.view {
  max-width: 1080px; margin: 0 auto; padding: 16px 14px calc(var(--bottomnav-h) + 34px);
}

/* ---------- bottom nav (phone) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-soft);
  display: flex;
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; text-decoration: none; color: var(--muted); font-size: 10.5px; font-weight: 600;
}
.bottomnav a.active { color: var(--accent-strong); }
.bottomnav a.active svg { transform: translateY(-1px); }

/* ---------- fab ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--bottomnav-h) + 18px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px; border-radius: 18px; border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  box-shadow: 0 4px 14px rgba(146, 118, 31, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 60; transition: transform .12s;
}
.fab:active { transform: scale(0.94); }

/* ---------- generic UI ---------- */
.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 22px; font-weight: 800; color: var(--header-fill); letter-spacing: -0.01em; }
.page-head .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.card {
  background: #fff; border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.card h3 { font-size: 15px; font-weight: 700; color: var(--header-fill); margin-bottom: 8px; }
.card.clickable { cursor: pointer; }
.card.clickable:active { background: var(--section-bg); }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack-8 > * + * { margin-top: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none; border-radius: 10px; padding: 10px 16px;
  font-size: 14px; font-weight: 700; cursor: pointer; text-decoration: none;
  background: var(--card-bg); color: var(--text);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-strong); }
.btn.subtle { background: var(--section-bg); color: var(--text-2); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.small { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* status chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.4px;
  border-radius: 5px; padding: 2.5px 8px; white-space: nowrap;
}
.chip.new        { background: var(--warn-bg); color: var(--warn); }
.chip.docs_pending{ background: var(--warn-bg); color: var(--warn); }
.chip.submitted  { background: var(--info-bg); color: var(--info); }
.chip.rework     { background: var(--danger-bg); color: var(--danger); }
.chip.completed  { background: var(--ok-bg); color: var(--ok); }
.chip.neutral    { background: var(--stripe); color: var(--text-2); }

.tag {
  display: inline-block; font-size: 11px; font-weight: 600;
  color: var(--text-2); background: var(--stripe);
  border-radius: 5px; padding: 2px 7px;
}

.empty {
  text-align: center; color: var(--muted); padding: 30px 16px;
}
.empty svg { color: var(--border); margin-bottom: 8px; }
.empty h3 { color: var(--text-2); font-size: 15px; margin-bottom: 4px; }

/* list rows */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--stripe);
}
.list-row:last-child { border-bottom: none; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--card-bg); color: var(--header-fill);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
}
.avatar.red { background: var(--danger-bg); color: var(--danger); }
.avatar.amber { background: var(--warn-bg); color: var(--warn); }
.avatar.blue { background: var(--info-bg); color: var(--info); }
.avatar.green { background: var(--ok-bg); color: var(--ok); }

/* ---------- search & filters ---------- */
.searchbox { position: relative; margin-bottom: 12px; }
.searchbox input {
  width: 100%; padding: 11px 14px 11px 40px;
  border: 1.5px solid var(--border-soft); border-radius: 12px;
  background: #fff; outline: none;
}
.searchbox input:focus { border-color: var(--accent); }
.searchbox svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.filter-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 6px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-pill {
  flex-shrink: 0; border: 1.5px solid var(--border-soft); background: #fff;
  color: var(--text-2); font-size: 12.5px; font-weight: 600;
  padding: 6px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.filter-pill.active { background: var(--header-fill); border-color: var(--header-fill); color: #fff; }
.filter-pill .count { opacity: 0.65; margin-left: 3px; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-2); margin-bottom: 5px; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border-soft); border-radius: 10px;
  background: #fff; color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 64px; }
.field .suffix-wrap { position: relative; }
.field .suffix-wrap .suffix {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 13px;
}

/* checklist */
.check-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 4px; border-bottom: 1px solid var(--stripe);
}
.check-item:last-child { border-bottom: none; }
.check-item input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer;
}
.check-item .label { flex: 1; font-size: 14px; }
.check-item.done .label { color: var(--muted); text-decoration: line-through; }
.check-item .when { font-size: 11.5px; color: var(--muted); }

/* timeline */
.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border-soft); border-radius: 2px;
}
.tl-item { position: relative; padding: 0 0 14px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ""; position: absolute; left: -21px; top: 5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--accent);
}
.tl-item.system::before { border-color: var(--info); }
.tl-item .meta { font-size: 11.5px; color: var(--muted); }
.tl-item .note { font-size: 13.5px; margin-top: 1px; white-space: pre-wrap; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: #fff; border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.stat .v { font-size: 24px; font-weight: 800; color: var(--header-fill); line-height: 1.1; }
.stat .v.alert { color: var(--danger); }
.stat .l { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 3px; }

/* tables (desktop-width data) */
.table-wrap { overflow-x: auto; border: 1px solid var(--border-soft); border-radius: var(--radius); background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
table.data th {
  text-align: left; padding: 9px 12px; background: var(--header-fill); color: #fff;
  font-size: 11.5px; letter-spacing: 0.4px; text-transform: uppercase; white-space: nowrap;
}
table.data td { padding: 9px 12px; border-top: 1px solid var(--stripe); vertical-align: top; }
table.data tr:nth-child(even) td { background: var(--stripe); }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(21, 21, 19, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--page-bg); width: 100%; max-width: 620px;
  max-height: 92dvh; border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column;
  animation: slideup .18s ease-out;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
}
.modal-head h2 { font-size: 17px; font-weight: 800; color: var(--header-fill); }
.modal-body { padding: 4px 16px calc(18px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; }

/* toasts */
.toasts { position: fixed; bottom: calc(var(--bottomnav-h) + 14px); left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 28px)); }
.toast {
  background: var(--header-fill); color: #fff; font-size: 13.5px; font-weight: 600;
  padding: 11px 16px; border-radius: 11px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
  animation: slideup .18s ease-out; text-align: center;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* masked ID toggle */
.masked { font-variant-numeric: tabular-nums; }

/* kv list */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 600; white-space: nowrap; }
.kv dd { color: var(--text); word-break: break-word; }

/* section divider in views */
.section-title {
  font-size: 12px; font-weight: 800; letter-spacing: 1.1px; text-transform: uppercase;
  color: var(--muted); margin: 20px 0 9px;
}

/* ============ DESKTOP ============ */
@media (min-width: 900px) {
  body { font-size: 15.5px; }
  .topnav { display: flex; }
  .bottomnav { display: none; }
  .fab { bottom: 26px; right: 26px; }
  .view { padding: 26px 22px 60px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span2 { grid-column: span 2; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; max-height: 86dvh; }
  .toasts { bottom: 26px; }
}

/* small phones */
@media (max-width: 360px) {
  .lock-pad { grid-template-columns: repeat(3, 64px); }
  .brand-name { display: none; }
}

/* ============ PRINT (receipts & report) ============ */
.print-area { display: none; }
@media print {
  body > .app, body > .lock-screen, .toasts, .modal-backdrop { display: none !important; }
  .print-area { display: block; }
  @page { margin: 12mm; }
}
