/* =============================================================================
   app.css - 위해 식의약품 안전 AI 챗봇 통합 스타일시트
   Replaces: layout.css, style.css, contents.css
   EXO.TEN | 2026
   ============================================================================= */

/* =============================================================================
   1. CSS Custom Properties (Design Tokens)
   ============================================================================= */

:root {
    /* Brand - 관세청 스타일 가이드 */
    --color-primary: #4c72fc;
    --color-primary-light: #6b8afd;
    --color-primary-dark: #160b2e;
    --color-secondary: #8f6be1;
    --color-gradient: linear-gradient(to right, #4c72fc, #8f6be1);

    /* Semantic - Result cards */
    --color-danger: #c0392b; /* 위해 식품/의약품 */
    --color-warning: #e67e22; /* 위해 의심식품/의약품 */
    --color-safe: #27ae60; /* (미사용) */
    --color-neutral: #7f8c8d; /* 위해여부 미확인 */

    /* Category */
    --color-cat-food: #27ae60;
    --color-cat-medi: #4c72fc;
    --color-cat-unknown: #8f6be1;

    /* Neutral tones */
    --color-neutral-dark: #414570;
    --color-neutral-mid: #747795;
    --color-neutral-light: #ecf0f9;

    /* UI */
    --color-bg: #f5f5f5;
    --color-surface: #ffffff;
    --color-border: #d1e0f9;
    --color-text: #353856;
    --color-text-secondary: #666666;
    --color-text-muted: #747795;
    --color-placeholder: #999999;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Sidebar - 300px per style guide */
    --sidebar-width: 300px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;

    /* Border radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 50%;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* =============================================================================
   2. Global Reset & Base
   ============================================================================= */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    height: 100dvh;
    /* background: var(--color-bg); */
    font-family:
        'Pretendard Variable',
        'Pretendard',
        -apple-system,
        BlinkMacSystemFont,
        'Segoe UI',
        Roboto,
        'Helvetica Neue',
        Arial,
        sans-serif;
    color: var(--color-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.5px;
}

/* =============================================================================
   3. Global Layout
   ============================================================================= */

.app-layout {
    display: flex;
    flex-direction: row;
    height: 100%;
}

.app-sidebar {
    width: var(--sidebar-width);
    background: var(--color-primary-dark);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    overflow: hidden;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    height: 100vh;
}

.app-sidebar--open {
    transform: translateX(0);
}

.app-main {
    flex: 1;
    display: flex;
    transition: margin-left var(--transition-normal);
    height: 100%;
    overflow: hidden;
    position: relative; /* absolute-position 별이 .app-main 내부에 갇히도록 */
    isolation: isolate; /* stacking context 분리 — 별 애니메이션이 외부 layout 에 영향 X */
}

/* =============================================================================
   4. Header
   ============================================================================= */

.app-header {
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    height: 54px;
    gap: 8px;
}

/* Header Tabs */
.app-header__tabs {
    display: flex;
    flex: 1;
    height: 100%;
}

.app-header__tab {
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.5);
    background: none;
    border: none;
    cursor: pointer;
    position: relative;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.app-header__tab--active {
    color: #ffffff;
    font-weight: 600;
}

.app-header__tab--active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--color-gradient);
    border-radius: 3px 3px 0 0;
}

.app-header__tab--disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.app-header__end-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px 10px 42px;
    font-size: 14px;
    font-family: inherit;
    color: #fff;
    background-color: transparent;
    border: none;
    border-radius: 50px;
    box-shadow:
        inset 0 0 0 2px #4c72fc,
        0 0 10px 0 #8f6be1;
    cursor: pointer;
    transition: background-color 0.3s;
}

.app-header__end-btn::before {
    content: '';
    position: absolute;
    left: 15px;
    width: 20px;
    height: 20px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m16 17 5-5-5-5'/%3E%3Cpath d='M21 12H9'/%3E%3Cpath d='M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4'/%3E%3C/svg%3E")
        center/contain no-repeat;
}

.app-header__end-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.app-header__title {
    font-size: 16px;
    font-weight: 700;
    flex: 1;
    margin: 0;
}

.app-header__logo {
    height: 28px;
    width: auto;
    object-fit: contain;
    flex: 1;
}

.sidebar__logo {
    width: 80%;
    height: auto;
    object-fit: contain;
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.sidebar__logo:hover {
    opacity: 0.85;
}

.app-header__hamburger {
    display: flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.app-header__hamburger:hover {
    background: rgba(255, 255, 255, 0.1);
}

.app-main--sidebar-open .app-header__hamburger,
.app-main--sidebar-open .category-page__menu-btn {
    visibility: hidden;
}

/* =============================================================================
   5. Sidebar Components
   ============================================================================= */

.sidebar__header {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.sidebar__close-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.15s;
    align-self: flex-start;
}

.sidebar__close-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.sidebar__toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.sidebar__toggle-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.sidebar__cats {
    display: flex;
    gap: 4px;
    padding: 12px 0;
    justify-content: center;
}

.sidebar__cat {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    border: none;
    transition: var(--transition-fast);
    font-family: inherit;
}

.sidebar__cat:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
}

.sidebar__cat--active {
    background: white;
    color: var(--color-primary-dark);
    font-weight: 600;
}

.sidebar__section-label {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.5);
    padding: 12px 16px 8px;
    margin: 0;
}

