/* XPRTX — оболочка веб-приложения. Стиль — по мотивам мини-приложения URAL BUILD BOT:
   стеклянные карточки, ячейки как в iOS, оранжевый акцент бренда.
   В Telegram цвета берутся из темы Telegram (--tg-theme-*), в браузере — свои, светлые и тёмные. */

:root {
  --brand: #f08a24;
  --brand-2: #f5a524;
  --ok: #30a46c;
  --warn: #f5a524;
  --r: 16px;
  --r-sm: 12px;
  --side: 232px;

  /* браузер, светлая тема */
  --bg: #f1f1f4;
  --card: #ffffff;
  --text: #111114;
  --hint: #8a8a8e;
  --link: #2a7de1;
  --btn: #2a7de1;
  --btn-text: #ffffff;
  --head: #8a8a8e;
  --danger: #e5484d;
  --glass-a: 74%;
  --glass-b: color-mix(in srgb, #fff 38%, transparent);
  --glass-sh: 0 6px 24px #0000000f, inset 0 1px 0 #ffffff59;
  --blob-o: .38;
  color-scheme: light;
}

/* браузер, тёмная тема: по системе или принудительно (?theme=dark) */
@media (prefers-color-scheme: dark) {
  :root:not(.tg):not([data-theme="light"]) {
    --bg: #0c0c0f; --card: #1c1c21; --text: #f2f2f5; --hint: #8e8e96; --link: #5aa2ff;
    --btn: #3b8cf0; --head: #8e8e96; --danger: #ff6369;
    --glass-a: 70%; --glass-b: color-mix(in srgb, #fff 10%, transparent);
    --glass-sh: 0 6px 24px #00000040, inset 0 1px 0 #ffffff12; --blob-o: .22;
    color-scheme: dark;
  }
}
:root:not(.tg)[data-theme="dark"] {
  --bg: #0c0c0f; --card: #1c1c21; --text: #f2f2f5; --hint: #8e8e96; --link: #5aa2ff;
  --btn: #3b8cf0; --head: #8e8e96; --danger: #ff6369;
  --glass-a: 70%; --glass-b: color-mix(in srgb, #fff 10%, transparent);
  --glass-sh: 0 6px 24px #00000040, inset 0 1px 0 #ffffff12; --blob-o: .22;
  color-scheme: dark;
}

/* внутри Telegram — его тема */
:root.tg {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #fff));
  --text: var(--tg-theme-text-color, #111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2a7de1);
  --btn: var(--tg-theme-button-color, #2a7de1);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --head: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
}
:root.tg.tg-dark { --glass-b: color-mix(in srgb, #fff 10%, transparent);
  --glass-sh: 0 6px 24px #00000040, inset 0 1px 0 #ffffff12; --blob-o: .22; color-scheme: dark; }

:root { --sep: color-mix(in srgb, var(--hint) 22%, transparent);
        --glass: color-mix(in srgb, var(--card) var(--glass-a), transparent); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* фоновые пятна, как в старом боте */
.blobs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.blobs i { position: absolute; border-radius: 50%; filter: blur(46px); opacity: var(--blob-o);
  animation: drift 18s ease-in-out infinite alternate; }
.blobs i:nth-child(1) { width: 260px; height: 260px; left: -60px; top: -40px; background: var(--brand); }
.blobs i:nth-child(2) { width: 300px; height: 300px; right: -90px; top: 120px; background: var(--btn); animation-duration: 22s; }
.blobs i:nth-child(3) { width: 220px; height: 220px; left: 30px; bottom: -60px; background: var(--ok); opacity: calc(var(--blob-o) * .6); animation-duration: 26s; }
@keyframes drift { to { transform: translate(30px, 40px) scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .blobs i, .card { animation: none !important; } }

/* раскладка: телефон — одна колонка; широкое окно — меню слева */
#app { position: relative; z-index: 1; padding: 12px 16px calc(32px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; }
#side { display: none; }
@media (min-width: 900px) {
  body.authed #side { display: flex; flex-direction: column; gap: 2px; position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--side); padding: 18px 12px; z-index: 30; border-right: 1px solid var(--sep);
    background: color-mix(in srgb, var(--card) 55%, transparent);
    -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px); }
  body.authed #app { margin: 0 0 0 var(--side); max-width: none; padding: 28px 40px 60px; }
  body.authed #app > * { max-width: 720px; }
  body.authed .homeonly-phone { display: none; }
}
.logo-line { display: flex; align-items: center; gap: 10px; margin: 2px 8px 18px; }
.mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 800; font-size: 15px; }
.wordmark { font-weight: 800; letter-spacing: .08em; font-size: 17px; }
.side-org { margin: 0 8px 14px; padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer; border: 0;
  text-align: left; background: color-mix(in srgb, var(--hint) 10%, transparent); width: calc(100% - 16px); }
.side-org .t { font-size: 14px; font-weight: 600; }
.side-org .d { font-size: 12px; }
.sdi { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: var(--text);
  font-size: 15px; padding: 9px 10px; border-radius: 11px; cursor: pointer; text-align: left; width: 100%; }
.sdi .i { width: 19px; height: 19px; color: var(--link); }
.sdi:hover { background: color-mix(in srgb, var(--hint) 12%, transparent); }
.sdi.on { background: color-mix(in srgb, var(--btn) 18%, transparent); font-weight: 600; }
.sdi[disabled] { opacity: .45; cursor: default; }
.sdi[disabled]:hover { background: none; }
.side-foot { margin-top: auto; font-size: 11.5px; color: var(--hint); line-height: 1.5; padding: 0 10px; }

/* значки */
.i { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* заголовки */
.top { display: flex; align-items: center; gap: 10px; margin: 6px 2px 4px; min-height: 36px; }
h1 { font-size: 26px; margin: 0; font-weight: 700; letter-spacing: -.3px; }
.sub { color: var(--hint); margin: 4px 4px 18px; font-size: 14px; }
.cap { color: var(--head); font-size: 13px; text-transform: uppercase; letter-spacing: .3px; margin: 22px 16px 6px; }
.back { border: 0; background: color-mix(in srgb, var(--btn) 12%, transparent); color: var(--link); cursor: pointer;
  border-radius: 16px; padding: 6px 12px 6px 8px; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }
.tg .back { display: none; }       /* в Telegram — системная кнопка «Назад» */

/* стекло */
.card, .tile, .field { background: var(--glass); border: 1px solid var(--glass-b); box-shadow: var(--glass-sh);
  -webkit-backdrop-filter: blur(20px) saturate(1.5); backdrop-filter: blur(20px) saturate(1.5); }
.card { border-radius: var(--r); overflow: hidden; animation: cardIn .45s cubic-bezier(.22, .9, .3, 1) both; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } }

/* ячейки */
.cell { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; position: relative;
  width: 100%; border: 0; background: none; text-align: left; }
button.cell { cursor: pointer; }
button.cell:active { background: color-mix(in srgb, var(--hint) 12%, transparent); }
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 60px; right: 0; border-top: 1px solid var(--sep); }
.cell.plain + .cell.plain::before { left: 14px; }
.ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none;
  color: var(--link); background: color-mix(in srgb, var(--btn) 13%, transparent); }
.ico .i { width: 19px; height: 19px; }
.ico.brand { color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); font-weight: 700; font-size: 14px; }
.grow { flex: 1; min-width: 0; }
.t { font-weight: 500; }
.d { color: var(--hint); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--hint); font-size: 20px; line-height: 1; }
.chk { color: var(--link); font-weight: 700; }
.lbl { width: 92px; color: var(--hint); font-size: 14px; flex: none; }

/* плитки разделов */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--r); cursor: pointer;
  text-align: left; min-height: 104px; }
