: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;
    --ios-red: #ff3b30;
    --blue: var(--tg-theme-button-color, #007aff);
    --green: #34c759;
    --sep: rgba(120, 120, 128, 0.24);
    --fill: rgba(120, 120, 128, 0.16);
    --radius: 12px;
    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;
}

#denied.welcome {
    display: block;
    font-weight: 400;
    line-height: 1.45;
    padding-top: calc(48px + env(safe-area-inset-top));
}

#denied.welcome a { color: inherit; }

.menu-btn {
    width: 100%;
    text-align: left;
    background: var(--card);
    border: 0;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
}

.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; }

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 15px;
}

.check-row input {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    appearance: auto;
    -webkit-appearance: checkbox;
    accent-color: var(--tg-theme-button-color, #007aff);
}

.list-btn .item-meta { font-size: 13px; }

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.stat {
    background: var(--card);
    border-radius: 12px;
    padding: 12px 14px;
}

.stat span {
    display: block;
    color: var(--hint);
    font-size: 12px;
    margin-bottom: 4px;
}

.stat b { font-weight: 600; }

.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); }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.grid-2 > .menu-btn {
    min-width: 0;
    margin-bottom: 0;
}

.page-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
}

.page-title {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 22px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-icons {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.icon-btn {
    width: 36px;
    height: 36px;
    padding: 6px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    opacity: 0.38;
}

.icon-btn svg {
    display: block;
    width: 100%;
    height: 100%;
}

.icon-btn:active { opacity: 0.7; }

.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;
}

.cart-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.cart-price {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    gap: 6px;
    color: var(--hint);
    font-size: 15px;
    flex-wrap: wrap;
}

.qty-input {
    width: 44px;
    flex: 0 0 44px;
    text-align: center;
    background: var(--bg);
    border: 0;
    border-radius: 8px;
    padding: 6px 4px;
}

.del-btn {
    flex: 0 0 auto;
    width: auto;
    padding: 6px 10px;
    font-size: 13px;
}

.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; }

.order-cancel { margin-top: 16px; }

.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;
}

.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;
}

.large-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: 0.37px;
    line-height: 1.12;
    margin: 4px 0 20px;
}

.ios-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    margin: -8px 0 12px;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
}

.section-head {
    color: var(--hint);
    font-size: 13px;
    line-height: 1.3;
    margin: 20px 0 8px 12px;
    text-transform: uppercase;
}

.section-head:first-child { margin-top: 8px; }

.ios-group {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}

.ios-row,
.ios-list-row,
.ios-cell {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 48px;
    padding: 14px 16px;
    border: none;
    background: var(--card);
    color: var(--text);
    font-size: 17px;
    text-align: left;
    cursor: pointer;
}

.ios-row + .ios-row,
.ios-list-row + .ios-list-row,
.ios-cell + .ios-cell { border-top: 0.5px solid var(--sep); }

.ios-row:active,
.ios-list-row:active { background: var(--fill); }

.ios-icon {
    width: 30px;
    height: 30px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
    margin-top: 2px;
}