.sidebar__list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.sidebar__list::-webkit-scrollbar {
    width: 4px;
}

.sidebar__list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar__list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.sidebar__date {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    padding: 8px 8px 4px;
    margin: 0;
}

.sidebar__item {
    position: relative;
    padding: 10px 36px 10px 12px; /* 우측 ⋮ 버튼 자리 확보 */
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 2px;
    transition: var(--transition-fast);
}

.sidebar__item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar__item-menu-btn {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0;
    transition:
        opacity 0.15s ease,
        background-color 0.15s ease;
}

.sidebar__item:hover .sidebar__item-menu-btn,
.sidebar__item-menu-btn:focus {
    opacity: 1;
}

.sidebar__item-menu-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* 모바일에서는 항상 표시 (hover 없음) */
@media (max-width: 768px) {
    .sidebar__item-menu-btn {
        opacity: 1;
    }
}

.sidebar__item-menu {
    position: absolute;
    top: 36px;
    right: 6px;
    min-width: 120px;
    background: #2a2344;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    padding: 4px 0;
    z-index: 30;
}

.sidebar__item-menu-option {
    display: block;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.sidebar__item-menu-option:hover {
    background: rgba(255, 255, 255, 0.08);
}

.sidebar__item-menu-option--danger {
    color: #ff9a9a;
}

.sidebar__item-menu-option--danger:hover {
    background: rgba(220, 68, 68, 0.18);
}

.sidebar__item--active {
    background: rgba(255, 255, 255, 0.12);
}

.sidebar__item-tag {
    font-size: 11px;
    font-weight: 600;
}

.sidebar__item-tag--danger {
    color: var(--color-danger);
}

.sidebar__item-tag--warning {
    color: var(--color-warning);
}

.sidebar__item-tag--safe {
    color: var(--color-safe);
}

.sidebar__item-tag--unknown {
    color: var(--color-neutral);
}

/* 한 행에 태그·이름·시간 배치 (세로 높이 최소화) */
.sidebar__item-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.sidebar__item-name {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar__item-time {
    flex-shrink: 0;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.4);
    white-space: nowrap;
}

/* 구 .sidebar__item-meta 스타일은 다른 곳에서 사용될 여지 남겨 유지 */
.sidebar__item-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
}

.sidebar__footer {
    padding: 16px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar__footer-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #4c72fc;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

/* 사이드바 푸터: 사용자 이름이 가용 폭을 차지하고 로그아웃 버튼은 우측에 고정 */
.sidebar__footer-username {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar__logout-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.sidebar__logout-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.sidebar__empty {
    padding: 1rem;
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.3);
    text-align: center;
}

/* =============================================================================
   6. Chat Area
   ============================================================================= */
.chat-wrap {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    z-index: 11;
    overflow: hidden;
    height: 100%;
}

.chat-body {
    display: flex;
    flex-grow: 1;
    overflow-y: auto;
    padding: 4rem;
    background: #fff;
    border-radius: 1.5rem 1.5rem 0 0;
    flex-direction: column;
    height: 100dvh;
}

.chat-msg {
    display: flex;
    gap: 7px;
    margin-bottom: 16px;
}

.chat-msg--user {
    flex-direction: row-reverse;
    margin-left: auto;
}

.chat-msg__avatar {
    width: 55px;
    height: 72px;
    object-fit: contain;
}

.chat-msg__bubble {
    background: var(--color-neutral-light);
    border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
    padding: 14px 18px;
    font-size: 15px;
    font-weight: 500;
    /*     box-shadow: var(--shadow-sm); */
    word-break: break-word;
    color: var(--color-text);
}

.chat-msg--user .chat-msg__bubble {
    background: var(--color-primary);
    color: #ffffff;
    border-radius: var(--radius-lg) 0 var(--radius-lg) var(--radius-lg);
}

/* AI 메시지의 우측 컬럼이 남은 가로폭을 모두 사용하도록 (결과 버블의 100% 폭이 의미를 갖게 함). */
.chat-msg:not(.chat-msg--user) > div {
    flex: 1;
    min-width: 0;
}

/* 결과 버블: 토글 열기/닫기·페이지네이션 등 콘텐츠 변동에 흔들리지 않도록 폭 고정.
   - 데스크톱: 우측 영역 가득 채우되 1000px 까지 (대형 모니터에서 너무 넓어지지 않도록 캡)
   - 모바일: 우측 영역(viewport - avatar)을 그대로 채워 일관 폭 유지 */
.chat-msg__bubble--result {
    width: 100%;
    max-width: 1000px;
    box-sizing: border-box;
}

/* 좁은 버블 안의 와이드 테이블은 가로 스크롤로 처리 */
.chat-msg__bubble--result .result-card__table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* 모바일: 표 셀이 너무 좁아져 한글이 글자 단위로 wrap 되는 문제 방지.
   표에 min-width 부여 + 셀 nowrap → 부족하면 wrap 의 가로 스크롤로 처리. */
@media (max-width: 768px) {
    .chat-msg__bubble--result .result-card__table {
        min-width: 520px;
    }
    .chat-msg__bubble--result .result-card__table thead th,
    .chat-msg__bubble--result .result-card__table tbody td {
        white-space: nowrap;
    }
}

/* AI Message Label */
.chat-msg__label {
    font-size: 15px;
    font-weight: 700;
    color: #353856;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #414570 0%, #8f6be1 20%, #4c72fc 40%, #30bcac 60%, #4c72fc 80%, #414570 100%);
    background-clip: text;
    -webkit-background-clip: text;
    background-size: 200% auto;
    color: transparent;
    animation: textShine 5s ease-in-out infinite alternate;
}

@keyframes textShine {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 200% 50%;
    }
}

