:root {
  --bg: var(--tg-theme-bg-color, #0e1117);
  --bg2: var(--tg-theme-secondary-bg-color, #161b24);
  --text: var(--tg-theme-text-color, #e7ebf3);
  --muted: var(--tg-theme-hint-color, #8790a3);
  --accent: var(--tg-theme-button-color, #5b7cfa);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 9%, transparent);
  --hover: color-mix(in srgb, var(--text) 4%, transparent);
  --good: #3ccf91;
  --bad: #f06a6a;
  --warn: #e8b04a;
  --r: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
#app { min-height: 100%; display: flex; flex-direction: column; }

.gate { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 380px; text-align: center; }
.logo { font-size: 22px; font-weight: 700; letter-spacing: .3px; margin-bottom: 8px; }
.gate-actions { display: grid; gap: 10px; margin-top: 18px; }
.plan { text-align: left; background: var(--bg2); border-radius: var(--r); padding: 14px; }
.plan b { display: block; margin-bottom: 4px; }

.btn { border: 0; border-radius: var(--r); padding: 11px 16px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: var(--bg2); }
.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 36px; height: 36px; border: 0; border-radius: 9px; background: var(--bg2);
}
.icon-btn:hover { filter: brightness(1.15); }
.count {
  position: absolute; top: -4px; right: -4px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--accent); color: var(--accent-text);
  font-size: 11px; line-height: 17px; font-weight: 700;
}

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; min-width: 0; }
.status span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent); }
.dot.off { background: var(--bad); }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.tier { font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 6px; background: var(--bg2); color: var(--muted); white-space: nowrap; }

.new-pill {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top, 0px)); z-index: 6;
  background: var(--accent); color: var(--accent-text); border-radius: 20px; padding: 6px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

.feed-wrap { container-type: inline-size; flex: 1; padding: 0 0 calc(16px + env(safe-area-inset-bottom, 0px)); }
.feed-head, .row-main {
  display: grid; align-items: center; gap: 10px;
  grid-template-columns: 64px minmax(130px, 1.2fr) 72px 82px 82px 60px 82px minmax(110px, 1fr);
  padding: 0 16px;
}
.feed-head {
  position: sticky; top: calc(57px + env(safe-area-inset-top, 0px)); z-index: 4;
  height: 34px; color: var(--muted); font-size: 12px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.r { text-align: right; }
.row { border-bottom: 1px solid var(--line); }
.row-main { min-height: 46px; cursor: pointer; }
.row-main:hover { background: var(--hover); }
.row.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { background: color-mix(in srgb, var(--accent) 18%, transparent); } to { background: transparent; } }
.c-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.c-wallet { display: flex; align-items: center; gap: 6px; min-width: 0; }
.c-wallet .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sound-btn.off { color: var(--muted); }
.copy { border: 0; background: none; padding: 3px; color: var(--muted); border-radius: 5px; line-height: 0; flex: none; }
.copy:hover { color: var(--text); background: var(--bg2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--bg2); color: var(--muted); white-space: nowrap; }
.tag.seen { color: var(--accent); }
.tag.warn { color: var(--warn); }
.lbl { display: none; }

.details { padding: 4px 16px 14px; background: var(--hover); }
.details-grid { overflow-x: auto; }
.ptable { border-collapse: collapse; width: 100%; min-width: 460px; font-size: 13px; font-variant-numeric: tabular-nums; }
.ptable th, .ptable td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable th:first-child, .ptable td:first-child { text-align: left; color: var(--muted); }
.ptable th { color: var(--muted); font-weight: 500; }
.dmeta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 6px; font-size: 13px; }
.dlinks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.dlinks a { background: var(--bg2); padding: 6px 10px; border-radius: 8px; font-size: 13px; }

.empty { text-align: center; padding: 48px 16px; }

@container (max-width: 760px) {
  .feed-head { display: none; }
  .row-main {
    grid-template-columns: 1fr auto; grid-template-areas: "w t" "k k" "g g";
    gap: 6px 10px; padding: 12px 16px;
  }
  .c-wallet { grid-area: w; }
  .c-time { grid-area: t; text-align: right; }
  .kpis { grid-area: k; display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 6px; }
  .kpis .num { text-align: left; background: var(--bg2); border-radius: 8px; padding: 5px 8px; }
  .lbl { display: block; font-size: 10px; color: var(--muted); }
  .tags { grid-area: g; }
  .tags:empty { display: none; }
  .ptable { min-width: 340px; font-size: 12px; }
  .ptable th, .ptable td { padding: 6px 4px; }
  .details { padding: 4px 12px 14px; }
}
@container (min-width: 761px) { .kpis { display: contents; } }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.sheet {
  position: fixed; z-index: 21; top: 0; right: 0; bottom: 0; width: min(440px, 100%);
  display: flex; flex-direction: column; background: var(--bg); border-left: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(30px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.sheet-foot { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.fgroup { margin-top: 14px; }
.fgroup > summary { cursor: pointer; font-weight: 600; padding: 6px 0; list-style: none; display: flex; justify-content: space-between; }
.fgroup > summary::after { content: "▾"; color: var(--muted); }
.fgroup:not([open]) > summary::after { content: "▸"; }
.fgroup .badge { color: var(--accent); font-weight: 600; font-size: 12px; margin-left: 6px; }
.frow { display: grid; grid-template-columns: 1fr 78px 78px; gap: 8px; align-items: center; padding: 5px 0; }
.frow label { font-size: 13px; }
.frow .unit { color: var(--muted); font-size: 11px; }
.frow input {
  width: 100%; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg2); color: var(--text); font: inherit; font-size: 13px;
}
.frow input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); border-color: transparent; }
.frow input.set { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.fhead { display: grid; grid-template-columns: 1fr 78px 78px; gap: 8px; color: var(--muted); font-size: 11px; padding-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0; }
.chip { border: 1px solid var(--line); background: var(--bg2); border-radius: 18px; padding: 6px 12px; font-size: 13px; }
.chip.on { background: color-mix(in srgb, var(--bad) 18%, var(--bg2)); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.locked { margin-top: 18px; padding: 14px; border-radius: var(--r); background: var(--bg2); }
.locked b { display: block; margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--bg2); border: 1px solid var(--line); padding: 9px 14px; border-radius: 10px; z-index: 30; font-size: 13px;
}
