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

:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --border: #e2e5ec;
    --text: #1e2a3a;
    --text-secondary: #6b7a8d;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    --secondary: #10b981;
    --secondary-hover: #059669;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --danger: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.08);
    --transition: .2s ease;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ── 상단 바 ──────────────────────────────────────────────── */
.top-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.top-bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.logo-area {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

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

.logo-ai {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
}

.logo-sub {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ── 헤더 네비게이션 ── */
.header-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-link {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.nav-link:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-logout {
    color: var(--danger);
}

.nav-logout:hover {
    background: #fef2f2;
    color: var(--danger);
}

.nav-user {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    padding: 4px 10px;
    background: var(--primary-light);
    border-radius: 20px;
}

/* ── 로그인 페이지 ── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 8px;
}

/* ── 범용 페이지 컨테이너 ── */
.page-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

.page-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    margin: 0 auto;
}

.page-card h2 {
    font-size: 20px;
    font-weight: 700;
}

.section-box {
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.section-box h3 {
    font-size: 15px;
    font-weight: 600;
}

/* ── 데이터 테이블 ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.data-table tbody tr:hover {
    background: var(--primary-light);
}

/* ── 버튼 (소형) ── */
.btn-small {
    padding: 6px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary {
    background: var(--secondary);
    color: #fff;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

/* ── 성공 박스 ── */
.success-box {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 14px;
    margin-bottom: 16px;
}

.keyword-badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.action-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── 버튼 ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-back {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-back:hover { background: #f1f5f9; }

.btn-generate {
    padding: 14px 48px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all .2s;
    font-family: inherit;
    box-shadow: 0 4px 15px rgba(59, 130, 246, .3);
}
.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, .4);
}
.btn-generate:disabled { opacity: .6; cursor: not-allowed; transform: none; }

/* ── 스피너 ───────────────────────────────────────────────── */
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ══════════════════════════════════════════════════════════════
   인덱스 페이지 (입력 폼)
   ══════════════════════════════════════════════════════════════ */
.index-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 60px);
    padding: 40px 20px;
}

.index-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    max-width: 520px;
    width: 100%;
}

.index-title {
    text-align: center;
    margin-bottom: 32px;
}
.index-title h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}
.index-title p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 6px;
}
.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    transition: border var(--transition);
    outline: none;
}
.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}

.index-card .btn-generate {
    width: 100%;
    margin-top: 8px;
}

/* ── 카테고리 탭 ─────────────────────────────────────────── */
.category-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
}
.cat-tab {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: var(--transition);
}
.cat-tab:hover {
    color: var(--text);
}
.cat-tab.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.url-type-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.url-type-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.url-type-btn {
    padding: 5px 12px;
    border: 1px solid var(--border);
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
}
.url-type-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}
.url-type-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.url-type-detect {
    font-size: 12px;
    font-weight: 500;
}

.error-box {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 20px;
}

.index-steps {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}
.index-steps .step {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 0;
    line-height: 1.7;
}

/* ══════════════════════════════════════════════════════════════
   분석 결과 페이지
   ══════════════════════════════════════════════════════════════ */
.analyze-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.analysis-result {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.analysis-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.analysis-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.analysis-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
}

.analysis-table-wrapper {
    overflow-x: auto;
}

.analysis-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.analysis-table thead th {
    background: #1e293b;
    color: #fff;
    padding: 12px 16px;
    font-weight: 600;
    text-align: center;
    font-size: 12px;
    letter-spacing: .3px;
    white-space: nowrap;
}

.analysis-table tbody td {
    padding: 10px 16px;
    border-bottom: 1px solid #f1f5f9;
    text-align: center;
    vertical-align: middle;
}

.analysis-table tbody tr:hover { background: #f8fafc; }
.analysis-table tbody tr:last-child td { border-bottom: none; }

.analysis-table tbody td:first-child {
    text-align: left !important;
    padding-left: 16px;
    font-weight: 500;
    color: var(--text-secondary);
}

.section-header td {
    background: #f1f5f9 !important;
    font-weight: 700 !important;
    color: var(--text) !important;
    font-size: 12px !important;
    text-transform: uppercase;
    letter-spacing: .5px;
    text-align: left !important;
    padding-left: 16px !important;
}

.val-highlight {
    color: var(--primary);
    font-weight: 700;
}

.blog-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 12px;
}
.blog-link:hover { text-decoration: underline; }

