/* === 기본 리셋 === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #E4002B;
    --primary-light: #FF4D6A;
    --primary-bg: #FFF5F7;
    --bg: #F8F9FA;
    --white: #FFFFFF;
    --gray-100: #F1F3F5;
    --gray-200: #E9ECEF;
    --gray-300: #DEE2E6;
    --gray-400: #CED4DA;
    --gray-500: #ADB5BD;
    --gray-600: #868E96;
    --gray-700: #495057;
    --gray-800: #343A40;
    --gray-900: #212529;
    --positive: #40C057;
    --neutral: #CED4DA;
    --negative: #FA5252;
    --user-bubble: #4263EB;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === 헤더 === */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: contain;
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.header-sub {
    color: var(--gray-600);
    font-size: 13px;
}

/* === 메인 === */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* === 채팅 레이아웃 === */
.chat-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 100px;
}

/* === 메시지 === */
.message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    justify-content: flex-end;
}

.message.user .message-content {
    background: var(--user-bubble);
    color: white;
    border-radius: var(--radius) var(--radius) 4px var(--radius);
    max-width: 70%;
}

.message.bot .message-content {
    background: var(--white);
    border-radius: var(--radius) var(--radius) var(--radius) 4px;
    border: 1px solid var(--gray-200);
    max-width: 90%;
}

.message-content {
    padding: 12px 16px;
    box-shadow: var(--shadow);
}

.message-content p {
    margin-bottom: 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--primary-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* === 추천 텍스트 === */
.recommendation-text {
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-line;
}

.recommendation-text strong {
    color: var(--primary);
}

/* === 추천 칩 === */
.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.chip {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--primary-light);
    background: var(--primary-bg);
    color: var(--primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover {
    background: var(--primary);
    color: white;
}

/* === 상품 카드 === */
.product-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.product-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 16px;
    transition: box-shadow 0.2s;
}

.product-card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.badge.brand {
    background: var(--gray-100);
    color: var(--gray-700);
}

.badge.category {
    background: #EDF2FF;
    color: #4263EB;
}

.badge.sli {
    background: #FFF3BF;
    color: #E67700;
    font-weight: 600;
}

.price {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
}

.card-title a {
    color: var(--gray-900);
    text-decoration: none;
}

.card-title a:hover {
    color: var(--primary);
}

/* === Aspect 바 차트 === */
.aspect-bars {
    margin: 8px 0;
}

.aspect-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.aspect-label {
    font-size: 11px;
    color: var(--gray-600);
    width: 60px;
    flex-shrink: 0;
    text-align: right;
}

.bar-container {
    flex: 1;
    height: 12px;
    background: var(--gray-100);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
}

.bar-segment {
    height: 100%;
    transition: width 0.5s ease;
}

.bar-segment.positive { background: var(--positive); }
.bar-segment.neutral { background: var(--neutral); }
.bar-segment.negative { background: var(--negative); }

.bar-label {
    font-size: 11px;
    color: var(--positive);
    width: 36px;
    text-align: right;
    font-weight: 600;
}

/* === 카드 푸터 === */
.card-footer {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-100);
    flex-wrap: wrap;
}

.stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--gray-600);
}

.stat-icon {
    font-size: 14px;
}

.stat.score {
    margin-left: auto;
    font-weight: 700;
    color: var(--primary);
    font-size: 13px;
}

/* === 입력 영역 === */
.chat-input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 12px 16px;
    z-index: 100;
}

.chat-input-area form {
    max-width: 800px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-wrapper input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--gray-300);
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

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

.input-wrapper input::placeholder {
    color: var(--gray-500);
}

#send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

#send-btn:hover {
    background: var(--primary-light);
}

#send-btn:disabled {
    background: var(--gray-400);
    cursor: not-allowed;
}

/* === 타이핑 인디케이터 === */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* HTMX 로딩 */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: flex;
}

/* === 상품 상세 페이지 === */
.detail-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
}

