/* Telegram-native look: colours come from the user's Telegram theme (--tg-theme-*), so light / dark / custom themes just work.
   Typeface: Estedad (self-hosted). Icons: Lucide (inlined). */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #efeff4);
  --sec: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #2481cc));
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec-head: var(--tg-theme-section-header-text-color, #6d6d72);
  --sub: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, #8e8e93));
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --sep: color-mix(in srgb, var(--hint) 26%, transparent);
  --soft: color-mix(in srgb, var(--hint) 13%, transparent);
  --bar: var(--tg-theme-bottom-bar-bg-color, var(--tg-theme-secondary-bg-color, #f8f8f8));
  --ok: #34c759; --warn: #ff9500; --red: #ff3b30;
  --top: max(var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px), env(safe-area-inset-top, 0px));
  --bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  --radius: 16px;
  --shadow: 0 1px 2px color-mix(in srgb, #000 6%, transparent), 0 6px 18px -8px color-mix(in srgb, #000 14%, transparent);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
/* gradient chips: set --c1/--c2 with a colour class */
.c-blue { --c1: #55b0ff; --c2: #2f7bd6; } .c-green { --c1: #67dc86; --c2: #2fb457; } .c-purple { --c1: #c98bf5; --c2: #8e4fd6; }
.c-red { --c1: #ff8a7d; --c2: #e8412f; } .c-orange { --c1: #ffbe4d; --c2: #f08a00; } .c-teal { --c1: #5ad8e6; --c2: #1fa0b8; }
.c-pink { --c1: #ff86b8; --c2: #ec3f7e; } .c-gray { --c1: #adb4c0; --c2: #7c8494; } .c-indigo { --c1: #8d9aff; --c2: #5560e6; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 400 15.5px/1.5 "Estedad", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Tahoma, sans-serif; -webkit-font-smoothing: antialiased; font-feature-settings: "ss01"; overscroll-behavior-y: contain; }
button, input, select { font-family: inherit; }
#app { padding: calc(var(--top) + 6px) 0 calc(var(--bottom) + 88px); min-height: 100vh; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.i { width: 20px; height: 20px; flex: none; display: block; }
.i.s { width: 16px; height: 16px; } .i.l { width: 24px; height: 24px; }

h1 { font-size: 27px; font-weight: 700; margin: 14px 16px 2px; letter-spacing: -.2px; display: flex; align-items: center; justify-content: space-between; gap: 8px; line-height: 1.3; }
.lead { margin: 0 16px 10px; color: var(--hint); font-size: 14px; }
.crumb { display: flex; gap: 6px; align-items: center; margin: 4px 16px 0; font-size: 13px; color: var(--hint); flex-wrap: wrap; }
.crumb a { color: var(--accent); text-decoration: none; font-weight: 500; }
.sect { margin: 20px 0 0; }
.sect > h2 { margin: 0 30px 8px; font-size: 13px; font-weight: 600; color: var(--sec-head); letter-spacing: .1px; }
.sect > .foot { margin: 8px 30px 0; font-size: 12.5px; color: var(--hint); }
.list { margin: 0 16px; background: var(--sec); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }

/* rows */
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; min-height: 54px; position: relative; color: inherit; text-decoration: none; }
a.row, .row.tap { cursor: pointer; } a.row:active, .row.tap:active { background: var(--soft); }
.row + .row::before { content: ""; position: absolute; inset-inline: 62px 0; top: 0; height: .5px; background: var(--sep); }
.row.noicon + .row::before { inset-inline-start: 14px; }
.ico { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--c1, #adb4c0), var(--c2, #7c8494)); box-shadow: 0 3px 8px -3px var(--c2, #7c8494); }
.ico .i { width: 19px; height: 19px; }
.body { flex: 1; min-width: 0; }
.title { font-size: 15.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title.wrap { white-space: normal; font-weight: 500; }
.sub { font-size: 12.5px; color: var(--sub); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.val { color: var(--hint); font-size: 14px; flex: none; }
.chev { flex: none; color: var(--hint); opacity: .55; }
.pill { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 20px; flex: none; color: #fff; background: var(--hint); white-space: nowrap; }
.pill.ok { background: var(--ok); } .pill.warn { background: var(--warn); } .pill.bad { background: var(--red); } .pill.info { background: #2f7bd6; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; color: var(--sub); background: var(--soft); padding: 3px 8px; border-radius: 8px; }
.chip .i { width: 13px; height: 13px; }
.chip.ok { color: #1f9d46; background: color-mix(in srgb, var(--ok) 16%, transparent); } .chip.bad { color: var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); }
.chip.key { color: #b57700; background: color-mix(in srgb, var(--warn) 18%, transparent); } .chip.fk { color: #2f7bd6; background: color-mix(in srgb, #2f7bd6 15%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--hint); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* hero */
.hero { margin: 8px 16px 0; padding: 22px 18px 18px; border-radius: 22px; color: #fff; position: relative; overflow: hidden;
  background: radial-gradient(120% 140% at 100% 0%, #ff86b8 0%, transparent 55%), radial-gradient(120% 140% at 0% 100%, #5560e6 0%, transparent 60%), linear-gradient(135deg, #ec3f7e, #8e4fd6); box-shadow: 0 14px 30px -14px #8e4fd6; }
.hero::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 85% 15%, rgba(255,255,255,.22), transparent 40%); pointer-events: none; }
.hero .top { display: flex; align-items: center; gap: 14px; position: relative; z-index: 1; }
.hero .av { width: 60px; height: 60px; border-radius: 20px; background: rgba(255,255,255,.2); backdrop-filter: blur(6px); display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); }
.hero .av .i { width: 32px; height: 32px; }
.hero .name { font-size: 24px; font-weight: 700; line-height: 1.2; } .hero .handle { opacity: .85; font-size: 13.5px; direction: ltr; text-align: right; }
.hero .meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; position: relative; z-index: 1; }
.hero .m { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.18); backdrop-filter: blur(6px); padding: 5px 11px; border-radius: 20px; font-size: 12.5px; font-weight: 500; }
.hero .m .dot { background: #7dff9e; width: 8px; height: 8px; }

/* stat tiles */
.grid { margin: 12px 16px 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--sec); border-radius: var(--radius); padding: 12px 10px 11px; position: relative; overflow: hidden; box-shadow: var(--shadow); color: inherit; text-decoration: none; display: block; }
a.tile:active { transform: scale(.97); }
.tile::after { content: ""; position: absolute; inset-inline-end: -18px; top: -18px; width: 62px; height: 62px; border-radius: 50%; background: var(--c2); opacity: .1; }
.tile .ti { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--c1), var(--c2)); margin-bottom: 8px; }
.tile .ti .i { width: 17px; height: 17px; }
.tile b { display: block; font-size: 21px; font-weight: 700; letter-spacing: -.3px; line-height: 1.2; } .tile span { font-size: 11.5px; color: var(--hint); }

/* cards */
.cards { margin: 0 16px; display: grid; gap: 10px; }
.card { background: var(--sec); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: block; color: inherit; text-decoration: none; position: relative; }
a.card:active { transform: scale(.985); background: color-mix(in srgb, var(--sec) 92%, var(--hint)); }
.card .hd { display: flex; align-items: center; gap: 12px; }
.card .desc { font-size: 13px; color: var(--sub); margin-top: 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .act { display: flex; gap: 8px; margin-top: 12px; }

/* buttons */
.btnrow { margin: 14px 16px 0; display: flex; gap: 8px; }
.btn { flex: 1; appearance: none; border: 0; border-radius: 14px; padding: 13px 14px; font-weight: 600; font-size: 15px; background: var(--btn); color: var(--btn-text); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { opacity: .75; } .btn[disabled] { opacity: .5; }
.btn.danger { background: var(--sec); color: var(--danger); box-shadow: var(--shadow); }
.mini { appearance: none; border: 0; background: color-mix(in srgb, var(--btn) 14%, transparent); color: var(--accent); font-size: 13.5px; font-weight: 600; padding: 7px 12px; border-radius: 12px; cursor: pointer; flex: none; display: inline-flex; align-items: center; gap: 5px; }
.mini .i { width: 15px; height: 15px; }
.mini.danger { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); } .mini.ghost { background: var(--soft); color: var(--sub); }
.mini:active { opacity: .6; } .mini[disabled] { opacity: .4; }
.iconbtn { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 12px; }

/* search + segmented control */
.search { margin: 10px 16px 0; position: relative; }
.search input { width: 100%; border: 0; border-radius: 12px; padding: 11px 40px 11px 14px; font-size: 15px; background: var(--soft); color: var(--text); outline: none; }
.search input::placeholder { color: var(--hint); }
.search .i { position: absolute; inset-inline-start: auto; right: 12px; top: 50%; transform: translateY(-50%); color: var(--hint); width: 18px; height: 18px; pointer-events: none; }
.seg { margin: 12px 16px 0; display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--sub); padding: 8px; border-radius: 10px; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; }
.seg button.on { background: var(--sec); color: var(--text); box-shadow: 0 1px 4px color-mix(in srgb, #000 14%, transparent); }

/* data grid */
.gridwrap { margin: 12px 16px 0; background: var(--sec); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.scroller { direction: ltr; overflow: auto; max-height: calc(100vh - 330px); min-height: 90px; -webkit-overflow-scrolling: touch; }
table.dg { border-collapse: separate; border-spacing: 0; direction: ltr; font-size: 13px; width: max-content; min-width: 100%; }
.dg th { position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--sec) 86%, var(--hint)); text-align: left; font-weight: 600; font-size: 12px; padding: 9px 12px; white-space: nowrap; color: var(--sub); border-bottom: .5px solid var(--sep); cursor: pointer; user-select: none; }
.dg th .t { display: block; font-weight: 400; font-size: 10.5px; opacity: .75; font-family: var(--mono); }
.dg th .i { width: 12px; height: 12px; display: inline-block; vertical-align: -2px; margin-left: 4px; }
.dg th.sorted { color: var(--accent); }
.dg td { padding: 9px 12px; border-bottom: .5px solid var(--sep); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; }
.dg td.n { text-align: right; color: #2f7bd6; } .dg td.t { font-family: "Estedad", var(--mono); }
.dg td.null { color: var(--hint); font-style: italic; opacity: .7; }
.dg td.b span { font-weight: 600; font-size: 11.5px; padding: 2px 8px; border-radius: 8px; font-family: "Estedad", sans-serif; }
.dg td.b .y { background: color-mix(in srgb, var(--ok) 18%, transparent); color: #1f9d46; } .dg td.b .no { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.dg tr:active td { background: var(--soft); } .dg tr:last-child td { border-bottom: 0; }
.dg td.pk, .dg th.pk { position: sticky; left: 0; background: var(--sec); z-index: 1; box-shadow: 1px 0 0 var(--sep); } .dg th.pk { z-index: 3; background: color-mix(in srgb, var(--sec) 86%, var(--hint)); }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: .5px solid var(--sep); font-size: 12.5px; color: var(--sub); }
.pager .mid { flex: 1; text-align: center; line-height: 1.4; } .pager .mid b { color: var(--text); font-weight: 600; }
.tools { margin: 10px 16px 0; display: flex; gap: 8px; align-items: center; }
.tools select { appearance: none; border: 0; background: var(--soft); color: var(--text); font-size: 13.5px; padding: 8px 12px; border-radius: 12px; }

/* structure */
.col .nm { font-family: var(--mono); direction: ltr; text-align: right; font-weight: 600; font-size: 14px; }
.col .ty { font-family: var(--mono); font-size: 12px; color: var(--sub); direction: ltr; text-align: right; }
pre.code, pre.log { margin: 0; padding: 12px 14px; font: 12px/1.55 var(--mono); direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all; max-height: 320px; overflow: auto; color: var(--text); }
pre.code { max-height: none; font-size: 11.5px; color: var(--sub); }

/* bottom sheet */
#sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; background: rgba(0,0,0,.4); animation: fadeo .18s; }
#sheet[hidden] { display: none; }
@keyframes fadeo { from { opacity: 0; } to { opacity: 1; } }
#sheet .pane { width: 100%; max-height: 82vh; overflow: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 8px 0 calc(var(--bottom) + 16px); animation: up .22s cubic-bezier(.2,.8,.2,1); }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
#sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 4px auto 6px; }
#sheet .kv { padding: 10px 14px; position: relative; } #sheet .kv + .kv::before { content: ""; position: absolute; inset-inline: 14px 0; top: 0; height: .5px; background: var(--sep); }
#sheet .k { font-size: 12px; color: var(--hint); display: flex; gap: 6px; align-items: center; direction: ltr; } #sheet .k code { font-family: var(--mono); opacity: .8; }
#sheet .v { margin-top: 3px; font-family: var(--mono); font-size: 13px; word-break: break-word; white-space: pre-wrap; direction: auto; unicode-bidi: plaintext; text-align: start; }
#sheet .v.null { color: var(--hint); font-style: italic; }

.empty { text-align: center; color: var(--hint); padding: 46px 24px; }
.empty .ei { width: 64px; height: 64px; border-radius: 22px; margin: 0 auto 12px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--c1, #adb4c0), var(--c2, #7c8494)); } .empty .ei .i { width: 32px; height: 32px; }
.skel { height: 64px; margin: 0 16px 10px; border-radius: var(--radius); background: linear-gradient(90deg, var(--soft), color-mix(in srgb, var(--hint) 24%, transparent), var(--soft)); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }
.err { margin: 24px 16px; padding: 16px; border-radius: var(--radius); background: color-mix(in srgb, var(--danger) 12%, var(--sec)); color: var(--danger); text-align: center; }

#tabs { position: fixed; inset-inline: 0; bottom: 0; display: flex; background: color-mix(in srgb, var(--bar) 88%, transparent); border-top: .5px solid var(--sep); padding: 6px 6px calc(var(--bottom) + 4px); backdrop-filter: saturate(180%) blur(22px); -webkit-backdrop-filter: saturate(180%) blur(22px); z-index: 5; }
#tabs[hidden] { display: none; }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0 3px; color: var(--hint); text-decoration: none; font-size: 10.5px; font-weight: 500; border-radius: 12px; }
#tabs a .i { width: 24px; height: 24px; transition: transform .15s; }
#tabs a.on { color: var(--accent); } #tabs a.on .i { transform: translateY(-1px) scale(1.06); }
#toast { position: fixed; inset-inline: 16px; bottom: calc(var(--bottom) + 80px); background: color-mix(in srgb, var(--text) 90%, transparent); color: var(--bg); padding: 11px 14px; border-radius: 14px; text-align: center; font-size: 14px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s; z-index: 30; }
#toast.show { opacity: 1; transform: none; }
.ltr { direction: ltr; unicode-bidi: embed; }

/* projects */
.row.off { opacity: .5; }
.sh { margin: 6px 16px 10px; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field { margin: 0 16px 14px; } .field label { display: block; font-size: 13px; font-weight: 600; color: var(--sec-head); margin: 0 4px 6px; }
.field input { width: 100%; border: 0; border-radius: 12px; padding: 12px 14px; font-size: 15px; background: var(--sec); color: var(--text); outline: 2px solid transparent; transition: outline-color .15s; box-shadow: var(--shadow); }
.field input:focus { outline-color: color-mix(in srgb, var(--btn) 55%, transparent); } .field input[readonly] { opacity: .7; }
.field small { display: block; margin: 6px 4px 0; font-size: 12px; color: var(--hint); line-height: 1.6; } .field small .i { display: inline-block; vertical-align: -3px; }
.pw { display: flex; gap: 8px; align-items: center; } .pw input { flex: 1; }
.tpl .radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--sep); flex: none; }
.tpl.on .radio { border-color: var(--btn); background: radial-gradient(circle, var(--btn) 45%, transparent 50%); }
pre.src { max-height: none; font-size: 12px; line-height: 1.6; padding: 10px 0; overflow: auto; white-space: pre; word-break: normal; color: var(--text); }
pre.src .ln { display: inline-block; width: 42px; padding-right: 10px; text-align: right; color: var(--hint); opacity: .55; user-select: none; border-right: .5px solid var(--sep); margin-right: 10px; }
.spin { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--soft); border-top-color: var(--btn); margin: 0 auto 12px; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
