/* Parent Mini App CRM workspace visual layer.
   Loaded after feature styles so it can progressively enhance existing markup. */

:root {
    --crm-accent: #6f7cff;
    --crm-accent-strong: #8b5cf6;
    --crm-cyan: #22d3ee;
    --crm-success: #34d399;
    --crm-warning: #fbbf24;
    --crm-danger: #fb7185;
    --crm-surface: rgba(14, 22, 42, 0.66);
    --crm-surface-strong: rgba(20, 30, 56, 0.82);
    --crm-border: rgba(255, 255, 255, 0.13);
    --crm-border-strong: rgba(139, 124, 246, 0.32);
    --crm-shadow: 0 22px 70px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    --crm-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

.crm-workspace,
.bot-settings-workspace,
.mini-shop-dashboard {
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
}

.crm-workspace,
.bot-settings-workspace {
    display: grid;
    gap: 16px;
}

.crm-workspace__hero,
.bot-settings-workspace__hero,
.mini-shop-dashboard__hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    border: 1px solid var(--crm-border-strong);
    border-radius: 28px;
    background:
        radial-gradient(circle at 84% 10%, rgba(34, 211, 238, 0.16), transparent 34%),
        radial-gradient(circle at 14% 0%, rgba(139, 92, 246, 0.28), transparent 42%),
        linear-gradient(145deg, rgba(24, 32, 64, 0.9), rgba(12, 19, 38, 0.76));
    box-shadow: var(--crm-shadow);
    backdrop-filter: blur(28px) saturate(150%);
    -webkit-backdrop-filter: blur(28px) saturate(150%);
}

.crm-workspace__hero::before,
.bot-settings-workspace__hero::before,
.mini-shop-dashboard__hero::before {
    content: '';
    position: absolute;
    inset: -45% -20% auto 42%;
    height: 190px;
    border-radius: 50%;
    background: linear-gradient(110deg, rgba(111, 124, 255, 0.34), rgba(34, 211, 238, 0.04));
    filter: blur(24px);
    transform: rotate(-12deg);
    pointer-events: none;
    z-index: -1;
}

.crm-workspace__hero,
.bot-settings-workspace__hero {
    padding: 22px;
}

.crm-workspace__hero-row,
.bot-settings-workspace__hero-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.crm-workspace__eyebrow,
.bot-settings-workspace__eyebrow,
.mini-shop-dashboard__eyebrow {
    margin: 0 0 6px;
    color: rgba(197, 211, 255, 0.78);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.crm-workspace__title,
.bot-settings-workspace__title,
.mini-shop-dashboard__hero h1 {
    margin: 0;
    font-size: clamp(23px, 5vw, 34px);
    font-weight: 760;
    letter-spacing: -0.035em;
}

.crm-workspace__context,
.bot-settings-workspace__context,
.mini-shop-dashboard__hero > p:last-child {
    margin: 8px 0 0;
    color: var(--color-text-secondary);
    max-width: 620px;
}

.crm-icon-button,
.bot-settings-workspace__back {
    display: inline-grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--crm-border);
    border-radius: 15px;
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: transform 180ms var(--crm-ease), background 180ms ease, border-color 180ms ease;
}

.crm-icon-button:hover,
.bot-settings-workspace__back:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(139, 124, 246, 0.52);
    transform: translateY(-2px);
}

.crm-icon-button:active,
.bot-settings-workspace__back:active {
    transform: translateY(0) scale(0.97);
}

.crm-icon-button svg,
.settings-module__icon svg,
.crm-contact-card__avatar svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.crm-kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 20px;
}

