/* ========================================
   Support Chaos Monkey — Demo UI
   ======================================== */

:root {
    /* Surface */
    --bg-base:      #0b0e14;
    --bg-surface:   #131720;
    --bg-elevated:  #1a1f2e;
    --bg-hover:     #1f2537;
    --border:       #1e2433;
    --border-light: #2a3144;

    /* Text */
    --text-primary:   #e4e8f1;
    --text-secondary: #7a8299;
    --text-muted:     #4a5168;

    /* Accents */
    --accent:       #00d4aa;
    --accent-dim:   rgba(0, 212, 170, 0.12);
    --accent-glow:  rgba(0, 212, 170, 0.25);
    --danger:       #ff4757;
    --danger-dim:   rgba(255, 71, 87, 0.12);
    --danger-glow:  rgba(255, 71, 87, 0.3);
    --warning:      #ffbe0b;
    --warning-dim:  rgba(255, 190, 11, 0.12);
    --success:      #00d68f;

    /* Tier colors */
    --tier-l1: #3b82f6;
    --tier-l2: #a855f7;
    --tier-l3: #f97316;

    /* Typography */
    --font-ui:   'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

    /* Sizing */
    --sidebar-w: 340px;
    --header-h:  64px;
    --radius:    10px;
    --radius-sm: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-ui);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ---- Header ---- */

header {
    height: var(--header-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon { height: 28px; width: 28px; }

.header-brand h1 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.header-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* System status pill */
.system-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    border-radius: 50px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-mono);
    transition: all 0.3s;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.healthy {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-dot.degraded {
    background: var(--warning);
    box-shadow: 0 0 8px var(--warning);
    animation: pulse-dot 2s infinite;
}

.status-dot.critical {
    background: var(--danger);
    box-shadow: 0 0 8px var(--danger);
    animation: pulse-dot 1s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.status-label {
    color: var(--text-secondary);
}

/* Cart button */
#cart-btn {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-ui);
    font-weight: 600;
    transition: all 0.2s;
}

#cart-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

#cart-count {
    background: var(--accent);
    color: var(--bg-base);
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* ---- Shop Grid (logo + products together) ---- */

.shop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 1rem;
    overflow: visible;
}

/* Products container is transparent to grid — its children become grid items */
.shop-grid .products {
    display: contents;
}

/* Logo cell spans 1 column and 2 rows, sitting among products */
/* ---- Error Banner ---- */

.error-banner {
    position: fixed;
    top: calc(var(--header-h) + 12px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: #fff;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 8px 32px rgba(255, 71, 87, 0.35);
    animation: slide-down 0.3s ease-out;
    max-width: 460px;
}

.error-banner.hidden { display: none; }

@keyframes slide-down {
    from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ---- App Layout ---- */

.app-layout {
    display: flex;
    min-height: calc(100vh - var(--header-h));
}

/* ---- Shop Area ---- */

.shop-area {
    flex: 1;
    min-width: 0;
    padding: 1.25rem 1.5rem 2rem;
}

.filters {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.filters button {
    padding: 0.4rem 1rem;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border-radius: 50px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-ui);
    transition: all 0.2s;
}

.filters button:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.filters button.active {
    background: var(--accent);
    color: var(--bg-base);
    border-color: var(--accent);
    font-weight: 600;
}

/* Product cards (rendered by JS into #products which uses display:contents) */

.card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.card img {
    width: 100%;
    height: 180px;
    object-fit: cover;
}

.card-body {
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-body h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
}

.card-body .desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex: 1;
    margin-bottom: 0.6rem;
    line-height: 1.4;
}

.card-body .price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.25rem;
    font-family: var(--font-mono);
}

.card-body .stock {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

.card-body button {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(0, 212, 170, 0.2);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-ui);
    transition: all 0.2s;
}

.card-body button:hover {
    background: var(--accent);
    color: var(--bg-base);
}

/* ---- Chaos Sidebar ---- */

.chaos-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    padding: 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
    max-height: calc(100vh - var(--header-h));
    position: sticky;
    top: var(--header-h);
}

