/* WB Profit shell: shared light tokens and accessible layout. */
:root {
    color-scheme: light;
    --wb-canvas: #f6f7fb;
    --wb-surface: #ffffff;
    --wb-surface-muted: #f1f3f7;
    --wb-surface-alt: #eef1f5;
    --wb-text: #182230;
    --wb-muted: #526173;
    --wb-primary: #4338ca;
    --wb-primary-hover: #3730a3;
    --wb-primary-soft: #eef2ff;
    --wb-border: #d7dee8;
    --wb-success: #166534;
    --wb-warning: #92400e;
    --wb-danger: #b91c1c;
    --wb-radius-sm: 8px;
    --wb-radius-md: 12px;
    --wb-shadow: 0 2px 8px rgba(24, 34, 48, .06);
    --wb-sidebar-width: 248px;
    --wb-control-height: 40px;
    --wb-scrollbar-track: #e9edf3;
    --wb-scrollbar-thumb: #8a99ac;
    --wb-scrollbar-thumb-hover: #64748b;
    /* Legacy names keep existing screens on the same token layer. */
    --page-bg: var(--wb-canvas);
    --surface-bg: var(--wb-surface);
    --surface-muted-bg: var(--wb-surface-muted);
    --surface-alt-bg: var(--wb-surface-alt);
    --text-main: var(--wb-text);
    --text-muted: var(--wb-muted);
    --border-color: var(--wb-border);
    --shadow-soft: var(--wb-shadow);
    --button-bg: var(--wb-surface);
    --button-text: var(--wb-text);
    --button-hover-bg: var(--wb-primary-soft);
    --primary-bg: var(--wb-primary);
    --primary-hover-bg: var(--wb-primary-hover);
    --primary-text: #ffffff;
    --success-bg: var(--wb-success);
    --success-hover-bg: #14532d;
    --danger-bg: var(--wb-danger);
    --danger-text: #ffffff;
    --link-hover: var(--wb-primary-hover);
    --table-row-odd: #ffffff;
    --table-row-even: var(--wb-surface-alt);
    --table-row-hover: #e7eafe;
    --status-pending-bg: #fef3c7;
    --status-pending-text: var(--wb-warning);
    --status-running-bg: #e0e7ff;
    --status-running-text: #3730a3;
    --status-success-bg: #dcfce7;
    --status-success-text: var(--wb-success);
    --status-failed-bg: #fee2e2;
    --status-failed-text: var(--wb-danger);
    --code-bg: #f3f4f6;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
    background: var(--wb-canvas);
    color: var(--wb-text);
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    margin: 0;
    background: var(--wb-canvas);
    color: var(--wb-text);
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
}

:where(html, body, .wb-shell, .wb-shell *) {
    scrollbar-color: var(--wb-scrollbar-thumb) var(--wb-scrollbar-track);
    scrollbar-width: thin;
}
:where(html, body, .wb-shell, .wb-shell *)::-webkit-scrollbar { width: 10px; height: 10px; }
:where(html, body, .wb-shell, .wb-shell *)::-webkit-scrollbar-track { background: var(--wb-scrollbar-track); }
:where(html, body, .wb-shell, .wb-shell *)::-webkit-scrollbar-thumb { background: var(--wb-scrollbar-thumb); border-radius: 8px; }
:where(html, body, .wb-shell, .wb-shell *)::-webkit-scrollbar-thumb:hover { background: var(--wb-scrollbar-thumb-hover); }
@media (forced-colors: active) {
    :where(html, body, .wb-shell, .wb-shell *) { scrollbar-color: auto; }
}

body *, body *::before, body *::after { box-sizing: border-box; }
a { color: var(--wb-primary); }
a:hover { color: var(--wb-primary-hover); }

.wb-shell__skip {
    position: fixed;
    z-index: 100;
    top: 8px;
    left: 8px;
    padding: 8px 12px;
    border-radius: var(--wb-radius-sm);
    background: var(--wb-text);
    color: #fff;
    transform: translateY(-160%);
}
.wb-shell__skip:focus { transform: translateY(0); }