.crm-kpi {
    position: relative;
    overflow: hidden;
    min-height: 94px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 19px;
    background: rgba(255, 255, 255, 0.065);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.crm-kpi::after {
    content: '';
    position: absolute;
    right: -18px;
    bottom: -30px;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.08;
    filter: blur(2px);
}

.crm-kpi--success { color: var(--crm-success); }
.crm-kpi--accent { color: #a78bfa; }
.crm-kpi--cyan { color: var(--crm-cyan); }
.crm-kpi--warning { color: var(--crm-warning); }

.crm-kpi__value {
    display: block;
    color: var(--color-text-primary);
    font-size: 24px;
    font-weight: 780;
    letter-spacing: -0.04em;
}

.crm-kpi__label {
    display: block;
    margin-top: 8px;
    color: var(--color-text-muted);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.25;
}

.crm-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--crm-border);
    border-radius: 22px;
    background: var(--crm-surface);
    box-shadow: var(--crm-shadow);
    backdrop-filter: blur(22px) saturate(135%);
    -webkit-backdrop-filter: blur(22px) saturate(135%);
}

.crm-search {
    position: relative;
    display: flex;
    align-items: center;
}

.crm-search__icon {
    position: absolute;
    left: 15px;
    z-index: 1;
    color: var(--color-text-muted);
    pointer-events: none;
}

.crm-search__input {
    width: 100%;
    min-height: 46px;
    padding: 0 16px 0 44px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    color: var(--color-text-primary);
    background: rgba(255, 255, 255, 0.065);
    outline: none;
    transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.crm-search__input:focus {
    border-color: rgba(111, 124, 255, 0.7);
    background: rgba(255, 255, 255, 0.095);
    box-shadow: 0 0 0 4px rgba(111, 124, 255, 0.12);
}

.crm-segments {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 2px;
    scrollbar-width: none;
}

.crm-segments::-webkit-scrollbar { display: none; }

.crm-segment {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 999px;
    color: var(--color-text-secondary);
    background: transparent;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: color 180ms ease, background 180ms ease, border-color 180ms ease, transform 180ms var(--crm-ease);
}

.crm-segment:hover { transform: translateY(-1px); }
.crm-segment.is-active {
    color: #fff;
    border-color: rgba(139, 124, 246, 0.4);
    background: linear-gradient(135deg, rgba(111, 124, 255, 0.32), rgba(139, 92, 246, 0.24));
    box-shadow: 0 8px 22px rgba(81, 70, 180, 0.18);
}

.crm-contact-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.crm-contact-card {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 13px;
    align-items: center;
    min-height: 108px;
    padding: 16px;
    border: 1px solid var(--crm-border);
    border-radius: 22px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.045)),
        var(--crm-surface);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(22px) saturate(135%);
    -webkit-backdrop-filter: blur(22px) saturate(135%);
    transition: transform 220ms var(--crm-ease), border-color 220ms ease, background 220ms ease;
}

.crm-contact-card:hover {
    transform: translateY(-3px);
    border-color: rgba(139, 124, 246, 0.38);
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.055)),
        var(--crm-surface-strong);
}

.crm-contact-card__avatar {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 17px;
    color: #eef2ff;
    background: linear-gradient(145deg, rgba(111, 124, 255, 0.9), rgba(139, 92, 246, 0.72));
    box-shadow: 0 10px 26px rgba(71, 63, 160, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    font-size: 15px;
    font-weight: 800;
}

.crm-contact-card__main { min-width: 0; }
.crm-contact-card__name {
    overflow: hidden;
    color: var(--color-text-primary);
    font-size: 15px;
    font-weight: 760;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-contact-card__channels {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 10px;
    margin-top: 5px;
    color: var(--color-text-muted);
    font-size: 11px;
}

.crm-contact-card__channel {
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.crm-contact-card__tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 9px;
}

.crm-contact-card__tag {
    padding: 4px 8px;
    border: 1px solid rgba(34, 211, 238, 0.18);
    border-radius: 999px;
    color: rgba(207, 250, 254, 0.88);
    background: rgba(34, 211, 238, 0.08);
    font-size: 10px;
    font-weight: 700;
}

.crm-contact-card__time {
    align-self: start;
    color: var(--color-text-muted);
    font-size: 10px;
    white-space: nowrap;
}

.crm-state {
    display: grid;
    place-items: center;
    min-height: 210px;
    padding: 28px;
    border: 1px dashed rgba(255, 255, 255, 0.16);
    border-radius: 24px;
    color: var(--color-text-secondary);
    text-align: center;
    background: rgba(255, 255, 255, 0.045);
}

.crm-state__orb {
    width: 54px;
    height: 54px;
    margin-bottom: 14px;
    border-radius: 18px;
    background: linear-gradient(145deg, rgba(111, 124, 255, 0.38), rgba(34, 211, 238, 0.18));
    box-shadow: 0 14px 35px rgba(64, 72, 180, 0.2);
}

.crm-state--loading .crm-state__orb {
    animation: crm-orb-pulse 1.4s ease-in-out infinite;
}

/* Bot settings control center */
.bot-settings-workspace__map {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.settings-module {
    position: relative;
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    gap: 13px;
    align-items: center;
    min-height: 92px;
    padding: 15px;
    border: 1px solid var(--crm-border);
    border-radius: 21px;
    color: var(--color-text-primary);
    text-align: left;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.095), rgba(255, 255, 255, 0.045));
    box-shadow: 0 15px 42px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.07);
    cursor: pointer;
    overflow: hidden;
    transition: transform 220ms var(--crm-ease), border-color 220ms ease, background 220ms ease;
}

