/**
 * SmartStock Design System (Alipay Blue Edition)
 * Inspired by Ant Design Mobile (WeChat)
 */

:root {
    /* Primary Colors (Alipay Blue) */
    --primary: #1677FF;
    --primary-light: #E6F4FF;
    --primary-hover: #1677FF;
    --primary-active: #0050B3;

    /* Semantic Colors */
    --success: #52C41A;
    --warning: #FAAD14;
    --error: #FF4D4F;
    --info: #1677FF;

    /* Backgrounds */
    --bg-page: #F5F7FA;
    --bg-card: #FFFFFF;
    --bg-mask: rgba(0, 0, 0, 0.45);

    /* Text Colors */
    --text-primary: rgba(0, 0, 0, 0.88);
    --text-secondary: rgba(0, 0, 0, 0.45);
    --text-disabled: rgba(0, 0, 0, 0.25);
    --text-reverse: #FFFFFF;

    /* Shadows */
    --shadow-card: 0 4px 12px 0 rgba(0, 5, 20, 0.05);
    --shadow-float: 0 8px 24px -6px rgba(0, 0, 0, 0.16);

    /* Radius */
    --radius-s: 4px;
    --radius-m: 8px;
    --radius-l: 12px;
    --radius-xl: 16px;

    /* Spacing */
    --space-xs: 4px;
    --space-s: 8px;
    --space-m: 12px;
    --space-l: 16px;
    --space-xl: 24px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-page);
    line-height: 1.5;
    font-size: 14px;
}

/* --- Layout Components --- */

.page-container {
    max-width: 500px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 80px;
    /* Tabbar margin */
}

.section-header {
    padding: var(--space-l);
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.user-info {
    display: flex;
    align-items: center;
}

.user-name {
    color: var(--text-secondary);
    font-size: 13px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin-left: 8px;
    background-color: #f0f0f0;
}

/* --- Card System (Alipay Style) --- */

.card {
    background: var(--bg-card);
    border-radius: var(--radius-l);
    margin: var(--space-m);
    padding: var(--space-l);
    box-shadow: var(--shadow-card);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:active {
    transform: scale(0.98);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-m);
}

.card-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    border-left: 4px solid var(--primary);
    padding-left: var(--space-s);
}

.card-content {
    color: var(--text-primary);
}

/* --- Dashboard Widgets --- */

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-m);
}

.stat-item {
    padding: var(--space-m);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-value.currency::before {
    content: '￥';
    font-size: 14px;
    margin-right: 2px;
}

.stat-trend {
    font-size: 11px;
    margin-top: 4px;
}

.trend-up {
    color: var(--success);
}

.trend-down {
    color: var(--error);
}

/* --- Financial Risk Indicators (Story 6.4) --- */

.risk-alert {
    background: #FFF2F0;
    border: 1px solid #FFCCC7;
    border-radius: var(--radius-m);
    padding: var(--space-m);
    margin: var(--space-m);
    display: flex;
    align-items: flex-start;
    gap: var(--space-s);
}

.risk-icon {
    color: var(--error);
    margin-top: 2px;
}

.risk-text {
    color: #A8071A;
    font-weight: 500;
}

/* --- Breathing Red Alert (v2.0) --- */
.heart-card-breathing {
    animation: breathing-glow 2s infinite ease-in-out;
    border: 1.5px solid rgba(255, 77, 79, 0.2);
    transition: all 0.3s;
}

@keyframes breathing-glow {
    0% {
        box-shadow: 0 0 5px rgba(255, 77, 79, 0.1);
        border-color: rgba(255, 77, 79, 0.2);
    }

    50% {
        box-shadow: 0 0 25px rgba(255, 77, 79, 0.6);
        border-color: var(--error);
    }

    100% {
        box-shadow: 0 0 5px rgba(255, 77, 79, 0.1);
        border-color: rgba(255, 77, 79, 0.2);
    }
}

/* --- Supply Chain Funnel (Horizontal) --- */

.funnel-container {
    display: flex;
    justify-content: space-between;
    padding: var(--space-m) 0;
    position: relative;
}

.funnel-step {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
}

.funnel-step::after {
    content: '';
    position: absolute;
    right: -15%;
    top: 25%;
    width: 30%;
    height: 1px;
    background: #E8E8E8;
}

.funnel-step:last-child::after {
    display: none;
}

.funnel-count {
    font-size: 18px;
    font-weight: 600;
    color: var(--primary);
}

.funnel-label {
    font-size: 11px;
    color: var(--text-secondary);
}

.funnel-step.active-filter {
    background: var(--primary-light);
    border-radius: var(--radius-m);
    box-shadow: inset 0 0 0 1px var(--primary);
    transform: translateY(-2px);
    transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.funnel-step.active-filter::after {
    background: var(--primary);
}

/* --- Navigation Tabbar --- */

.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.02);
    z-index: 1000;
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-secondary);
    font-size: 10px;
    text-decoration: none;
    transition: color 0.1s linear;
}

