/**
 * App shell V8: цветовые темы — канон совпадает с golden home_v3.html.
 * Ключ localStorage: home-v3-theme (см. /api/app-v8/registry → client_shell_ui_theme).
 */
:root[data-theme="burgundy"] {
    --color-primary: #cc5553;
    --color-primary-light: #df7876;
    --color-secondary: #8e96a3;
    --color-secondary-light: #b5bcc6;
    --color-highlight: #c85a58;
    --color-neutral: #4b5563;
    --color-muted: #9ca3af;
    --color-page: #ffffff;
    --color-frame: #fafafa;
    --color-surface: #ffffff;
    --color-surface-soft: #fafafe;
    --color-border: #e7e7ee;
    --color-border-strong: #ebecef;
    --color-soft-bg: #fff3f3;
    --color-shadow: rgba(0, 0, 0, 0.04);
}
:root[data-theme="green"] {
    --color-primary: #16a34a;
    --color-primary-light: #22c55e;
    --color-secondary: #fbbf24;
    --color-secondary-light: #fde047;
    --color-highlight: #f97316;
    --color-neutral: #475569;
    --color-muted: #94a3b8;
    --color-page: #edf6f0;
    --color-frame: #f4fbf5;
    --color-surface: #ffffff;
    --color-surface-soft: #f7fdf8;
    --color-border: #dbe8de;
    --color-border-strong: #d5e5d8;
    --color-soft-bg: #eefbf1;
    --color-shadow: rgba(22, 163, 74, 0.1);
}
:root[data-theme="red"] {
    --color-primary: #dc2626;
    --color-primary-light: #ef4444;
    --color-secondary: #9ca3af;
    --color-secondary-light: #d1d5db;
    --color-highlight: #fb7185;
    --color-neutral: #4b5563;
    --color-muted: #9ca3af;
    --color-page: #f5f5f5;
    --color-frame: #fbfbfb;
    --color-surface: #ffffff;
    --color-surface-soft: #fcfcfd;
    --color-border: #e5e7eb;
    --color-border-strong: #ececf1;
    --color-soft-bg: #fff1f1;
    --color-shadow: rgba(220, 38, 38, 0.1);
}
:root[data-theme="blue"] {
    --color-primary: #2563eb;
    --color-primary-light: #3b82f6;
    --color-secondary: #fb7185;
    --color-secondary-light: #fda4af;
    --color-highlight: #06b6d4;
    --color-neutral: #475569;
    --color-muted: #94a3b8;
    --color-page: #eff6ff;
    --color-frame: #f8fbff;
    --color-surface: #ffffff;
    --color-surface-soft: #f8fbff;
    --color-border: #dbe8f7;
    --color-border-strong: #d7e3f1;
    --color-soft-bg: #eef4ff;
    --color-shadow: rgba(37, 99, 235, 0.1);
}
:root[data-theme="purple"] {
    --color-primary: #9333ea;
    --color-primary-light: #a855f7;
    --color-secondary: #ec4899;
    --color-secondary-light: #f472b6;
    --color-highlight: #8b5cf6;
    --color-neutral: #5b5563;
    --color-muted: #a59cad;
    --color-page: #f5f0ff;
    --color-frame: #fbf8ff;
    --color-surface: #ffffff;
    --color-surface-soft: #fcfaff;
    --color-border: #ece2fb;
    --color-border-strong: #eadcf9;
    --color-soft-bg: #f6efff;
    --color-shadow: rgba(147, 51, 234, 0.1);
}
:root[data-theme="orange"] {
    --color-primary: #fb923c;
    --color-primary-light: #fdba74;
    --color-secondary: #f472b6;
    --color-secondary-light: #f9a8d4;
    --color-highlight: #fde047;
    --color-neutral: #57534e;
    --color-muted: #a8a29e;
    --color-page: #fff7ed;
    --color-frame: #fffaf3;
    --color-surface: #ffffff;
    --color-surface-soft: #fffdf8;
    --color-border: #f5e7d5;
    --color-border-strong: #f2dfc8;
    --color-soft-bg: #fff3e6;
    --color-shadow: rgba(251, 146, 60, 0.12);
}
:root[data-theme="teal"] {
    --color-primary: #0d9488;
    --color-primary-light: #14b8a6;
    --color-secondary: #f472b6;
    --color-secondary-light: #fb923c;
    --color-highlight: #fbbf24;
    --color-neutral: #475569;
    --color-muted: #94a3b8;
    --color-page: #edfdf9;
    --color-frame: #f6fffc;
    --color-surface: #ffffff;
    --color-surface-soft: #f7fffd;
    --color-border: #d7efe8;
    --color-border-strong: #d0e8e1;
    --color-soft-bg: #eafcf8;
    --color-shadow: rgba(13, 148, 136, 0.1);
}

.theme-trigger {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px var(--color-shadow);
    cursor: pointer;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
    flex-shrink: 0;
}
.theme-trigger:active {
    transform: scale(0.96);
}
.theme-trigger-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 2px solid #fff;
    background: var(--color-highlight);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
}