.ios-icon svg { width: 17px; height: 17px; fill: currentColor; }
.ios-icon.blue { background: var(--blue); }
.ios-icon.orange { background: #ff9500; }
.ios-icon.purple { background: #af52de; }
.ios-icon.gray { background: #8e8e93; }

.ios-row-label {
    flex: 1;
    font-weight: 400;
    line-height: 1.35;
    word-break: break-word;
}

.ios-row-meta {
    color: var(--hint);
    font-size: 15px;
    flex-shrink: 0;
    margin-left: 8px;
}

.chevron {
    width: 7px;
    height: 7px;
    border-right: 1.8px solid var(--hint);
    border-top: 1.8px solid var(--hint);
    transform: rotate(45deg);
    flex-shrink: 0;
    margin-top: 10px;
}

.list-stack { margin-bottom: 12px; }

.ios-list-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ios-list-title { font-size: 17px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.ios-list-subtitle { font-size: 16px; line-height: 1.35; color: var(--text); word-break: break-word; }
.ios-list-meta { font-size: 15px; line-height: 1.35; color: var(--hint); word-break: break-word; }

.badge {
    align-self: flex-start;
    margin-top: 2px;
    font-size: 15px;
    font-weight: 600;
    color: var(--blue);
    flex-shrink: 0;
    white-space: nowrap;
}

.ios-list-aside {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
    margin-top: 2px;
}

.ios-list-aside .badge { align-self: flex-end; margin-top: 0; }

.ios-list-dates {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
    margin-top: 2px;
    font-size: 12px;
    line-height: 1.25;
    color: var(--hint);
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ios-list-aside .ios-list-dates { margin-top: 0; }

.ios-empty {
    color: var(--hint);
    text-align: center;
    font-size: 16px;
    padding: 48px 16px;
    line-height: 1.4;
}

.ios-cell { cursor: default; }
.ios-cell-stack { flex: 1; min-width: 0; }
.cell-label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; text-transform: uppercase; }
.cell-text { font-size: 17px; line-height: 1.4; word-break: break-word; }
.cell-text.pre { white-space: pre-wrap; }
.assembly-summary { font-size: 15px; line-height: 1.45; }
.assembly-card { margin-bottom: 16px; }
.cell-value { margin-left: auto; color: var(--hint); font-size: 17px; text-align: right; flex-shrink: 0; }

.order-items-group { overflow: hidden; }

.order-item-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
}

.order-item-row + .order-item-row { border-top: 0.5px solid var(--sep); }
.order-item-main { min-width: 0; flex: 1; }
.order-item-title { font-size: 17px; line-height: 1.35; word-break: break-word; }
.order-item-meta { margin-top: 4px; font-size: 15px; line-height: 1.35; color: var(--hint); }
.order-item-badge {
    flex-shrink: 0;
    margin-top: 2px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(52, 199, 89, 0.12);
    color: var(--green);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
}

.status-badge {
    flex-shrink: 0;
    margin-top: 2px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.status-badge-ready { background: rgba(52, 199, 89, 0.12); color: var(--green); }
.status-badge-shipped { background: rgba(0, 122, 255, 0.12); color: var(--blue); }
.status-cell { align-items: center; justify-content: space-between; }
.status-cell .cell-label { margin: 0; }

.history-group { padding: 8px 16px 12px; }
.history-empty { padding: 14px 0; color: var(--hint); font-size: 15px; text-align: center; }
.order-history { position: relative; padding-left: 18px; }
.order-history::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 10px;
    bottom: 10px;
    width: 1px;
    background: linear-gradient(180deg, rgba(120, 120, 128, 0.08), rgba(120, 120, 128, 0.18), rgba(120, 120, 128, 0.08));
}

.order-history .history-event { position: relative; padding: 10px 0 12px; border-bottom: 0; }
.order-history .history-event:last-child { padding-bottom: 4px; }
.order-history .history-event::before {
    content: "";
    position: absolute;
    left: -18px;
    top: 16px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--card);
    border: 2px solid var(--blue);
    box-sizing: border-box;
}

.history-event-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.history-event-author { font-size: 15px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.history-event-time { flex-shrink: 0; font-size: 13px; line-height: 1.3; color: var(--hint); font-variant-numeric: tabular-nums; }
.history-event-text { font-size: 15px; line-height: 1.45; word-break: break-word; }

.item-row { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; background: var(--card); }
.item-row + .item-row { border-top: 0.5px solid var(--sep); }
.item-row-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.item-row-body { flex: 1; min-width: 0; }
.item-title { font-size: 17px; font-weight: 400; line-height: 1.4; word-break: break-word; }
.item-fields { display: flex; gap: 10px; flex-wrap: wrap; }
.item-field-wrap { display: inline-flex; align-items: center; background: var(--fill); border-radius: 8px; padding-right: 10px; }
.item-field { border: none; border-radius: 8px; padding: 8px 8px 8px 12px; font-size: 17px; background: transparent; color: var(--text); width: 88px; outline: none; }
.item-field-qty { width: 52px; }
.item-field-suffix { font-size: 15px; color: var(--hint); }
.item-del { border: none; background: none; color: var(--ios-red); font-size: 15px; padding: 4px 0; cursor: pointer; flex-shrink: 0; }
.row-check { color: var(--blue); font-size: 17px; font-weight: 600; flex-shrink: 0; min-width: 20px; text-align: center; visibility: hidden; }
.row-check.on { visibility: visible; }
.ios-hint { color: var(--hint); font-size: 16px; padding: 16px; line-height: 1.4; }

.qty-row { display: flex; align-items: stretch; padding: 0; }
.qty-btn { flex: 1; border: none; background: var(--card); color: var(--blue); font-size: 24px; padding: 16px 8px; cursor: pointer; }
.qty-btn + .qty-btn { border-left: 0.5px solid var(--sep); }
.qty-value { font-size: 20px; font-weight: 600; color: var(--text); min-width: 80px; }
.qty-btn:active { background: var(--fill); }

.total-bar { padding: 8px 4px 16px; font-size: 17px; font-weight: 600; }
.btn-group { margin-top: 20px; }
.btn-group + .btn-group { margin-top: 10px; }
.ios-btn {
    display: block;
    width: 100%;
    border: none;
    border-radius: var(--radius);
    padding: 16px;
    font-size: 17px;
    background: var(--card);
    color: var(--blue);
    cursor: pointer;
    text-align: center;
}
.ios-btn:active { opacity: 0.55; }
.ios-btn.filled { background: var(--blue); color: #fff; font-weight: 600; }
.ios-btn.destructive { color: var(--ios-red); }
.prompt-title { font-size: 22px; font-weight: 700; line-height: 1.3; margin: 0 0 16px; word-break: break-word; }

.proc-table-wrap { overflow: auto; background: var(--card); border-radius: var(--radius); }
.proc-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.proc-table th, .proc-table td { padding: 10px 8px; text-align: left; vertical-align: top; border-top: 0.5px solid var(--sep); }
.proc-table thead th { border-top: none; font-size: 11px; font-weight: 600; color: var(--hint); text-transform: uppercase; white-space: nowrap; }
.proc-cell-input { width: 100%; min-width: 0; padding: 8px 10px; border: none; border-radius: 8px; background: var(--fill); color: var(--text); font: inherit; font-size: 13px; outline: none; box-sizing: border-box; }
.proc-cell-composition-input { display: block; min-height: 38px; resize: none; overflow: hidden; line-height: 1.35; white-space: pre-wrap; }
.proc-cell-amount { text-align: right; }
.proc-create-btn { width: 100%; padding: 8px; font-size: 13px; white-space: nowrap; }
.proc-actions { white-space: nowrap; text-align: right; }
.proc-icon-btn { border: none; background: transparent; color: var(--blue); padding: 4px; cursor: pointer; line-height: 1; }
.proc-delete-btn { color: var(--ios-red); }
.proc-launch-btn { padding: 6px 10px; font-size: 12px; white-space: nowrap; margin-left: 4px; }
.proc-cell-nowrap { white-space: nowrap; }
.proc-cell-composition { white-space: pre-wrap; line-height: 1.35; word-break: break-word; }
.proc-status-main { font-weight: 600; white-space: nowrap; }
.proc-status-link { border: none; background: transparent; padding: 0; color: var(--blue); font: inherit; font-weight: 600; cursor: pointer; }
.proc-status-people { margin-top: 4px; color: var(--hint); font-size: 12px; line-height: 1.35; }
.proc-cell-muted { color: var(--hint); font-size: 12px; }
.proc-empty { text-align: center; color: var(--hint); padding: 24px 12px !important; }
.proc-archive-sep td { padding-top: 12px !important; padding-bottom: 12px !important; }
.proc-archive-btn { display: block; width: 100%; }
.proc-cell-pickup { padding-left: 6px; padding-right: 6px; font-size: 13px; }
.proc-table th:nth-child(1), .proc-table td:nth-child(1) { width: 14%; }
.proc-table th:nth-child(2), .proc-table td:nth-child(2) { width: 13%; }
.proc-table th:nth-child(3), .proc-table td:nth-child(3) { width: 12%; }
.proc-table th:nth-child(4), .proc-table td:nth-child(4) { width: 28%; }
.proc-table th:nth-child(5), .proc-table td:nth-child(5) { width: 9%; }
.proc-table th:nth-child(6), .proc-table td:nth-child(6) { width: 14%; }
.proc-table th:nth-child(7), .proc-table td:nth-child(7) { width: 12%; }
.proc-icon-btn { vertical-align: middle; }
.note-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    font-size: 16px;
    line-height: 1.45;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}
.input {
    width: 100%;
    padding: 14px 16px;
    font-size: 28px;
    border: none;
    border-radius: var(--radius);
    margin-bottom: 20px;
    background: var(--card);
    color: var(--text);
    outline: none;
}
