/* FIT 健康管理师 - 聊天界面样式 */

:root {
    --primary-color: #198754;
}

* {
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.app-container {
    max-width: 500px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

/* Status Panel - Compact 5-column grid */
.status-panel {
    background: linear-gradient(135deg, #198754 0%, #20c997 100%);
    color: white;
    padding: 6px 8px;
    display: grid;
    grid-template-columns: repeat(4, 1fr) auto;
    gap: 2px;
    align-items: center;
}

.status-item {
    text-align: center;
}

.status-item.status-location-item {
    justify-self: end;
    padding-right: 2px;
}

.status-value {
    font-size: 1rem;
    font-weight: bold;
}

.status-label {
    font-size: 0.55rem;
    opacity: 0.9;
}

/* Responsive Status Panel */
@media (max-width: 400px) {
    .status-panel {
        grid-template-columns: repeat(4, 1fr);
        padding: 4px 6px;
    }
    .status-item.status-location-item {
        grid-column: 1 / -1;
        justify-self: center;
        padding-right: 0;
    }
    .status-value {
        font-size: 0.9rem;
    }
}

.status-good { color: #90EE90; }
.status-warning { color: #FFD700; }
.status-bad { color: #FF6B6B; }

/* Merged Status Badge */
.status-badge-merged {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.status-badge-merged.home { background: rgba(255,255,255,0.9); color: #155724; }
.status-badge-merged.travel { background: #fff3cd; color: #856404; }
.status-badge-merged.abroad { background: #cce5ff; color: #004085; }
.status-badge-merged.vacation { background: #f8d7da; color: #721c24; }
.status-badge-merged.remote { background: #e2e3e5; color: #383d41; }

/* ============ Tab Navigation Component ============ */
.health-tabs {
    background: #f5f5f5;
}

.tab-nav {
    display: flex;
    background: linear-gradient(135deg, #198754 0%, #20c997 100%);
    padding: 0;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 2px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.6rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.tab-btn i {
    font-size: 0.8rem;
    margin-bottom: 1px;
}

.tab-btn.active {
    color: white;
    background: rgba(255, 255, 255, 0.15);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: white;
    border-radius: 2px 2px 0 0;
}

.tab-btn:hover:not(.active) {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
}

.tab-btn.tab-collapse {
    flex: 0 0 36px;
    background: rgba(0, 0, 0, 0.1);
}

.tab-btn.tab-collapse i {
    transition: transform 0.3s ease;
}

.tab-btn.tab-collapse.collapsed i {
    transform: rotate(180deg);
}

/* Tab Content Wrapper */
.tab-content-wrapper {
    max-height: 280px;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.tab-content-wrapper.collapsed {
    max-height: 0;
}

/* Tab Content Panels */
.tab-content {
    display: none;
    padding: 8px;
    background: white;
}

.tab-content.active {
    display: block;
}

/* ============ Prediction Tab ============ */
.prediction-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.prediction-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 6px;
    padding: 6px 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #e0e0e0;
}

.prediction-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.prediction-card .card-icon {
    font-size: 1rem;
    color: #198754;
    margin-bottom: 2px;
}

.prediction-card .card-value {
    font-size: 0.85rem;
    font-weight: bold;
    color: #333;
}

.prediction-card .card-label {
    font-size: 0.5rem;
    color: #666;
}

.prediction-card .card-badge {
    display: inline-block;
    font-size: 0.45rem;
    padding: 1px 4px;
    border-radius: 6px;
    background: #e9ecef;
    color: #666;
    margin-top: 1px;
}

.prediction-card .card-badge.trend-up {
    background: rgba(25, 135, 84, 0.15);
    color: #198754;
}

.prediction-card .card-badge.trend-down {
    background: rgba(220, 53, 69, 0.15);
    color: #dc3545;
}

.prediction-card.advice-card .advice-text {
    font-size: 0.55rem;
    line-height: 1.2;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    min-height: 20px;
    margin-bottom: 2px;
}

/* Ensure label is visible in advice card */
.prediction-card.advice-card .card-label {
    font-size: 0.5rem;
    color: #666;
    margin-top: 2px;
}

/* Exercise Detail Inline */
.exercise-detail-inline {
    margin-top: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.exercise-detail-inline.collapsed {
    display: none;
}

.exercise-stats-row {
    display: flex;
    justify-content: space-around;
}

.exercise-stats-row .stat-item {
    text-align: center;
    font-size: 0.65rem;
    color: #666;
}

.exercise-stats-row .stat-item span {
    font-size: 0.9rem;
    font-weight: bold;
    color: #198754;
}

/* ============ Indicators Tab ============ */
.indicators-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.indicator-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    padding: 8px 4px;
    text-align: center;
    border: 1px solid #e0e0e0;
}

.indicator-card .indicator-value {
    font-size: 0.9rem;
    font-weight: bold;
    color: #333;
}

.indicator-card .indicator-value.status-good {
    color: #198754;
}

.indicator-card .indicator-value.status-warning {
    color: #ffc107;
}

.indicator-card .indicator-value.status-bad {
    color: #dc3545;
}

.indicator-card .indicator-label {
    font-size: 0.55rem;
    color: #666;
}

/* ============ Trends Tab ============ */
.trends-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.trends-summary-row {
    display: flex;
    gap: 8px;
    font-size: 0.65rem;
    color: #666;
}

.trends-summary-row .summary-item strong {
    color: #333;
}

.trends-summary-row .summary-item strong.trend-good {
    color: #198754;
}

.trends-summary-row .summary-item strong.trend-warning {
    color: #ffc107;
}

.period-toggle {
    display: flex;
    gap: 4px;
}

.period-btn {
    padding: 3px 10px;
    border-radius: 10px;
    border: 1px solid #ddd;
    background: white;
    font-size: 0.65rem;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.period-btn.active {
    background: #198754;
    border-color: #198754;
    color: white;
}

.trends-charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.chart-card {
    background: #f8f9fa;
    border-radius: 6px;
    padding: 6px;
}

.chart-card .chart-label {
    font-size: 0.55rem;
    color: #666;
}

.chart-card .chart-value {
    font-size: 0.8rem;
    font-weight: bold;
    color: #333;
    margin: 2px 0;
}

.chart-card .chart-value.trend-good {
    color: #198754;
}

.chart-card .chart-value.trend-warning {
    color: #ffc107;
}

.chart-card .chart-bars {
    height: 24px;
}

/* Mini bars */
.mini-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 100%;
}

.mini-bar {
    flex: 1;
    min-height: 3px;
    border-radius: 2px;
    background: rgba(25, 135, 84, 0.3);
    transition: height 0.3s ease;
}

.mini-bar.bar-good { background: rgba(25, 135, 84, 0.6); }
.mini-bar.bar-neutral { background: rgba(108, 117, 125, 0.3); }
.mini-bar.bar-warning { background: rgba(255, 193, 7, 0.6); }

.chart-bars .no-data {
    font-size: 0.6rem;
    color: #999;
}

/* Mobile responsive for tabs */
@media (max-width: 400px) {
    .prediction-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 4px;
    }

    .prediction-card {
        padding: 4px 2px;
    }

    .prediction-card .card-icon {
        font-size: 0.85rem;
    }

    .prediction-card .card-value {
        font-size: 0.75rem;
    }

    .prediction-card .card-label {
        font-size: 0.45rem;
    }

    .prediction-card .card-badge {
        font-size: 0.4rem;
        padding: 1px 3px;
    }

    .prediction-card.advice-card .advice-text {
        font-size: 0.45rem;
        min-height: 16px;
        -webkit-line-clamp: 1;
    }

    .trends-header {
        flex-direction: column;
        gap: 6px;
        align-items: flex-start;
    }
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
}

.message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-start;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #e3f2fd;
    margin-left: 10px;
}

.message.assistant .message-avatar {
    background: #e8f5e9;
    margin-right: 10px;
}

.message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.message.user .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-bottom-left-radius: 4px;
}

/* Input Area */
.input-area {
    background: white;
    border-top: 1px solid #eee;
    padding: 10px 15px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.input-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.image-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #f0f0f0;
    color: #666;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
}

.image-btn:hover {
    background: #e0e0e0;
}

.message-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 22px;
    padding: 10px 18px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.message-input:focus {
    border-color: var(--primary-color);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
}

.send-btn:hover {
    background: #157347;
}

.send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Loading */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Image Preview - Multiple Images */
.images-preview {
    display: none;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: #f8f9fa;
    border-radius: 12px;
}

.images-preview.has-images {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.image-thumb {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--primary-color);
}

.image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-thumb .remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: #ff4444;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-more-btn {
    width: 60px;
    height: 60px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #999;
    transition: all 0.2s;
}

.add-more-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 8px;
    padding: 10px 15px;
    overflow-x: auto;
    background: white;
    border-top: 1px solid #f0f0f0;
}

.quick-btn {
    white-space: nowrap;
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid #ddd;
    background: white;
    font-size: 0.85rem;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Markdown rendering */
.message-content p { margin: 0 0 8px 0; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 5px 0; padding-left: 20px; }
.message-content li { margin: 3px 0; }
.message-content strong { font-weight: 600; }
.message-content table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.85rem; }
.message-content th, .message-content td { border: 1px solid #ddd; padding: 6px 10px; text-align: left; }
.message-content th { background: #f5f5f5; }

/* Priority badges for advice */
.card-badge.priority-urgent {
    background: rgba(220, 53, 69, 0.15);
    color: #dc3545;
}

.card-badge.priority-important {
    background: rgba(255, 193, 7, 0.15);
    color: #b38600;
}

/* ============ Modal Styles ============ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    background: linear-gradient(135deg, #198754 0%, #20c997 100%);
    color: white;
    border-radius: 16px 16px 0 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
}

.modal-close:hover {
    opacity: 1;
}

.modal-body {
    padding: 20px;
}

/* Lifespan Modal */
.lifespan-main {
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    margin-bottom: 20px;
}

.lifespan-number {
    font-size: 3rem;
    font-weight: bold;
    color: #198754;
}

.lifespan-unit {
    font-size: 0.9rem;
    color: #666;
}

.factors-section, .improvement-section {
    margin-bottom: 15px;
}

.factors-section h4, .improvement-section h4 {
    font-size: 0.9rem;
    color: #333;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
}

.factor-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 6px;
    border-radius: 8px;
    font-size: 0.85rem;
}

.factor-item.positive {
    background: rgba(25, 135, 84, 0.1);
}

.factor-item.negative {
    background: rgba(220, 53, 69, 0.1);
}

.factor-name {
    color: #333;
}

.factor-impact {
    font-weight: bold;
}

.factor-impact.positive {
    color: #198754;
}

.factor-impact.negative {
    color: #dc3545;
}

.improvement-item {
    background: #f8f9fa;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.improvement-title {
    font-weight: 600;
    color: #198754;
    margin-bottom: 4px;
}

.improvement-gain {
    color: #198754;
    font-size: 0.9rem;
}

/* Advice Modal */
.advice-item {
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 10px;
    border-left: 4px solid;
}

.advice-item.urgent {
    background: rgba(220, 53, 69, 0.1);
    border-color: #dc3545;
}

.advice-item.important {
    background: rgba(255, 193, 7, 0.1);
    border-color: #ffc107;
}

.advice-item.normal {
    background: rgba(13, 110, 253, 0.1);
    border-color: #0d6efd;
}

.advice-item.positive {
    background: rgba(25, 135, 84, 0.1);
    border-color: #198754;
}

.advice-text {
    font-size: 0.9rem;
    color: #333;
    margin-bottom: 4px;
}

.advice-reason {
    font-size: 0.75rem;
    color: #666;
}

.advice-priority-tag {
    display: inline-block;
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-right: 6px;
}

.advice-priority-tag.urgent {
    background: #dc3545;
    color: white;
}

.advice-priority-tag.important {
    background: #ffc107;
    color: #333;
}

.advice-priority-tag.normal {
    background: #0d6efd;
    color: white;
}

.advice-priority-tag.positive {
    background: #198754;
    color: white;
}


/* ============ Streaming Output ============ */
.streaming-cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--primary-color);
    animation: blink 1s infinite;
    margin-left: 2px;
    vertical-align: text-bottom;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.tool-status {
    color: #666;
    font-style: italic;
}

/* ============ Message Images ============ */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    object-fit: cover;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

.message-text {
    word-break: break-word;
}

/* 全屏查看图片 */
.image-fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: pointer;
}

.fullscreen-image {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

.image-fullscreen-overlay .close-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 40px;
    color: white;
    cursor: pointer;
}

/* 移动端适配 */
@media (max-width: 576px) {
    .message-image {
        max-width: 150px;
        max-height: 150px;
    }
}
