/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;700&display=swap');

/* 루트 변수 */
:root {
    --primary: hsl(210, 100%, 50%);
    --primary-dark: hsl(210, 100%, 40%);
    --secondary: hsl(280, 70%, 60%);
    --success: hsl(120, 60%, 50%);
    --danger: hsl(0, 70%, 60%);
    --warning: hsl(45, 100%, 60%);
    
    --bg-gradient: linear-gradient(135deg, hsl(240, 30%, 15%) 0%, hsl(260, 40%, 25%) 100%);
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-border: rgba(255, 255, 255, 0.15);
    
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-dark: #1a1a1a;
    
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-hover: 0 12px 48px rgba(0, 0, 0, 0.4);
    
    --excluded-bg: rgba(255, 59, 48, 0.15);
    --excluded-border: rgba(255, 59, 48, 0.4);
}

/* 리셋 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* 페이지 레이아웃 */
.page {
    min-height: 100vh;
}

/* ======= 로그인 화면 ======= */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 48px 40px;
    text-align: center;
}

.app-title {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 32px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-secondary);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    transition: all 0.3s ease;
}

.form-group select option {
    background: #1a1a2e;
    color: #ffffff;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}

.error-message {
    margin-top: 16px;
    padding: 12px;
    background: rgba(255, 59, 48, 0.2);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 14px;
    display: none;
}

.error-message.show {
    display: block;
}

.login-info {
    margin-top: 24px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
}

/* ======= Glassmorphism 카드 ======= */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
    transition: all 0.3s ease;
}

.glass-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

/* ======= 버튼 ======= */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 16px rgba(66, 153, 225, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(66, 153, 225, 0.6);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), hsl(0, 70%, 50%));
    color: white;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(66, 153, 225, 0.5);
}

/* ======= 헤더 ======= */
.app-header {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    padding: 20px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.app-header h1 {
    font-size: 24px;
    font-weight: 700;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info span {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ======= 탭 내비게이션 ======= */
.tabs {
    display: flex;
    gap: 0;
    padding: 0 32px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tab-btn {
    padding: 16px 32px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    position: relative;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.tab-content {
    display: none !important;
    padding: 32px;
}

.tab-content.active {
    display: block !important;
}

/* ======= 컨테이너 ======= */
.container {
    max-width: 1400px;
    margin: 0 auto;
}

/* ======= 폼 레이아웃 ======= */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.input-with-add {
    display: flex;
    gap: 8px;
}

.input-with-add select {
    flex: 1;
}

h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-primary);
}

h3 {
    font-size: 20px;
    font-weight: 600;
    margin: 24px 0 16px;
    color: var(--text-primary);
}

/* ======= 데이터 그리드 탭 ======= */
.data-tabs {
    display: flex;
    gap: 8px;
    margin: 24px 0 16px;
    flex-wrap: wrap;
}

.data-tab-btn {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
}

.data-tab-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-color: var(--primary);
}

.data-tab-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* ======= 그리드 툴바 ======= */
.grid-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.spacer {
    flex: 1;
}

.row-count-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.row-count-select {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.row-count-select:focus {
    outline: none;
    border-color: var(--primary);
}

.row-count-select option {
    background: #2d3748;
    color: white;
}

/* ======= AG-Grid 커스터마이징 ======= */
.grid-container {
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    min-height: 400px; /* 기본 높이 유지 */
}

/* 팩터 그리드 전용 스타일 - 공백 최소화 */
#queryFactorGrid.grid-container {
    min-height: 80px !important;
    height: auto !important;
}

.ag-theme-alpine {
    --ag-background-color: rgba(255, 255, 255, 0.95);
    --ag-header-background-color: #f8f9fa;
    --ag-odd-row-background-color: rgba(0, 0, 0, 0.02);
    --ag-row-hover-color: rgba(66, 153, 225, 0.1);
    --ag-selected-row-background-color: rgba(66, 153, 225, 0.2);
    --ag-border-color: #e0e0e0;
    --ag-font-family: 'Noto Sans KR', sans-serif;
}

/* 분석 제외된 행 스타일 */
.ag-row.excluded-row {
    background-color: var(--excluded-bg) !important;
    border-left: 3px solid var(--excluded-border) !important;
}

.ag-row.excluded-row:hover {
    background-color: rgba(255, 59, 48, 0.25) !important;
}

/* ======= 폼 액션 ======= */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    justify-content: flex-end;
}

/* ======= 보정 이력 목록 ======= */
.calibration-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    margin: 24px 0;
}

.calibration-item {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.calibration-item:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.calibration-item.selected {
    border-color: var(--primary);
    background: rgba(66, 153, 225, 0.15);
}

.calibration-item h4 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.calibration-item p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 4px 0;
}

/* ======= 표시 옵션 ======= */
.display-options {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin: 16px 0;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
}

.display-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.display-options label:hover {
    color: var(--text-primary);
}

.display-options input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* ======= AG-Grid 병합 셀 스타일 (복구 및 보강) ======= */
.cell-span {
    background-color: #ffffff !important;
    color: #000000 !important; /* 확실한 검은색 */
    border-bottom: 1px solid #e0e0e0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-weight: 800 !important;
    text-align: center;
    height: 100% !important;
    pointer-events: none; /* 클릭 방해 금지 */
}

/* AG Grid 텍스트 잘림 방지 */
.ag-cell {
    display: flex;
    align-items: center;
    white-space: normal !important;
    line-height: 1.2 !important;
    padding: 8px !important;
}

.ag-header-cell-label {
    justify-content: center;
    text-align: center;
}

.text-right {
    justify-content: flex-end;
    text-align: right;
}

.text-danger {
    color: var(--danger) !important;
}

.font-bold {
    font-weight: 700 !important;
}

/* ======= 모달 스타일 (추가) ======= */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}
.modal.show {
    display: flex;
}
.modal-content {
    background: #1e1e2f;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 32px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    position: relative;
    color: white;
}
.close-modal {
    position: absolute;
    top: 20px;
    right: 24px;
    font-size: 28px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1;
}
.close-modal:hover {
    color: white;
}

.user-table-container {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}
.user-table {
    width: 100%;
    border-collapse: collapse;
}
.user-table th, .user-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.user-table th {
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    position: sticky;
    top: 0;
}
.user-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.flatpickr-day.has-data {
    border: 2px solid #60a5fa !important;
    font-weight: bold;
    position: relative;
}
.flatpickr-day.has-data:after {
    content: "";
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #60a5fa;
    display: block;
}

/* ======= 반응형 디자인 ======= */
@media (max-width: 768px) {
    .app-header {
        padding: 16px 20px;
        flex-direction: column;
        gap: 12px;
    }
    
    .app-header h1 {
        font-size: 20px;
    }
    
    .tabs {
        padding: 0 20px;
        overflow-x: auto;
    }
    
    .tab-btn {
        padding: 12px 20px;
        font-size: 14px;
        white-space: nowrap;
    }
    
    .tab-content {
        padding: 20px;
    }
    
    .glass-card {
        padding: 20px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .data-tabs {
        flex-direction: column;
    }
    
    .data-tab-btn {
        width: 100%;
    }
    
    .grid-container {
        height: 300px !important;
    }
    
    .calibration-list {
        grid-template-columns: 1fr;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
    }
}

/* 스크롤바 스타일 */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}
