@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============================================
   DESIGN TOKENS
   ============================================ */
:root {
    --bg-base:       #F5F7FF;
    --bg-surface:    #FFFFFF;
    --bg-elevated:   #EEF1FB;
    --text-primary:  #0F172A;
    --text-secondary:#475569;
    --text-muted:    #94A3B8;
    --accent:        #4F46E5;
    --accent-hover:  #4338CA;
    --accent-soft:   rgba(79,70,229,0.10);
    --gold:          #F59E0B;
    --border:        rgba(15,23,42,0.08);
    --border-medium: rgba(15,23,42,0.14);
    --shadow-sm:     0 1px 4px rgba(15,23,42,0.06);
    --shadow-md:     0 4px 20px rgba(15,23,42,0.08);
    --shadow-lg:     0 16px 48px rgba(15,23,42,0.12);
    --shadow-accent: 0 8px 24px rgba(79,70,229,0.28);
    --radius-sm:     8px;
    --radius-md:     12px;
    --radius-lg:     20px;

    --cat-waste-bg:      #FEF2F2;
    --cat-waste-fg:      #DC2626;
    --cat-waste-border:  #FECACA;
    --cat-booster-bg:    #FFFBEB;
    --cat-booster-fg:    #B45309;
    --cat-booster-border:#FDE68A;
    --cat-scale-bg:      #F0FDF4;
    --cat-scale-fg:      #15803D;
    --cat-scale-border:  #BBF7D0;
    --cat-maintain-bg:   #EFF6FF;
    --cat-maintain-fg:   #1D4ED8;
    --cat-maintain-border:#BFDBFE;
}

.dark-mode {
    --bg-base:       #080C18;
    --bg-surface:    #0E1425;
    --bg-elevated:   #151D32;
    --text-primary:  #F1F5F9;
    --text-secondary:#94A3B8;
    --text-muted:    #4B5A6E;
    --accent:        #818CF8;
    --accent-hover:  #6366F1;
    --accent-soft:   rgba(129,140,248,0.12);
    --gold:          #FCD34D;
    --border:        rgba(255,255,255,0.06);
    --border-medium: rgba(255,255,255,0.10);
    --shadow-sm:     0 1px 4px rgba(0,0,0,0.3);
    --shadow-md:     0 4px 20px rgba(0,0,0,0.35);
    --shadow-lg:     0 16px 48px rgba(0,0,0,0.5);
    --shadow-accent: 0 8px 28px rgba(99,102,241,0.35);

    --cat-waste-bg:      rgba(220,38,38,0.14);
    --cat-waste-fg:      #F87171;
    --cat-waste-border:  rgba(248,113,113,0.25);
    --cat-booster-bg:    rgba(217,119,6,0.14);
    --cat-booster-fg:    #FCD34D;
    --cat-booster-border:rgba(252,211,77,0.25);
    --cat-scale-bg:      rgba(22,163,74,0.14);
    --cat-scale-fg:      #4ADE80;
    --cat-scale-border:  rgba(74,222,128,0.25);
    --cat-maintain-bg:   rgba(37,99,235,0.14);
    --cat-maintain-fg:   #60A5FA;
    --cat-maintain-border:rgba(96,165,250,0.25);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-base:       #080C18;
        --bg-surface:    #0E1425;
        --bg-elevated:   #151D32;
        --text-primary:  #F1F5F9;
        --text-secondary:#94A3B8;
        --text-muted:    #4B5A6E;
        --accent:        #818CF8;
        --accent-hover:  #6366F1;
        --accent-soft:   rgba(129,140,248,0.12);
        --gold:          #FCD34D;
        --border:        rgba(255,255,255,0.06);
        --border-medium: rgba(255,255,255,0.10);
        --shadow-sm:     0 1px 4px rgba(0,0,0,0.3);
        --shadow-md:     0 4px 20px rgba(0,0,0,0.35);
        --shadow-lg:     0 16px 48px rgba(0,0,0,0.5);
        --shadow-accent: 0 8px 28px rgba(99,102,241,0.35);
        --cat-waste-bg:      rgba(220,38,38,0.14);
        --cat-waste-fg:      #F87171;
        --cat-waste-border:  rgba(248,113,113,0.25);
        --cat-booster-bg:    rgba(217,119,6,0.14);
        --cat-booster-fg:    #FCD34D;
        --cat-booster-border:rgba(252,211,77,0.25);
        --cat-scale-bg:      rgba(22,163,74,0.14);
        --cat-scale-fg:      #4ADE80;
        --cat-scale-border:  rgba(74,222,128,0.25);
        --cat-maintain-bg:   rgba(37,99,235,0.14);
        --cat-maintain-fg:   #60A5FA;
        --cat-maintain-border:rgba(96,165,250,0.25);
    }
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s, color 0.3s;
    min-height: 100vh;
}

