/**
 * [LabelCheck] v2.3 - Simplified Mobile-First UX
 */

:root {
    --bg: #FAFAFA;
    --surface: #FFFFFF;
    --text: #212121;
    --text-sec: #616161;
    --border: rgba(0, 0, 0, 0.12);
    --accent: #B68D5D;
    --hover-bg: rgba(0, 0, 0, 0.04);
    
    --grade-s: #D32F2F;
    --grade-a: #E65100;
    --grade-b: #FBC02D;
    --grade-c: #388E3C;
    --grade-d: #1976D2;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    --transition: all 0.2s ease-in-out;
}

[data-theme="dark"] {
    --bg: #121212;
    --surface: #1E1E1E;
    --text: #F5F5F5;
    --text-sec: #BDBDBD;
    --border: rgba(255, 255, 255, 0.12);
    --hover-bg: rgba(255, 255, 255, 0.08);
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    
    --grade-s: #E53935;
    --grade-a: #FB8C00;
    --grade-b: #FDD835;
    --grade-c: #43A047;
    --grade-d: #42A5F5;
}

[data-theme="dark"] .brand-logo-wrap {
    border: 1px solid #333 !important;
}

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

body {
    background-color: var(--bg); color: var(--text);
    font-family: 'Inter', "Pretendard", sans-serif;
    line-height: 1.5; font-size: 14px;
    padding-bottom: 70px;
}

/* Base Top Header */
#main-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1000;
}
.header-top {
    padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; max-width: 1200px; margin: 0 auto;
}
.logo-area { display: flex; align-items: center; gap: 8px; }
.logo-area h1 { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; }

.theme-toggle {
    background: transparent; border: none; color: var(--text); padding: 8px; cursor: pointer; border-radius: 50%; min-width: 44px; min-height: 44px;
}
[data-theme="dark"] .light-icon { display: none; }
[data-theme="light"] .dark-icon { display: none; }

/* Views */
main { max-width: 1200px; margin: 0 auto; }
.view-section { display: none; padding: 0 16px 24px; animation: fadeIn 0.2s ease; }
.view-section.active { display: block; }
@keyframes fadeIn { from{opacity:0;} to{opacity:1;} }

/* --- Tab 1: Search Specifics --- */
.search-section { position: relative; width: 100%; padding-top: 16px; }
.search-input {
    width: 100%;
    background: var(--surface); border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px 14px 44px; font-size: 16px; color: var(--text);
    outline: none; transition: var(--transition);
}
.search-input:focus { border-color: var(--grade-s); }
.search-icon { position: absolute; left: 16px; top: 31px; color: var(--text-sec); }

.search-history-row { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 0; }
.history-chip { display: flex; align-items: center; gap: 4px; padding: 6px 12px; background: var(--hover-bg); border-radius: 20px; font-size: 13px; color: var(--text-sec); white-space: nowrap; }

/* Grade Toggle Chips */
.grade-filter-scroll { display: flex; gap: 8px; overflow-x: auto; padding: 16px 0 8px; scrollbar-width: none; }
.grade-filter-scroll::-webkit-scrollbar { display: none; }
.grade-chip {
    padding: 8px 24px; border: 1px solid var(--border); border-radius: 20px;
    background: var(--surface); color: var(--text); font-weight: 700; font-size: 14px;
    cursor: pointer; min-height: 44px; transition: var(--transition);
}
.grade-chip[data-grade="S"].active { background: var(--grade-s); color: #fff; border-color: var(--grade-s); }
.grade-chip[data-grade="A"].active { background: var(--grade-a); color: #fff; border-color: var(--grade-a); }
.grade-chip[data-grade="B"].active { background: var(--grade-b); color: #212121; border-color: var(--grade-b); }
.grade-chip[data-grade="C"].active { background: var(--grade-c); color: #fff; border-color: var(--grade-c); }
.grade-chip[data-grade="D"].active { background: var(--grade-d); color: #fff; border-color: var(--grade-d); }

.grade-legend {
    background: var(--hover-bg); padding: 8px; border-radius: 8px; text-align: center;
    font-size: 11px; color: var(--text-sec); font-weight: 600; font-family: 'Inter', sans-serif;
    letter-spacing: -0.2px; margin-bottom: 8px;
}

.count-header {
    display: flex; justify-content: space-between; padding: 12px 0;
    font-size: 14px; font-weight: 600; color: var(--text); border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
}

/* --- View Toggle Button Group --- */
.view-toggle {
    display: inline-flex; border: 1px solid var(--border);
    border-radius: 8px; overflow: hidden;
}
.view-toggle button {
    padding: 6px 12px; font-size: 13px; border: none; background: transparent; color: var(--text-sec);
    cursor: pointer; min-width: 44px; min-height: 36px; transition: 0.2s; font-weight: 600;
}
.view-toggle button.active {
    background: var(--text); color: var(--surface);
}

/* --- Brand Grid & Card Architectures --- */

/* Outer Wrapper */
.brand-item {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow);
    overflow: hidden; display: flex; flex-direction: column;
}

.brand-logo-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}
.brand-logo-wrap.list { width: 48px; height: 48px; padding: 4px; }
.brand-logo-wrap.grid { width: 56px; height: 56px; padding: 6px; }
.brand-logo-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
}

/* =========================================
   BOTTOM SHEET MODAL
   ========================================= */
.modal-backdrop {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 2000;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,0.7); }
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.bottom-sheet {
    position: fixed; bottom: 0; left: 0; right: 0;
    margin: 0 auto; max-width: 480px; width: 100%;
    background: var(--surface); border-top-left-radius: 20px; border-top-right-radius: 20px;
    z-index: 2001; transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.1, 0.82, 0.25, 1);
    display: flex; flex-direction: column; max-height: 70vh;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    pointer-events: none;
}
.bottom-sheet.open { transform: translateY(0); pointer-events: auto; }

