:root {
  --bg: #f6f7f2;
  --card: #ffffff;
  --text: #151712;
  --muted: #68705f;
  --line: #dfe4d8;
  --brand: #205f3b;
  --brand-2: #17472d;
  --danger: #b42318;
  --warn: #b76e00;
  --ok: #1f7a3f;
  --shadow: 0 8px 24px rgb(31 38 25 / 8%);
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-height: 100%; -webkit-text-size-adjust: 100%; }
[id] { scroll-margin-top: 7rem; }
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

.topbar {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: 1fr;
  gap: .7rem;
  padding: .8rem 1rem;
  background: rgb(246 247 242 / 94%);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}
.topbar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
}
.brand {
  color: var(--text);
  font-weight: 850;
  letter-spacing: -.04em;
  font-size: 1.35rem;
}
.mainnav, .topbar-meta, .langswitch, .actions-row, .toolbar {
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-wrap: wrap;
}
.mainnav a, .langswitch a {
  padding: .35rem .55rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: .92rem;
}
.mainnav a.on, .langswitch a.on {
  color: var(--brand-2);
  background: #e5efe6;
  text-decoration: none;
}
.topbar-meta { justify-content: flex-start; }
.logout { margin: 0; flex-shrink: 0; }

.container {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 1rem;
}
.layout-bare .container {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

h1, h2, h3 {
  margin: 0 0 .7rem;
  line-height: 1.12;
  letter-spacing: -.03em;
  max-width: 100%;
  overflow-wrap: anywhere;
  hyphens: auto;
}
h1 { font-size: clamp(2rem, 10vw, 4rem); }
h2 { font-size: 1.28rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.hint { font-size: .92rem; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.pagehead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
}
.pagehead > * { min-width: 0; }
.backlink {
  display: inline-block;
  margin: 0 0 .85rem;
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: rgb(32 95 59 / 35%);
  text-underline-offset: 4px;
}
.backlink:hover {
  color: var(--brand);
}

.card, .flash, .notice {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin: 0 0 1rem;
}
.narrow { width: min(430px, 100%); }
.flash { border-left: 6px solid var(--brand); }
.flash-error { border-left-color: var(--danger); }
.flash-success { border-left-color: var(--ok); }
.notice {
  background: #fff9e7;
  border-color: #efd896;
  box-shadow: none;
}

.grid { display: grid; gap: 1rem; }
.stats, .dashboard-grid {
  display: grid;
  gap: 1rem;
  margin: 1rem 0;
}
.stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dashboard-grid .attention-card { grid-column: 1 / -1; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stat-num {
  font-size: clamp(1.8rem, 8vw, 3.5rem);
  font-weight: 850;
  letter-spacing: -.05em;
}
.stat-date {
  font-size: clamp(1.2rem, 4vw, 1.9rem);
  letter-spacing: -.035em;
}
.stat-label { color: var(--muted); font-size: .9rem; }
.stat-warn { border-color: #e8bc7b; background: #fff7e8; }

.form { display: grid; gap: .8rem; }
.inline-form { display: flex; gap: .6rem; align-items: end; flex-wrap: wrap; }
.inline { display: inline; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }

.seg-field { display: grid; gap: .3rem; }
.seg-label { color: var(--muted); font-size: .92rem; }
.seg-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
}
.seg-option {
  position: relative;
  margin: 0;
}
.seg-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.seg-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .65rem .75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-weight: 650;
  text-align: center;
  cursor: pointer;
  user-select: none;
}
.seg-option input:focus-visible + span {
  outline: 3px solid #cfe5d4;
  border-color: var(--brand);
}
.seg-option input:checked + span {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.result-entry { display: grid; gap: .85rem; }
.result-entry-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.result-entry-toolbar input[type="search"] {
  flex: 1 1 220px;
  font-size: 1.05rem;
  padding: .85rem 1rem;
}
.result-filter-meta { font-size: .9rem; white-space: nowrap; }
.result-entry-table .value-input {
  min-width: 5.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.unit-cell { white-space: nowrap; }
.unit-readonly {
  display: inline-block;
  padding: .72rem .2rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.result-entry-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: .35rem;
  margin-top: .15rem;
  border-top: 1px solid var(--line);
}
.result-entry-actions .btn-save {
  min-height: 50px;
  min-width: 9rem;
  padding: .8rem 1.6rem;
  font-size: 1.06rem;
  font-weight: 800;
  letter-spacing: -.02em;
  box-shadow: 0 10px 24px rgb(32 95 59 / 18%);
}
.result-entry-actions .btn-save:hover {
  box-shadow: 0 12px 28px rgb(32 95 59 / 24%);
}
tr[data-result-row][hidden] { display: none; }

label { display: grid; gap: .3rem; color: var(--muted); font-size: .92rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .72rem .78rem;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid #cfe5d4;
  border-color: var(--brand);
}
.copybox { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.btn, button.btn, .linkbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: .65rem .9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn-primary {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}
.btn-primary:hover { background: var(--brand-2); }
.btn-danger { color: #fff; border-color: var(--danger); background: var(--danger); }
.btn-small { min-height: 34px; padding: .4rem .65rem; font-size: .88rem; }
.linkbtn {
  min-height: auto;
  padding: .35rem .55rem;
  border: 0;
  background: transparent;
  color: var(--brand);
}
button[disabled] { opacity: .7; cursor: progress; }

.search-shell { max-width: 860px; }
.search-form {
  display: grid;
  gap: .7rem;
}
.search-form input[type="search"] {
  font-size: 1.08rem;
  padding: .9rem 1rem;
}
.live-results {
  display: grid;
  gap: 1rem;
}
.live-group { margin-bottom: 0; }
.live-list {
  display: grid;
  gap: .55rem;
}
.live-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .2rem .8rem;
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgb(246 247 242 / 54%);
}
.live-item:hover {
  border-color: var(--brand);
  text-decoration: none;
}
.live-main {
  min-width: 0;
  font-weight: 750;
  overflow-wrap: anywhere;
}
.live-sub {
  min-width: 0;
  grid-column: 1;
  font-size: .92rem;
  overflow-wrap: anywhere;
}
.live-meta {
  grid-row: 1 / span 2;
  grid-column: 2;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: .45rem;
  text-align: right;
  font-size: .9rem;
}
.live-history {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.live-item-staff {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .55rem .75rem;
  color: var(--text);
  background: rgb(246 247 242 / 54%);
}
.live-staff-body {
  display: grid;
  gap: .2rem;
  min-width: 0;
}
.live-staff-meta {
  grid-row: 1;
  grid-column: 2;
  align-self: start;
}
.live-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}
mark {
  padding: 0 .08em;
  border-radius: .25em;
  color: inherit;
  background: #dcefd7;
}

.results {
  width: 100%;
  border-collapse: collapse;
  font-size: .94rem;
}
.results th, .results td {
  border-bottom: 1px solid var(--line);
  padding: .65rem .35rem;
  vertical-align: top;
}
.results th {
  color: var(--muted);
  font-size: .8rem;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.results th.num { text-align: right; }
.cat {
  margin-top: 1rem;
  color: var(--brand-2);
}
.cat a, .trend-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgb(32 95 59 / 30%);
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}
.visit-block {
  padding: .7rem 0 0;
  border-top: 1px solid var(--line);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .5rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 700;
}
.badge-low { color: #2c4f91; background: #e5edff; }
.badge-normal { color: #146c2e; background: #e4f6e8; }
.badge-high { color: #97231c; background: #ffe7e5; }
.badge-none { color: var(--muted); background: #eef1ea; }
.flagrow-low, .flagrow-high { background: #fffafa; }

.kv { display: grid; gap: .65rem; margin: 0; }
.kv div {
  display: grid;
  grid-template-columns: minmax(105px, .7fr) 1fr;
  gap: .75rem;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 650; }

.chart {
  margin: 1rem 0 0;
  width: 100%;
  overflow-x: auto;
}
.trend-chart {
  min-height: 240px;
  min-width: 320px;
}
.mini-trends {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.mini-trend h2 {
  font-size: 1.05rem;
}

.healthcard-section { margin-bottom: 1rem; }
.share-controls {
  display: grid;
  grid-template-columns: minmax(280px, .85fr) minmax(320px, 1.15fr);
  gap: 1rem;
  align-items: start;
}
.share-create, .share-list { margin-bottom: 0; }
.printfoot { display: none; }

@media (min-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding-inline: 1.4rem;
  }
  .mainnav { justify-content: center; }
  .container { padding: 1.4rem; }
  .grid.two { grid-template-columns: 1fr 1fr; }
  .card, .flash, .notice { padding: 1.25rem; }
}

@media (max-width: 640px) {
  .container { padding: .85rem; }
  h1 { font-size: clamp(1.55rem, 7vw, 2.15rem); }
  .pagehead { gap: .35rem; }
  .stats { grid-template-columns: 1fr; }
  .dashboard-grid { gap: .7rem; margin-top: .85rem; }
  .stat { padding: .85rem; }
  .stat-num { font-size: clamp(1.6rem, 9vw, 2.6rem); }
  .stat-date { font-size: clamp(1.05rem, 5vw, 1.5rem); }
  .live-item { grid-template-columns: 1fr; }
  .live-sub, .live-meta { grid-column: 1; }
  .live-meta {
    grid-row: auto;
    justify-content: flex-start;
    text-align: left;
  }
  .results { display: block; overflow-x: auto; white-space: nowrap; }
  .pair { grid-template-columns: 1fr; }
  .kv div { grid-template-columns: 1fr; gap: .1rem; }
  .share-controls { grid-template-columns: 1fr; }
  .mini-trends { grid-template-columns: 1fr; }
}

@media print {
  :root { --bg: #fff; --card: #fff; --text: #000; --muted: #555; --line: #bbb; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .no-print, .topbar, .flash, .notice.no-print, .btn, .mainnav { display: none !important; }
  .container { width: 100%; padding: 0; }
  .card {
    border: 0;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    margin: 0 0 12pt;
  }
  .card { border-top: 1px solid #bbb; padding-top: 10pt; }
  h1 { font-size: 24pt; }
  h2 { font-size: 15pt; }
  .results th, .results td { padding: 4pt 3pt; }
  .badge { border: 1px solid #777; color: #000; background: #fff; }
  .printfoot {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    font-size: 9pt;
    color: #555;
    border-top: 1px solid #bbb;
    padding-top: 4pt;
  }
  @page { margin: 14mm; }
}
