:root {
  --brand: #2E6B34; --brand-d: #1F4D24; --accent: #C8E25A;
  --bg: #F4F6EE; --card: #fff; --ink: #1C241D; --muted: #66705F; --line: #E2E6DA;
  --ok: #2F8F46; --ok-bg: #E4F4E6; --warn: #B7791F; --warn-bg: #FDF3DD; --bad: #C0392B; --bad-bg: #FBE6E3;
  --info-bg: #EAF0FB; --info: #2C5DB4;
  --r: 14px; --shadow: 0 1px 2px rgba(20,40,20,.06), 0 4px 14px rgba(20,40,20,.06);
  --nav-h: 64px; --top-h: 56px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .tiny { font-size: .75rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: .75rem; padding: 0 1rem;
  background: var(--brand); color: #fff; padding-top: env(safe-area-inset-top); box-sizing: content-box; }
.topbar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; min-width: 0; }
.topbar .brand img { width: 32px; height: 32px; border-radius: 8px; object-fit: contain; background: #fff; }
.topbar .brand .mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--brand-d); display: grid; place-items: center; font-weight: 800; }
.topbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar select { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 10px; padding: .35rem .6rem; max-width: min(46vw, 340px); }
.topbar select option { color: var(--ink); }
.layout { display: flex; min-height: calc(100vh - var(--top-h)); }
.sidebar { display: none; }
main { flex: 1; padding: 1rem 1rem calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto; }
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--brand-d); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: rgba(255,255,255,.72); font-size: .72rem; position: relative; }
.bottomnav a svg { width: 23px; height: 23px; }
.bottomnav a.on { color: var(--brand-d); background: var(--accent); font-weight: 700; }
.badge { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .68rem; font-weight: 700; display: grid; place-items: center; }
@media (min-width: 900px) {
  .bottomnav { display: none; }
  .sidebar { display: block; width: 230px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--line); padding: 1rem .6rem; position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); overflow: auto; }
  .sidebar a { display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; border-radius: 10px; color: var(--ink); margin-bottom: 2px; position: relative; }
  .sidebar a svg { width: 20px; height: 20px; color: var(--muted); }
  .sidebar a:hover { background: var(--bg); }
  .sidebar a.on { background: var(--brand); color: #fff; font-weight: 600; }
  .sidebar a.on svg { color: var(--accent); }
  .sidebar .sec { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1rem .8rem .3rem; }
  .sidebar .badge { position: static; margin-left: auto; }
  main { padding: 1.5rem 2rem 2rem; }
}