/* ============================================
   NAVBAR
   ============================================ */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 64px;
    background: rgba(255,255,255,0.80);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    transition: background 0.3s, border-color 0.3s;
}
.dark-mode .navbar {
    background: rgba(8,12,24,0.85);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}
.brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #4F46E5, #7C3AED);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(79,70,229,0.35);
}
.brand-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.navbar-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

#language-selector {
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-medium);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}
#language-selector:focus { border-color: var(--accent); }

.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-medium);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.btn-icon:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}
.btn-icon .icon-dark { display: none; }
.dark-mode .btn-icon .icon-light { display: none; }
.dark-mode .btn-icon .icon-dark { display: block; }

/* ============================================
   HERO
   ============================================ */
.hero {
    position: relative;
    overflow: hidden;
    background: linear-gradient(150deg, #0F0B2D 0%, #1E1B4B 30%, #3730A3 65%, #4F46E5 100%);
    padding: 80px 40px 72px;
    text-align: center;
}
.hero-inner {
    position: relative;
    z-index: 2;
    max-width: 680px;
    margin: 0 auto;
}
.hero-badge {
    display: inline-block;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.20);
    color: rgba(255,255,255,0.90);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 5px 16px;
    border-radius: 100px;
    margin-bottom: 24px;
    backdrop-filter: blur(8px);
}
.hero-title {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 800;
    color: #FFFFFF;
    line-height: 1.15;
    letter-spacing: -0.03em;
    margin-bottom: 20px;
}
.hero-subtitle {
    font-size: 1.05rem;
    color: rgba(255,255,255,0.72);
    line-height: 1.7;
    font-weight: 400;
    max-width: 520px;
    margin: 0 auto;
}

/* Ambient glow orbs */
.hero-orb {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}
.hero-orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(139,92,246,0.45) 0%, transparent 70%);
    bottom: -200px;
    right: -100px;
}
.hero-orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(6,182,212,0.30) 0%, transparent 70%);
    top: -150px;
    left: -80px;
}

/* ============================================
   MAIN LAYOUT
   ============================================ */
.container {
    max-width: 1340px;
    margin: 0 auto;
    padding: 36px 28px 60px;
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

/* ============================================
   PANEL / CARD
   ============================================ */
.panel {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    padding: 28px;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    margin-bottom: 24px;
}
.panel-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */
.form-group {
    margin-bottom: 20px;
}
label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
input[type="number"] {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="number"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.helper-text {
    display: block;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ============================================
   DROP ZONE
   ============================================ */
.drop-zone {
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-md);
    padding: 36px 20px;
    text-align: center;
    cursor: pointer;
    background: var(--bg-elevated);
    transition: all 0.2s;
    margin-bottom: 16px;
}
.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-soft);
}
.drop-zone-icon {
    width: 52px;
    height: 52px;
    background: var(--accent-soft);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
    color: var(--accent);
    transition: background 0.2s;
}
.drop-zone:hover .drop-zone-icon,
.drop-zone.dragover .drop-zone-icon {
    background: var(--accent);
    color: white;
}
.drop-zone-text {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.drop-zone-support {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.drop-zone input[type="file"] { display: none; }

#fileNameDisplay {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    text-align: center;
    padding: 8px 0;
    min-height: 32px;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn-primary {
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, #4F46E5, #7C3AED);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    margin-top: 8px;
    box-shadow: var(--shadow-accent);
    transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
}
.btn-primary:hover {
    opacity: 0.92;
    transform: translateY(-1px);
    box-shadow: 0 12px 30px rgba(79,70,229,0.38);
}
.btn-primary:active {
    transform: translateY(0);
}

.btn-download {
    display: none;
    padding: 9px 18px;
    background: var(--text-primary);
    color: var(--bg-surface);
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}
.btn-download:hover { opacity: 0.80; }

/* ============================================
   LOADING
   ============================================ */
#loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--accent);
}
.loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   AI REPORT
   ============================================ */
.ai-report {
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: 20px 22px;
    font-size: 0.92rem;
    line-height: 1.75;
    color: var(--text-secondary);
    transition: background 0.3s;
}

/* ============================================
   TABLE
   ============================================ */
/* ============================================
   PAGE-FLIP LOADER
   ============================================ */
#resultsLoading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 420px;
    gap: 36px;
}