.sheet-drag-handle {
    width: 40px; height: 4px; background: var(--text-sec); opacity: 0.4;
    border-radius: 2px; margin: 12px auto 8px; flex-shrink: 0;
}
.sheet-close-btn {
    position: absolute; top: 12px; right: 12px;
    background: transparent; border: none; font-size: 15px; font-weight: 700; color: var(--text-sec);
    width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; gap: 4px;
    cursor: pointer; z-index: 10;
}
.sheet-content {
    padding: 0 20px 24px 20px; overflow-y: auto; text-align: left;
}

.sheet-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; margin-top: 8px; }
.sheet-logo { width: 64px; height: 64px; border-radius: 8px; background: #fff; padding: 6px; border: 1px solid var(--border); display:flex; align-items:center; justify-content:center; flex-shrink: 0;}
.sheet-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sheet-title-info { flex-grow: 1; }
.sheet-title-info .en { font-size: 18px; font-weight: 800; color: var(--text); margin-bottom: 2px; }
.sheet-title-info .ko { font-size: 14px; color: var(--text-sec); font-weight: 500; }
.sheet-grade-badge { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; color: #fff; margin-left: auto; flex-shrink: 0;}

.sheet-divider { height: 1px; background: var(--border); margin: 0 0 16px 0; }
[data-theme="dark"] .sheet-divider { background: #333; }

.detail-row { display: flex; flex-direction: column; margin-top: 12px; font-size: 14px; }
.detail-label { font-weight: 800; color: var(--text); font-size: 12px; margin-bottom:4px; opacity:0.8; }
.detail-value { color: var(--text); font-weight: 500; }
.wash-wrap { padding: 4px 8px; border-radius: 4px; font-size: 13px; font-weight: 700; display: inline-flex; align-items:center; gap: 4px; align-self: flex-start;}

.shop-link-btn {
    display: block; width: 100%; height: 48px; line-height: 48px; text-align: center;
    border-radius: 8px; color: #fff !important; font-size: 15px; font-weight: 700; text-decoration: none;
    margin-top: 24px; transition: opacity 0.2s;
}
.shop-link-btn:active { opacity: 0.8; }


/* =========================================
   LIST VIEW (Default)
   ========================================= */
.list-view .brand-list-container {
    display: grid; gap: 12px; grid-template-columns: 1fr;
}
@media (min-width: 600px) { .list-view .brand-list-container { grid-template-columns: repeat(2, 1fr); gap: 16px; } }
@media (min-width: 1024px) { .list-view .brand-list-container { grid-template-columns: repeat(3, 1fr); gap: 16px; } }

.list-view .brand-card {
    height: 120px; display: flex; flex-direction: row; align-items: center;
    padding: 12px 16px; cursor: pointer; position: relative; overflow: hidden;
    transition: box-shadow 0.2s, background-color 0.15s;
}
.brand-card:hover, .brand-card:focus { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.brand-card:active { background-color: var(--hover-bg); }

.card-interact-icon {
    position: absolute; bottom: 12px; right: 16px; color: var(--text-sec);
    display: flex; align-items: center; gap: 2px; font-size: 11px; font-weight: 600;
}
.list-view .logo-container {
    width: 48px; height: 48px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    position: relative;
}
.list-view .card-text-block {
    display: flex; flex-direction: column; justify-content: center; text-align: left;
    margin-left: 12px; flex-grow: 1; min-width: 0; padding-right: 32px;
}
.list-view .card-name-en {
    font-size: 15px; font-weight: 800; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px;
}
.list-view .card-name-ko {
    font-size: 12px; color: var(--text-sec); font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 8px;
}
.list-view .card-sublines { display: flex; gap: 4px; overflow: hidden; align-items: center; }
.sub-chip {
    font-size: 10px; padding: 2px 6px; border-radius: 4px; background: var(--hover-bg);
    color: var(--text-sec); white-space: nowrap; font-weight: 600;
}
.list-view .grade-badge-card {
    position: absolute; right: 16px; top: 16px;
    width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800; color: #fff; font-family: 'Inter', sans-serif;
}

/* =========================================
   GRID VIEW
   ========================================= */
.grid-view .brand-list-container {
    display: grid; gap: 12px;
    grid-template-columns: repeat(3, 1fr); /* Mobile <= 480px */
}
@media (min-width: 481px) { .grid-view .brand-list-container { grid-template-columns: repeat(4, 1fr); gap: 16px; } }
@media (min-width: 769px) { .grid-view .brand-list-container { grid-template-columns: repeat(6, 1fr); gap: 16px; } }

.grid-view .brand-card {
    display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
    height: 140px; padding: 16px 8px; cursor: pointer; position: relative; overflow: hidden;
    transition: box-shadow 0.2s, background-color 0.15s;
}
.grid-view .card-interact-icon {
    bottom: 8px; right: 8px;
}
.grid-view .logo-container {
    width: 56px; height: 56px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px; position: relative;
}
.grid-view .card-text-block {
    display: flex; flex-direction: column; align-items: center; width: 100%;
}
.grid-view .card-name-en {
    font-size: 13px; font-weight: 800; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%;
    margin-bottom: 2px;
}
.grid-view .card-name-ko {
    display: none !important;
}
.grid-view .card-sublines { display: none; }
.grid-view .grade-badge-card {
    position: absolute; right: 8px; top: 8px;
    width: 24px; height: 24px; border-radius: 50%;
    font-size: 11px; font-weight: 800; color: #fff; font-family: 'Inter', sans-serif;
    display: flex; align-items: center; justify-content: center;
}

/* Removing inline Grid Expansion styles entirely since UX moved to bottom-sheet */


/* Empty States */
.empty-state {
    grid-column: 1 / -1; /* span full grid */
    text-align: center; padding: 60px 16px; color: var(--text-sec);
}
.empty-state p { font-size: 14px; margin-top: 8px; }
.btn-reset { margin-top: 16px; min-height: 44px; padding: 0 20px; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-md); color: var(--text); font-weight: 600; cursor: pointer; }

/* Accordion Sections (Tab 2, Tab 3) */
.grade-section { margin-bottom: 12px; }
.section-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); font-size: 16px; font-weight: 700; cursor: pointer;
    transition: background-color 0.2s;
}
.section-header:active { background-color: var(--hover-bg); }
.section-header[data-grade="S"] { border-left: 4px solid var(--grade-s); }
.section-header[data-grade="A"] { border-left: 4px solid var(--grade-a); }
.section-header[data-grade="B"] { border-left: 4px solid var(--grade-b); }
.section-header[data-grade="C"] { border-left: 4px solid var(--grade-c); }
.section-header[data-grade="D"] { border-left: 4px solid var(--grade-d); }

.section-content {
    margin-bottom: 24px;
    padding-top: 12px;
}
.section-content .brand-list-container {
    margin-bottom: 12px;
}

/* =========================================
   TIER CHART STYLES (Print Optimized)
   ========================================= */
#tier-chart-content { 
    transform-origin: top center; 
    transition: transform 0.2s ease;
}
.tier-row { 
    display: flex; flex-direction: column; align-items: center; 
    margin-bottom: 24px; width: 100%; min-height: 100px;
}
.tier-header-bar {
    width: 100%; padding: 8px 16px; color: #fff; font-weight: 800; font-size: 14px;
    display: flex; justify-content: space-between; border-radius: 8px; margin-bottom: 16px;
}
.tier-header-bar span:first-child { font-size: 28px; font-weight: 800; }
.tier-items { 
    display: flex; flex-wrap: wrap; justify-content: center; 
    gap: 16px 12px; width: 100%;
}
.tier-brand-tile { 
    display: flex; flex-direction: column; align-items: center; 
    width: 72px; cursor: pointer; position: relative;
    transition: transform 0.1s;
}
.tier-brand-tile:active { transform: scale(0.95); }
.tier-brand-tile .img-wrap {
    width: 56px; height: 56px; background: #fff; border: 1px solid var(--border); border-radius: 8px;
    display: flex; align-items: center; justify-content: center; margin-bottom: 6px; padding: 4px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.tier-brand-tile img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tier-brand-tile span {
    font-size: 13px; font-weight: 600; text-align: center; line-height: 1.2; 
    word-break: break-all; overflow: hidden; max-height: 32px; color: var(--text);
}

/* Pyramid shape logic (Desktop default) */
.overall-pyramid .tier-row[data-t="S"] .tier-items { max-width: 40%; }
.overall-pyramid .tier-row[data-t="A"] .tier-items { max-width: 60%; }
.overall-pyramid .tier-row[data-t="B"] .tier-items { max-width: 80%; }
.overall-pyramid .tier-row[data-t="C"] .tier-items { max-width: 90%; }
.overall-pyramid .tier-row[data-t="D"] .tier-items { max-width: 100%; }

/* Responsive adjustments */
@media (max-width: 768px) {
    .tier-row { margin-bottom: 20px; }
    .tier-header-bar { padding: 6px 12px; margin-bottom: 12px; height: 40px; align-items: center; border-radius: 4px; }
    .tier-header-bar span:first-child { font-size: 20px; }
    .tier-brand-tile { width: 64px; }
    .tier-brand-tile .img-wrap { width: 48px; height: 48px; border-radius: 6px; }
    .tier-brand-tile span { font-size: 11px; }
    
    .overall-pyramid .tier-row .tier-items { max-width: 100% !important; }
}

@media (max-width: 480px) {
    #tier-chart-content { touch-action: pinch-zoom; }
    #view-tierchart .tier-items { 
        display: grid !important; 
        grid-template-columns: repeat(3, 1fr) !important; 
        gap: 16px 8px !important; 
    }
    #view-tierchart .tier-brand-tile { width: 100% !important; }
    #view-tierchart .tier-brand-tile .img-wrap { width: 44px; height: 44px; margin: 0 auto 6px; }
    #view-tierchart .tier-brand-tile span { font-size: 11px; font-weight: 700; line-height: 1.1; }
    
    #view-tierchart .tier-header-bar { border-radius: 0; margin-left: -16px; margin-right: -16px; width: calc(100% + 32px); height: 44px; }
    #view-tierchart .tier-header-bar span:first-child { font-size: 18px; }
}

