:root {
  --bg: #1c1b1f;
  --bar: #45464f;
  --card: #45464f;
  --card-2: #3a3a42;
  --line: #5c5d68;
  --accent: #c3c5ff;
  --accent-ink: #1b2067;
  --accent-soft: #a9acf0;
  --ring: #c3c5ff;
  --title: #c3c5ff;
  --text: #f2f1f6;
  --muted: #8f8f9b;
  --danger: #ff8a80;
  --good: #7fd88a;
  --ok: #e6d46a;
  --mid: #f2a65e;
  --bad: #f07b7b;
  --badge-ink: #10331a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35);
}
[data-theme="light"] {
  --bg: #f1f1f6;
  --bar: #ffffff;
  --card: #ffffff;
  --card-2: #f4f4fa;
  --line: #d9d9e3;
  --accent: #c3c5ff;
  --accent-ink: #1b2067;
  --accent-soft: #5c62d6;
  --ring: #6e73e6;
  --title: #3d43b8;
  --text: #1c1b1f;
  --muted: #74747f;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; }

/* ---------- верхня панель ---------- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  height: 56px; padding: 0 8px;
  background: var(--bar); box-shadow: var(--shadow);
}
.appbar h1 {
  margin: 0; text-align: center; font-size: 21px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar-left, .appbar-right {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%;
}
.appbar-left:empty, .appbar-right:empty { pointer-events: none; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: #e2531f; color: #2b0d00; font-weight: 600; font-size: 16px; flex: none;
}
.icon { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

main { padding: 16px 14px 32px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- картки ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px 14px 20px;
  display: flex; align-items: center; gap: 12px; min-height: 92px;
  text-align: left; width: 100%;
}
.card .grow { flex: 1; min-width: 0; }
.card .name { color: var(--title); font-weight: 600; font-size: 18px; line-height: 1.3; }
.card .sub { color: var(--muted); font-size: 14px; margin-top: 4px; letter-spacing: .2px; }
.card .sub.err { color: var(--danger); }
.card.dim .name { opacity: .7; }

/* ---------- кільце ---------- */
.ring { position: relative; flex: none; }
.ring svg { display: block; transform: rotate(-90deg); }
.ring .track { stroke: var(--card-2); }
.ring .bar { stroke: var(--ring); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring .val {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 600; font-size: 17px; color: var(--text); font-variant-numeric: tabular-nums;
}
.ring.big .val { font-weight: 400; font-size: 32px; }

/* ---------- сегменти/чіпи ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: flex; background: var(--card); border-radius: 999px; padding: 3px; flex: 1; min-width: 0; }
.seg button {
  flex: 1; padding: 7px 6px; border-radius: 999px; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pill {
  background: var(--card); border-radius: 999px; padding: 9px 12px; font-size: 14px; color: var(--muted);
  display: inline-flex; gap: 6px; align-items: center;
}

/* ---------- підсумок ---------- */
.summary { display: flex; gap: 16px; align-items: center; }
.summary .label { color: var(--muted); font-size: 14px; }
.summary .big { font-size: 15px; margin-top: 6px; }
.summary .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
.refresh { color: var(--accent); font-size: 14px; font-weight: 600; margin-top: 8px; display: inline-flex; gap: 6px; align-items: center; }
.refresh.busy .icon { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- панель з заголовком (огляд, місяці) ---------- */
.panel { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--card); }
.panel-head {
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px 0 26px; min-height: 56px; font-size: 21px; font-weight: 500;
}
.panel-body { padding: 14px 26px 18px; }
.overview { display: flex; justify-content: space-around; gap: 6px; padding: 26px 8px 18px; }
.overview .col { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 14px; }
.info-btn { width: 40px; height: 40px; border-radius: 8px; background: rgba(27, 32, 103, .14); display: grid; place-items: center; }
.info-btn .icon { stroke: var(--accent-ink); }
.info-text { padding: 0 20px 16px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.badge {
  min-width: 62px; height: 36px; padding: 0 10px; border-radius: 8px; display: grid; place-items: center;
  font-weight: 700; font-size: 18px; color: var(--badge-ink); background: var(--good);
}
.badge.ok { background: var(--ok); color: #3a3000; }
.badge.mid { background: var(--mid); color: #3d1d00; }
.badge.bad { background: var(--bad); color: #3f0000; }
.badge.none { background: var(--card-2); color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 9px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 76px; max-width: 132px;
}
.chip .d { font-size: 14px; }
.chip .g {
  min-width: 52px; height: 38px; padding: 0 8px; border-radius: 6px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: 17px;
}
.chip .g.summary { background: var(--good); color: var(--badge-ink); font-weight: 700; }
.chip .g.missing { background: var(--card-2); color: var(--muted); }
.chip .g.text { font-size: 14px; }
.chip .t { font-size: 13px; font-weight: 600; text-align: center; line-height: 1.2;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* ---------- форми / налаштування ---------- */
.section-title { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; margin: 14px 4px 2px; }
.form { background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.field label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); outline: none;
}
.field input:focus { border-color: var(--accent); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }
.btn {
  width: 100%; padding: 14px; border-radius: 12px; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 16px;
}
.btn.ghost { background: var(--card); color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.error-box { background: rgba(240, 123, 123, .15); color: var(--danger); padding: 10px 12px; border-radius: 10px; font-size: 14px; }

.row {
  background: var(--card); border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center; gap: 12px;
}
.row .grow { flex: 1; min-width: 0; }
.row .t1 { font-size: 16px; }
.row .t2 { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row .x { color: var(--muted); font-size: 22px; width: 32px; height: 32px; }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--card-2); border-radius: 999px; transition: .2s; border: 1px solid var(--line); }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: .2s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--accent-ink); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; line-height: 1.5; }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.add-card { justify-content: center; color: var(--accent); font-weight: 600; min-height: 64px; border: 1.5px dashed var(--line); background: transparent; box-shadow: none; }

.skeleton { background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); height: 92px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- нижній лист / тост ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet.hidden, .toast.hidden { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--card); border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom)); max-height: 80vh; overflow: auto;
}
.sheet-body h3 { margin: 0 0 12px; color: var(--title); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: #2b2b31; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.4);
  max-width: 90vw;
}