.page-flip-book {
    display: flex;
    filter: drop-shadow(0 12px 32px rgba(79,70,229,0.22));
}

.pfb-left {
    width: 56px;
    height: 140px;
    background: linear-gradient(160deg, rgba(79,70,229,0.12), rgba(124,58,237,0.08));
    border: 1px solid var(--border-medium);
    border-right: none;
    border-radius: 6px 0 0 6px;
    position: relative;
    overflow: hidden;
}
.pfb-left::before,
.pfb-left::after,
.pfb-left > span {
    content: '';
    position: absolute;
    left: 10px; right: 10px;
    height: 2px;
    background: var(--accent-soft);
    border-radius: 2px;
}
.pfb-left::before { top: 30px; }
.pfb-left::after  { top: 46px; box-shadow: 0 14px 0 var(--accent-soft), 0 28px 0 var(--accent-soft); }

.pfb-right {
    width: 56px;
    height: 140px;
    position: relative;
    perspective: 500px;
}

.pfb-page {
    position: absolute;
    inset: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: 0 6px 6px 0;
    transform-origin: left center;
    transform-style: preserve-3d;
}
.pfb-page::before,
.pfb-page::after {
    content: '';
    position: absolute;
    left: 10px; right: 10px;
    height: 2px;
    background: var(--border);
    border-radius: 2px;
}
.pfb-page::before { top: 30px; }
.pfb-page::after  { top: 46px; box-shadow: 0 14px 0 var(--border), 0 28px 0 var(--border); }

.pfb-page:nth-child(1) { z-index: 3; animation: page-flip 2.1s ease-in-out infinite; }
.pfb-page:nth-child(2) { z-index: 2; animation: page-flip 2.1s ease-in-out 0.28s infinite; }
.pfb-page:nth-child(3) { z-index: 1; animation: page-flip 2.1s ease-in-out 0.56s infinite; }

@keyframes page-flip {
    0%   { transform: rotateY(0deg); }
    30%  { transform: rotateY(0deg); }
    70%  { transform: rotateY(-165deg); }
    100% { transform: rotateY(-165deg); }
}

.page-flip-text {
    font-size: 0.90rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    animation: pulse-text 2.1s ease-in-out infinite;
}
@keyframes pulse-text {
    0%, 100% { opacity: 0.5; }
    50%       { opacity: 1;   }
}

/* ============================================
   REPORT VISUALS v2
   ============================================ */

/* ── Donut SVG colors + HTML bar colors ── */
.dseg-waste    { fill: var(--cat-waste-fg);    background: var(--cat-waste-fg);    }
.dseg-booster  { fill: var(--cat-booster-fg);  background: var(--cat-booster-fg);  }
.dseg-scale    { fill: var(--cat-scale-fg);    background: var(--cat-scale-fg);    }
.dseg-maintain { fill: var(--cat-maintain-fg); background: var(--cat-maintain-fg); }

.donut-svg    { display: block; flex-shrink: 0; }
.donut-cnum   { font-size: 20px; font-weight: 800; fill: var(--text-primary);  font-family: 'Inter', sans-serif; }
.donut-csub   { font-size: 8px;  font-weight: 600; fill: var(--text-muted);    font-family: 'Inter', sans-serif; text-transform: uppercase; letter-spacing: 1.2px; }

/* ── Base card ── */
.rv-wrap      { display: flex; flex-direction: column; gap: 16px; margin-bottom: 20px; }
.rv-card      { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 20px 22px; box-shadow: var(--shadow-sm); }
.rv-head      { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding-bottom: 13px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }

/* ── Overview layout ── */
.rv-overview-body { display: flex; gap: 24px; align-items: flex-start; }
.rv-donut-col     { display: flex; flex-direction: column; align-items: center; gap: 14px; flex-shrink: 0; }
.rv-stats-col     { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* Donut legend */
.donut-legend { display: flex; flex-direction: column; gap: 7px; width: 100%; }
.dl-row       { display: flex; align-items: center; gap: 8px; }
.dl-badge     { flex: 1; min-width: 0; }
.dl-count     { font-size: 0.82rem; font-weight: 700; color: var(--text-primary); }
.dl-pct       { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); min-width: 38px; text-align: right; }