.theme-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.34);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.24s ease;
    box-sizing: border-box;
}
.theme-modal.active {
    opacity: 1;
    pointer-events: auto;
}
.theme-selector {
    width: min(360px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    border-radius: 30px;
    background: #fff;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.28);
    padding: 24px;
    transform: scale(0.94);
    transition: transform 0.24s ease;
    box-sizing: border-box;
}
.theme-modal.active .theme-selector {
    transform: scale(1);
}

/*
 * Staff phone mockup / scaled shell: keep picker inside the device frame.
 * Root must live inside .staff-device-frame (not under body).
 */
.staff-device-frame > #theme-modal-root {
    position: absolute;
    inset: 0;
    z-index: 220;
    pointer-events: none;
}
.staff-device-frame > #theme-modal-root .theme-modal,
.staff-device-frame .theme-modal {
    position: absolute;
    inset: 0;
    z-index: 220;
    align-items: flex-end;
    justify-content: center;
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}
.staff-device-frame > #theme-modal-root .theme-modal.active {
    pointer-events: auto;
}
.staff-device-frame .theme-selector {
    width: 100%;
    max-width: none;
    max-height: min(78%, calc(100% - 24px));
    border-radius: 22px;
    padding: 16px;
    margin: 0;
}
.staff-device-frame .theme-selector-title {
    font-size: 18px;
    margin-bottom: 2px;
}
.staff-device-frame .theme-selector-sub {
    font-size: 12px;
    margin-bottom: 12px;
}
.staff-device-frame .theme-option {
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 16px;
}
.staff-device-frame .theme-option:hover {
    transform: none;
}
.staff-device-frame .theme-color {
    width: 20px;
    height: 38px;
    border-radius: 10px;
}
.staff-device-frame .theme-close-btn {
    padding: 12px 14px;
    border-radius: 14px;
}

/* shell=content: frame is full viewport — still avoid 100vw bleed */
html.shell-content .staff-device-frame .theme-selector {
    max-height: min(82%, calc(100% - 16px));
}
.theme-option {
    width: 100%;
    border: 2px solid transparent;
    border-radius: 20px;
    background: #fff;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    margin-bottom: 10px;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}
.theme-option:hover {
    transform: translateX(2px);
}
.theme-option.active {
    border-color: var(--color-primary);
    background: color-mix(in srgb, var(--color-soft-bg) 70%, #fff);
}
.theme-color-duo {
    display: flex;
    gap: 4px;
}
.theme-color {
    width: 24px;
    height: 46px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}
.theme-close-btn {
    width: 100%;
    margin-top: 6px;
    padding: 14px 16px;
    border-radius: 18px;
    border: none;
    background: #f3f4f6;
    color: #4b5563;
    font-weight: 700;
    cursor: pointer;
}
.theme-selector-title {
    font-size: 22px;
    font-weight: 900;
    color: #111827;
    margin-bottom: 4px;
}
.theme-selector-sub {
    font-size: 14px;
    color: #6b7280;
    font-weight: 600;
    margin-bottom: 20px;
}
.theme-option-title {
    font-weight: 900;
    color: #111827;
}
.theme-option-text {
    flex: 1;
    text-align: left;
}
.theme-option-sub {
    font-size: 12px;
    color: #6b7280;
    font-weight: 600;
}
.theme-kicker {
    color: var(--color-highlight);
}
.theme-brand {
    color: var(--color-neutral);
}
.theme-brand-accent {
    color: var(--color-primary);
}
.theme-copy-primary {
    color: var(--color-neutral);
}
.theme-copy-muted {
    color: var(--color-muted);
}
.theme-search-icon {
    background: var(--color-soft-bg);
    color: var(--color-primary);
}
.theme-search-tail {
    background: var(--color-surface-soft);
    border-color: var(--color-border-strong);
    color: var(--color-muted);
}
.theme-profile-btn {
    color: var(--color-primary);
    border-color: var(--color-border-strong);
    background: var(--color-surface);
}

/* Применение темы к оболочке app-v8 */
html[data-theme] body {
    transition: background 0.3s ease;
}
html[data-theme] body .shell-viewport {
    background: var(--color-page);
}
html[data-theme] .phone-shell {
    background: var(--color-frame);
    transition: background 0.3s ease;
}
html[data-theme] .shell-content {
    background: var(--color-frame);
    transition: background 0.3s ease;
}
html[data-theme] .shell-home {
    background: var(--color-page);
    transition: background 0.3s ease;
}
html[data-theme] .shell-home-kicker {
    color: var(--color-highlight);
}
html[data-theme] .shell-brand-mark {
    color: var(--color-neutral);
}
html[data-theme] .shell-brand-accent {
    color: var(--color-primary);
}
html[data-theme] .shell-tab.active {
    color: var(--color-primary);
}
html[data-theme] .shell-tabbar {
    border-top-color: var(--color-border);
    background: color-mix(in srgb, var(--color-surface) 96%, transparent);
}
/*
 * Центральный таб «Главная»: цветное кольцо только при .active.
 * Иначе градиент палитры на неактивном табе выглядел как вторая «подсветка»
 * при переключении на Еду/Поиск и т.д.
 */
html[data-theme] .shell-tab--center:not(.active) .shell-tab-center-ring {
    background: linear-gradient(145deg, #e5e7eb, #f3f4f6);
    color: #9ca3af;
    border: 1px solid var(--color-border);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
    opacity: 1;
}
html[data-theme] .shell-tab--center.active .shell-tab-center-ring {
    background: linear-gradient(145deg, var(--color-primary), var(--color-primary-light));
    color: #fff;
    border: 1px solid color-mix(in srgb, var(--color-primary) 28%, transparent);
    box-shadow: 0 8px 22px var(--color-shadow);
    opacity: 1;
}
html[data-theme]:not([data-theme="burgundy"]) .shell-home-icon-btn {
    border-color: var(--color-border);
    color: var(--color-primary);
}
html[data-theme]:not([data-theme="burgundy"]) .shell-segment-icon {
    color: var(--color-primary) !important;
}
html[data-theme]:not([data-theme="burgundy"]) .shell-kpi-card--discount .shell-kpi-label i {
    color: var(--color-primary) !important;
}
html[data-theme]:not([data-theme="burgundy"]) .shell-home-balance-value,
html[data-theme]:not([data-theme="burgundy"]) .shell-kpi-value {
    color: var(--color-primary);
}