.chat-msg__time {
    font-size: 13px;
    color: var(--color-neutral-mid);
    margin-top: 4px;
}

.chat-msg--user .chat-msg__time {
    color: rgba(255, 255, 255, 0.5);
    text-align: right;
}

/* Chat Notice (system notification badge) */
.chat-notice {
    text-align: center;
    margin: 12px 0;
}

.chat-notice__badge {
    display: inline-block;
    background: rgba(76, 114, 252, 0.1);
    color: #4c72fc;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 20px;
}

/* Feedback Buttons */
.chat-feedback {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    align-items: center;
}

.chat-feedback__btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--color-neutral-mid);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-feedback__btn:hover {
    background: var(--color-neutral-light);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.chat-feedback__time {
    font-size: 11px;
    color: var(--color-neutral-mid);
    margin-left: auto;
}

/* =============================================================================
   7. Chat Input Bar
   ============================================================================= */

.chat-input {
    padding-bottom: env(safe-area-inset-bottom);
    min-height: 82px;          /* 첨부가 늘어나도 자연 확장 */
    display: flex;
    align-items: flex-end;     /* 카메라 버튼이 입력창 하단에 정렬되도록 */
    gap: 8px;
    padding: 1.5rem;
    background: #fff;
    flex-shrink: 0;
    margin-top: auto;
    z-index: 100;
    background-color: white;
}

.chat-input__cam-btn {
    width: 45px;
    height: 45px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.chat-input__cam-btn:hover {
    background: var(--color-primary-light);
}

/* 입력 컨트롤 wrapper: 첨부 staging + textarea + 전송 버튼을 한 둥근 박스로 묶음 (Claude/GPT 스타일).
   기존에는 textarea 자체에 그라디언트 테두리가 있었으나, 첨부 영역까지 같은 테두리로 감싸기 위해
   border 를 wrap 으로 이동. */
.chat-input__field-wrap {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    border: 1px solid transparent;
    background:
        linear-gradient(var(--color-surface), var(--color-surface)) padding-box,
        linear-gradient(to right, #00a8ff, #8f6be1) border-box;
    border-radius: 1.5rem;
    padding: 6px 50px 6px 6px;  /* 우측 50px = 전송 버튼 자리 확보 */
    min-height: 50px;
}

.chat-input__field-wrap:focus-within {
    box-shadow: 0 0 0 2px rgba(76, 114, 252, 0.2);
}

.chat-input__field {
    width: 100%;
    border: none;
    background: transparent;
    border-radius: 0;
    padding: 8px 14px;
    font-size: 15px;
    resize: none;
    font-family: inherit;
    outline: none;
    min-height: 36px;
    max-height: 120px;
    color: var(--color-text);
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.chat-input__field::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.chat-input__field::placeholder {
    color: var(--color-placeholder);
}

.chat-input__send-btn {
    position: absolute;
    right: 7px;
    bottom: 7px;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1;
}

.chat-input__send-btn .blind {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* 원형 배경 (i_send_bg.png) */
.chat-input__send-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url('../images/i_send_bg.png') no-repeat center/contain;
    border-radius: 50%;
    transition:
        filter var(--transition-fast),
        opacity var(--transition-fast);
    filter: grayscale(1) brightness(1.2);
    opacity: 0.5;
}

/* 전송 아이콘 */
.chat-input__send-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url('../images/i_send.png') no-repeat 40% 50%;
    background-size: 1.8rem;
}

/* 활성 상태: 원래 색상 복원 */
.chat-input__send-btn--active::before {
    filter: none;
    opacity: 1;
}

.chat-input__send-btn--active:hover::before {
    filter: brightness(1.1);
    opacity: 1;
}

/* =============================================================================
   8. Result Cards
   ============================================================================= */

.result-card {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    margin-top: 16px;
}

.result-card__header {
    padding: 12px 16px;
    color: white;
    font-weight: 700;
    font-size: 14px;
}

.result-card__header--danger {
    background: var(--color-danger);
}

.result-card__header--warning {
    background: none;
}

.result-card__header--safe {
    background: var(--color-safe);
}

.result-card__header--unknown {
    background: var(--color-neutral);
}

.result-card__body {
    padding: 16px;
}

.result-card__tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    border: 1px solid var(--color-border);
    margin-bottom: 12px;
    color: var(--color-text-secondary);
}

.result-card__divider {
    height: 1px;
    background: var(--color-border);
    margin: 12px 0;
    border: none;
}

.result-card__row {
    display: flex;
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.6;
}

.result-card__label {
    width: 72px;
    flex-shrink: 0;
    color: var(--color-text-muted);
    font-weight: 500;
}

.result-card__value {
    flex: 1;
    font-weight: 600;
    color: var(--color-text);
}

/* Result Card: Summary Info Table */
.result-card__summary {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.6;
}

.result-card__summary th {
    width: 80px;
    padding: 6px 10px;
    text-align: left;
    font-weight: 500;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
    white-space: nowrap;
}

.result-card__summary td {
    padding: 6px 10px;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}

.result-card__summary tr:last-child th,
.result-card__summary tr:last-child td {
    border-bottom: none;
}

/* Block Detail Inline */
.block-detail-inline {
    margin-top: 14px;
}

/* Block Detail Grid */
.block-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    font-size: 13px;
    line-height: 1.6;
}

.block-detail-item {
    display: flex;
    padding: 6px 10px;
    border-bottom: 1px solid var(--color-border);
    gap: 8px;
    align-items: baseline;
    min-width: 0;
}

.block-detail-item:nth-last-child(-n + 2) {
    border-bottom: none;
}

.block-detail-item__label {
    flex-shrink: 0;
    width: 90px;
    font-weight: 500;
    color: var(--color-text-muted);
}

.block-detail-item__value {
    flex: 1;
    min-width: 0;
    color: var(--color-text);
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* 모바일: 1열 + 라벨·값 세로 스택 (768px 이하, 코드베이스 표준 브레이크포인트) */
@media (max-width: 768px) {
    .block-detail-grid {
        grid-template-columns: 1fr;
    }

    .block-detail-item {
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        padding: 8px 10px;
    }

    .block-detail-item__label {
        width: auto;
        font-size: 11px;
    }

    .block-detail-item__value {
        font-size: 13px;
        line-height: 1.5;
    }

    .block-detail-item:last-child {
        border-bottom: none;
    }
}

/* Block Detail: 상태 표시 */
.block-detail-loading {
    text-align: center;
    padding: 40px;
}

.block-detail-loading .spinner {
    margin: 0 auto 16px;
}

.block-detail-empty {
    text-align: center;
    padding: 24px;
    color: var(--color-text-muted);
    font-size: 13px;
}

.block-detail-error {
    text-align: center;
    padding: 40px;
    color: var(--color-danger);
}

.block-detail-divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 16px 0;
}

/* Block Detail: 이미지 */
.block-detail-images {
    margin-top: 16px;
}

.block-detail-images__title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 13px;
}