/* Summary stats row */
.ss-row  { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ss-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.ss-val  { font-size: 1.1rem; font-weight: 800; color: var(--text-primary); letter-spacing: -0.02em; line-height: 1; }
.ss-lbl  { font-size: 0.68rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Category progress bars */
.cb-list  { display: flex; flex-direction: column; gap: 9px; }
.cb-row   { display: flex; align-items: center; gap: 10px; }
.cb-label { font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); width: 128px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-track { flex: 1; height: 7px; background: var(--border-medium); border-radius: 4px; overflow: hidden; }
.cb-fill  { height: 100%; border-radius: 4px; transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.cb-stat  { font-size: 0.78rem; font-weight: 600; color: var(--text-primary); min-width: 62px; text-align: right; }
.cb-stat em { font-style: normal; color: var(--text-muted); font-weight: 400; margin-left: 3px; }

/* ── Keyword cards ── */
.kw-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.kw-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.kw-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.kw-name     { font-size: 0.83rem; font-weight: 700; color: var(--text-primary); line-height: 1.4; flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: keep-all; }
.kw-metrics  { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kw-m        { display: flex; flex-direction: column; gap: 2px; }
.kw-mv       { font-size: 0.86rem; font-weight: 700; color: var(--text-primary); }
.kw-ml       { font-size: 0.66rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kw-bar-track{ height: 4px; background: var(--border-medium); border-radius: 2px; overflow: hidden; }
.kw-bar-fill { height: 100%; border-radius: 2px; transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.kw-match    { font-size: 0.69rem; color: var(--text-muted); font-weight: 500; }

/* ── AI section cards ── */
.ais-card         { border-radius: var(--radius-md); border: 1px solid var(--border); margin-bottom: 16px; overflow: hidden; box-shadow: var(--shadow-sm); }
.ais-card:last-child { margin-bottom: 0; }
.ais-1 { border-top: 3px solid var(--accent); }
.ais-2 { border-top: 3px solid var(--cat-waste-fg); }
.ais-3 { border-top: 3px solid var(--cat-scale-fg); }
.ais-0 { border-top: 3px solid var(--accent); }

/* Section header row with numbered badge */
.ais-head         { display: flex; align-items: center; gap: 11px; background: var(--bg-elevated); padding: 14px 20px; border-bottom: 1px solid var(--border); }
.ais-num          { width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: 0.72rem; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; }
.ais-1 .ais-num   { background: var(--accent); }
.ais-2 .ais-num   { background: var(--cat-waste-fg); }
.ais-3 .ais-num   { background: var(--cat-scale-fg); }
.ais-head h2      { font-size: 0.90rem; font-weight: 700; letter-spacing: -0.01em; color: var(--text-primary); margin: 0; word-break: keep-all; }

/* Body — Korean typography optimised */
.ais-body         { padding: 22px 24px; font-size: 0.92rem; line-height: 1.95; color: var(--text-secondary); word-break: keep-all; overflow-wrap: break-word; }
.ais-body h3      { font-size: 0.90rem; font-weight: 700; color: var(--text-primary); margin: 22px 0 9px; padding-bottom: 7px; border-bottom: 1px solid var(--border); word-break: keep-all; }
.ais-body h3:first-child { margin-top: 0; }
.ais-body p       { margin-bottom: 13px; word-break: keep-all; overflow-wrap: break-word; }
.ais-body p:last-child { margin-bottom: 0; }
.ais-body strong  { color: var(--text-primary); font-weight: 700; }
.ais-body ul, .ais-body ol { padding-left: 20px; margin-bottom: 13px; }
.ais-body li      { margin-bottom: 9px; word-break: keep-all; overflow-wrap: break-word; }
.ais-body li:last-child { margin-bottom: 0; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .rv-overview-body { flex-direction: column; }
    .rv-donut-col     { flex-direction: row; align-items: flex-start; width: 100%; }
    .donut-legend     { flex: 1; width: auto; }
    .ss-row           { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
    .rv-card          { padding: 14px; }
    .rv-overview-body { gap: 16px; }
    .kw-grid          { grid-template-columns: 1fr; }
    .ss-row           { grid-template-columns: repeat(3, 1fr); }
    .cb-label         { width: 96px; font-size: 0.70rem; }
    .dl-badge         { font-size: 0.68rem; padding: 2px 7px; }
    .ais-head         { padding: 12px 16px; gap: 9px; }
    .ais-num          { width: 20px; height: 20px; font-size: 0.68rem; }
    .ais-head h2      { font-size: 0.84rem; }
    .ais-body         { padding: 16px; font-size: 0.88rem; line-height: 1.88; }
    .ais-body h3      { font-size: 0.86rem; margin: 18px 0 8px; }
    .ais-body li      { margin-bottom: 7px; }
}

/* Results simultaneous reveal */
#resultsContent {
    opacity: 1;
}
#resultsContent.reveal {
    animation: results-reveal 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes results-reveal {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0);    }
}

#campaignFilterBar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 12px;
}
.campaign-filter-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    margin: 0;
}
#campaignSelect {
    flex: 1;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-medium);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}