.tile .ico { width: 40px; height: 40px; border-radius: 12px; }
.tile .t { font-weight: 600; }
.tile[disabled] { cursor: default; opacity: .6; }
.soon { font-size: 11.5px; font-weight: 600; color: var(--hint); }

/* поля ввода */
.form { display: grid; gap: 0; }
.inp { display: flex; align-items: center; gap: 10px; padding: 0 14px; min-height: 50px; position: relative; }
.inp + .inp::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; border-top: 1px solid var(--sep); }
.inp label { width: 92px; flex: none; color: var(--hint); font-size: 14px; }
.inp input, .inp select { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 14px 0;
  font-size: 16px; -webkit-appearance: none; appearance: none; }
.inp input::placeholder { color: color-mix(in srgb, var(--hint) 75%, transparent); }
.inp input[readonly] { color: var(--hint); }
.inp select { cursor: pointer; }
.note { color: var(--hint); font-size: 13px; margin: 8px 16px 0; line-height: 1.4; }

/* кнопки */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; border: 0;
  border-radius: 14px; background: var(--btn); color: var(--btn-text); font-size: 16px; font-weight: 600; cursor: pointer;
  margin-top: 16px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: color-mix(in srgb, var(--btn) 12%, transparent); color: var(--link); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btns { display: flex; gap: 8px; }
