:root {
  --bg: #f6f8f8; --card: #fff; --text: #17201f; --muted: #5f6b6a; --line: #dfe6e5;
  --primary: #0f766e; --primary-ink: #fff; --primary-soft: #e3f3f1;
  --ok: #15803d; --ok-soft: #e6f6ec; --info: #1d4ed8; --info-soft: #e8eefc;
  --warn: #a16207; --warn-soft: #fdf3dc; --danger: #b91c1c; --danger-soft: #fdeaea;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.45rem; margin: .2rem 0 .3rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1.4rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
a { color: var(--primary); }
.muted { color: var(--muted); } .small { font-size: .86rem; } .center { text-align: center; }
.pre { white-space: pre-wrap; margin: .3rem 0 0; }
code.secret { font-size: 1.1rem; background: var(--primary-soft); padding: .15rem .4rem; border-radius: 6px; user-select: all; word-break: break-all; }

/* Layout */
main { max-width: 860px; margin: 0 auto; padding: 12px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.page { display: flex; flex-direction: column; gap: 10px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input, .toolbar select { width: auto; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; } .topbar .who { color: var(--muted); font-size: .9rem; }
.logo { background: var(--primary); color: #fff; font-weight: 800; font-size: .75rem; padding: .3rem .45rem; border-radius: 8px; letter-spacing: .04em; }
.banner { background: var(--warn-soft); color: var(--warn); padding: 8px 16px; font-size: .9rem; text-align: center; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; overflow-x: auto;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1 0 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); font-size: .72rem; color: var(--muted); text-decoration: none;
}
.bottomnav a span { font-size: 1.2rem; }
.bottomnav a.active { color: var(--primary); font-weight: 700; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.card.clickable { width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.card.clickable:active { transform: scale(.995); }
.card.inactive { opacity: .6; }
.card.notice { background: var(--primary-soft); border-color: transparent; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-meta { display: flex; gap: 10px; color: var(--muted); font-size: .86rem; margin-top: 2px; align-items: center; }
.row-meta.wrap { flex-wrap: wrap; }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.btn.link { background: none; border: none; color: var(--primary); min-height: 32px; padding: 0 4px; font-weight: 500; }
.btn.block { width: 100%; }
.btn:disabled, .btn.disabled { opacity: .55; cursor: default; }
.btn.back { align-self: flex-start; }
.icon-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; min-width: 44px; min-height: 44px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.label { font-size: .86rem; font-weight: 600; color: var(--muted); }
.hint { font-size: .8rem; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font: inherit; cursor: pointer; min-height: 40px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Badges & boxes */
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #eef1f1; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.danger { background: var(--danger-soft); color: var(--danger); }
.error-box { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; }
.ok-box { background: var(--ok-soft); color: var(--ok); padding: 10px 12px; border-radius: 10px; }
.warn-box { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Stats & tables */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.stat b { display: block; font-size: 1.6rem; } .stat span { font-size: .82rem; color: var(--muted); }
.stat.danger b { color: var(--danger); } .stat.warn b { color: var(--warn); } .stat.info b { color: var(--info); }
.table-wrap { overflow-x: auto; }
table.mini { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; font-size: .9rem; }
table.mini th, table.mini td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.mini th { color: var(--muted); font-weight: 600; font-size: .8rem; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 2px; }
.tab { flex: 0 0 auto; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font: inherit; font-size: .88rem; cursor: pointer; min-height: 40px; }
.tab.active { background: var(--text); color: #fff; border-color: var(--text); }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 6px; }
.photo { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.photo img, .photo-grid > a img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; border-radius: 8px; }
.photo figcaption { padding: 6px 8px; font-size: .75rem; color: var(--muted); display: flex; flex-direction: column; }
.photo-missing { aspect-ratio: 4/3; display: grid; place-items: center; color: var(--muted); font-size: .8rem; }
.qr { width: 200px; height: 200px; background: #fff; border-radius: 8px; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.timeline li { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; font-size: .9rem; }
ul.plain { padding-left: 0; list-style: none; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--bg); width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
.modal-head { position: sticky; top: 0; background: var(--bg); display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 14px 16px 20px; }
@media (min-width: 700px) { .modal-backdrop { align-items: center; } .modal { border-radius: 18px; } }

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.brand b { display: block; font-size: 1.2rem; } .brand small { color: var(--muted); }

/* Loading & toasts */
.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 30px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 60; pointer-events: none; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .9rem; box-shadow: var(--shadow); }
details summary { cursor: pointer; color: var(--primary); }
