/* ДеМарк - общий вид Mini App: токены, темы и примитивы для главной, магазина, базы знаний и мероприятий.
   Раздел объявляет свой акцент (--accent, --accent-soft, --accent-ink) - это цвета его плитки на главной.
   Тема: светлая по умолчанию, тёмная по теме Telegram (shell.js ставит data-theme) либо по системе. */

:root {
    color-scheme: light;
    --ground: #F1F3F8;
    --card: #FFFFFF;
    --ink: #12151C;
    --ink-2: #4A5265;
    --ink-3: #7B8497;
    --line: #DFE3EC;
    --events: #F0452E;  --events-soft: #FDE9E5;  --events-ink: #FFFFFF;
    --shop: #5B5BE8;    --shop-soft: #EBEBFD;    --shop-ink: #FFFFFF;
    --kb: #0E9F6E;      --kb-soft: #DFF5EC;      --kb-ink: #FFFFFF;
    --ok: #1B7F4B;      --ok-soft: #E2F4EA;
    --wait: #A35B00;    --wait-soft: #FBEFD9;
    --bad: #C8321F;     --bad-soft: #FDE9E5;
    --shadow: 0 18px 40px rgba(18, 21, 28, 0.16);
    --display: "Unbounded", "Golos Text", system-ui, sans-serif;
    --body: "Golos Text", "Segoe UI", system-ui, -apple-system, sans-serif;
    --radius: 16px;
    --radius-sm: 12px;
    /* главная без своего цвета: акцент - чернила */
    --accent: var(--ink);
    --accent-soft: var(--line);
    --accent-ink: var(--ground);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --ground: #0F1116;
        --card: #191C24;
        --ink: #F1F3F8;
        --ink-2: #B3BACB;
        --ink-3: #7F889C;
        --line: #2A2F3B;
        --events: #FF5A43;  --events-soft: #3A1D18;  --events-ink: #14100F;
        --shop: #8C8CFF;    --shop-soft: #22224A;    --shop-ink: #14142E;
        --kb: #3FCB97;      --kb-soft: #12332A;      --kb-ink: #0B1F17;
        --ok: #5BD08F;      --ok-soft: #14301F;
        --wait: #F1B355;    --wait-soft: #33260F;
        --bad: #FF6B57;     --bad-soft: #3A1D18;
        --shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --ground: #0F1116;
    --card: #191C24;
    --ink: #F1F3F8;
    --ink-2: #B3BACB;
    --ink-3: #7F889C;
    --line: #2A2F3B;
    --events: #FF5A43;  --events-soft: #3A1D18;  --events-ink: #14100F;
    --shop: #8C8CFF;    --shop-soft: #22224A;    --shop-ink: #14142E;
    --kb: #3FCB97;      --kb-soft: #12332A;      --kb-ink: #0B1F17;
    --ok: #5BD08F;      --ok-soft: #14301F;
    --wait: #F1B355;    --wait-soft: #33260F;
    --bad: #FF6B57;     --bad-soft: #3A1D18;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

/* База */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--ground); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; min-height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
input, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
[hidden], .hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Страница и шапка */
.page { max-width: 1080px; margin: 0 auto; padding: 24px 16px calc(40px + env(safe-area-inset-bottom)); }
.masthead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 20px; }
.masthead-main { min-width: 0; flex: 1 1 240px; }
.masthead-kicker { display: flex; align-items: center; gap: 10px; min-height: 20px; margin-bottom: 6px; font-size: 12.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.masthead-logo { width: 26px; height: 26px; border-radius: 8px; object-fit: cover; }
.masthead h1 { font-family: var(--display); font-weight: 700; font-size: clamp(26px, 7vw, 40px); line-height: 1.1; letter-spacing: -0.02em; text-wrap: balance; }
.masthead-sub { margin-top: 8px; color: var(--ink-2); max-width: 56ch; }
.hub-back { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); }
.hub-back svg.i { width: 16px; height: 16px; stroke-width: 2.4; }
.balance { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: 36px; padding: 0 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 13.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip:empty { display: none; }

/* Кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 14px; font-weight: 600; font-size: 15px; background: var(--card); border: 1px solid var(--line); transition: filter 150ms, transform 100ms, border-color 150ms; }
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn-quiet { background: var(--ground); }
.btn-sm { min-height: 38px; padding: 0 14px; border-radius: 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; filter: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-grid; place-items: center; background: var(--card); border: 1px solid var(--line); transition: border-color 150ms, transform 100ms; }
.icon-btn:hover { border-color: var(--ink-3); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 0; color: var(--accent); font-weight: 600; font-size: 13.5px; }

/* Переключатель вида / вкладок */
.seg { display: inline-flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); transition: background 150ms, color 150ms; }
.seg button[aria-selected="true"] { background: var(--ink); color: var(--ground); }
.seg-block { display: flex; margin-bottom: 18px; }
.seg-block button { flex: 1; min-width: 0; }