.btns .btn { margin-top: 10px; }
.chip { border: 0; border-radius: 16px; padding: 6px 12px; font-size: 14px; cursor: pointer; display: inline-flex;
  align-items: center; gap: 5px; background: color-mix(in srgb, var(--btn) 12%, transparent); color: var(--link); }
.chip.red { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* статусы */
.pill { font-size: 12.5px; padding: 3px 9px; border-radius: 20px; white-space: nowrap; font-weight: 600; }
.pill.active { color: var(--link); background: color-mix(in srgb, var(--btn) 14%, transparent); }
.pill.accepted { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.pill.expired, .pill.revoked { color: var(--hint); background: color-mix(in srgb, var(--hint) 14%, transparent); }
.pill.locked { color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, transparent); }

.err { background: color-mix(in srgb, var(--danger) 11%, transparent); color: var(--danger); border-radius: 12px;
  padding: 10px 12px; margin: 12px 0 0; font-size: 14px; }
.okbox { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); border-radius: 12px;
  padding: 10px 12px; margin: 12px 0 0; font-size: 14px; }
.empty { color: var(--hint); text-align: center; padding: 30px 12px; font-size: 15px; }
.linkbox { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; padding: 12px 14px;
  color: var(--text); user-select: all; -webkit-user-select: all; }

/* экран входа */
.hero { min-height: calc(100vh - 80px); display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; padding: 24px 8px; }
.hero .mark { width: 84px; height: 84px; border-radius: 24px; font-size: 34px; box-shadow: 0 12px 34px #f08a2459; margin-bottom: 18px; }
.hero h1 { font-size: 28px; }
.hero .sub { max-width: 340px; margin: 8px auto 0; font-size: 15px; line-height: 1.45; }
.hero .card { width: 100%; max-width: 380px; margin-top: 22px; text-align: left; }
.hero .btn { max-width: 380px; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--hint) 30%, transparent);
  border-top-color: var(--brand); animation: rot .8s linear infinite; margin: 24px auto; }
@keyframes rot { to { transform: rotate(360deg); } }

/* всплывающее сообщение */
#toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
.hero-form { width: 100%; max-width: 400px; margin-top: 22px; text-align: left; }
.hero-form .card { max-width: none; margin-top: 0; }
.hero-form .btn, .hero .hero-form .btn { max-width: none; }
.cell.inv { align-items: flex-start; }
.cell.inv .ico { margin-top: 2px; }
.cell.inv .chip { align-self: center; flex: none; }
.meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.meta .d { font-size: 12.5px; }
.btns { align-items: center; }