#campaignSelect:focus { border-color: var(--accent); }

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    margin-top: 4px;
    max-height: 580px;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}
thead { position: sticky; top: 0; z-index: 10; }
/* 첫 번째 컬럼(키워드) 모바일 고정 */
th:first-child,
td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: inherit;
}
thead th:first-child { z-index: 11; }
tbody tr:hover td:first-child { background: var(--bg-elevated); }
th {
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}
td strong {
    color: var(--text-primary);
    font-weight: 600;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-elevated); }
.table-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 48px 20px;
    font-size: 0.9rem;
}

/* ============================================
   CATEGORY BADGES
   ============================================ */
.cat-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
    white-space: nowrap;
}
.cat-waste {
    background: var(--cat-waste-bg);
    color: var(--cat-waste-fg);
    border-color: var(--cat-waste-border);
}
.cat-booster {
    background: var(--cat-booster-bg);
    color: var(--cat-booster-fg);
    border-color: var(--cat-booster-border);
}
.cat-scale {
    background: var(--cat-scale-bg);
    color: var(--cat-scale-fg);
    border-color: var(--cat-scale-border);
}
.cat-maintain {
    background: var(--cat-maintain-bg);
    color: var(--cat-maintain-fg);
    border-color: var(--cat-maintain-border);
}

/* ============================================
   ACTION TEXT IN TABLE
   ============================================ */
.action-text {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.84rem;
}
.action-sub {
    display: block;
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.4;
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* ── Tablet (≤1024px) ─────────────────────── */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 300px 1fr;
        gap: 18px;
        padding: 28px 20px 48px;
    }
    .hero { padding: 64px 32px 60px; }
}

/* ── Tablet portrait / large mobile (≤900px) */
@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr;
        padding: 20px 16px 48px;
        gap: 16px;
    }
    .hero {
        padding: 52px 24px 48px;
    }
    .hero-title { font-size: 1.85rem; }
    .hero-subtitle { font-size: 0.95rem; }
    .navbar { padding: 0 16px; }
    .brand-name { display: none; }

    /* 설정 패널이 먼저, 결과 패널이 아래 */
    .panel { padding: 20px; }

    /* 테이블 최대높이 완화 */
    .table-wrapper { max-height: 420px; }
}