.block-detail-images__grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.block-detail-images__img {
    max-width: 200px;
    height: auto;
    border-radius: var(--radius-sm);
}

@media (max-width: 768px) {
    .block-detail-images__img {
        max-width: 120px;
    }
}

/* 별 반짝임 효과 (메인/서브 배경) — web_design 기준 */
.star {
    position: absolute;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    opacity: 0;
    animation:
        twinkle 1.5s infinite ease-in-out,
        drift 10s infinite alternate ease-in-out;
    pointer-events: none;
}

@keyframes twinkle {
    0%,
    100% {
        opacity: 0;
        transform: scale(0.1);
    }
    50% {
        opacity: 1;
        transform: scale(0.2);
    }
}

@keyframes drift {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(-10px);
    }
}

/* Popup: 닫기 버튼 */
.popup-close-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary, #f0f0f0);
    border: none;
    border-radius: 50%;
    font-size: 25px;
    font-weight: 600;
    cursor: pointer;
    color: var(--color-text-muted);
    transition:
        background var(--transition-fast),
        color var(--transition-fast);
}

.popup-modal__close {
    font-size: 25px !important;
    background: none;
}

.popup-close-btn:hover {
    background: var(--color-border);
    color: var(--color-text);
}

/* Sidebar: 빈 상태 */
.sidebar__empty {
    padding: 16px;
    text-align: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 13px;
}

/* Sidebar: 사용자 정보 */
.sidebar__footer-name {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50px;
}

.sidebar__footer-id {
    font-size: 14px;
}

/* Result Card: Detail Table */
.result-card__table-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

.result-card__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    line-height: 1.5;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.result-card__table thead th {
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    color: var(--color-text-secondary);
    background: var(--color-neutral-light);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.result-card__table tbody td {
    padding: 7px 10px;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}

.result-card__table tbody tr:last-child td {
    border-bottom: none;
}

.result-card__cell--danger {
    color: var(--color-danger);
    font-weight: 600;
}

.result-card__cell--warning {
    color: var(--color-warning);
    font-weight: 600;
}

/* Result Card: Natural Language Style */
.result-verdict {
    font-size: 15px;
    margin: 0 0 10px;
    color: var(--color-text);
}

.result-text--danger {
    color: var(--color-danger);
}

.result-text--warning {
    color: var(--color-warning);
}

.result-ingredients {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.result-ingredient {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--color-text);
}

.result-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.5px;
}

.result-badge--danger {
    background: rgba(192, 57, 43, 0.1);
    color: var(--color-danger);
}

.result-badge--warning {
    background: rgba(230, 126, 34, 0.1);
    color: var(--color-warning);
}

.result-badge--safe {
    background: rgba(127, 140, 141, 0.1);
    color: var(--color-neutral);
}

.result-guidance {
    font-size: 13px;
    line-height: 1.6;
    color: var(--color-text-muted);
    margin: 0;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

/* ── Structured Result Card (renderStructuredCard) ── */
/* 데스크톱: 항상 2열 (식품+의약품 가로 비교) / 모바일: 1열 세로 스택 */
.result-fixed-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 12px;
}