@media print {
    body, html { background: #fff !important; color: #000 !important; }
    #main-header, .bottom-nav, .floating-top, #btn-back-tier, #btn-print-tier, #zoom-controls, #tier-tooltip { display: none !important; }
    #main-container { padding: 0 !important; margin: 0 !important; width: 100% !important; max-width:none !important;}
    .view-section { padding: 0 !important; }
    #view-tierchart { display: block !important; }
    .tier-row { page-break-inside: avoid; margin-bottom: 40px; }
    #tier-chart-content { transform: scale(1) !important; width: 100% !important; }
    body[data-theme="dark"] .tier-brand-tile .img-wrap, .tier-brand-tile .img-wrap { border: 1px solid #ccc !important; }
    body[data-theme="dark"] .tier-brand-tile span { color: #000 !important; }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* Floating Top */
.floating-top {
    position: fixed; bottom: 84px; right: 16px;
    width: 48px; height: 48px; border-radius: 50%;
    background: var(--text); color: var(--surface);
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: 0.3s; z-index: 900;
}
.floating-top.visible { opacity: 1; pointer-events: auto; }

/* Tooltip */
.tier-tooltip {
    background: #fff;
    color: #212121;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    max-width: 280px;
    font-size: 13px;
    line-height: 1.4;
    border: 1px solid rgba(0,0,0,0.1);
}
[data-theme="dark"] .tier-tooltip {
    background: #2a2a2a;
    color: #e0e0e0;
    border-color: rgba(255,255,255,0.1);
}

/* Fixed Bottom Nav */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; height: 60px;
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; z-index: 3000; padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-sec); border: none; background: transparent; cursor: pointer;
    min-width: 48px; min-height: 48px; gap: 4px; pointer-events: auto;
}
.nav-btn span { font-size: 11px; font-weight: 700; width: 100%; text-align: center; }
.nav-btn.active { color: var(--accent); }

/* Skeleton Override */
.skeleton-card { gap: 12px; position:relative; }
.skel-logo { width: 48px; height: 48px; border-radius: var(--radius-sm); }
.skel-text-main { height: 16px; width: 60%; margin-bottom: 8px; border-radius:4px; }
.skel-text-sub { height: 12px; width: 40%; margin-bottom: 12px; border-radius:4px; }
.skel-chips { height: 14px; width: 80%; border-radius: 4px; }
.skel-badge { width: 28px; height: 28px; border-radius: 50%; position:absolute; right:16px; top:16px; }
.skeleton-box {
    background: linear-gradient(90deg, var(--border) 25%, var(--hover-bg) 50%, var(--border) 75%);
    background-size: 200% 100%; animation: skeleton-loading 1.5s infinite;
}
@keyframes skeleton-loading { from{background-position:200% 0;} to{background-position:-200% 0;} }