/* ── Mobile (≤600px) ─────────────────────── */
@media (max-width: 600px) {
    /* Navbar */
    .navbar { height: 56px; padding: 0 14px; }
    .brand-icon { width: 32px; height: 32px; }
    #language-selector { font-size: 0.78rem; padding: 6px 8px; }
    .btn-icon { width: 34px; height: 34px; }

    /* Hero */
    .hero { padding: 40px 16px 36px; }
    .hero-badge { font-size: 0.72rem; padding: 4px 12px; }
    .hero-title {
        font-size: 1.55rem;
        letter-spacing: -0.02em;
    }
    .hero-subtitle { font-size: 0.88rem; }

    /* Layout */
    .container { padding: 14px 12px 40px; gap: 14px; }
    .panel { padding: 16px; border-radius: 14px; }
    .panel-header { flex-wrap: wrap; gap: 10px; padding-bottom: 14px; margin-bottom: 18px; }
    .panel-header h2 { font-size: 0.92rem; }

    /* Form */
    .form-group { margin-bottom: 16px; }
    label { font-size: 0.76rem; }
    input[type="number"] { font-size: 0.95rem; padding: 10px 12px; }

    /* Drop zone */
    .drop-zone { padding: 28px 16px; }
    .drop-zone-icon { width: 44px; height: 44px; margin-bottom: 10px; }
    .drop-zone-text { font-size: 0.84rem; }

    /* Buttons */
    .btn-primary { font-size: 0.9rem; padding: 13px 16px; }
    .btn-download {
        width: 100%;
        text-align: center;
        margin-top: 4px;
    }
    /* download 버튼이 panel-header에서 줄바꿈되도록 */
    #downloadBtn { order: 3; }

    /* Campaign filter */
    #campaignFilterBar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 10px 12px;
    }
    #campaignSelect { width: 100%; }

    /* Table */
    .table-wrapper {
        max-height: 360px;
        border-radius: 10px;
    }
    th { font-size: 0.70rem; padding: 9px 10px; }
    td { font-size: 0.80rem; padding: 10px 10px; }
    .cat-badge { font-size: 0.70rem; padding: 3px 8px; }
    .action-text { font-size: 0.80rem; }
    .action-sub { font-size: 0.72rem; }

    /* AI report */
    .ai-report { font-size: 0.87rem; padding: 16px; }

    /* Page flip loader */
    #resultsLoading { min-height: 300px; gap: 24px; }
    .page-flip-book { transform: scale(0.85); }
    .page-flip-text { font-size: 0.82rem; }
}

/* ── Small mobile (≤380px) ───────────────── */
@media (max-width: 380px) {
    .hero-title { font-size: 1.35rem; }
    .navbar-controls { gap: 6px; }
    #language-selector { padding: 5px 6px; }
    th { padding: 8px 8px; }
    td { padding: 8px 8px; }
}

/* ============================================
   HERO — KOREAN WORD BREAK
   ============================================ */
.hero-title    { word-break: keep-all; }
.hero-subtitle { word-break: keep-all; }

/* ============================================
   TABLE TOUCH SCROLL
   ============================================ */
.table-wrapper { -webkit-overflow-scrolling: touch; }

/* ============================================
   MINI CARDS ROW  (Health · Waste · Conv Diag)
   ============================================ */
.rv-mini-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

/* ============================================
   HEALTH SCORE CARD
   ============================================ */
.health-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 8px 0 4px;
}
.health-circle { display: flex; align-items: baseline; gap: 2px; }
.health-num {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.04em;
}
.health-sub   { font-size: 0.82rem; font-weight: 500; color: var(--text-muted); }
.health-grade {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 10px;
    border-radius: 100px;
    border: 1px solid transparent;
}
.health-excellent .health-num   { color: var(--cat-scale-fg);   }
.health-good      .health-num   { color: var(--cat-maintain-fg);}
.health-fair      .health-num   { color: var(--cat-booster-fg); }
.health-poor      .health-num   { color: var(--cat-waste-fg);   }
.health-excellent .health-grade { background: var(--cat-scale-bg);    color: var(--cat-scale-fg);    border-color: var(--cat-scale-border);    }
.health-good      .health-grade { background: var(--cat-maintain-bg); color: var(--cat-maintain-fg); border-color: var(--cat-maintain-border); }
.health-fair      .health-grade { background: var(--cat-booster-bg);  color: var(--cat-booster-fg);  border-color: var(--cat-booster-border);  }
.health-poor      .health-grade { background: var(--cat-waste-bg);    color: var(--cat-waste-fg);    border-color: var(--cat-waste-border);    }

/* ============================================
   WASTE ANALYSIS CARD
   ============================================ */