@media (min-width: 1281px) {
    .result-fixed-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.result-card--fixed {
    margin-top: 0;
    box-shadow: 0 2px 20px 0 rgba(19, 87, 196, 0.14);
}

.result-fixed-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: #f7f9ff;
}

.result-fixed-card__header--danger {
    background: rgba(192, 57, 43, 0.08);
}

.result-fixed-card__header--warning {
    background: rgba(230, 126, 34, 0.1);
}

.result-fixed-card__header--unknown {
    background: #f4f6f8;
}

.result-fixed-card__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text);
}

.result-fixed-card__decision {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--color-border);
    background: #fff;
}

.result-fixed-card__decision--danger {
    color: var(--color-danger);
    border-color: rgba(192, 57, 43, 0.35);
    background: rgba(192, 57, 43, 0.06);
}

.result-fixed-card__decision--warning {
    color: var(--color-warning);
    border-color: rgba(230, 126, 34, 0.35);
    background: rgba(230, 126, 34, 0.08);
}

.result-fixed-card__decision--unknown {
    color: var(--color-neutral);
    border-color: rgba(127, 140, 141, 0.35);
    background: rgba(127, 140, 141, 0.08);
}

.result-fixed-card__lead {
    margin: 0;
    font-size: 14px;
    line-height: 1.65;
    color: var(--color-text);
}

.result-fixed-card__section {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}

.result-fixed-card__section-title {
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 8px;
}

.result-fixed-card__meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.result-fixed-card__meta-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.result-fixed-card__meta-row span {
    font-size: 13px;
    color: var(--color-text-muted);
    flex-shrink: 0;
    width: 130px;            /* "통관보류사유 코드"와 같은 긴 라벨이 한 줄에 들어가는 폭 */
    white-space: nowrap;     /* 라벨은 줄바꿈 금지 */
}

.result-fixed-card__meta-row strong {
    font-size: 13px;
    color: var(--color-text);
    text-align: left;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.result-fixed-card__stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.result-fixed-card__stat {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 8px;
    background: #fafbfc;
}

.result-fixed-card__stat span {
    display: block;
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 3px;
}

.result-fixed-card__stat strong {
    display: block;
    font-size: 13px;
    color: var(--color-text);
}

.result-fixed-card__paragraph {
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--color-text-secondary);
}

/* Slot Clarify Buttons (disambiguation: product_name vs ingredient) */
.slot-clarify-btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 2px solid var(--color-primary);
    background: var(--color-surface);
    color: var(--color-primary);
    transition:
        background var(--transition-fast),
        color var(--transition-fast);
}

.slot-clarify-btn:hover {
    background: var(--color-primary);
    color: #ffffff;
}

/* Result Follow-Up (inline guidance at bottom of result bubble) */
.result-follow-up {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
    font-size: 13px;
    color: var(--color-text-muted);
}

/* =============================================================================
   9. Category Selection (main.html)
   ============================================================================= */

.category-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: var(--space-xl);
}

.category-page__title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: var(--space-xl);
    color: var(--color-text);
    text-align: center;
}

/* .category-btn {
    width: 100%;
    max-width: 400px;
    padding: 20px 24px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    text-align: left;
    margin-bottom: 12px;
    transition: var(--transition-fast);
    color: white;
    font-family: inherit;
} */

.category-btn__name {
    font-size: 18px;
    font-weight: 700;
    display: block;
}

.category-btn__desc {
    font-size: 13px;
    opacity: 0.8;
    margin-top: 4px;
    display: block;
}

.category-btn--food {
    background: var(--color-cat-food);
}

.category-btn--food:hover {
    filter: brightness(1.1);
}

.category-btn--medi {
    background: var(--color-cat-medi);
}

.category-btn--medi:hover {
    filter: brightness(1.1);
}

.category-btn--unknown {
    background: var(--color-cat-unknown);
}

.category-btn--unknown:hover {
    filter: brightness(1.1);
}

/* =============================================================================
   10. Popup / Modal System
   ============================================================================= */

.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}

.popup-overlay--visible {
    display: flex;
}

.popup-modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    max-width: 420px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: popup-fadein var(--transition-normal);
}

.popup-modal__header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    padding: 10px 20px;
    font-size: 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--color-border);
}

.popup-modal__body {
    padding: 20px;
}

.popup-modal__footer {
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
}

.popup-btn {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition-fast);
}

.popup-btn--primary {
    background: var(--color-primary);
    color: white;
    border: none;
}

.popup-btn--primary:hover {
    background: var(--color-primary-light);
}

.popup-btn--secondary {
    background: white;
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
}

.popup-btn--secondary:hover {
    background: #f0f4ff;
}

/* =============================================================================
   11. Bottom Sheet (Mobile Popup)
   ============================================================================= */

.popup-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 85vh;
    overflow-y: auto;
    z-index: 201;
    transform: translateY(100%);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-lg);
}

.popup-sheet--visible {
    transform: translateY(0);
}

.popup-sheet__handle {
    width: 40px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    margin: 12px auto;
}

/* =============================================================================
   12. Image Thumbnails
   ============================================================================= */

