/* 房贷决策助手 H5 - 全局样式 */
/* 严格遵循 PRD v2.0 第13节 UI/UX 设计规范 */

:root {
    --primary: #1A73E8;
    --primary-light: #E8F0FE;
    --primary-dark: #1557B0;
    --success: #34A853;
    --success-light: #E6F4EA;
    --warning: #FBBC04;
    --warning-light: #FEF7E0;
    --warning-orange: #FF6D00;
    --danger: #EA4335;
    --danger-light: #FCE8E6;
    --text-primary: #202124;
    --text-secondary: #5F6368;
    --text-hint: #9AA0A6;
    --bg-page: #F8F9FA;
    --bg-card: #FFFFFF;
    --bg-input: #FFFFFF;
    --border: #E8EAED;
    --border-focus: #1A73E8;

    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;

    --font-xs: 11px;
    --font-sm: 13px;
    --font-md: 14px;
    --font-lg: 16px;
    --font-xl: 18px;
    --font-xxl: 24px;
    --font-hero: 32px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: var(--font-md);
    color: var(--text-primary);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

.app-container {
    width: 100%;
    max-width: 100vw;
    min-height: 100%;
    position: relative;
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

@media (min-width: 769px) {
    .app-container {
        max-width: 480px;
        margin: 0 auto;
        box-shadow: var(--shadow-lg);
    }
}

/* 页面容器 */
.page {
    display: none;
    animation: slideIn 0.25s ease-out;
    padding: var(--space-md);
    padding-top: 0;
}

.page.active {
    display: block;
}

.page-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    background: var(--bg-page);
    margin: 0 calc(-1 * var(--space-md));
    padding: 0 var(--space-md);
    margin-bottom: var(--space-md);
}

.page-header .back-btn {
    position: absolute;
    left: var(--space-md);
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    font-size: var(--font-xl);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-header h1 {
    font-size: var(--font-xl);
    font-weight: 600;
    margin: 0;
}

.page-title {
    user-select: none;
}

/* 首页头部 */
.home-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    margin: 0 calc(-1 * var(--space-md));
    background: var(--bg-page);
    position: sticky;
    top: 0;
    z-index: 50;
}

.home-header .brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.home-header .brand h1 {
    font-size: var(--font-xl);
    font-weight: 600;
    margin: 0;
}

.home-header .status-badge {
    font-size: var(--font-xs);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.status-badge.locked {
    background: var(--warning-light);
    color: var(--warning-orange);
}

.status-badge.unlocked {
    background: var(--success-light);
    color: var(--success);
}

/* 功能分区 */
.section-title {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    font-weight: 600;
    margin: var(--space-lg) 0 var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.section-title:first-child {
    margin-top: var(--space-sm);
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

@media (min-width: 481px) and (max-width: 768px) {
    .feature-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 769px) {
    .feature-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.feature-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    min-height: 88px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
    overflow: hidden;
}

.feature-card:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-sm);
}

.feature-card.locked {
    opacity: 0.85;
}

.feature-card .icon {
    font-size: var(--font-xxl);
    line-height: 1;
}

.feature-card .title {
    font-size: var(--font-md);
    font-weight: 500;
    margin-top: var(--space-sm);
}

.feature-card .subtitle {
    font-size: var(--font-xs);
    color: var(--text-hint);
    margin-top: var(--space-xs);
}

.feature-card .lock-icon {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    font-size: var(--font-sm);
    color: var(--text-hint);
}

.feature-card.free .lock-icon {
    display: none;
}

/* 卡片 */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: var(--font-lg);
    font-weight: 600;
    margin: 0 0 var(--space-md);
}

.result-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--primary);
}

.result-card.success { border-left-color: var(--success); }
.result-card.warning { border-left-color: var(--warning); }
.result-card.danger { border-left-color: var(--danger); }