.settings-module::before {
    content: '';
    position: absolute;
    inset: auto -25px -40px auto;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: var(--module-tone, var(--crm-accent));
    opacity: 0.09;
    filter: blur(3px);
}

.settings-module:hover {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--module-tone, var(--crm-accent)) 46%, transparent);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.055));
}

.settings-module:active { transform: translateY(0) scale(0.985); }
.settings-module--ai { --module-tone: #8b5cf6; }
.settings-module--memory { --module-tone: #22d3ee; }
.settings-module--connections { --module-tone: #34d399; }
.settings-module--requests { --module-tone: #fbbf24; }
.settings-module--broadcasts { --module-tone: #fb7185; grid-column: 1 / -1; }

.settings-module__icon {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 16px;
    color: #fff;
    background: color-mix(in srgb, var(--module-tone, var(--crm-accent)) 30%, rgba(255, 255, 255, 0.05));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.settings-module__label {
    display: block;
    font-size: 14px;
    font-weight: 760;
}

.settings-module__hint {
    display: block;
    margin-top: 4px;
    color: var(--color-text-muted);
    font-size: 11px;
}

.settings-module__arrow {
    color: var(--color-text-muted);
    font-size: 20px;
    transition: transform 180ms var(--crm-ease), color 180ms ease;
}

.settings-module:hover .settings-module__arrow {
    color: #fff;
    transform: translateX(3px);
}

.bot-settings-workspace__connector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 18px;
    color: var(--color-text-muted);
    font-size: 11px;
}

.bot-settings-workspace__connector-line {
    position: relative;
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(139, 124, 246, 0.7), rgba(34, 211, 238, 0.55), transparent);
}

.bot-settings-workspace__connector-line::after {
    content: '';
    position: absolute;
    top: -3px;
    left: 12%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #a78bfa;
    box-shadow: 0 0 14px rgba(167, 139, 250, 0.9);
    animation: crm-connector-flow 3.2s linear infinite;
}

/* Mini Shop hierarchy upgrade */
.mini-shop-dashboard { gap: 14px; }
.mini-shop-dashboard__hero {
    padding: 24px;
    margin-bottom: 14px;
}

.mini-shop-dashboard__grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 12px;
}

.mini-shop-dashboard__widget {
    grid-column: span 6;
    position: relative;
    overflow: hidden;
    border-radius: 23px;
    border-color: var(--crm-border);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.045));
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.07);
    transition: transform 220ms var(--crm-ease), border-color 220ms ease;
}

.mini-shop-dashboard__widget:hover {
    transform: translateY(-3px);
    border-color: rgba(139, 124, 246, 0.34);
}

.mini-shop-dashboard__widget[data-widget='overview'],
.mini-shop-dashboard__widget[data-widget='quick_actions'] {
    grid-column: 1 / -1;
}