.thumb-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.thumb-item {
    width: 54px;
    height: 60px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    background: #c0c8d0;
    flex-shrink: 0;
}

.thumb-item__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* 입력 컨트롤(.chat-input__field-wrap) 내부의 첨부 staging 영역.
   wrap 의 둥근 테두리 안에 textarea 와 함께 들어가 있어 별도 테두리/배경은 두지 않음. */
.chat-attachments {
    display: none;
    padding: 4px 8px 0;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}
.chat-attachments.chat-attachments--has-items {
    display: flex;
}
.chat-attachments__item {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    overflow: visible;
    position: relative;
    background: #c0c8d0;
    flex-shrink: 0;
    border: 1px solid var(--color-border);
}
.chat-attachments__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: var(--radius-sm);
}
.chat-attachments__remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.chat-attachments__remove:hover {
    background: #c0392b;
}
@media (max-width: 768px) {
    .chat-attachments {
        padding: 4px 6px 0;
        gap: 6px;
    }
    .chat-attachments__item {
        width: 48px;
        height: 48px;
    }
}

.thumb-item__label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 10px;
    text-align: center;
    padding: 2px;
}

/* =============================================================================
   13. Radio Selection (Ingredient Confirmation)
   ============================================================================= */

.match-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.match-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    border: 2px solid transparent;
}

.match-item:hover {
    background: #f8f9fa;
}

.match-item--selected {
    background: #f0f4ff;
    border-color: var(--color-primary);
}

.match-item__radio {
    width: 20px;
    height: 20px;
    border-radius: var(--radius-full);
    border: 2px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition-fast);
}

.match-item--selected .match-item__radio {
    border-color: var(--color-primary);
}

.match-item__radio-dot {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    display: none;
}

.match-item--selected .match-item__radio-dot {
    display: block;
}

.match-item__info {
    flex: 1;
    min-width: 0;
}

.match-item__name {
    font-weight: 600;
    font-size: 14px;
}

.match-item__desc {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

/* 체크박스 스타일 (다중 선택 팝업) */
.match-item__check-label {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    cursor: pointer;
}

.match-item__checkbox {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    accent-color: var(--color-primary);
}

.match-item__db-label {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-left: 6px;
}

/* 자동완성 드롭다운 */
.suggest-wrap {
    position: relative;
}

.suggest-dropdown {
    position: relative;
    left: 0;
    right: 0;
    z-index: 100;
    list-style: none;
    margin: 4px 0 0;
    padding: 4px 0;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    max-height: 150px;
    overflow-y: auto;
}

.suggest-item {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.1s;
}

.suggest-item:hover {
    background: #f0f4ff;
}

/* 채팅바용: 입력 위로 떠오르는 자동완성 (chat-input__field-wrap 내부에 absolute 배치) */
.suggest-dropdown--above {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    margin: 0;
    z-index: 200;
    max-height: 220px;
}

.confirm-box {
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 12px;
    font-size: 13px;
}

/* =============================================================================
   14. Loading / Spinner
   ============================================================================= */

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.progress-bar {
    width: 150px;
    height: 4px;
    background: var(--color-border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar__fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 2px;
    animation: progress-fill 3s ease-in-out infinite;
}

@keyframes progress-fill {
    0% {
        width: 0;
    }
    50% {
        width: 80%;
    }
    100% {
        width: 100%;
    }
}

/* =============================================================================
   15. OCR Tag
   ============================================================================= */

.ocr-tag {
    display: inline-block;
    padding: 4px 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

/* =============================================================================
   16. Login Page
   ============================================================================= */

.login-page {
    height: 100vh;
    background: var(--color-primary-dark);
    display: flex;
    flex-direction: column;
}

.login-header {
    background: var(--color-primary-dark);
    color: white;
    text-align: center;
    padding: 20px;
}

.login-header__title {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
}

.login-tabs {
    display: flex;
    max-width: 600px;
    margin: 0 auto;
    background: var(--color-primary-dark);
    width: 100%;
}

.login-tab {
    flex: 1;
    padding: 12px;
    text-align: center;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition-fast);
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    border: none;
    background: none;
    font-family: inherit;
}

.login-tab--active {
    background: white;
    color: var(--color-primary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.login-tab--disabled {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.5);
    cursor: not-allowed;
}

.login-form {
    max-width: 420px;
    width: 100%;
    margin: 30px auto;
    padding: 0 20px;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    margin-bottom: 12px;
    box-sizing: border-box;
    transition: var(--transition-fast);
}

.login-input:focus {
    border-color: var(--color-primary-light);
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition-fast);
    margin-top: 8px;
}

.login-btn:hover {
    background: var(--color-primary-light);
}

.login-links {
    text-align: center;
    margin-top: 16px;
    font-size: 13px;
    color: var(--color-text-muted);
}

.login-links a {
    color: var(--color-text-secondary);
    text-decoration: none;
}

.login-links a:hover {
    text-decoration: underline;
}

/* =============================================================================
   17. Block Detail Panel
   ============================================================================= */

.block-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 380px;
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    z-index: 150;
    overflow-y: auto;
}

.block-panel--open {
    transform: translateX(0);
}

.block-panel__header {
    padding: 16px 20px;
    background: var(--color-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1;
}

.block-panel__title {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
}

.block-panel__close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.block-panel__close:hover {
    background: rgba(255, 255, 255, 0.15);
}

.block-panel__body {
    padding: 20px;
}

/* =============================================================================
   18. Animations
   ============================================================================= */

@keyframes popup-fadein {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.fade-in {
    animation: msg-fadein 0.3s ease;
}

@keyframes msg-fadein {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================================================
   19. Utility Classes
   ============================================================================= */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.hidden {
    display: none;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--color-text-muted);
}

.mt-xs {
    margin-top: var(--space-xs);
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mt-xl {
    margin-top: var(--space-xl);
}

/* =============================================================================
   20a. Form Elements (shared across pages)
   ============================================================================= */

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition-fast);
}

.form-input:focus {
    border-color: var(--color-primary-light);
}

.form-input--error {
    border-color: #d64550;
}

.form-input::placeholder {
    color: var(--color-placeholder, #999);
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 2px solid transparent;
    transition:
        background var(--transition-fast),
        color var(--transition-fast);
    text-decoration: none;
}

.btn--primary {
    background: var(--color-primary);
    color: #ffffff;
    border-color: var(--color-primary);
}

.btn--primary:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary-light);
}

.btn--full {
    width: 100%;
}

.btn.btn-login {
    width: 100%;
    background-image: linear-gradient(52deg, #4c72fc, #8f6be1);
    color: #fff;
    font-size: 17px;
    border: 0;
    border-color: none;
}

/* =============================================================================
   21. Responsive - Mobile First
   ============================================================================= */

/* Desktop: sidebar toggleable via JS class on .app-main */
@media (min-width: 1281px) {
    .app-main--sidebar-open {
        margin-left: var(--sidebar-width);
    }

    .sidebar-backdrop {
        display: none !important;
    }

    .mobile-only {
        display: none;
    }
}

/* Mobile overrides */
/* 사이드바 오버레이: 1280px 이하 (태블릿 포함) */
@media (max-width: 1280px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
        z-index: 300;
    }

    .app-sidebar--open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 299;
        display: none;
    }

    .sidebar-backdrop--visible {
        display: block;
    }

    .app-main {
        margin-left: 0;
    }

    .app-header__hamburger {
        display: flex;
    }

    .app-header__hamburger img {
        width: 22px;
        height: 18px;
    }

    .desktop-only {
        display: none;
    }
}