.waste-body { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 8px 0 4px; }
.waste-stat { display: flex; flex-direction: column; gap: 4px; }
.waste-val  { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.03em; color: var(--text-primary); line-height: 1; }
.waste-red  { color: var(--cat-waste-fg); }
.waste-lbl  { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.waste-sep  { width: 1px; height: 38px; background: var(--border-medium); flex-shrink: 0; }

/* ============================================
   CONVERSION DIAGNOSTIC CARD
   ============================================ */
.convd-body { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.convd-type { font-size: 0.76rem; font-weight: 700; padding: 4px 10px; border-radius: 100px; display: inline-block; width: fit-content; border: 1px solid transparent; }
.convd-balanced   { background: var(--cat-scale-bg);    color: var(--cat-scale-fg);    border-color: var(--cat-scale-border);   }
.convd-traffic    { background: var(--cat-booster-bg);  color: var(--cat-booster-fg);  border-color: var(--cat-booster-border); }
.convd-conversion { background: var(--cat-waste-bg);    color: var(--cat-waste-fg);    border-color: var(--cat-waste-border);   }
.convd-both       { background: var(--cat-waste-bg);    color: var(--cat-waste-fg);    border-color: var(--cat-waste-border);   }
.convd-metrics { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.convd-m  { display: flex; flex-direction: column; gap: 2px; }
.convd-mv { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.convd-ml { font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

/* ============================================
   NEGATIVE KEYWORD LIST
   ============================================ */
#negativeListSection { margin-top: 8px; }
.neg-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    max-height: 380px;
}
.neg-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.neg-table th {
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}
.neg-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
    word-break: keep-all;
    overflow-wrap: break-word;
}
.neg-table td strong { color: var(--text-primary); font-weight: 600; }
.neg-table tr:last-child td  { border-bottom: none; }
.neg-table tbody tr:hover    { background: var(--bg-elevated); }
.neg-empty { text-align: center; color: var(--text-muted); padding: 24px; font-size: 0.9rem; }

/* ============================================
   RESPONSIVE — NEW COMPONENTS + MOBILE FIXES
   ============================================ */

/* ── Tablet (≤900px) ── */
@media (max-width: 900px) {
    .rv-mini-row { gap: 12px; }
}

/* ── Mobile (≤600px) ── */
@media (max-width: 600px) {

    /* Mini card row: health + waste side by side, conv full width below */
    .rv-mini-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .rv-mini-row .rv-mini-card:last-child { grid-column: span 2; }

    /* Health card */
    .health-num   { font-size: 1.9rem; }
    .health-sub   { font-size: 0.75rem; }
    .health-grade { font-size: 0.68rem; padding: 2px 8px; }

    /* Waste card */
    .waste-val  { font-size: 1.1rem; }
    .waste-body { gap: 10px; }
    .waste-sep  { height: 30px; }

    /* Conv card */
    .convd-mv   { font-size: 0.9rem; }
    .convd-type { font-size: 0.70rem; }

    /* Summary stats: keep 3 cols, compact */
    .ss-row  { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .ss-card { padding: 10px 8px; }
    .ss-val  { font-size: 0.90rem; }
    .ss-lbl  { font-size: 0.60rem; }

    /* Negative list */
    .neg-table th { font-size: 0.68rem; padding: 9px 10px; }
    .neg-table td { font-size: 0.80rem; padding: 10px 10px; }
    .neg-wrapper  { max-height: 300px; border-radius: 10px; }
    #negativeListSection .btn-download { width: 100%; text-align: center; }

    /* Table: limit sticky keyword column width */
    td:first-child { max-width: 130px; }
    td:first-child strong {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Theme toggle: slightly larger touch target */
    .btn-icon { width: 38px; height: 38px; }
}

/* ── Small mobile (≤380px) ── */
@media (max-width: 380px) {
    /* Stack all mini cards */
    .rv-mini-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .rv-mini-row .rv-mini-card:last-child { grid-column: auto; }

    .health-num  { font-size: 1.7rem; }
    .health-body { padding: 4px 0; }

    /* Waste: vertical stack on smallest screens */
    .waste-body {
        flex-direction: column;
        gap: 8px;
    }
    .waste-sep { width: 100%; height: 1px; }
}

/* ============================================================
   FULL RESPONSIVE SYSTEM — TABLE → CARD CONVERSION
   Mobile-first: base (0px+) → tablet (768px+) → desktop (1024px+)
   ============================================================ */

/* ── Mobile card layout (0 – 767px) ── */
@media (max-width: 767px) {

    /* Hide the table header row */
    #resultTable thead {
        display: none;
    }

    /* Each data row becomes a card */
    #resultTable tbody tr {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        grid-template-areas:
            "kw  kw  kw  cat"
            "clk spd ord acs"
            "mch mch bid bid"
            "act act act act";
        gap: 0;
        border: 1px solid var(--border);
        border-radius: 14px;
        margin-bottom: 14px;
        padding: 14px 12px 10px;
        background: var(--bg-surface);
        box-shadow: var(--shadow-sm);
    }

    /* Empty-state row: plain block, no card style */
    #resultTable tbody tr.table-empty-row {
        display: block;
        border: none;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        padding: 28px 16px;
        margin-bottom: 0;
        text-align: center;
    }
    #resultTable tbody tr.table-empty-row td {
        display: block;
        grid-area: unset;
        padding: 0;
        font-size: 0.9rem;
        color: var(--text-muted);
    }
    #resultTable tbody tr.table-empty-row td::before {
        display: none;
    }

    /* Assign each td to its grid area */
    #resultTable tbody tr td:nth-child(1) { grid-area: kw; }
    #resultTable tbody tr td:nth-child(2) { grid-area: mch; }
    #resultTable tbody tr td:nth-child(3) { grid-area: clk; }
    #resultTable tbody tr td:nth-child(4) { grid-area: spd; }
    #resultTable tbody tr td:nth-child(5) { grid-area: ord; }
    #resultTable tbody tr td:nth-child(6) { grid-area: acs; }
    #resultTable tbody tr td:nth-child(7) { grid-area: bid; }
    #resultTable tbody tr td:nth-child(8) { grid-area: cat; }
    #resultTable tbody tr td:nth-child(9) { grid-area: act; }

    /* Base td reset for card */
    #resultTable tbody tr td {
        display: block;
        padding: 4px 4px 6px;
        font-size: 0.82rem;
        border: none;
        background: transparent;
        white-space: normal;
        max-width: none;
    }
    #resultTable tbody tr td strong {
        display: inline;
        overflow: visible;
        white-space: normal;
    }

    /* Keyword: prominent, spans 3 cols */
    #resultTable tbody tr td:nth-child(1) {
        font-size: 0.93rem;
        font-weight: 600;
        padding-bottom: 8px;
        align-self: center;
        word-break: break-all;
    }

    /* Category badge: right-aligned */
    #resultTable tbody tr td:nth-child(8) {
        text-align: right;
        align-self: center;
        padding-bottom: 8px;
    }

    /* Action: full-width, top border separator */
    #resultTable tbody tr td:nth-child(9) {
        border-top: 1px solid var(--border);
        padding-top: 10px;
        margin-top: 6px;
    }

    /* Data labels via ::before for numeric cells */
    #resultTable tbody tr td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 0.62rem;
        font-weight: 700;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 2px;
    }

    /* No label for keyword, category, action (self-evident in card) */
    #resultTable tbody tr td:nth-child(1)::before,
    #resultTable tbody tr td:nth-child(8)::before,
    #resultTable tbody tr td:nth-child(9)::before {
        display: none;
    }

    /* Table wrapper: no horizontal scroll needed in card layout */
    .table-wrapper {
        overflow-x: visible;
        max-height: none;
        border: none;
        border-radius: 0;
        background: transparent;
    }
}