/* Карточки и списки */
.card { position: relative; display: flex; flex-direction: column; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-media { position: relative; aspect-ratio: 16 / 10; background: var(--accent-soft); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-media.no-image { display: grid; place-items: center; color: var(--accent); }
.card-media.no-image svg.i { width: 40px; height: 40px; opacity: 0.6; }
.card-body { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px 16px; flex: 1; }
.card-title { font-weight: 700; font-size: 17px; line-height: 1.25; text-wrap: balance; }
.card-foot { margin-top: auto; padding-top: 6px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 16px; text-align: left; border-top: 1px solid var(--line); transition: background 120ms; }
.row:first-child { border-top: 0; }
.row.is-link { cursor: pointer; }
.row.is-link:hover { background: var(--ground); }
.row-icon { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 20px; line-height: 1; }
.row-icon.ok { background: var(--ok-soft); color: var(--ok); }
.row-icon.wait { background: var(--wait-soft); color: var(--wait); }
.row-icon.bad { background: var(--bad-soft); color: var(--bad); }
.row-body { flex: 1; min-width: 0; line-height: 1.3; }
.row-body b { display: block; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-body small { display: block; margin-top: 2px; font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-aside { flex: none; display: inline-flex; align-items: center; gap: 8px; color: var(--ink-3); }
.amount { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; color: var(--ink); }
.amount.positive { color: var(--ok); }
.amount.negative { color: var(--bad); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--ground); color: var(--ink-2); }
.pill svg.i { width: 14px; height: 14px; stroke-width: 2.4; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.wait { background: var(--wait-soft); color: var(--wait); }
.pill.hot { background: var(--accent-soft); color: var(--accent); }
.pill.on-media { position: absolute; left: 12px; top: 12px; background: var(--card); color: var(--ink); }
.pill.on-media.hot { background: var(--accent); color: var(--accent-ink); }
.avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.person { min-width: 0; line-height: 1.25; }
.person b { display: block; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person small { display: block; font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Поле ввода */
.field { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 8px 0 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); transition: border-color 150ms; }
.field:focus-within { border-color: var(--accent); }
.field > svg.i { color: var(--ink-3); }
.field input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; font-size: 16px; }   /* 16px - iOS не приближает поле */
.field input::placeholder { color: var(--ink-3); }
.field .icon-btn { width: 32px; height: 32px; border-radius: 10px; border: 0; background: var(--ground); }

/* Текст из админки: описания, статьи, информационный блок */
.prose { line-height: 1.65; word-break: break-word; }
.prose p, .prose ul, .prose ol, .prose blockquote, .prose pre, .prose table { margin-bottom: 12px; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-weight: 700; line-height: 1.25; margin: 18px 0 8px; }
.prose h1 { font-size: 20px; }
.prose h2 { font-size: 18px; }
.prose h3, .prose h4 { font-size: 16px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li + li { margin-top: 4px; }
.prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.prose img { border-radius: 12px; }
.prose blockquote { padding-left: 14px; border-left: 3px solid var(--line); color: var(--ink-2); }
.prose pre, .prose code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.prose pre { padding: 12px; border-radius: 12px; background: var(--ground); overflow-x: auto; }
.prose table { display: block; overflow-x: auto; border-collapse: collapse; }
.prose td, .prose th { padding: 6px 10px; border: 1px solid var(--line); text-align: left; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }

/* Шторка (карточка события, товар, статья) */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 18, 0.55); animation: fade 200ms ease-out; }
.sheet-panel { position: relative; width: 100%; max-width: 640px; max-height: 94dvh; overflow-y: auto; background: var(--card); border-radius: 22px 22px 0 0; box-shadow: var(--shadow); animation: rise 240ms cubic-bezier(0.2, 0.8, 0.2, 1); padding-bottom: env(safe-area-inset-bottom); }
.sheet-close { position: absolute; right: 12px; top: 12px; z-index: 2; }
.sheet-media { aspect-ratio: 16 / 9; background: var(--accent-soft); }
.sheet-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet-body { padding: 20px 20px 28px; display: flex; flex-direction: column; gap: 16px; }
.sheet-body h2 { font-family: var(--display); font-weight: 700; font-size: clamp(20px, 5.4vw, 26px); line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance; padding-right: 36px; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding-right: 40px; }
.sheet-head .row-icon { width: 44px; height: 44px; font-size: 22px; }
.sheet-head h2 { padding-right: 0; font-size: 19px; }
.sheet-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.sheet-actions.even { grid-template-columns: 1fr 1fr; }
.sheet-note { font-size: 13px; color: var(--ink-3); margin-top: -6px; }
.sheet-note:empty { display: none; }
.facts { display: flex; flex-direction: column; gap: 8px; }
.facts div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.facts dt { color: var(--ink-2); }
.facts dd { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Состояния */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80; max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 12px; background: var(--ink); color: var(--ground); font-weight: 500; font-size: 14px; box-shadow: var(--shadow); animation: toast-rise 200ms ease-out; }
.toast.error { background: var(--bad); color: #fff; }
.loader { position: fixed; inset: 0; display: grid; place-items: center; background: var(--ground); z-index: 90; }
.loader span, .spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 800ms linear infinite; }
.loader.done { display: none; }
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 16px; color: var(--ink-3); font-size: 14px; }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty-icon { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); color: var(--ink-3); }
.empty-icon svg.i { width: 26px; height: 26px; }
.empty-title { font-family: var(--display); font-weight: 500; font-size: 18px; color: var(--ink); margin-bottom: 6px; }
.empty button { margin-top: 14px; }

/* Вход не из Telegram */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 22px; }
.gate-card h2 { font-family: var(--display); font-weight: 500; font-size: 19px; line-height: 1.2; text-wrap: balance; }
.gate-card p { color: var(--ink-2); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }
@keyframes toast-rise { from { opacity: 0; transform: translate(-50%, 12px); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
    .sheet { align-items: center; padding: 24px; }
    .sheet-panel { border-radius: 22px; max-height: 90dvh; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
