:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --surface-2: #eef2f2;
  --text: #13201f;
  --muted: #5d6b6a;
  --border: #d8e0df;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #d5efec;
  --danger: #b42318;
  --danger-soft: #fde7e5;
  --warn: #a15c07;
  --warn-soft: #fdf0d8;
  --ok: #157f3c;
  --ok-soft: #dcf3e4;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 5%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1413;
    --surface: #152020;
    --surface-2: #1c2928;
    --text: #e6eeed;
    --muted: #93a3a1;
    --border: #2a3a39;
    --brand: #2bb3a5;
    --brand-ink: #04211e;
    --brand-soft: #123b37;
    --danger: #ff8a7f;
    --danger-soft: #3a1a17;
    --warn: #f0b45c;
    --warn-soft: #362810;
    --ok: #6fd796;
    --ok-soft: #133222;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: -0.01em; }
.bolt { color: var(--brand); }
.who { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; }

.app { max-width: 640px; margin: 0 auto; padding: 16px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border-radius: 10px;
  font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabs a span { font-size: 18px; line-height: 22px; font-weight: 700; }
.tabs a.active { color: var(--brand); background: var(--brand-soft); }

h1 { font-size: 22px; margin: 4px 0 14px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 24px 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

label.field { display: block; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  min-height: 46px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.kwh-input {
  font-size: 40px; font-weight: 700; text-align: center;
  font-variant-numeric: tabular-nums; padding: 14px;
}
.unit { font-size: 15px; color: var(--muted); text-align: center; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn {
  min-width: 44px; min-height: 44px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 18px;
}

.monthnav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.monthnav .label { font-weight: 700; font-size: 17px; text-align: center; flex: 1; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 12px; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px;
  font-weight: 600; color: var(--muted); cursor: pointer; min-height: 40px;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.list li.clickable { cursor: pointer; }
.list li.mine .title::after {
  content: "ich"; margin-left: 6px; font-size: 11px; font-weight: 700; vertical-align: 2px;
  background: var(--brand-soft); color: var(--brand); padding: 1px 6px; border-radius: 99px;
}

.badge {
  display: inline-block; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted);
}
.badge.lock { background: var(--warn-soft); color: var(--warn); }
.badge.admin { background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 6px; border-bottom: 1px solid var(--border); text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: none; }
tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--border); }
td.total { font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.notice { border-radius: 10px; padding: 12px; font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.info { background: var(--brand-soft); color: var(--text); }

.subtabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.subtabs a {
  flex: none; padding: 8px 12px; border-radius: 99px; text-decoration: none;
  background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 14px;
}
.subtabs a.on { background: var(--brand); color: var(--brand-ink); }

dialog {
  border: 0; border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog .dlg { padding: 18px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.qr { display: block; margin: 8px auto; width: min(280px, 70vw); height: auto; image-rendering: pixelated; background: #fff; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 15px; font-weight: 600;
  max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgb(0 0 0 / 25%);
}
.toast.error { background: var(--danger); color: #fff; }

.hero { text-align: center; padding: 28px 8px 8px; }
.hero .big { font-size: 56px; line-height: 1; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.hidden { display: none !important; }

@media (max-width: 420px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
}
