* { box-sizing: border-box; }

:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --border: #e6e8f0;
    --border-strong: #d7dae5;
    --text: #171923;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef1ff;

    --secondary: #f1f2f7;
    --secondary-hover: #e4e6f0;
    --secondary-text: #40465c;

    --success: #16a34a;
    --success-bg: #ecfdf3;
    --warn: #b45309;
    --warn-bg: #fef6e7;
    --error: #dc2626;
    --error-bg: #fef2f2;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgba(23, 25, 35, 0.05);
    --shadow-md: 0 6px 20px rgba(23, 25, 35, 0.07), 0 1px 3px rgba(23, 25, 35, 0.05);

    --surface-alt: #fafbfd;
    --row-hover: #fafbff;
    --banner-text: #92400e;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1117;
        --surface: #171923;
        --surface-raised: #1d202c;
        --border: #2a2d3a;
        --border-strong: #383c4c;
        --text: #edeef2;
        --text-secondary: #9a9fb0;
        --text-muted: #6b7080;

        --primary: #818cf8;
        --primary-hover: #a5b0fb;
        --primary-light: rgba(129, 140, 248, 0.16);

        --secondary: #242736;
        --secondary-hover: #2e3241;
        --secondary-text: #c3c6d4;

        --success: #4ade80;
        --success-bg: rgba(74, 222, 128, 0.14);
        --warn: #fbbf24;
        --warn-bg: rgba(251, 191, 36, 0.14);
        --error: #f87171;
        --error-bg: rgba(248, 113, 113, 0.14);

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
        --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);

        --surface-alt: #1b1e29;
        --row-hover: #1c2030;
        --banner-text: #fde68a;

        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #171923;
    --surface-raised: #1d202c;
    --border: #2a2d3a;
    --border-strong: #383c4c;
    --text: #edeef2;
    --text-secondary: #9a9fb0;
    --text-muted: #6b7080;

    --primary: #818cf8;
    --primary-hover: #a5b0fb;
    --primary-light: rgba(129, 140, 248, 0.16);

    --secondary: #242736;
    --secondary-hover: #2e3241;
    --secondary-text: #c3c6d4;

    --success: #4ade80;
    --success-bg: rgba(74, 222, 128, 0.14);
    --warn: #fbbf24;
    --warn-bg: rgba(251, 191, 36, 0.14);
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.14);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);

    --surface-alt: #1b1e29;
    --row-hover: #1c2030;
    --banner-text: #fde68a;

    color-scheme: dark;
}

html { -webkit-font-smoothing: antialiased; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard Variable",
        "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background 0.2s ease, color 0.2s ease;
}

/* 라이트/다크 전환 시 body만 부드럽게 바뀌고 카드·네비게이션·입력창 등은 색이 바로
   툭 바뀌어서, 전환 중간에 배경과 카드 색이 안 맞는 어색한 프레임이 보이던 문제가
   있었다 — 주요 요소들도 같이 전환되도록 맞춘다. */
nav, .card, input, select, textarea, button, th, td, .status,
.compliance-tab-panel {
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeInUp 0.28s ease both; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid var(--primary-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -2px;
    margin-right: 7px;
}

/* ---------- theme toggle ---------- */
#theme-toggle {
    position: fixed;
    top: 12px;
    right: 16px;
    z-index: 50;
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    line-height: 1;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-sm);
}
#theme-toggle:hover { background: var(--secondary); }

/* ---------- nav ---------- */
nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 60px 0 28px;
    display: flex;
    align-items: center;
    gap: 2px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}
nav .brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14.5px;
    color: var(--text);
    padding: 14px 20px 14px 0;
    margin-right: 8px;
    border-right: 1px solid var(--border);
    white-space: nowrap;
    flex-shrink: 0;
}
nav .brand .logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    font-size: 13px;
}
nav a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 16px 14px;
    display: inline-block;
    font-size: 13.5px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;
}
nav a:hover { color: var(--text); }
nav a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
nav .spacer { flex: 1; }
nav .key-info {
    color: var(--primary);
    background: var(--primary-light);
    font-size: 12px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    letter-spacing: 0.01em;
    white-space: nowrap;
}
nav .ftc-logo {
    height: 28px;
    margin: 0 16px;
    flex-shrink: 0;
}
.compliance-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
}
.compliance-tab-btn {
    padding: 10px 18px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border-radius: 0;
    white-space: nowrap;
}
.compliance-tab-btn:hover { color: var(--text); }
.compliance-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
nav a[href*="logout"] {
    color: var(--text-muted);
    border: none;
    margin-left: 4px;
    border-radius: var(--radius-sm);
}
nav a[href*="logout"]:hover { color: var(--text); background: var(--secondary); }

/* ---------- layout ---------- */
main { max-width: 1140px; margin: 32px auto 64px; padding: 0 20px; }
h1 { font-size: 21px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.01em; }
h3 { font-weight: 600; }
.hint { color: var(--text-secondary); font-size: 13px; line-height: 1.6; margin-bottom: 18px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s ease;
}

/* ---------- forms ---------- */
label { font-size: 12.5px; font-weight: 600; color: var(--secondary-text); display: block; margin-bottom: 6px; }

input[type=text], input[type=password], select, textarea {
    padding: 10px 12px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    width: 100%;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type=text]:focus, input[type=password]:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