/* ---------- components ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 1rem; margin-bottom: .9rem; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: .6rem; }
.row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; } .row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: .8rem; }
.grid.k4 { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .grid.k4 { grid-template-columns: repeat(4, 1fr); } .grid.c2 { grid-template-columns: 1fr 1fr; } .grid.c3 { grid-template-columns: repeat(3, 1fr); } }
.page-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; flex: 1; min-width: 0; }
.back { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; background: #fff; box-shadow: var(--shadow); color: var(--ink); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; border: 0; border-radius: 11px; padding: .65rem 1rem; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; min-height: 44px; }
.btn:active { transform: translateY(1px); }
.btn.sec { background: #fff; color: var(--brand); border: 1.5px solid var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: var(--bad); }
.btn.lime { background: var(--accent); color: var(--brand-d); }
.btn.sm { min-height: 34px; padding: .35rem .7rem; font-size: .85rem; border-radius: 9px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 18px; height: 18px; }

label.f { display: block; margin-bottom: .8rem; }
label.f > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; padding: .65rem .75rem; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(46,107,52,.15); }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }

.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--bg); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); } .chip.info { background: var(--info-bg); color: var(--info); }
.chip.brand { background: var(--brand); color: #fff; }

.tabs { display: flex; gap: .4rem; overflow-x: auto; margin-bottom: 1rem; }
.tabs button { border: 0; background: #fff; padding: .45rem .9rem; border-radius: 999px; font-weight: 600; color: var(--muted); box-shadow: var(--shadow); white-space: nowrap; cursor: pointer; }
.tabs button.on { background: var(--brand); color: #fff; }

.list-item { display: flex; align-items: center; gap: .8rem; padding: .85rem 1rem; background: #fff; border-radius: var(--r); box-shadow: var(--shadow); margin-bottom: .6rem; color: var(--ink); }
.list-item .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--bg); color: var(--brand); flex-shrink: 0; }
.list-item .ic svg { width: 22px; height: 22px; }
.list-item .t { font-weight: 600; }
.list-item .chev { color: var(--muted); }

.stat { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: .9rem 1rem; }
.stat .v { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: .78rem; color: var(--muted); font-weight: 600; }
.stat.good .v { color: var(--ok); } .stat.mid .v { color: var(--warn); } .stat.low .v { color: var(--bad); }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s; }

/* checklist items */
.ck-item { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: .9rem; margin-bottom: .7rem; border-left: 5px solid var(--line); }
.ck-item.yes { border-left-color: var(--ok); } .ck-item.no { border-left-color: var(--bad); } .ck-item.na { border-left-color: #9AA39A; }
.ck-item .q { font-weight: 600; margin-bottom: .55rem; }
.ck-item .meta { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .55rem; }
.seg { display: grid; grid-template-columns: 1fr 1fr .7fr; gap: .45rem; }
.seg button { border: 1.5px solid var(--line); background: #fff; border-radius: 10px; min-height: 46px; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button.on.yes { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg button.on.no { background: var(--bad); border-color: var(--bad); color: #fff; }
.seg button.on.na { background: #7E877E; border-color: #7E877E; color: #fff; }
.ck-extra { margin-top: .6rem; display: grid; gap: .5rem; }
.photo-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--bg); cursor: zoom-in; border: 1px solid var(--line); }
.thumb.lg { width: 100%; height: auto; max-height: 260px; object-fit: cover; }

/* score buttons */
.score { display: flex; gap: .35rem; flex-wrap: wrap; }
.score button { width: 42px; height: 42px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; }
.score button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.score button.na.on { background: #7E877E; border-color: #7E877E; }
.score button.na { width: auto; padding: 0 .7rem; }

/* SOP view */
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; position: relative; padding: .2rem 0 1rem 3rem; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 2.1rem; height: 2.1rem; border-radius: 50%; background: var(--accent); color: var(--brand-d); font-weight: 800; display: grid; place-items: center; }
.steps li:not(:last-child)::after { content: ''; position: absolute; left: 1.03rem; top: 2.3rem; bottom: .2rem; width: 2px; background: var(--line); }
.steps li img { margin-top: .5rem; border-radius: 12px; max-width: 100%; max-height: 260px; }

/* tables */
.tbl-wrap { overflow-x: auto; background: #fff; border-radius: var(--r); box-shadow: var(--shadow); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #FAFBF7; }
tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 200px; }

/* editor rows */
.ed-row { display: flex; gap: .5rem; align-items: flex-start; background: var(--bg); border-radius: 12px; padding: .6rem; margin-bottom: .5rem; }
.ed-row .n { font-weight: 800; color: var(--muted); width: 1.6rem; padding-top: .6rem; text-align: center; }
.ed-row .tools { display: flex; flex-direction: column; gap: .25rem; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 0; background: #fff; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.del { color: var(--bad); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, var(--brand) 0%, var(--brand-d) 55%, #142F17 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 22px; padding: 2rem 1.6rem; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 1rem; display: grid; place-items: center; background: var(--accent); color: var(--brand-d); font-size: 1.8rem; font-weight: 900; overflow: hidden; }
.login-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

/* misc */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .5; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1C241D; color: #fff; padding: .7rem 1.1rem; border-radius: 12px; z-index: 100; max-width: 92vw; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 500; }
.toast.err { background: var(--bad); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,15,.55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 1.2rem 1.2rem calc(1.2rem + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 60; display: grid; place-items: center; padding: 1rem; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.offline { background: var(--warn); color: #fff; text-align: center; font-size: .82rem; padding: .3rem; font-weight: 600; }
.alert { padding: .7rem .9rem; border-radius: 12px; margin-bottom: .9rem; font-size: .9rem; }
.alert.warn { background: var(--warn-bg); color: #7A5212; } .alert.bad { background: var(--bad-bg); color: #8E2A20; } .alert.info { background: var(--info-bg); color: #1F4687; } .alert.ok { background: var(--ok-bg); color: #1E6431; }
.sticky-foot { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0 .4rem; }
@media (min-width: 900px) { .sticky-foot { bottom: 0; } }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: .5rem; }
.bar-chart .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-chart .b i { width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px; background: var(--brand); display: block; min-height: 2px; }
.bar-chart .b span { font-size: .65rem; color: var(--muted); white-space: nowrap; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 3rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.more-grid a { display: flex; }
@media print { .topbar, .bottomnav, .sidebar, .no-print { display: none !important; } main { padding: 0; } .card, .tbl-wrap { box-shadow: none; border: 1px solid #ddd; } }

.mob-only { display: block; } .desk-only { display: none !important; }
@media (min-width: 700px) { .mob-only { display: none !important; } .desk-only { display: block !important; } }