.result-label {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.result-value {
    font-size: var(--font-hero);
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.result-value.amount-change {
    animation: pulse 0.3s ease;
}

/* 输入 */
.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
    font-weight: 500;
}

input, select {
    width: 100%;
    height: 48px;
    padding: 0 var(--space-md);
    font-size: var(--font-lg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

input::placeholder {
    color: var(--text-hint);
}

.input-row {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.input-row input, .input-row select {
    flex: 1;
}

.input-unit {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* 滑块 */
input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    -webkit-appearance: none;
    border: none;
    padding: 0;
    margin: var(--space-sm) 0;
}

input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    background: var(--primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    -webkit-appearance: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--primary);
    border-radius: var(--radius-full);
    cursor: pointer;
    border: none;
}

.slider-value {
    text-align: center;
    font-size: var(--font-sm);
    color: var(--primary);
    font-weight: 500;
}

/* 单选组 */
.radio-group {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.radio-group label {
    display: flex;
    align-items: center;
    padding: 10px var(--space-md);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-md);
    transition: all 0.2s;
    margin-bottom: 0;
    color: var(--text-primary);
}

.radio-group input {
    width: auto;
    height: auto;
    margin-right: var(--space-sm);
    display: none;
}

.radio-group label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

/* 按钮 */
.btn {
    width: 100%;
    height: 48px;
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-lg);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: #FFFFFF;
}

.btn-primary:active {
    background: var(--primary-dark);
}

.btn-secondary {
    height: 44px;
    background: var(--bg-page);
    color: var(--primary);
    font-size: var(--font-md);
    font-weight: 500;
    border: 1.5px solid var(--primary);
    border-radius: 10px;
}

.btn-secondary:active {
    background: var(--primary-light);
}

.btn-danger {
    height: 44px;
    background: var(--danger-light);
    color: var(--danger);
    font-size: var(--font-md);
    border: 1.5px solid var(--danger);
    border-radius: 10px;
}

.btn-sm {
    height: 32px;
    padding: 0 var(--space-md);
    font-size: var(--font-sm);
    border-radius: 6px;
    width: auto;
}

.btn:disabled, .btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* 锁定遮罩 */
.locked-overlay {
    position: relative;
    overflow: hidden;
}

.locked-overlay::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    border-radius: var(--radius-md);
}

.lock-badge {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #FFFFFF;
    padding: 6px var(--space-md);
    border-radius: 20px;
    font-size: var(--font-sm);
    font-weight: 500;
    z-index: 10;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(26,115,232,0.3);
    cursor: pointer;
    transition: transform 0.15s;
}

.lock-badge:active {
    transform: translateX(-50%) scale(0.95);
}

.locked-text {
    filter: blur(4px);
    user-select: none;
    color: transparent;
}

/* 页面锁定占位 */
.page-locked {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    text-align: center;
    gap: var(--space-md);
}

.page-locked .lock-emoji {
    font-size: 48px;
}

.page-locked h3 {
    margin: 0;
    font-size: var(--font-xl);
}

.page-locked p {
    color: var(--text-secondary);
    margin: 0;
}

/* 风险等级 */
.risk-level {
    transition: background-color 0.3s ease, color 0.3s ease;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-weight: 600;
    display: inline-block;
}

.risk-level.comfortable { background: var(--success-light); color: var(--success); }
.risk-level.normal { background: var(--warning-light); color: #F9A825; }
.risk-level.tight { background: #FFF3E0; color: var(--warning-orange); }
.risk-level.danger { background: var(--danger-light); color: var(--danger); }

/* 进度条 */
.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin: var(--space-sm) 0;
}

.progress-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* 星星 */
.star-rating {
    color: var(--warning);
    font-size: var(--font-xl);
    letter-spacing: 2px;
}

.star-rating .empty {
    color: var(--border);
}

/* 底部导航 */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 769px) {
    .bottom-nav {
        left: 50%;
        transform: translateX(-50%);
        max-width: 480px;
    }
}

.bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 12px;
    font-size: var(--font-xs);
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    flex: 1;
}

.bottom-nav .nav-item.active {
    color: var(--primary);
}

.bottom-nav .nav-item .nav-icon {
    font-size: 20px;
    margin-bottom: 2px;
}

.nav-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    background: var(--danger);
    color: #FFFFFF;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

/* 提示条 */
.tip-box {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    font-size: var(--font-sm);
    margin-bottom: var(--space-md);
}

.tip-box.warning {
    background: var(--warning-light);
    color: #F9A825;
}

.tip-box.danger {
    background: var(--danger-light);
    color: var(--danger);
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
    color: var(--text-hint);
}

.empty-state .emoji {
    font-size: var(--font-xxl);
    margin-bottom: var(--space-sm);
}

/* 表格 */
.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.compare-table th {
    background: var(--bg-page);
    padding: 10px var(--space-sm);
    text-align: center;
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.compare-table td {
    padding: 10px var(--space-sm);
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.compare-table tr:last-child td {
    border-bottom: none;
}

/* AI 聊天气泡 */
.chat-bubble {
    max-width: 80%;
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    font-size: var(--font-md);
    line-height: 1.5;
}

.chat-bubble.user {
    background: var(--primary);
    color: #FFFFFF;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.chat-bubble.ai {
    background: var(--bg-card);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* AI 输入框 */
.chat-input-bar {
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: var(--space-sm) var(--space-md);
    display: flex;
    gap: var(--space-sm);
    z-index: 90;
    padding-bottom: calc(var(--space-sm) + env(safe-area-inset-bottom));
}

@media (min-width: 769px) {
    .chat-input-bar {
        left: 50%;
        transform: translateX(-50%);
        max-width: 480px;
    }
}

.chat-input-bar input {
    flex: 1;
    height: 44px;
}

.chat-input-bar button {
    width: auto;
    height: 44px;
    padding: 0 var(--space-md);
}

/* AI 思考动画 */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: var(--space-md);
    align-items: center;
}

.ai-typing span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: var(--radius-full);
    animation: bounce 1.2s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

/* 动画 */
@keyframes slideIn {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); color: var(--primary); }
    100% { transform: scale(1); }
}

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-8px); }
}

/* 隐藏 */
.hidden {
    display: none !important;
}
