:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a9099);
  --link: var(--tg-theme-link-color, #2a7de1);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --ok: #2f9e5b;
  --radius: 14px;
  --tabs-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17191c; --bg2: #0f1113; --section: #1d2024; --text: #eceef1; --hint: #8b929b;
    --link: #5aa2ff; --accent: #3b8cf0;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--link); }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--sep);
}
.brand { font-weight: 700; font-size: 17px; display: flex; gap: 8px; align-items: center; }
.quota { font-size: 12.5px; color: var(--hint); background: var(--bg2); padding: 4px 10px; border-radius: 999px; }

.view { padding: 14px 16px 24px; max-width: 640px; margin: 0 auto; }
h1 { font-size: 21px; line-height: 1.25; margin: 4px 0 6px; }
h2 { font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .04em;
     margin: 22px 4px 8px; }
.muted { color: var(--hint); }
.small { font-size: 13px; }

.card { background: var(--section); border-radius: var(--radius); padding: 14px 16px; }
.card + .card { margin-top: 10px; }
.list { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.item {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 12px 14px;
  background: none; border: 0; border-bottom: 1px solid var(--sep); cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--bg2); }
.item .cover {
  flex: 0 0 40px; height: 54px; border-radius: 6px; display: grid; place-items: center; font-size: 18px;
  color: #fff; font-weight: 700;
}
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .sub { color: var(--hint); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--hint); font-size: 18px; }

.search { display: flex; gap: 8px; }
.results { margin-top: 12px; }
.results > h2:first-child { margin-top: 8px; }
.input, .textarea {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--sep);
  background: var(--section); outline: none;
}
.input:focus, .textarea:focus { border-color: var(--accent); }
.textarea { width: 100%; min-height: 96px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 16px;
  border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-text); font-weight: 600;
  cursor: pointer; min-height: 46px;
}
.btn.block { width: 100%; }
.btn.secondary { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.stack { display: grid; gap: 8px; margin-top: 12px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.fact { background: var(--bg2); border-radius: 10px; padding: 8px 10px; }
.fact b { display: block; font-size: 16px; }
.fact span { font-size: 12px; color: var(--hint); }

.estimate { display: grid; gap: 6px; }
.estimate div { display: flex; justify-content: space-between; gap: 12px; }
.estimate b { font-variant-numeric: tabular-nums; }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
        background: var(--bg2); color: var(--hint); white-space: nowrap; }
.chip.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.chip.done { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.failed, .chip.cancelled { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

.progress { height: 8px; border-radius: 99px; background: var(--bg2); overflow: hidden; margin: 12px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.progress.indeterminate > i { width: 35%; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.notice { background: color-mix(in srgb, var(--accent) 9%, var(--section)); border-radius: var(--radius);
          padding: 12px 14px; font-size: 14px; }
.warn { background: color-mix(in srgb, #f5a524 14%, var(--section)); }
.empty { text-align: center; padding: 36px 16px; color: var(--hint); }
.empty .big { font-size: 40px; margin-bottom: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); }
.file-drop { display: grid; place-items: center; gap: 6px; padding: 26px 12px; border: 1.5px dashed var(--sep);
             border-radius: var(--radius); background: var(--section); text-align: center; cursor: pointer; }
.file-drop input { display: none; }

.skeleton { background: linear-gradient(90deg, var(--bg2), var(--section), var(--bg2)); background-size: 200% 100%;
            animation: shimmer 1.2s infinite; border-radius: 10px; height: 64px; margin-bottom: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg); border-top: 1px solid var(--sep);
}
.tab { display: grid; place-items: center; align-content: center; gap: 2px; background: none; border: 0;
       color: var(--hint); font-size: 11.5px; cursor: pointer; }
.tab span:first-child { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .75; }
.tab[aria-selected="true"] { color: var(--accent); font-weight: 600; }
.tab[aria-selected="true"] span:first-child { filter: none; opacity: 1; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 14px + env(safe-area-inset-bottom));
         background: rgba(20, 22, 25, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
         max-width: calc(100% - 32px); z-index: 20; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
           animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
