:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #1d1d1f);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #0f6e6e);
  --accent: var(--tg-theme-button-color, #138a85);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93a32);
  --coral: #f0704a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; }
body { padding-bottom: 88px; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid rgba(127,127,127,.15); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--coral); flex: none; }
.title { font-weight: 700; font-size: 16px; }
.sub { color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subject { max-width: 45%; padding: 7px 10px; border-radius: 10px; border: 1px solid rgba(127,127,127,.3);
  background: var(--bg2); color: var(--text); font: inherit; }

.tabs { position: sticky; top: 63px; z-index: 4; display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px;
  background: var(--bg2); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid rgba(127,127,127,.25);
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.tab .n { margin-left: 6px; color: var(--hint); font-size: 12px; }
.tab.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.tab.on .n { color: var(--accent-text); opacity: .8; }

.list { padding: 4px 16px 16px; display: grid; gap: 8px; }
.card { width: 100%; text-align: left; display: grid; gap: 3px; padding: 12px 14px; border-radius: var(--radius);
  border: 0; background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
  box-shadow: 0 1px 0 rgba(0,0,0,.04); }
.card:active { transform: scale(.99); }
.card .main { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.card .main .amt { font-weight: 600; white-space: nowrap; }
.card .meta { color: var(--hint); font-size: 13px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg2); color: var(--hint); }
.badge.over { background: rgba(217,58,50,.12); color: var(--danger); }
.badge.kind { background: rgba(19,138,133,.12); color: var(--link); }
.empty { padding: 28px 8px; text-align: center; color: var(--hint); }

.add { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 6;
  padding: 13px 20px; border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 700; box-shadow: 0 6px 18px rgba(0,0,0,.18); cursor: pointer; }

.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; background: rgba(0,0,0,.35); }
.sheet-card { width: 100%; max-height: 92vh; overflow-y: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; background: var(--bg); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.icon { border: 0; background: var(--bg2); color: var(--text); width: 32px; height: 32px; border-radius: 50%;
  font-size: 14px; cursor: pointer; }
.form { display: grid; gap: 12px; margin-top: 12px; }
.field { display: grid; gap: 5px; }
.field > span { font-size: 13px; color: var(--hint); }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border-radius: 10px; font: inherit;
  border: 1px solid rgba(127,127,127,.3); background: var(--bg2); color: var(--text); }
.field textarea { min-height: 70px; resize: vertical; }
.field.check { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.field.check input { width: 20px; height: 20px; }
.field.check > span { color: var(--text); font-size: 15px; }
.readonly { padding: 10px 12px; border-radius: 10px; background: var(--bg2); color: var(--hint); white-space: pre-wrap; }
.req::after { content: " *"; color: var(--danger); }
.scope { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--bg2); display: grid; gap: 6px; }
.scope-label { font-size: 13px; color: var(--hint); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions button { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--accent); background: transparent;
  color: var(--link); font: inherit; font-weight: 600; cursor: pointer; }
.buttons { display: flex; gap: 10px; margin-top: 18px; }
.buttons button { flex: 1; padding: 12px; border-radius: 12px; border: 0; font: inherit; font-weight: 700; cursor: pointer; }
.primary { background: var(--accent); color: var(--accent-text); }
.danger { background: rgba(217,58,50,.1); color: var(--danger); }
button:disabled { opacity: .5; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20;
  padding: 12px 14px; border-radius: 12px; background: #1d1d1f; color: #fff; font-size: 14px; text-align: center; }
.toast.bad { background: var(--danger); }
.gate { padding: 40px 24px; text-align: center; color: var(--hint); }