.mini-shop-dashboard__widget-header {
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mini-shop-dashboard__state {
    padding: 5px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.mini-shop-dashboard__metrics {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
}

.mini-shop-dashboard__metrics > div {
    min-height: 86px;
    padding: 13px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 17px;
    background: rgba(255, 255, 255, 0.045);
}

.mini-shop-dashboard__metrics span {
    display: block;
    color: var(--color-text-muted);
    font-size: 10px;
    line-height: 1.25;
}

.mini-shop-dashboard__metrics strong {
    display: block;
    margin-top: 8px;
    font-size: 18px;
    letter-spacing: -0.03em;
}

/* Memory/training progressive enhancement */
.mybots-training__nanotraining-card {
    position: relative;
    overflow: hidden;
    border-color: rgba(139, 124, 246, 0.28) !important;
    background:
        radial-gradient(circle at 90% 0%, rgba(34, 211, 238, 0.13), transparent 40%),
        linear-gradient(145deg, rgba(111, 124, 255, 0.14), rgba(255, 255, 255, 0.045)) !important;
}

[data-action='view-category'],
.mybots-training__card-title,
.mybots-training__card-description,
.mybots-training__card-meta,
.mybots-training__card-tags {
    transition: color 180ms ease, transform 220ms var(--crm-ease), border-color 220ms ease;
}

[data-action='view-category'] {
    border-radius: 20px !important;
    border-color: var(--crm-border) !important;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.04)) !important;
}

[data-action='view-category']:hover {
    transform: translateY(-3px);
    border-color: rgba(34, 211, 238, 0.28) !important;
}

.mybots-training__status-chip {
    border-radius: 999px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

.mybots-training__form-control {
    border-radius: 16px !important;
    border-color: rgba(255, 255, 255, 0.13) !important;
    background: rgba(255, 255, 255, 0.065) !important;
}

@keyframes crm-orb-pulse {
    0%, 100% { transform: scale(0.92); opacity: 0.55; }
    50% { transform: scale(1.06); opacity: 1; }
}

@keyframes crm-connector-flow {
    from { left: 6%; }
    to { left: 92%; }
}

.crm-reveal {
    animation: crm-reveal 560ms var(--crm-ease) both;
    animation-delay: calc(var(--crm-index, 0) * 55ms);
}

@keyframes crm-reveal {
    from { opacity: 0; transform: translateY(14px) scale(0.985); filter: blur(5px); }
    to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

@media (max-width: 760px) {
    .crm-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .crm-toolbar { grid-template-columns: 1fr; }
    .crm-contact-list { grid-template-columns: 1fr; }
    .mini-shop-dashboard__widget { grid-column: 1 / -1; }
    .mini-shop-dashboard__metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
    .crm-workspace__hero,
    .bot-settings-workspace__hero,
    .mini-shop-dashboard__hero { border-radius: 24px; }

    .crm-workspace__hero,
    .bot-settings-workspace__hero { padding: 18px; }

    .crm-workspace__hero-row,
    .bot-settings-workspace__hero-row { align-items: center; }
    .crm-workspace__title,
    .bot-settings-workspace__title { font-size: 23px; }
    .crm-kpi { min-height: 86px; padding: 12px; }
    .crm-kpi__value { font-size: 21px; }
    .bot-settings-workspace__map { grid-template-columns: 1fr; }
    .settings-module--broadcasts { grid-column: auto; }
    .crm-contact-card { grid-template-columns: auto minmax(0, 1fr); }
    .crm-contact-card__time { grid-column: 2; justify-self: start; }
    .mini-shop-dashboard__metrics { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .crm-reveal,
    .crm-state--loading .crm-state__orb,
    .bot-settings-workspace__connector-line::after {
        animation: none !important;
    }

    .crm-contact-card,
    .settings-module,
    .mini-shop-dashboard__widget,
    .crm-icon-button,
    .bot-settings-workspace__back {
        transition-duration: 0.01ms !important;
    }
}
