:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: var(--tg-theme-bg-color, #0d1118);
  --surface: var(--tg-theme-secondary-bg-color, #1b222c);
  --text: var(--tg-theme-text-color, #f5f7fb);
  --muted: var(--tg-theme-hint-color, #939ca9);
  --accent: var(--tg-theme-button-color, #3487f5);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 13%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled, select:disabled { opacity: .55; cursor: default; }
.shell { width: min(100%, 760px); margin: 0 auto; padding: max(env(safe-area-inset-top), 20px) 18px max(env(safe-area-inset-bottom), 32px); }
.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 0 22px; }
.mark { flex: 0 0 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 800; font-size: 24px; }
.identity { min-width: 0; flex: 1; }
.eyebrow, .kicker { margin: 0; font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 1px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 21px; line-height: 1.2; }
h2 { margin: 2px 0 0; font-size: 25px; letter-spacing: -.03em; }
h3 { margin: 0; font-size: 17px; }
.role { flex: none; padding: 6px 9px; border-radius: 999px; background: var(--soft); color: var(--accent); font-size: 11px; font-weight: 700; }
.tabs { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; padding: 4px; margin-bottom: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 1 0 auto; padding: 9px 12px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 700; font-size: 13px; white-space: nowrap; }
.tabs button.active { background: var(--accent); color: var(--accent-text); }
.page { display: grid; gap: 14px; }
.page[hidden], [hidden] { display: none !important; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 15px; margin-bottom: 2px; }
.count-box { display: flex; flex-direction: column; text-align: right; color: var(--muted); font-size: 11px; line-height: 1.1; }
.count-box strong { color: var(--accent); font-size: 30px; line-height: 1; }
.card { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 4px 16px rgba(0,0,0,.025); padding: 17px; }
.stats-row { display: flex; gap: 12px; align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.stats-row:last-child { border: 0; }
.rank { width: 25px; color: var(--muted); font-weight: 800; font-size: 13px; }
.stats-name { min-width: 0; flex: 1; overflow-wrap: anywhere; font-weight: 700; }
.stats-value { text-align: right; font-weight: 800; }
.stats-value small { display: block; color: var(--muted); font-weight: 500; }
.empty { margin: 0; padding: 18px 3px; color: var(--muted); text-align: center; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-grid label:not(.toggle-row) { display: grid; gap: 6px; min-width: 0; }
label span { font-size: 12px; font-weight: 700; }
input:not([type=checkbox]), select { width: 100%; min-width: 0; height: 43px; border: 1px solid var(--line); border-radius: 11px; padding: 0 12px; color: var(--text); background: var(--bg); outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; min-height: 43px; gap: 10px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.full { grid-column: 1 / -1; }
.primary, .inline-form button, .save-access { min-height: 43px; border: 0; border-radius: 11px; padding: 10px 15px; background: var(--accent); color: var(--accent-text); font-weight: 800; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.stack { display: grid; gap: 13px; }
.subhead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.subhead span { color: var(--muted); font-size: 12px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.inline-form button { min-width: 90px; }
.search { margin-top: 1px; }
.word-list { display: flex; flex-wrap: wrap; gap: 7px; max-height: 330px; overflow-y: auto; }
.chip { display: inline-flex; align-items: center; gap: 7px; min-height: 31px; padding: 4px 9px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font-size: 12px; }
.chip button { border: 0; background: none; color: var(--muted); font-size: 17px; line-height: 1; padding: 0; }
.chip button:hover { color: #aa4338; }
.chip.builtin { color: var(--muted); }
.chip.disabled { opacity: .52; text-decoration: line-through; }
.intro { padding: 0 2px 3px; }
.access-list { display: grid; gap: 11px; }
.person-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.person-head strong { overflow-wrap: anywhere; }
.person-head small { color: var(--muted); }
.permission-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 0; }
.permission-grid label { display: flex; align-items: center; gap: 7px; }
.save-access { width: 100%; min-height: 38px; background: var(--soft); color: var(--accent); }
.notice { margin: 0 0 16px; border-radius: 12px; padding: 11px 14px; background: var(--soft); color: var(--accent); font-size: 13px; }
.notice.error { background: #f8e8e3; color: #9a382f; }
.loading { margin-top: 80px; text-align: center; color: var(--muted); }
@media (max-width: 520px) {
  .shell { padding-left: 14px; padding-right: 14px; }
  .form-grid, .permission-grid { grid-template-columns: 1fr; }
  .role { max-width: 94px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Mini App layout */
.shell { width: min(100%, 680px); padding: max(env(safe-area-inset-top), 18px) 16px max(env(safe-area-inset-bottom), 32px); }
.hero-card { position: relative; padding: 15px 17px 16px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 23px; background: linear-gradient(135deg, var(--soft), var(--surface) 66%); }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 9px; margin-bottom: 15px; }
.brand-line { display: flex; align-items: center; gap: 9px; margin-bottom: 0; font-size: 13px; font-weight: 800; letter-spacing: .01em; color: var(--accent); }
.hero-body { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.hero-copy { min-width: 0; }
.ui-language { display: grid; gap: 4px; flex: 0 0 118px; font-size: 10px; color: var(--muted); }
.ui-language select { width: 100%; min-height: 34px; padding: 4px 6px; font-size: 12px; }
.mark { flex: 0 0 28px; width: 28px; height: 28px; border-radius: 9px; font-size: 17px; }
.hero-card .eyebrow { margin-bottom: 4px; }
.hero-card h1 { margin: 0 0 9px; font-size: clamp(23px, 6vw, 29px); white-space: normal; overflow-wrap: anywhere; }
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.share-bot { min-height: 33px; padding: 6px 10px; border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); border-radius: 999px; color: var(--accent); background: var(--soft); font-size: 11px; font-weight: 750; }
.role { display: inline-flex; max-width: none; overflow: visible; padding: 6px 10px; font-size: 12px; white-space: normal; }
.section-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 24px; }
.section-grid button { min-height: 66px; display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); text-align: left; font-size: 14px; font-weight: 750; }
.section-grid button.active { border-color: var(--accent); background: var(--soft); color: var(--accent); }
.section-icon { display: grid; place-items: center; flex: 0 0 32px; height: 32px; border-radius: 10px; background: var(--soft); color: var(--accent); font-size: 17px; }
.section-grid button.active .section-icon { background: var(--accent); color: var(--accent-text); }
.page { gap: 13px; }
.section-head { margin: 0 2px 3px; }
.section-head h2 { font-size: 25px; }
.refresh-access { flex: none; min-height: 36px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--accent); background: var(--surface); font-size: 12px; font-weight: 750; }
.danger { min-height: 43px; border: 1px solid #b7514d; border-radius: 11px; padding: 10px 15px; background: #8e302f; color: #fff; font-weight: 800; }
.card { padding: 17px; border-radius: 19px; box-shadow: none; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-heading h3 { margin-top: 3px; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.metric-card { display: flex; flex-direction: column; min-height: 118px; padding: 15px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); }
.metric-card span { font-size: 12px; color: var(--muted); }
.metric-card strong { margin-top: 5px; font-size: 33px; line-height: 1.1; color: var(--accent); font-variant-numeric: tabular-nums; }
.metric-card small { margin-top: auto; font-size: 11px; color: var(--muted); }
.metric-wide { grid-column: 1 / -1; min-height: 88px; background: linear-gradient(105deg, var(--surface), var(--soft)); }
.metric-wide strong { font-size: 29px; }
.period-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.period-grid button { min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--bg); font-size: 13px; font-weight: 700; }
.period-grid button.active { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.period-custom { grid-column: 1 / -1; }
.month-wrap, .field-label { display: grid; gap: 7px; }
.month-wrap span, .field-label span { font-size: 12px; font-weight: 700; color: var(--muted); }
.result-card { display: grid; gap: 14px; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.result-grid div { display: flex; flex-direction: column; padding: 12px; border-radius: 13px; background: var(--bg); }
.result-grid strong { color: var(--accent); font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result-grid span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.amount-line { padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.count-badge { min-width: 28px; padding: 4px 7px; text-align: center; border-radius: 9px; color: var(--accent); background: var(--soft); font-size: 12px; font-weight: 800; }
.stats-row { padding: 12px 0; }
.stats-value { white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats-value small { white-space: normal; font-size: 11px; }
.publish-card { display: grid; gap: 13px; border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.publish-card .primary { width: 100%; }
.publish-card .hint { line-height: 1.5; }
.form-grid { gap: 13px; }
.access-list .card { padding: 15px; }
.loading { margin-top: 50px; }
.explain { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); }
.explain summary { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 750; }
.explain p { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.save-status { margin: 0; min-height: 18px; color: var(--accent); font-size: 12px; font-weight: 700; }
.save-status.error { color: #d26758; }
.command-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.command-row:last-child { border-bottom: 0; }
.command-copy { display: grid; gap: 3px; min-width: 0; }
.command-copy strong { color: var(--accent); font-size: 13px; overflow-wrap: anywhere; }
.command-copy span { color: var(--muted); font-size: 12px; }
.command-toggle { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.command-toggle span, .command-access { color: var(--muted); font-size: 11px; white-space: nowrap; }
.fine-card { display: grid; gap: 7px; }
.fine-top { display: flex; align-items: start; gap: 10px; }
.fine-copy { min-width: 0; display: grid; gap: 3px; flex: 1; }
.fine-copy strong { overflow-wrap: anywhere; }
.fine-meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.fine-card.cancelled { opacity: .65; }
.fine-link { color: var(--accent); font-size: 12px; text-decoration: none; }
#fines-actions { position: sticky; bottom: max(env(safe-area-inset-bottom), 8px); z-index: 2; background: var(--surface); }
@media (max-width: 520px) {
  .shell { padding-left: 14px; padding-right: 14px; }
  .permission-grid, .form-grid { grid-template-columns: 1fr; }
  .section-grid button { min-height: 61px; }
}