/* 모바일 UI: 768px 이하 */
@media (max-width: 768px) {
    .popup-modal {
        display: none;
    }

    .thumb-item {
        width: 48px;
        height: 54px;
    }

    .block-panel {
        width: 100%;
    }

    .chat-msg {
        max-width: 95%;
        gap: 8px;
        margin-bottom: 12px;
    }

    .chat-msg:not(.chat-msg--user) {
        max-width: 100%;
    }

    .chat-msg__avatar {
        width: 45px;
        height: 59px;
    }

    /* 판별 기준 등 메타 행: 좁은 화면에서 라벨/값 세로 스택 + 행 구분선으로 가독성 확보.
       라벨은 옅은 배경의 둥근 배지, 값은 자연 폭. bold 제거로 시각적 무게 균등. */
    .result-fixed-card__meta {
        gap: 0;     /* 행 padding + border-bottom 으로 간격을 만듦 */
    }
    .result-fixed-card__meta-row {
        flex-direction: column;
        gap: 4px;
        align-items: flex-start;
        padding: 8px 0;
        border-bottom: 1px dashed var(--color-border);
    }
    .result-fixed-card__meta-row:first-child {
        padding-top: 0;
    }
    .result-fixed-card__meta-row:last-child {
        padding-bottom: 0;
        border-bottom: none;
    }
    .result-fixed-card__meta-row span {
        background: var(--color-neutral-light);
        color: var(--color-text-muted);
        padding: 3px 9px;
        border-radius: 4px;
        font-size: 11px;
        font-weight: 600;
        line-height: 1.4;
        width: auto;
        white-space: nowrap;
    }
    .result-fixed-card__meta-row strong {
        font-size: 14px;
        font-weight: normal;
        word-break: keep-all;
        overflow-wrap: break-word;
    }

    .chat-msg__bubble {
        font-size: 13.5px;
        padding: 10px 14px;
        line-height: 1.6;
    }

    .chat-msg__label {
        font-size: 12.5px;
        margin-bottom: 2px;
    }

    .chat-body {
        padding: 1rem;
    }

    /* .category-page {
        padding: var(--space-md);
        justify-content: flex-start;
        padding-top: var(--space-xl);
    } */

    .slot-clarify-btn {
        padding: 6px 12px;
        font-size: 11px;
        border-width: 1.5px;
    }

    .result-detail-toggle {
        padding: 5px 8px;
        font-size: 11px;
        white-space: nowrap;
    }

    .popup-btn {
        padding: 10px;
    }
}

/* Result detail toggle button */
.result-detail-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 6px 10px;
    margin-top: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition-fast);
}

/* .result-detail-toggle:hover {
    border-color: var(--color-primary);
}

.result-detail-toggle.is-open {
    color: var(--color-primary);
    border-color: var(--color-primary);
}*/

/* ── Result Detail Wrap + Summary Preview ── */
.result-detail-wrap {
    margin-top: 12px;
}