input::placeholder { color: var(--text-muted); }

button, .btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
    white-space: nowrap;
}
button:hover { background: var(--primary-hover); }
button:active { transform: translateY(1px); }
button.secondary { background: var(--secondary); color: var(--secondary-text); box-shadow: none; }
button.secondary:hover { background: var(--secondary-hover); }
button:disabled { background: #eceef3; color: var(--text-muted); cursor: not-allowed; box-shadow: none; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; }
th {
    background: var(--surface-alt);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--row-hover); }

/* 매출액 순위 표: 회사명·카테고리 칸이 좁아서 줄바꿈이 심하고, 매출액 칸은 남는
   문제가 있어서 열 너비를 고정 배분한다. */
#ranking-table { table-layout: fixed; }
#ranking-table th:nth-child(1) { width: 7%; }
#ranking-table th:nth-child(2) { width: 22%; }
#ranking-table th:nth-child(3) { width: 36%; }
#ranking-table th:nth-child(4) { width: 25%; }
#ranking-table th:nth-child(5) { width: 10%; }

#popularity-table { table-layout: fixed; }
#popularity-table th:nth-child(1) { width: 8%; }
#popularity-table th:nth-child(2) { width: 32%; }
#popularity-table th:nth-child(3) { width: 15%; }
#popularity-table th:nth-child(4) { width: 45%; }

/* 회사명 검색 자동완성 목록 항목 */
.search-result-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--row-hover); }
.search-result-item.is-new { color: var(--text-muted); }

/* ---------- misc components ---------- */
.row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 160px; }

#log {
    background: #12141c;
    color: #7ee2a8;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px;
    padding: 14px;
    border-radius: var(--radius-md);
    height: 180px;
    overflow-y: auto;
    white-space: pre-wrap;
    margin-top: 12px;
    line-height: 1.6;
}

.status { font-size: 13px; color: var(--primary); margin: 10px 0; font-weight: 500; }
.warn { color: var(--warn); }
.error { color: var(--error); }

.status.error {
    background: var(--error-bg);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.two-col { display: flex; gap: 20px; align-items: flex-start; }
.two-col > .left { width: 280px; flex-shrink: 0; position: sticky; top: 80px; }
.two-col > .right { flex: 1; min-width: 0; }

ul.company-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 480px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
ul.company-list li {
    padding: 9px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background 0.1s ease;
}
ul.company-list li:last-child { border-bottom: none; }
ul.company-list li:hover { background: var(--primary-light); }
ul.company-list li.selected { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.article-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    margin-bottom: 12px;
    background: var(--surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.article-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.article-card:last-child { margin-bottom: 0; }
.article-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.article-card-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.article-code { font-weight: 700; font-size: 13px; color: var(--text); }
.article-desc { font-size: 13px; color: var(--text-secondary); }

.status-pills { display: inline-flex; gap: 4px; background: var(--secondary); padding: 3px; border-radius: var(--radius-pill); }
.status-pill {
    background: transparent;
    color: var(--text-secondary);
    box-shadow: none;
    padding: 5px 12px;
    font-size: 12px;
    border-radius: var(--radius-pill);
}
.status-pill:hover { background: var(--secondary-hover); color: var(--text); }
.status-pill.active { color: #fff; }
.status-pill-R.active { background: var(--error); }
.status-pill-Y.active { background: var(--warn); }
.status-pill-W.active { background: var(--success); }

.article-card .summary-input { margin-top: 2px; }
.article-card .evidence-quote {
    margin: 8px 0 0;
    padding: 8px 10px;
    background: var(--surface-alt);
    border-left: 3px solid var(--border-strong);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.login-box { max-width: 440px; margin: 72px auto; text-align: center; }
.login-box .logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    font-size: 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-md);
}
.login-box .login-ftc-logo { height: 56px; margin-bottom: 20px; }
.login-box h1 { font-size: 19px; }
.login-box .card { text-align: left; padding: 28px; }
.key-visibility-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    background: none;
    border: none;
    padding: 6px 8px;
    font-size: 15px;
    cursor: pointer;
    opacity: 0.55;
    line-height: 1;
}
.key-visibility-toggle:hover { opacity: 0.85; }
.key-visibility-toggle.active { opacity: 1; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
    background: var(--secondary);
    color: var(--secondary-text);
    letter-spacing: 0.02em;
}
.badge.badge-R { background: var(--error-bg); color: var(--error); }
.badge.badge-Y { background: var(--warn-bg); color: var(--warn); }
.badge.badge-W { background: var(--success-bg); color: var(--success); }

.evidence-quote {
    margin-top: 5px;
    font-size: 12px;
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.5;
}

.precedent-refs { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.precedent-chip {
    display: inline-block;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    background: var(--primary-light);
    color: var(--primary);
}
.precedent-chip a { color: inherit; text-decoration: none; }
.precedent-chip a:hover { text-decoration: underline; }

.banner {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--warn-bg);
    color: var(--banner-text);
    font-size: 13px;
    line-height: 1.6;
}

/* scrollbars */
#log::-webkit-scrollbar, ul.company-list::-webkit-scrollbar { width: 8px; }
#log::-webkit-scrollbar-thumb { background: #2a2f3d; border-radius: 8px; }
ul.company-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