.back-link {
    display: inline-block;
    color: var(--gray-600);
    text-decoration: none;
    margin-bottom: 16px;
    font-size: 14px;
}

.back-link:hover {
    color: var(--primary);
}

.detail-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.detail-header {
    padding: 24px;
    border-bottom: 1px solid var(--gray-200);
}

.detail-badges {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.detail-header h1 {
    font-size: 22px;
    margin-bottom: 8px;
}

.detail-price {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.detail-stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1px;
    background: var(--gray-200);
    border-bottom: 1px solid var(--gray-200);
    overflow: visible;
}

.stat-box {
    background: var(--white);
    padding: 16px;
    text-align: center;
    position: relative;
}

.stat-box.has-tooltip {
    cursor: help;
}

.stat-value {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-label {
    font-size: 12px;
    color: var(--gray-600);
    margin-top: 4px;
    display: block;
}

/* 등급 배지 */
.stat-grade {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 6px;
}

.stat-grade.excellent {
    background: #E8F5E9;
    color: #2E7D32;
}

.stat-grade.good {
    background: #F1F8E9;
    color: #558B2F;
}

.stat-grade.average {
    background: #FFF8E1;
    color: #F57F17;
}

.stat-grade.low {
    background: #FFF3E0;
    color: #E65100;
}

.stat-grade.verylow {
    background: #FFEBEE;
    color: #C62828;
}

/* 툴팁 */
.tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-900);
    color: white;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 1.6;
    text-align: left;
    width: 260px;
    z-index: 200;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}

/* 오른쪽 끝 항목의 툴팁이 잘리지 않도록 */
.stat-box:last-child .tooltip {
    left: auto;
    right: 0;
    transform: none;
}

.stat-box:last-child .tooltip::after {
    left: auto;
    right: 20px;
    transform: none;
}

.stat-box:first-child .tooltip {
    left: 0;
    transform: none;
}

.stat-box:first-child .tooltip::after {
    left: 20px;
    transform: none;
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--gray-900);
}

.stat-box.has-tooltip:hover .tooltip {
    display: block;
}

.detail-section {
    padding: 24px;
    border-bottom: 1px solid var(--gray-200);
}

.detail-section:last-child {
    border-bottom: none;
}

.detail-section h2 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--gray-800);
}

.detail-bars .aspect-row {
    gap: 12px;
}

.detail-bars .aspect-label {
    width: 80px;
    font-size: 13px;
}

.detail-bars .bar-container {
    min-width: 300px;
    height: 16px;
}

.bar-numbers {
    font-size: 12px;
    min-width: 160px;
    text-align: right;
    white-space: nowrap;
}

.bar-numbers .pos { color: var(--positive); }
.bar-numbers .neu { color: var(--gray-500); }
.bar-numbers .neg { color: var(--negative); }

.aspect-legend {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--gray-600);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.positive { background: var(--positive); }
.dot.neutral { background: var(--neutral); }
.dot.negative { background: var(--negative); }

/* === 성분 정보 === */
.ingredient-summary {
    font-size: 14px;
    margin-bottom: 12px;
}

.warning {
    color: var(--negative);
    font-weight: 600;
}

.effect-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.effect-tag {
    padding: 4px 10px;
    background: #E8F5E9;
    color: #2E7D32;
    border-radius: 12px;
    font-size: 12px;
}

.ingredient-list {
    margin-top: 8px;
}

.ingredient-list summary {
    cursor: pointer;
    font-size: 13px;
    color: var(--gray-600);
}

.ingredient-list p {
    margin-top: 8px;
    font-size: 12px;
    color: var(--gray-600);
    line-height: 1.8;
}

/* === 반응형 === */
@media (max-width: 600px) {
    .header-sub { display: none; }

    .message.user .message-content,
    .message.bot .message-content {
        max-width: 95%;
    }

    .aspect-label { width: 50px; font-size: 10px; }
    .bar-label { width: 30px; font-size: 10px; }

    .detail-header h1 { font-size: 18px; }
    .detail-price { font-size: 20px; }
}
