:root {
  --green: #1f6f43;
  --green-dark: #17553a;
  --green-soft: #e3f1e8;
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #66716b;
  --line: #e1e6e2;
  --red: #c0392b;
  --red-soft: #fbe9e7;
  --amber: #b7791f;
  --amber-soft: #fdf3e1;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

#offline { background: var(--amber); color: #fff; text-align: center; padding: 6px; font-size: 13px; position: sticky; top: 0; z-index: 50; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--green); color: #fff;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: 12px;
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .sub { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
main { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding-bottom: var(--safe-b);
}
.tabs button {
  flex: 1; max-width: 160px; border: 0; background: none; padding: 9px 4px 8px; font-size: 11.5px;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabs button .ico { font-size: 20px; line-height: 1; }
.tabs button.active { color: var(--green); font-weight: 600; }

@media (min-width: 900px) {
  .tabs { top: 0; bottom: auto; left: auto; right: 16px; background: transparent; border: 0; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .tabs button { color: rgba(255, 255, 255, .8); flex-direction: row; font-size: 14px; gap: 6px; padding: 8px 12px; border-radius: 8px; }
  .tabs button .ico { font-size: 16px; }
  .tabs button.active { color: #fff; background: rgba(255, 255, 255, .16); }
  .topbar { padding-right: 640px; }
  main { padding-bottom: 32px; }
}

/* ---------- Components ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; background: var(--green); color: #fff; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
}
.btn:hover { background: var(--green-dark); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.secondary { background: var(--green-soft); color: var(--green-dark); }
.btn.ghost { background: transparent; color: var(--green); padding: 8px 10px; min-height: 0; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.small { padding: 6px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 18px; padding: 6px; border-radius: 8px; }
.icon-btn:disabled { opacity: .25; cursor: default; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=password], input[type=date], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; min-height: 42px;
  outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
textarea { resize: vertical; min-height: 70px; }
.date-input { width: auto !important; }

.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green-dark); font-weight: 600; white-space: nowrap; }
.chip.gray { background: #eef0ee; color: var(--muted); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }

.progress { height: 8px; border-radius: 99px; background: #e8ece9; overflow: hidden; }
.progress > div { height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }
.progress.low > div { background: var(--red); }
.progress.mid > div { background: var(--amber); }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty .big { font-size: 34px; margin-bottom: 6px; }

.seg { display: inline-flex; background: #e8ece9; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- Auth ---------- */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 24px; }
.auth .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 10px; }
.auth h1 { text-align: center; }
.auth .lead { text-align: center; color: var(--muted); margin: 4px 0 18px; }
.error { background: var(--red-soft); color: var(--red); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.info { background: var(--green-soft); color: var(--green-dark); padding: 10px 12px; border-radius: 10px; font-size: 14px; }

/* ---------- Checklist ---------- */
.list > .item + .item { border-top: 1px solid var(--line); }
.item { display: flex; gap: 12px; padding: 12px 14px; align-items: flex-start; }
.tick {
  flex: none; width: 34px; height: 34px; border-radius: 50%; border: 2px solid #c5cdc8; background: #fff; cursor: pointer;
  display: grid; place-items: center; color: transparent; font-size: 18px; font-weight: 700; transition: all .15s; margin-top: 1px;
}
.tick:hover { border-color: var(--green); }
.tick.on { background: var(--green); border-color: var(--green); color: #fff; }
.tick:disabled { cursor: default; opacity: .6; }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 600; word-wrap: break-word; }
.item.done .t { color: var(--muted); text-decoration: line-through; text-decoration-color: #b8c2bc; }
.item .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.item .note-text { margin-top: 6px; font-size: 13.5px; color: #3c4741; background: #f6f8f6; border-radius: 8px; padding: 6px 9px; white-space: pre-wrap; word-wrap: break-word; }
.item .note-edit { margin-top: 8px; }
.item .actions { display: flex; gap: 2px; }

.summary { display: flex; align-items: center; gap: 14px; }
.ring { --p: 0; width: 62px; height: 62px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--green) calc(var(--p) * 1%), #e8ece9 0); }
.ring span { width: 50px; height: 50px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }

/* ---------- Admin ---------- */
.grid-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.sup-card { cursor: pointer; }
.sup-card:hover { box-shadow: 0 2px 10px rgba(0, 0, 0, .08); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .l { font-size: 12.5px; color: var(--muted); }

.card.sheet-wrap { padding: 0; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.sheet-hint { display: none; margin-top: -4px; }
table.sheet { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.sheet th, .sheet td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: center; white-space: nowrap; }
.sheet thead th { background: #f0f4f1; font-weight: 600; vertical-align: bottom; white-space: normal; min-width: 76px; max-width: 120px; line-height: 1.25; }
.sheet thead th .tg { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.sheet tbody tr:last-child td { border-bottom: 0; }
.sheet td.name, .sheet th.name { text-align: left; position: sticky; left: 0; background: #fff; z-index: 2; min-width: 120px; max-width: 160px;
  white-space: normal; box-shadow: 2px 0 4px -2px rgba(0, 0, 0, .15); cursor: pointer; }
.sheet thead th.name { background: #f0f4f1; cursor: default; }
.sheet td.total, .sheet th.total { min-width: 52px; background: #fafbfa; }
.sheet thead th.total { background: #f0f4f1; }
.sheet td.yes { color: var(--green); font-weight: 700; background: #f2faf5; }
.sheet td.no { color: #b7c0bb; }
.sheet td.na { background: #fafafa; }
.sheet td.has-note, .sheet td[data-tip] { position: relative; cursor: pointer; }
.sheet td.has-note::after { content: ''; position: absolute; top: 0; right: 0; border: 5px solid transparent; border-top-color: var(--amber); border-right-color: var(--amber); }

.tbl { width: 100%; border-collapse: collapse; }
.tbl td, .tbl th { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #fafbfa; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.inactive td { opacity: .55; }

/* ---------- Modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 25, 20, .45); z-index: 100; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal { background: #fff; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); animation: up .2s; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }
.modal .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 200; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red); }

.install-banner { display: flex; align-items: center; gap: 10px; background: var(--green-soft); border-radius: var(--radius); padding: 10px 14px; }

/* ---------- Phones ---------- */
@media (max-width: 600px) {
  main { padding-left: 12px; padding-right: 12px; }
  .sheet-hint { display: block; }
  table.sheet { font-size: 12px; }
  .sheet th, .sheet td { padding: 6px 5px; }
  .sheet thead th { min-width: 62px; max-width: 84px; font-size: 11px; }
  .sheet thead th .tg { font-size: 10.5px; }
  .sheet td.name, .sheet th.name { min-width: 92px; max-width: 110px; }
  .sheet td.name .small { font-size: 11px; }
  .sheet td.total, .sheet th.total { min-width: 42px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .stat .n { font-size: 20px; }
}