.wb-shell { display: grid; grid-template-columns: var(--wb-sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.wb-shell__sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    width: var(--wb-sidebar-width);
    height: 100vh;
    padding: 24px 16px 16px;
    overflow-y: auto;
    background: var(--wb-surface);
    border-right: 1px solid var(--wb-border);
}
.wb-shell__brand { display: flex; flex-direction: column; gap: 2px; padding: 0 8px 24px; }
.wb-shell__brand-link { color: var(--wb-text); font-size: 21px; font-weight: 750; line-height: 1.2; text-decoration: none; }
.wb-shell__brand-caption { color: var(--wb-muted); font-size: 12px; }
.wb-shell__nav { display: flex; flex-direction: column; gap: 4px; }
.wb-shell__menu-close { display: none; }
.wb-shell__nav-label { margin: 0 8px 6px; color: var(--wb-muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.wb-shell__nav-label--secondary { margin-top: 24px; }
.wb-shell__nav-link {
    display: flex;
    min-height: var(--wb-control-height);
    align-items: center;
    padding: 8px 12px;
    border-radius: var(--wb-radius-sm);
    color: var(--wb-text);
    font-weight: 650;
    text-decoration: none;
}
.wb-shell__nav-link:hover { background: var(--wb-primary-soft); color: var(--wb-primary-hover); }
.wb-shell__nav-link.is-active { background: var(--wb-primary-soft); color: var(--wb-primary); box-shadow: inset 3px 0 0 var(--wb-primary); }
.wb-shell__nav-link--secondary { color: var(--wb-muted); font-weight: 550; }

.wb-shell__operator { margin-top: auto; padding-top: 24px; }
.wb-shell__operator summary {
    min-height: var(--wb-control-height);
    padding: 8px;
    border-radius: var(--wb-radius-sm);
    color: var(--wb-muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 650;
}
.wb-shell__operator summary:hover { background: var(--wb-primary-soft); color: var(--wb-primary); }
.wb-shell__operator nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px 8px 20px; }
.wb-shell__operator nav a { min-height: var(--wb-control-height); padding: 8px 0; color: var(--wb-muted); font-size: 13px; }
.wb-shell__bot-stack { display: grid; gap: 8px; padding: 0 8px 8px; }
.wb-shell__bot-group { display: grid; gap: 5px; padding: 8px; border: 1px solid var(--wb-border); border-radius: var(--wb-radius-sm); background: var(--wb-canvas); font-size: 12px; }
.wb-shell__bot-group strong { font-size: 12px; }
.wb-shell__bot-group [data-bot-status] { color: var(--wb-muted); }
.wb-shell__bot-group > div { display: flex; gap: 6px; }
.wb-shell__bot-group button { min-height: var(--wb-control-height); padding: 7px 8px; border: 1px solid var(--wb-border); border-radius: 6px; background: var(--wb-surface); color: var(--wb-text); cursor: pointer; }
.wb-shell__bot-group button:hover { border-color: var(--wb-primary); color: var(--wb-primary); }
.wb-shell__bot-group button.disabled, .wb-shell__bot-group button:disabled { cursor: not-allowed; opacity: .55; }

.wb-shell__main { min-width: 0; }
.wb-shell__topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    display: flex;
    min-height: 64px;
    align-items: center;
    gap: 16px;
    padding: 12px clamp(16px, 3vw, 40px);
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--wb-border);
}
.wb-shell__menu-button { display: none; }
.wb-shell__context { display: flex; min-width: 0; flex-direction: column; gap: 1px; }
.wb-shell__context-label { color: var(--wb-muted); font-size: 12px; }
.wb-shell__context strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wb-shell__profile { display: flex; align-items: center; gap: 12px; margin-left: auto; color: var(--wb-muted); font-size: 14px; }
.wb-shell__profile-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wb-shell__profile a, .wb-shell__logout-form button { min-height: var(--wb-control-height); padding: 7px 8px; }
.wb-shell__logout-form { margin: 0; }
.wb-shell__logout-form button { border: 0; background: transparent; color: var(--wb-primary); cursor: pointer; }
.wb-shell__content { width: 100%; max-width: 1440px; min-height: calc(100vh - 64px); margin: 0 auto; padding: clamp(16px, 3vw, 32px); }

/* Shared controls and table affordances remain usable on old and new screens. */
button, input, select, textarea { font: inherit; }
button, input, select, textarea { min-height: var(--wb-control-height); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid var(--wb-primary); outline-offset: 2px; }
input, select, textarea { max-width: 100%; border: 1px solid var(--wb-muted); border-radius: var(--wb-radius-sm); }
.wb-shell__content .wb-ai-field input, .wb-shell__content .wb-ai-field select, .wb-shell__content .wb-ai-field textarea { border-color: var(--wb-muted); }
.wb-ai-table-wrap, .bi-wrapper, .monitor-limits__table-wrap { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
.wb-ai-table-wrap::after, .bi-wrapper::after, .monitor-limits__table-wrap::after { display: block; padding: 4px 0; color: var(--wb-muted); content: "Таблицу можно прокрутить по горизонтали"; font-size: 12px; }
.wb-ai-table, .wb-ai-guide-table { min-width: 680px; }
.bi-table { min-width: 700px; }
.monitor-limits__table { min-width: 620px; }
.wb-ai-table, .wb-ai-guide-table, .bi-table, .monitor-limits__table { font-variant-numeric: tabular-nums; }
.wb-ai-page, .monitoring-page, .product-category-section { max-width: 1200px; margin-inline: auto; }
.wb-ai-page { width: 100%; }
.wb-ai-context-nav { display: flex; flex-wrap: wrap; gap: 4px 8px; margin: 0 0 8px; padding-bottom: 8px; border-bottom: 1px solid var(--wb-border); }
.wb-ai-context-nav a { display: inline-flex; min-height: var(--wb-control-height); align-items: center; padding: 6px 10px; border-radius: var(--wb-radius-sm); color: var(--wb-muted); text-decoration: none; }
.wb-ai-context-nav a:hover, .wb-ai-context-nav a[aria-current="page"] { background: var(--wb-primary-soft); color: var(--wb-primary); }
.wb-ai-breadcrumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; color: var(--wb-muted); font-size: 13px; }

/* The shell owns the visual rhythm after every child stylesheet. */
.wb-shell__content .wb-ai-page { max-width: 1200px; padding: 0 0 48px; font-family: inherit; }
.wb-shell__content h1, .wb-shell-login__content h1 { font-size: 24px; line-height: 1.25; }
.wb-shell__content h2, .wb-shell-login__content h2 { font-size: 20px; line-height: 1.3; }
.wb-shell__content h3, .wb-shell-login__content h3 { font-size: 16px; line-height: 1.35; }
.wb-shell__content label, .wb-shell__content small, .wb-shell__content th { font-size: 12px; }
.wb-shell__content .wb-ai-heading h1, .wb-shell__content .wb-ai-guide-section h2 { font-size: 24px; }
.wb-shell__content .wb-ai-guide-section h3 { font-size: 16px; }
.wb-shell__content .wb-ai-eyebrow, .wb-shell__content .wb-ai-summary-grid span { font-size: 12px; }
.wb-shell__content .wb-ai-primary, .wb-shell__content .wb-ai-secondary, .wb-shell__content .wb-ai-danger-link { min-height: var(--wb-control-height); align-items: center; }
.wb-shell__content .wb-ai-primary, .wb-shell__content .wb-ai-secondary { display: inline-flex; }
.wb-shell__content .wb-ai-nav, .wb-shell__content .wb-ai-card, .wb-shell__content .wb-ai-panel,
.wb-shell__content .wb-ai-form, .wb-shell__content .wb-ai-guide-section, .wb-shell__content .wb-ai-line,
.wb-shell__content .wb-ai-table-wrap, .wb-shell__content .wb-ai-guide-table-wrap { border-radius: var(--wb-radius-md); box-shadow: var(--wb-shadow); }
.wb-shell__content .wb-ai-field input:focus, .wb-shell__content .wb-ai-field select:focus,
.wb-shell__content .wb-ai-field textarea:focus { border-color: var(--wb-primary); box-shadow: none; outline: 3px solid var(--wb-primary); outline-offset: 2px; }
.wb-shell__content [class*="card"], .wb-shell__content [class*="panel"] { background-image: none; }
.wb-shell__content:focus { outline: 3px solid var(--wb-primary); outline-offset: -3px; }

.wb-shell-login { display: grid; min-height: 100vh; place-items: start center; }
.wb-shell-login__content { width: min(100% - 32px, 560px); margin: 8vh auto 32px; }
.wb-shell-login__content .wb-ai-page { width: 100%; max-width: 560px; padding: 0; font-family: inherit; }
.wb-shell-login__content .wb-ai-form, .wb-shell-login__content .wb-ai-panel { padding: 24px; border: 1px solid var(--wb-border); border-radius: var(--wb-radius-md); background: var(--wb-surface); box-shadow: var(--wb-shadow); }
.wb-shell-login__content .wb-ai-field { margin: 0 0 16px; }
.wb-shell-login__content .wb-ai-field label { display: block; min-height: 20px; margin-bottom: 6px; font-size: 12px; font-weight: 650; }
.wb-shell-login__content .wb-ai-field input, .wb-shell-login__content .wb-ai-field select, .wb-shell-login__content .wb-ai-field textarea { width: 100%; padding: 8px 10px; }
.wb-shell-login__content .wb-ai-primary { display: inline-flex; min-height: var(--wb-control-height); align-items: center; justify-content: center; padding: 8px 16px; border: 1px solid var(--wb-primary); border-radius: var(--wb-radius-sm); background: var(--wb-primary); color: #fff; font: inherit; font-weight: 700; text-decoration: none; }
.wb-shell-login__content .wb-ai-primary:hover { background: var(--wb-primary-hover); color: #fff; }

@media (max-width: 900px) {
    .wb-shell { display: block; }
    .wb-shell__sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; transform: translateX(-105%); transition: transform .18s ease; box-shadow: 8px 0 24px rgba(24, 34, 48, .12); }
    .wb-shell.is-menu-open .wb-shell__sidebar { transform: translateX(0); }
    .wb-shell.is-menu-open::after { position: fixed; z-index: 20; inset: 0; background: rgba(24, 34, 48, .28); content: ""; }
    .wb-shell__menu-close { display: block; align-self: flex-end; min-height: var(--wb-control-height); margin: -8px 0 12px; padding: 7px 10px; border: 1px solid var(--wb-border); border-radius: var(--wb-radius-sm); background: var(--wb-surface); color: var(--wb-text); cursor: pointer; }
    .wb-shell__menu-button { display: inline-flex; min-height: var(--wb-control-height); align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--wb-border); border-radius: var(--wb-radius-sm); background: var(--wb-surface); color: var(--wb-text); cursor: pointer; }
    .wb-shell__topbar { padding-inline: 16px; }
    .wb-shell__content { padding: 20px 16px 28px; }
}

@media (max-width: 520px) {
    .wb-shell__topbar { gap: 10px; }
    .wb-shell__profile-name { display: none; }
    .wb-shell__content { padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

/* Keep intrinsic table/text widths inside the owning panel at small viewports. */
.wb-shell__content .wb-ai-panel, .wb-shell__content .relocation-card { min-width: 0; }
.wb-shell__content .relocation-page { grid-template-columns: minmax(0, 1fr); }
.wb-shell__content .relocation-card { overflow-wrap: anywhere; }
.wb-shell__content .task-table-wrap { max-width: 100%; overflow-x: auto; }
.wb-shell__content .filter-group { flex-wrap: wrap; min-width: 0; max-width: 100%; }
.wb-shell__content .wb-ai-summary-grid,
.wb-shell__content .wb-ai-detail-grid { grid-template-columns: repeat(auto-fit, minmax(min(225px, 100%), 1fr)); }
.wb-shell__content .wb-ai-recipe-header,
.wb-shell__content .wb-ai-line-grid { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.wb-shell__content .wb-ai-mono, .wb-shell__content dd { overflow-wrap: anywhere; }

.wb-shell__content [tabindex]:focus-visible { outline: 3px solid var(--wb-primary); outline-offset: 2px; }

:root[data-theme="dark"] {
    color-scheme: dark;
    --wb-canvas: #111827;
    --wb-surface: #1e293b;
    --wb-surface-muted: #172337;
    --wb-surface-alt: #29364b;
    --wb-text: #e2e8f0;
    --wb-muted: #adbcd0;
    --wb-primary: #a5b4fc;
    --wb-primary-hover: #c7d2fe;
    --wb-primary-soft: #2b355a;
    --wb-border: #405069;
    --wb-success: #86efac;
    --wb-warning: #fcd34d;
    --wb-danger: #fda4af;
    --wb-scrollbar-track: #172337;
    --wb-scrollbar-thumb: #71829a;
    --wb-scrollbar-thumb-hover: #adbcd0;
    --wb-shadow: 0 3px 14px rgba(0, 0, 0, .20);
    --primary-bg: #4f46e5;
    --primary-hover-bg: #4338ca;
    --primary-text: #fff;
    --success-hover-bg: #22c55e;
    --danger-text: #111827;
    --table-row-odd: var(--wb-surface);
    --table-row-even: #243247;
    --table-row-hover: #303c60;
    --status-pending-bg: #413419;
    --status-pending-text: #fcd34d;
    --status-running-bg: #1e3550;
    --status-running-text: #93c5fd;
    --status-success-bg: #173c32;
    --status-success-text: #86efac;
    --status-failed-bg: #48272f;
    --status-failed-text: #fda4af;
    --code-bg: #141e30;
}

/* The header follows the shared surface in either color scheme. */
:root[data-theme="dark"] .wb-shell__topbar { background: var(--wb-surface); }
.wb-shell__topbar .theme-toggle { flex-shrink: 0; }
.wb-shell-login__theme-toggle { position: absolute; top: 16px; right: 16px; z-index: 1; }
:root[data-theme="dark"] .wb-shell-login__content .wb-ai-primary { background: var(--primary-bg); border-color: var(--primary-bg); }
:root[data-theme="dark"] .wb-shell-login__content .wb-ai-primary:hover { background: var(--primary-hover-bg); }
:root[data-theme="dark"] .wb-shell__skip { background: var(--wb-surface-alt); color: var(--wb-text); }
@media (max-width: 520px) {
    .wb-shell__topbar .theme-toggle { padding: 7px 9px; }
    .wb-shell__topbar .theme-toggle__text { display: none; }
}
