:root {
    --bg: var(--tg-theme-bg-color, #f2f2f7);
    --card: var(--tg-theme-secondary-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1c1c1e);
    --hint: var(--tg-theme-hint-color, #8e8e93);
    --red: #d08a8a;
    color-scheme: light dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
    font-size: 17px;
}

button, input, select, textarea {
    font: inherit;
    appearance: none;
    -webkit-appearance: none;
}
input, select, textarea { color: inherit; }

.hidden { display: none !important; }

.screen {
    min-height: 100dvh;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

#loading, #denied {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.menu-btn {
    width: 100%;
    text-align: left;
    background: var(--card);
    border: 0;
    border-radius: 12px;
    padding: 14px 16px;
}

.section-title {
    margin: 8px 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.section-title:not(:first-child) {
    margin-top: 24px;
}

.user-card {
    background: var(--card);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}

.user-card.blocked { opacity: 0.55; }

.user-name { font-weight: 600; }

.user-meta, .agent-name {
    color: var(--hint);
    font-size: 15px;
    margin-top: 2px;
}

.bind-form, .bind-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.bind-form { flex-direction: column; }

.bind-form .bind-row { margin-top: 0; }

.agent-input {
    width: 100%;
    background: var(--bg);
    border: 0;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 16px;
}

.bind-btn, .block-btn {
    flex: 1;
    border: 0;
    border-radius: 10px;
    padding: 10px 12px;
    color: #fff;
    -webkit-text-fill-color: #fff;
}

.bind-btn {
    background: var(--tg-theme-button-color, #007aff);
}

.bind-btn:disabled {
    opacity: 0.55;
}

.block-btn {
    background: var(--red);
}

.card-error {
    color: var(--red);
    font-size: 14px;
    margin-top: 8px;
}

.card-error:empty { display: none; }

.empty { color: var(--hint); }

.menu-btn + .menu-btn { margin-top: 8px; }

.page-title {
    margin: 0 0 12px;
    font-size: 22px;
    font-weight: 700;
}

.list-btn {
    width: 100%;
    text-align: left;
    background: var(--card);
    border: 0;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
}

.item-card {
    background: var(--card);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
}

.item-name { font-weight: 600; }

.item-meta {
    color: var(--hint);
    font-size: 15px;
    margin-top: 4px;
}

.item-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.primary-btn, .danger-btn, .ghost-btn {
    flex: 1;
    border: 0;
    border-radius: 10px;
    padding: 12px;
    color: #fff;
    -webkit-text-fill-color: #fff;
}

.primary-btn {
    background: var(--tg-theme-button-color, #007aff);
}

.danger-btn { background: var(--red); }

.ghost-btn {
    background: var(--bg);
    color: var(--text);
    -webkit-text-fill-color: var(--text);
}

.primary-btn:disabled, .bind-btn:disabled { opacity: 0.55; }

.full { width: 100%; margin-top: 8px; }

.field {
    width: 100%;
    background: var(--card);
    border: 0;
    border-radius: 10px;
    padding: 12px;
    font-size: 16px;
    margin-bottom: 8px;
}

.total {
    font-weight: 700;
    margin: 12px 0;
}

.help-text { white-space: pre-wrap; line-height: 1.45; }
.help-text a { color: inherit; }
.help-text b { display: inline-block; margin: 12px 0 4px; }

.balance {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    font-size: 28px;
    font-weight: 700;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.pct { color: var(--hint); font-size: 14px; }

.proc-card textarea, .proc-card select { margin-bottom: 8px; }

.history-event {
    padding: 8px 0;
    border-bottom: 1px solid var(--bg);
}

.history-event:last-child { border-bottom: 0; }

.param-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--card);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
}

.param-row span { flex: 1; }

.param-input {
    width: 120px;
    text-align: right;
    background: var(--bg);
    border: 0;
    border-radius: 10px;
    padding: 8px 10px;
}

.param-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--card);
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
}

.param-wide {
    width: 100%;
    text-align: left;
    resize: vertical;
    min-height: 84px;
}