.result-summary-preview {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
    margin-bottom: 8px;
    border: 1px solid var(--color-border);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
}

.result-summary-preview::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    background: var(--color-primary);
}

.result-summary-preview__left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.result-summary-preview__label {
    font-size: 12px;
    color: #69708f;
    font-weight: 600;
}

.result-summary-preview__title {
    font-size: 21px;
    color: var(--color-text);
    font-weight: 800;
    line-height: 1.2;
}

.result-summary-preview__text {
    font-size: 13px;
    color: #71789a;
}

.result-summary-preview__suspects {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-danger, #d14343);
}

.result-summary-preview__right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
}

.result-summary-preview__decision {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
    border: 1px solid transparent;
    white-space: nowrap;
}

.result-summary-preview__decision::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.85;
}

.result-summary-preview--danger {
    border-color: rgba(192, 57, 43, 0.3);
    background: linear-gradient(90deg, rgba(192, 57, 43, 0.06) 0%, #fff 30%);
}

.result-summary-preview--danger .result-summary-preview__title {
    color: #8f2419;
}

.result-summary-preview--danger::before {
    background: var(--color-danger);
}

.result-summary-preview__decision--danger {
    background: rgba(192, 57, 43, 0.12);
    border-color: rgba(192, 57, 43, 0.35);
    color: #a53124;
}

.result-summary-preview--warning {
    border-color: rgba(230, 126, 34, 0.3);
    background: linear-gradient(90deg, rgba(230, 126, 34, 0.08) 0%, #fff 30%);
}

.result-summary-preview--warning .result-summary-preview__title {
    color: #9d4f11;
}

.result-summary-preview--warning::before {
    background: var(--color-warning);
}

.result-summary-preview__decision--warning {
    background: rgba(230, 126, 34, 0.14);
    border-color: rgba(230, 126, 34, 0.35);
    color: #b65f15;
}

.result-summary-preview--unknown {
    border-color: rgba(127, 140, 141, 0.3);
    background: linear-gradient(90deg, rgba(127, 140, 141, 0.08) 0%, #fff 30%);
}

.result-summary-preview--unknown .result-summary-preview__title {
    color: #405156;
}

.result-summary-preview--unknown::before {
    background: var(--color-neutral);
}

.result-summary-preview__decision--unknown {
    background: rgba(127, 140, 141, 0.14);
    border-color: rgba(127, 140, 141, 0.35);
    color: #526265;
}

.result-detail-wrap .result-detail-toggle {
    width: 100%;
    margin-top: 0;
}

.result-detail-toggle--danger {
    border-color: rgba(192, 57, 43, 0.3);
    color: #a53124;
    background: rgba(192, 57, 43, 0.06);
}

.result-detail-toggle--danger:hover {
    background: rgba(192, 57, 43, 0.12);
}

.result-detail-toggle--warning {
    border-color: rgba(230, 126, 34, 0.3);
    color: #b65f15;
    background: rgba(230, 126, 34, 0.08);
}

.result-detail-toggle--warning:hover {
    background: rgba(230, 126, 34, 0.14);
}

.result-detail-toggle--unknown {
    border-color: rgba(127, 140, 141, 0.3);
    color: #526265;
    background: rgba(127, 140, 141, 0.08);
}

.result-detail-toggle--unknown:hover {
    background: rgba(127, 140, 141, 0.14);
}

.result-detail-wrap .result-detail-panel {
    margin-top: 8px;
}

@media (max-width: 768px) {
    .result-summary-preview {
        flex-direction: column;
        gap: 10px;
        padding: 12px;
    }

    .result-summary-preview__title {
        font-size: 17px;
        line-height: 1.3;
    }

    .result-summary-preview__text {
        font-size: 12px;
    }

    .result-summary-preview__right {
        justify-content: flex-start;
    }

    .result-summary-preview__decision {
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* 다중 카드 배치 (잘모르겠어요: 식품+의약품) — 요약(.result-fixed-grid)과 동일 브레이크포인트 */
.result-detail-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 16px;
}
@media (min-width: 1281px) {
    .result-detail-row {
        grid-template-columns: repeat(2, 1fr);
    }
}
.result-detail-row .result-detail-toggle {
    width: 100%;
    margin-top: 0;
    padding: 6px 10px;
    font-size: 12px;
}

/* 공통 슬림 스크롤 */
/* 1. 크롬, 사파리, 엣지, 최신 삼성 브라우저용 */
/* 전체 스크롤바 너비 설정 */
::-webkit-scrollbar {
    width: 6px; /* 세로 스크롤바 두께 */
    height: 6px; /* 가로 스크롤바 두께 */
}

/* 스크롤바 막대(움직이는 부분) */
::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2); /* 반투명한 검정색 (얇고 은은하게) */
    border-radius: 10px; /* 막대 끝을 둥글게 */
}

/* 스크롤바 막대 마우스 호버 시 */
::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.4); /* 마우스 올리면 조금 더 진하게 */
}

/* 스크롤바 배경(트랙) - 보통 투명하게 둡니다 */
::-webkit-scrollbar-track {
    background-color: rgba(0, 0, 0, 0);
}

/* 2. 파이어폭스용 (표준 속성) */
* {
    scrollbar-width: thin; /* 얇게 설정 */
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent; /* 막대색 배경색 */
}