/* ── Tablet (768px – 1023px): restore normal table ── */
@media (min-width: 768px) {

    /* Restore table display */
    #resultTable thead {
        display: table-header-group;
    }

    #resultTable tbody tr {
        display: table-row;
        grid-template-columns: unset;
        grid-template-areas: unset;
        border: none;
        border-radius: 0;
        margin-bottom: 0;
        padding: 0;
        background: transparent;
        box-shadow: none;
    }

    #resultTable tbody tr td {
        display: table-cell;
        padding: 12px 14px;
        font-size: 0.875rem;
        max-width: none;
        white-space: normal;
    }

    #resultTable tbody tr td:nth-child(1) {
        font-size: 0.875rem;
        font-weight: normal;
    }

    #resultTable tbody tr td:nth-child(8) {
        text-align: left;
    }

    #resultTable tbody tr td:nth-child(9) {
        border-top: none;
        padding-top: 12px;
        margin-top: 0;
    }

    /* Hide all ::before labels on tablet+ */
    #resultTable tbody tr td::before {
        display: none !important;
    }

    /* Restore table wrapper scroll */
    .table-wrapper {
        overflow-x: auto;
        max-height: 480px;
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background: var(--bg-surface);
    }

    /* Empty row */
    #resultTable tbody tr.table-empty-row {
        display: table-row;
        border: none;
        background: transparent;
        box-shadow: none;
        padding: 0;
        margin-bottom: 0;
    }
    #resultTable tbody tr.table-empty-row td {
        display: table-cell;
        padding: 32px 16px;
        text-align: center;
        color: var(--text-muted);
        font-size: 0.9rem;
    }
}

/* ── Desktop (1024px+): 2-col layout ── */
@media (min-width: 1024px) {
    .table-wrapper {
        max-height: 540px;
    }

    #resultTable tbody tr td {
        padding: 13px 16px;
    }
}