.tab-item.active {
    color: var(--primary);
}

.tab-icon {
    font-size: 20px;
    margin-bottom: 2px;
}

/* --- Utilities --- */

/* --- Forms & Buttons --- */

.form-group {
    margin-bottom: var(--space-l);
}

.label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.input {
    width: 100%;
    height: 44px;
    border: 1px solid #E8E8E8;
    border-radius: var(--radius-m);
    padding: 0 var(--space-m);
    font-size: 16px;
    background: #FAFAFA;
}

.input:focus {
    border-color: var(--primary);
    background: #fff;
    outline: none;
}

/* --- Role-based Factory Care Mode (v2.0) --- */
.role-worker .input-large-font {
    font-size: 48px !important;
    font-weight: 800;
    height: 80px;
    color: var(--primary);
    text-align: center;
}

.role-worker .label-large-font {
    font-size: 20px !important;
    font-weight: 600;
    margin-bottom: var(--space-m);
}

.btn {
    height: 44px;
    border: none;
    border-radius: 22px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-s);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:active {
    background: var(--primary-active);
}

.btn-large {
    height: 54px;
    border-radius: var(--radius-l);
    width: 100%;
}

/* --- Evidence Display --- */

.evidence-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-s);
}

.evidence-image {
    width: 100%;
    aspect-ratio: 4/3;
    border-radius: var(--radius-m);
    object-fit: cover;
    background: #f0f0f0;
}

.timeline {
    border-left: 2px solid var(--primary-light);
    margin-left: var(--space-m);
    padding-left: var(--space-l);
    position: relative;
}

.timeline-item {
    margin-bottom: var(--space-l);
    position: relative;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: calc(-1 * var(--space-l) - 6px);
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid white;
}

/* --- Tabbar Fix --- */
.tabbar {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(56px + env(safe-area-inset-bottom));
}

.page-container {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

@keyframes fadeInCard {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeInCard 0.4s ease-out forwards;
}

/* --- Aging & Risk Management (v2.1) --- */
.aging-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-s);
    margin-top: var(--space-m);
}

.aging-item {
    padding: var(--space-s);
    border-radius: var(--radius-m);
    background: #FAFAFA;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.aging-label {
    font-size: 10px;
    color: var(--text-secondary);
}

.aging-value {
    font-size: 14px;
    font-weight: 600;
}

/* Color Coding based on Risk Tiers */
.color-ok {
    color: var(--success);
}

.color-90 {
    color: #FAAD14;
}

/* Amber - Caution */
.color-180 {
    color: #D46B08;
}

/* Dark Orange - Warning */
.color-1y {
    color: #CF1322;
}

/* Red - Danger */
.color-3y {
    color: #820014;
    background: #FFF1F0;
}

/* Dark Red/Background - Critical */

.consultant-risk-hint {
    border-left: 3px solid var(--error);
    padding-left: 8px;
    margin-top: 8px;
    font-style: italic;
}

/* --- Production Funnel Drilldown (v4.0) --- */
.funnel-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fbff;
    padding: 20px 15px;
    border-radius: 16px;
    border: 1px solid #eef4ff;
    margin: 10px 0;
}

.funnel-stage {
    flex: 1;
    text-align: center;
}

.funnel-val {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.funnel-val.highlight {
    color: var(--primary);
}

.funnel-label {
    font-size: 10px;
    color: var(--text-secondary);
}

.funnel-arrow {
    font-size: 10px;
    color: #cbdcfd;
}

/* --- SaaS Lifecycle & Status UI (v3.1) --- */

/* 1. Trial Countdown Banner */
.trial-banner {
    background: var(--primary-light);
    color: var(--primary-active);
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(22, 119, 255, 0.1);
    animation: slideDown 0.4s ease-out;
}

.trial-tag {
    background: var(--primary);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    margin-right: 8px;
    text-transform: uppercase;
}

/* 2. Glassmorphism Blocker (Locked State) */
.status-blocker-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.blocker-card {
    background: white;
    padding: var(--space-xl);
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    max-width: 400px;
}

.blocker-icon {
    font-size: 48px;
    color: var(--error);
    margin-bottom: var(--space-l);
}

/* 3. Shadow Admin Badge */
.shadow-badge {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background: #722ed1;
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    box-shadow: var(--shadow-float);
    z-index: 1500;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: move;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}