/* 순위 뱃지 */
.rank-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}
.rank-1 { background: linear-gradient(135deg, #f59e0b, #d97706); }
.rank-2 { background: linear-gradient(135deg, #94a3b8, #64748b); }
.rank-3 { background: linear-gradient(135deg, #c2884c, #a3703d); }
.rank-4 { background: #64748b; }
.rank-5 { background: #64748b; }

/* 선택 버튼 */
.select-btn {
    padding: 6px 14px;
    border: 2px solid var(--primary);
    background: transparent;
    color: var(--primary);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all .2s;
    font-family: inherit;
}
.select-btn:hover { background: var(--primary); color: #fff; }
.select-btn.selected { background: var(--primary); color: #fff; }

/* ── 벤치마크 조정 패널 ──────────────────────────────────── */
.adjust-panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.adjust-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, #eff6ff, #e0f2fe);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.adjust-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--primary);
}
.adjust-selected-info {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.adjust-body { padding: 20px 24px; }

.adjust-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.adjust-item {
    padding: 14px 16px;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.adjust-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 10px;
}
.adjust-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}
.adjust-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
    color: var(--text);
    font-family: inherit;
}
.adjust-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.adjust-btn.minus:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; }
.adjust-value {
    min-width: 56px;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.adjust-value.changed { color: var(--primary); }
.adjust-unit {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: 4px;
}

.adjust-action {
    text-align: center;
    padding-top: 4px;
}

/* ── 키워드별 조정 ─────────────────────────────────────────── */
.adjust-keyword-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.adjust-keyword-section > .adjust-label { margin-bottom: 12px; }

.adjust-keyword-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

.kw-adjust-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    gap: 12px;
}
.kw-checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    min-width: 100px;
}
.kw-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}
.kw-adjust-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    word-break: keep-all;
}
.kw-adjust-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.kw-adjust-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 24px;
    text-align: center;
}
.kw-adjust-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}
.kw-btn {
    width: 26px;
    height: 26px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
    color: var(--text);
    font-family: inherit;
    padding: 0;
}
.kw-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.kw-val {
    min-width: 24px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.kw-val.changed { color: var(--primary); }

/* ══════════════════════════════════════════════════════════════
   로딩 페이지 (글 생성 대기)
   ══════════════════════════════════════════════════════════════ */
.loading-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 60px);
    padding: 40px 20px;
}

.loading-page-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 48px 56px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 100%;
}

.loading-page-card .loading-spinner {
    width: 56px;
    height: 56px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 24px;
}

.loading-page-card h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
}

.loading-keyword {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.loading-timer {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 12px;
    font-variant-numeric: tabular-nums;
}

.loading-detail {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.loading-note {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 20px;
    opacity: .7;
}

/* ── 로딩 오버레이 (수정 등) ─────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loading-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 40px 48px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
    min-width: 360px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 24px;
}

.loading-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.loading-sub {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.loading-progress {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 2px;
    width: 0%;
    animation: progress-indeterminate 2s ease infinite;
}

@keyframes progress-indeterminate {
    0% { width: 5%; margin-left: 0; }
    50% { width: 40%; margin-left: 30%; }
    100% { width: 5%; margin-left: 95%; }
}

/* ── 토스트 ───────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: all .3s ease;
    pointer-events: none;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ── 스크롤바 ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── 반응형 ───────────────────────────────────────────────── */
@media (max-width: 900px) {
    .top-bar-inner { flex-wrap: wrap; gap: 8px; }
    .action-buttons { flex-wrap: wrap; }
    .analyze-container { padding: 16px; }
    .adjust-grid { grid-template-columns: 1fr; }
    .index-card { padding: 32px 24px; }
}

/* ── 형태소 확인 페이지 ───────────────────────────────────── */
.morpheme-original {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    padding: 12px 16px;
    background: #f0f4ff;
    border-radius: var(--radius-sm);
}
.morpheme-input {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 1px;
}
.morpheme-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 36px;
    margin-bottom: 16px;
}
.morpheme-tag {
    display: inline-block;
    padding: 6px 14px;
    background: var(--primary);
    color: white;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
}
