:root {
    --brand: #16a6bd;
    --brand-dark: #0a6572;
    --brand-soft: #e6f8fb;
    --ink: #101828;
    --muted: #667085;
    --line: #e4e7ec;
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-2: #fbfcfd;
    --sidebar: #0b1220;
    --sidebar-2: #111b2e;
    --sidebar-text: #aebbd0;
    --sidebar-muted: #5f7088;
    --success: #12b76a;
    --warning: #f79009;
    --danger: #f04438;
    --info: #2e90fa;
    --radius: 14px;
    --shadow: 0 8px 30px rgba(16, 24, 40, .06);
}

html[data-theme="dark"] {
    --ink: #e2e8f0;
    --muted: #94a3b8;
    --line: #1f2937;
    --bg: #0b1220;
    --panel: #111827;
    --panel-2: #0f172a;
    --sidebar: #070c16;
    --sidebar-2: #0b1220;
    --sidebar-text: #aebbd0;
    --sidebar-muted: #5f7088;
    --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.admin-body { overflow: hidden; }
body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { height: 100vh; overflow: hidden; }
.sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: 248px;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 22px 14px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 30;
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 10px; }
.brand img { width: 38px; height: 38px; border-radius: 11px; }
.brand strong { color: #fff; font-size: 16px; letter-spacing: .2px; }
.brand small { display: block; color: var(--sidebar-muted); font-size: 11px; margin-top: 2px; }
.nav-group { display: grid; gap: 4px; }
.nav-label {
    color: var(--sidebar-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    padding: 0 12px 7px;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 42px;
    padding: 0 12px;
    border-radius: 10px;
    color: var(--sidebar-text);
    cursor: pointer;
    font-weight: 500;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active {
    background: linear-gradient(90deg, rgba(22, 166, 189, .24), rgba(22, 166, 189, .07));
    color: #fff;
    box-shadow: inset 2px 0 0 var(--brand);
}
.nav-icon { width: 18px; text-align: center; opacity: .9; }
.nav-badge { margin-left: auto; background: rgba(255,255,255,.1); color: #dbeafe; border-radius: 20px; padding: 1px 7px; font-size: 11px; }
.sidebar-bottom { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; }
.user-mini { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #16a6bd, #0a6572); display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; flex: 0 0 auto; }
.user-mini small { display: block; color: var(--sidebar-muted); font-size: 11px; }

.main { height: 100vh; width: calc(100% - 248px); overflow-y: auto; overflow-x: hidden; margin-left: 248px; min-width: 0; }
.topbar {
    min-height: 72px;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    border-bottom: 2px solid color-mix(in srgb, var(--brand) 28%, transparent);
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.menu-btn { display: none; }
.tenant-switch { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 11px; }
.tenant-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); }
.topbar-search { flex: 1; max-width: 560px; display: flex; align-items: center; gap: 9px; background: var(--bg); border: 1px solid transparent; border-radius: 10px; padding: 9px 12px; color: var(--muted); }
.topbar-search:focus-within { background: var(--panel); border-color: #b9e7ef; box-shadow: 0 0 0 4px rgba(22,166,189,.08); }
.topbar-search input { border: 0; outline: 0; background: transparent; width: 100%; color: var(--ink); }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.sync-state { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(18,183,106,.12); }
.icon-btn { border: 1px solid var(--line); background: var(--panel); color: var(--muted); height: 38px; min-width: 38px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { color: var(--ink); border-color: #cfd6e0; }
.page { width: 100%; padding: 26px 28px 34px; max-width: 1600px; margin: 0 auto; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
h1 { margin: 0; font-size: 28px; letter-spacing: -.4px; }
.subtitle { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 38px; padding: 0 14px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--panel); color: var(--ink);
    cursor: pointer; white-space: nowrap; font-weight: 600; font-size: 13px;
}
.btn:hover { border-color: #cfd6e0; background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1197ad; }
.btn.soft { background: var(--brand-soft); border-color: #c6eef5; color: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #fecdca; background: var(--panel); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--brand); border-radius: var(--radius); padding: 16px 17px; box-shadow: var(--shadow); }
.stat-card .label { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 8px; }
.stat-card .value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 7px; }
.stat-card .hint { color: var(--muted); font-size: 11px; margin-top: 4px; }
.stat-card.amber .value { color: #b54708; }
.stat-card.blue .value { color: #175cd3; }
.stat-card.green .value { color: #027a48; }
.stat-card.red .value { color: #b42318; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 15px; }
.panel-body { padding: 16px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); color: var(--muted); padding: 7px 11px; border-radius: 999px; cursor: pointer; font-size: 12px; }
.chip.active { background: var(--brand-soft); border-color: #b9e7ef; color: var(--brand-dark); font-weight: 700; }
.chip .count { opacity: .7; margin-left: 4px; }
.toolbar .spacer { flex: 1; }
.filter-select, .form-control { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 8px 10px; color: var(--ink); font-size: 13px; outline: none; }
.form-control:focus { border-color: #b9e7ef; box-shadow: 0 0 0 3px rgba(22,166,189,.08); }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 12px 14px; background: var(--panel-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 13px 14px; border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent); vertical-align: middle; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--brand) 4%, var(--panel)); }
.data-table tbody tr.selected { background: color-mix(in srgb, var(--brand) 9%, var(--panel)); box-shadow: inset 3px 0 0 var(--brand); }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.cell-main { font-weight: 600; }
.cell-sub { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-badge:before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-badge.amber { background: #fffaeb; color: #b54708; }
.status-badge.blue { background: #eff8ff; color: #175cd3; }
.status-badge.green { background: #ecfdf3; color: #027a48; }
.status-badge.red { background: #fef3f2; color: #b42318; }
.status-badge.gray { background: #f2f4f7; color: #475467; }
html[data-theme="dark"] .status-badge.amber { background: rgba(247,144,9,.14); color: #fdb022; }
html[data-theme="dark"] .status-badge.blue { background: rgba(46,144,250,.14); color: #84caff; }
html[data-theme="dark"] .status-badge.green { background: rgba(18,183,106,.14); color: #75e0a7; }
html[data-theme="dark"] .status-badge.red { background: rgba(240,68,56,.14); color: #fda29b; }
html[data-theme="dark"] .status-badge.gray { background: rgba(148,163,184,.14); color: #cbd5e1; }
.money { font-weight: 700; font-variant-numeric: tabular-nums; }
.pagination { display: flex; gap: 4px; align-items: center; }
.pagination a, .pagination span { min-width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; font-size: 12px; padding: 0 6px; }
.pagination .current { background: var(--brand-soft); border-color: #b9e7ef; color: var(--brand-dark); font-weight: 700; }
.table-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }

.orders-layout { display: grid; grid-template-columns: minmax(0, 1fr) 430px; gap: 22px; align-items: start; }
.order-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; position: sticky; top: 96px; }
.order-head { padding: 18px; border-bottom: 1px solid var(--line); }
.eyebrow { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.order-head h2 { margin: 5px 0 8px; font-size: 20px; letter-spacing: -.3px; }
.order-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 13px; }
.order-body { padding: 16px 18px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.info .k { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.info .v { font-weight: 600; font-size: 13px; word-break: break-word; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.alert { display: flex; gap: 10px; align-items: flex-start; background: #fffaeb; border: 1px solid #fedf89; color: #93370d; border-radius: 10px; padding: 11px 12px; font-size: 12px; line-height: 1.45; margin-bottom: 14px; }
.alert strong { display: block; margin-bottom: 2px; }
html[data-theme="dark"] .alert { background: rgba(247,144,9,.12); border-color: rgba(247,144,9,.3); color: #fdb022; }
.items-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; }
.items-title h3 { margin: 0; font-size: 13px; }
.items-title span { color: var(--muted); font-size: 11px; }
.item-card { border: 1px solid var(--line); border-radius: 11px; padding: 11px; margin-bottom: 9px; background: var(--panel); }
.item-top { display: flex; gap: 10px; align-items: flex-start; }
.item-sku { width: 34px; height: 34px; border-radius: 9px; background: var(--bg); display: grid; place-items: center; color: var(--muted); font-size: 11px; font-weight: 700; flex: 0 0 auto; }
.item-name { font-weight: 600; line-height: 1.35; font-size: 12px; }
.item-meta { color: var(--muted); font-size: 11px; margin-top: 3px; }
.code-form { display: flex; gap: 7px; margin-top: 9px; }
.code-form input { flex: 1; min-width: 0; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 0 9px; outline: 0; font-size: 12px; background: var(--panel); color: var(--ink); }
.code-form input:focus { border-color: #b9e7ef; box-shadow: 0 0 0 3px rgba(22,166,189,.08); }
.timeline { display: grid; gap: 12px; }
.event { display: grid; grid-template-columns: 16px 1fr; gap: 9px; }
.event .pin { width: 9px; height: 9px; border-radius: 50%; background: #d0d5dd; margin-top: 4px; }
.event.done .pin { background: var(--success); }
.event.active .pin { background: var(--brand); box-shadow: 0 0 0 4px rgba(22,166,189,.12); }
.event .t { font-size: 12px; font-weight: 600; }
.event .d { font-size: 11px; color: var(--muted); margin-top: 2px; }

.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; }
.flash { margin-bottom: 16px; padding: 11px 13px; border-radius: 10px; background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; font-size: 13px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: 420px; padding: 12px 15px; border-radius: 11px; background: #111827; color: #fff; box-shadow: 0 16px 40px rgba(0,0,0,.25); font-size: 13px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #7a271a; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55); z-index: 25; }
.overlay.show { display: block; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 20%, rgba(22,166,189,.14), transparent 34rem), radial-gradient(circle at 85% 80%, rgba(10,101,114,.1), transparent 30rem), var(--bg); }
.login-card { width: min(100%, 460px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 20px 60px rgba(16,24,40,.1); padding: 32px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-brand img { width: 44px; height: 44px; border-radius: 12px; }
.login-brand strong { font-size: 18px; }
.login-brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.login-card h1 { font-size: 24px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
.form-group { display: grid; align-content: start; gap: 6px; margin-bottom: 14px; }
.form-group label { font-weight: 600; font-size: 12px; line-height: 16px; }
.form-group input:not([type="checkbox"]):not([type="radio"]) { height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--panel); color: var(--ink); outline: 0; }
.form-group input:not([type="checkbox"]):not([type="radio"]):focus { border-color: #b9e7ef; box-shadow: 0 0 0 3px rgba(22,166,189,.08); }
.form-group input[type="checkbox"],
.form-group input[type="radio"] {
    width: 16px;
    height: 16px;
    min-width: 16px;
    max-width: 16px;
    padding: 0;
    margin: 0;
    flex: 0 0 16px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    accent-color: var(--brand);
}
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.form-error { color: var(--danger); font-size: 12px; margin-top: 4px; }
.login-card .btn { width: 100%; height: 44px; margin-top: 8px; }
.login-foot { margin-top: 18px; text-align: center; color: var(--muted); font-size: 11px; }

@media (max-width: 1180px) {
    .orders-layout { grid-template-columns: 1fr; }
    .order-panel { position: static; }
}
@media (max-width: 1023px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    .sidebar.is-open { transform: translateX(0); }
    .main { width: 100%; margin-left: 0; }
    .menu-btn { display: inline-flex; }
    .topbar { padding: 0 16px; }
    .page { padding: 18px 16px 28px; }
    .stats { grid-template-columns: 1fr 1fr; }
    .tenant-switch { display: none; }
}
@media (max-width: 620px) {
    .stats { grid-template-columns: 1fr; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .sync-state { display: none; }
    .topbar-search { display: none; }
    .order-body { padding: 14px; }
}

body[data-order-card-mode="page"] .orders-layout {
    grid-template-columns: 1fr;
}

body[data-order-card-mode="page"] .orders-layout .order-panel {
    display: none;
}

@media (max-width: 1179px) {
    body[data-order-card-mode="auto"] .orders-layout {
        grid-template-columns: 1fr;
    }

    body[data-order-card-mode="auto"] .orders-layout .order-panel {
        display: none;
    }
}

.market-tabs {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 0 6px;
    margin: -4px 0 18px;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}
.market-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: 10px 10px 0 0;
    color: var(--muted);
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
}
.market-tab:hover { background: var(--panel-2); color: var(--ink); }
.market-tab.active {
    background: var(--panel);
    border-color: var(--line);
    color: var(--ink);
    box-shadow: inset 0 2px 0 var(--brand);
}
.market-icon {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
}
.market-icon.all { background: #667085; }
.market-icon.ozon { background: #005BFF; }
.market-icon.wb { background: linear-gradient(135deg, #7B1FA2, #CB11AB); }
.market-icon.ym { background: #FFCC00; color: #111827; }
.market-icon.czn { background: #00A651; }

.assembly-summary {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--panel-2);
}
.assembly-summary-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 12px;
}
.assembly-summary-head strong { color: var(--ink); font-size: 14px; }
.progress-track {
    height: 8px;
    margin-top: 9px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
}
.progress-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--brand), var(--brand-dark));
    transition: width .25s ease;
}
.assembly-summary-hint { margin-top: 6px; color: var(--muted); font-size: 11px; }

/* CRPT token status */
@keyframes crpt-token-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, .55); }
    50% { box-shadow: 0 0 0 8px rgba(220, 53, 69, 0); }
}
.crpt-token-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: 0 0 10px;
    background: #98a2b3;
    box-shadow: 0 0 0 4px rgba(152, 162, 179, .12);
}
.crpt-token-dot.ok { background: var(--success); box-shadow: 0 0 0 4px rgba(18, 183, 106, .12); }
.crpt-token-dot.warn { background: var(--warning); box-shadow: 0 0 0 4px rgba(247, 144, 9, .14); }
.crpt-token-dot.danger { background: var(--danger); box-shadow: 0 0 0 4px rgba(240, 68, 56, .14); }
.crpt-token-refresh.is-pulsing {
    background: #dc3545;
    border-color: #dc3545;
    color: #fff;
    animation: crpt-token-pulse 1.5s ease-in-out infinite;
}
.crpt-token-refresh.is-pulsing:hover {
    background: #b42318;
    border-color: #b42318;
}

[data-crpt-plugin-panel] [data-crpt-plugin-dot] {
    margin-top: 4px;
}

.inline-result {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 12px;
    line-height: 20px;
}
.panel-head > .inline-result {
    margin-right: 0;
    max-width: 100%;
}
.inline-result.is-ok {
    color: #027a48;
    background: #ecfdf3;
    border-color: #abefc6;
}
.inline-result.is-error {
    color: #b42318;
    background: #fef3f2;
    border-color: #fecdca;
}
.panel,
.panel-body,
.form-group { min-width: 0; max-width: 100%; }
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea { width: 100%; min-width: 0; max-width: 100%; }
.item-meta { overflow-wrap: anywhere; }

.tenant-switch select {
    max-width: 190px;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