.chaos-brand {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.chaos-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--danger-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.4rem;
}

.chaos-brand h2 {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.chaos-tagline {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
    font-weight: 500;
}

/* Active count */
.chaos-active-count {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.85rem;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: all 0.3s;
}

.chaos-active-count.has-active {
    background: var(--danger-dim);
    border-color: rgba(255, 71, 87, 0.25);
}

.active-count-number {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-muted);
    line-height: 1;
    transition: color 0.3s;
}

.chaos-active-count.has-active .active-count-number {
    color: var(--danger);
}

.active-count-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Scenario cards */
.chaos-scenarios {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chaos-scenario {
    padding: 0.75rem 0.85rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.25s;
}

.chaos-scenario.active {
    border-color: var(--danger);
    background: var(--danger-dim);
    box-shadow: 0 0 20px rgba(255, 71, 87, 0.08);
}

.scenario-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.3rem;
}

.scenario-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.scenario-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.tier-badge {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tier-l1 { background: rgba(59, 130, 246, 0.15); color: var(--tier-l1); }
.tier-l2 { background: rgba(168, 85, 247, 0.15); color: var(--tier-l2); }
.tier-l3 { background: rgba(249, 115, 22, 0.15); color: var(--tier-l3); }

.scenario-detail {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
    cursor: pointer;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-base);
    border: 1px solid var(--border-light);
    border-radius: 50px;
    transition: all 0.25s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.25s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--danger);
    border-color: var(--danger);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
    background: #fff;
}

/* Reset button */
.chaos-reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.6rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-ui);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: all 0.2s;
}

.chaos-reset-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-dim);
}

/* Footer note */
.chaos-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.chaos-footer p {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ---- Cart Overlay ---- */

.cart-overlay {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 380px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 40px rgba(0,0,0,0.4);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.cart-overlay.open { transform: translateX(0); }

.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.cart-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.cart-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.cart-close:hover { color: var(--text-primary); }

.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}

.cart-item-info { flex: 1; }

.cart-item-info .ci-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.cart-item-info .ci-detail {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.cart-item button {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.2rem 0.4rem;
    transition: opacity 0.2s;
}

.cart-item button:hover { opacity: 0.7; }

.cart-total {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#buy-btn {
    background: var(--accent);
    color: var(--bg-base);
    border: none;
    padding: 0.6rem 1.4rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: var(--font-ui);
    transition: all 0.2s;
}

#buy-btn:hover { filter: brightness(1.1); }
#buy-btn:disabled { background: var(--bg-elevated); color: var(--text-muted); cursor: not-allowed; filter: none; }

.checkout-success {
    text-align: center;
    padding: 2rem 1rem;
}

.checkout-success h3 {
    color: var(--success);
    margin-bottom: 0.8rem;
    font-size: 1.15rem;
}

.checkout-success p {
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.checkout-success strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.cart-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 2.5rem 1rem;
    font-size: 0.9rem;
}

/* ---- Mobile chaos toggle (FAB) ---- */

.chaos-mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 150;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(255, 71, 87, 0.4);
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
    .chaos-sidebar {
        position: fixed;
        top: 0; right: 0; bottom: 0;
        z-index: 250;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        max-height: 100vh;
        border-left: 1px solid var(--border);
        box-shadow: -8px 0 40px rgba(0,0,0,0.5);
    }

    .chaos-sidebar.open { transform: translateX(0); }

    .chaos-mobile-toggle { display: flex; }

    .system-status { display: none; }
}

@media (max-width: 480px) {
    .chaos-sidebar { width: 100%; }
    .cart-overlay { width: 100%; }
    header { padding: 0 1rem; }
    .shop-area { padding: 1rem; }
    .header-subtitle { display: none; }
}
