/* ====================
   기본 및 공통 스타일
   ==================== */
:root {
    --color-primary: #0ea5e9;
    /* sky-500 */
    --color-primary-dark: #0284c7;
    /* sky-600 */
    --color-secondary: #2563eb;
    /* blue-600 - calculator button */
    --color-secondary-dark: #1d4ed8;
    /* blue-700 */
    --color-success: #16a34a;
    /* emerald-600 */
    --color-success-dark: #15803d;
    /* emerald-700 */
    --color-danger: #dc2626;
    /* red-600 */
    --color-danger-dark: #b91c1c;
    /* red-700 */

    --color-text-base: #1e293b;
    /* slate-800 */
    --color-text-muted: #475569;
    /* slate-600 */
    --color-text-subtle: #64748b;
    /* slate-500 */
    --color-text-highlight: #0369a1;
    /* sky-700 */
    --color-bg-base: #f1f5f9;
    /* slate-100 */
    --color-bg-content: #ffffff;
    --color-bg-subtle: #f8fafc;
    /* slate-50 */
    --color-border: #cbd5e1;
    /* slate-300 */
    --border-radius: 0.5rem;
    /* rounded-lg */
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

/* [수정] 일관된 너비 계산을 위한 box-sizing 적용 */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background-color: var(--color-bg-base);
    color: var(--color-text-base);
    margin: 0;
    scroll-behavior: smooth;
}

.container {
    max-width: 80rem;
    /* max-w-5xl */
    margin: 0 auto;
    padding: 1rem;
}

@media (min-width: 768px) {
    .container {
        padding: 2rem;
    }
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
}

header h1 {
    font-size: 1.875rem;
    /* text-3xl */
    font-weight: 700;
    color: #0f172a;
    /* slate-900 */
}

@media (min-width: 768px) {
    header h1 {
        font-size: 2.25rem;
        /* md:text-4xl */
    }
}

header p {
    margin-top: 0.5rem;
    color: var(--color-text-muted);
}

.main-content {
    background-color: var(--color-bg-content);
    padding: 1.5rem;
    border-radius: 1rem;
    /* rounded-2xl */
    box-shadow: var(--shadow);
}

@media (min-width: 768px) {
    .main-content {
        padding: 2rem;
    }
}

footer {
    text-align: center;
    margin-top: 2rem;
    font-size: 0.875rem;
    color: var(--color-text-subtle);
}

.hidden {
    display: none !important;
}

.section-label {
    display: block;
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #334155;
    /* slate-700 */
}

.help-text {
    font-size: 0.75rem;
    color: var(--color-text-subtle);
    margin-top: 0.5rem;
    text-align: center;
    line-height: 1.5;
}

.help-text-small {
    font-size: 0.875rem;
    color: var(--color-text-subtle);
    margin-top: 0.25rem;
}

.text-highlight {
    font-weight: 600;
    color: var(--color-text-highlight);
}

.section-block {
    margin-bottom: 1.5rem;
}

/* ====================
   탭(Tabs) 스타일
   ==================== */
.tabs-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 1.5rem;
    border-radius: var(--border-radius);
    padding: 0.25rem;
    background-color: #e2e8f0;
    /* slate-200 */
    max-width: 48rem;
    /* max-w-2xl */
    margin-left: auto;
    margin-right: auto;
}

.tab-btn {
    flex-grow: 1;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    /* rounded-md */
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.tab-btn.active {
    background-color: var(--color-primary);
    color: white;
}

.tab-btn:not(.active) {
    background-color: transparent;
    color: var(--color-text-muted);
}

.panel {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ====================
   파일 드롭 영역
   ==================== */
.file-drop-area {
    border: 2px dashed var(--color-border);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out;
}

.file-drop-area:hover {
    background-color: #f8fafc;
    /* slate-50 */
}

.file-drop-area.dragover {
    background-color: #e0f2fe;
    /* sky-100 */
    border-color: var(--color-primary);
}

.drop-area-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
}

.drop-area-content i {
    width: 4rem;
    height: 4rem;
    color: #94a3b8;
    /* slate-400 */
    margin-bottom: 1rem;
}

.drop-area-content p {
    color: var(--color-text-muted);
    margin: 0;
}

/* ====================
   버튼 스타일
   ==================== */
.btn {
    width: 100%;
    color: white;
    font-weight: 700;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    cursor: pointer;
}

.btn:disabled {
    background-color: #94a3b8;
    /* slate-400 */
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--color-primary-dark);
}

.btn-primary:hover:not(:disabled) {
    background-color: #0369a1;
    /* sky-700 */
}

.btn-success {
    background-color: var(--color-success);
}

.btn-success:hover:not(:disabled) {
    background-color: var(--color-success-dark);
}

.btn-secondary {
    background-color: var(--color-secondary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--color-secondary-dark);
}

.btn i,
.btn svg {
    width: 1.25rem;
    height: 1.25rem;
}


/* ====================
   입력 필드 스타일
   ==================== */
.settings-section,
.result-section {
    margin-top: 2rem;
}

/* [수정] PDF 변환기 버튼 상단 여백 추가 */
.settings-section>.btn {
    margin-top: 1.5rem;
}

.input-group {
    display: flex;
    justify-content: center;
}

.quality-input,
.filename-input {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    text-align: center;
    font-weight: 700;
    color: var(--color-primary-dark);
    transition: box-shadow 0.2s, border-color 0.2s;
}

.quality-input:focus,
.filename-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.5);
    border-color: var(--color-primary);
}

.quality-input {
    width: 8rem;
    font-size: 1.25rem;
}

.filename-input {
    width: 100%;
    max-width: 20rem;
}

/* ====================
   이미지 미리보기
   ==================== */
.image-preview-grid {
    margin-top: 1.5rem;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

@media (min-width: 640px) {
    .image-preview-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .image-preview-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    .image-preview-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

.preview-item {
    position: relative;
    cursor: move;
}

.preview-item.dragging {
    opacity: 0.5;
    border: 2px solid var(--color-primary);
}

.preview-item img {
    width: 100%;
    height: 8rem;
    object-fit: cover;
    border-radius: var(--border-radius);
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    pointer-events: none;
}

.preview-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    border-radius: var(--border-radius);
    pointer-events: none;
}

.preview-item:hover .preview-overlay {
    opacity: 1;
}

.preview-text {
    color: white;
    font-size: 0.75rem;
    text-align: center;
    padding: 0.5rem;
}

.preview-order-badge {
    position: absolute;
    top: 0.25rem;
    left: 0.25rem;
    background-color: var(--color-primary-dark);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    width: 1.25rem;
    height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    z-index: 10;
}


/* ====================
   결과 영역
   ==================== */
.result-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 768px) {
    .result-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.result-card {
    background-color: var(--color-bg-subtle);
    padding: 1rem;
    border-radius: var(--border-radius);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.result-card img {
    width: 5rem;
    height: 5rem;
    object-fit: cover;
    border-radius: 0.375rem;
    flex-shrink: 0;
}

.result-card-info {
    flex-grow: 1;
    min-width: 0;
    /* Prevents text overflow issues */
}

.result-card-info p {
    margin: 0;
    font-size: 0.75rem;
    color: var(--color-text-subtle);
}

.result-card-info .filename {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text-base);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-card-info .size-change {
    font-weight: 700;
    color: var(--color-success);
}

.result-card-info .reduction {
    font-weight: 700;
    color: var(--color-danger);
}

.result-card-info .download-link {
    margin-top: 0.5rem;
    display: inline-block;
    background-color: white;
    color: var(--color-text-highlight);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    transition: background-color 0.2s;
}

.result-card-info .download-link:hover {
    background-color: #f0f9ff;
    /* sky-50 */
}

/* ====================
   PDF 병합기
   ==================== */
.file-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-list-item {
    background-color: var(--color-bg-base);
    padding: 0.75rem;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.file-list-item.dragging {
    opacity: 0.5;
    border: 2px solid var(--color-primary);
}

.file-list-item .item-content {
    display: flex;
    align-items: center;
}

.file-list-item .drag-handle {
    margin-right: 0.75rem;
    color: var(--color-text-subtle);
    cursor: move;
}

.file-list-item .item-name {
    font-weight: 500;
    color: var(--color-text-base);
}

.file-list-item .remove-btn {
    color: var(--color-danger);
    font-weight: 700;
    font-size: 1.25rem;
    padding: 0 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
}

.file-list-item .remove-btn:hover {
    color: var(--color-danger-dark);
}

.download-area {
    margin-top: 1rem;
    text-align: center;
}

.download-area a {
    display: block;
    /* inline-block -> block 변경 */
    width: 100%;
    text-decoration: none;
}

.spinner {
    animation: spin 1s linear infinite;
}

/* ====================
   계산기 스타일
   ==================== */
.calculator-container {
    width: 100%;
    margin: 0 auto;
}

.calculator-header {
    text-align: center;
    margin-bottom: 2rem;
}

.calculator-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    /* gray-800 */
}

@media (min-width: 768px) {
    .calculator-header h2 {
        font-size: 1.875rem;
    }
}

.calculator-header p {
    color: #6b7280;
    /* gray-500 */
    margin-top: 0.5rem;
}

.calculator-inputs {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.input-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    /* gray-700 */
    margin-bottom: 0.25rem;
}

.date-input,
.select-input {
    width: 100%;
    padding: 0.5rem 1rem;
    border: 1px solid #d1d5db;
    /* gray-300 */
    border-radius: var(--border-radius);
    transition: box-shadow 0.2s, border-color 0.2s;
    font-size: 1rem;
    /* 일관된 폰트 크기 적용 */
    height: 2.75rem;
    /* 일관된 높이 적용 */
}

.date-input:focus,
.select-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
    border-color: #3b82f6;
    /* blue-500 */
}

input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    filter: invert(0.6);
}

select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

.calculator-actions {
    margin-bottom: 2rem;
}

.calculator-result {
    padding: 1.5rem;
    background-color: #eff6ff;
    /* blue-50 */
    border-top: 4px solid #3b82f6;
    /* blue-500 */
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    text-align: center;
}

.calculator-result p {
    margin: 0;
    font-size: 1.125rem;
    color: #4b5563;
    /* gray-600 */
    margin-bottom: 0.5rem;
}

.calculator-result .return-date {
    font-size: 1.875rem;
    font-weight: 700;
    color: #1d4ed8;
    /* blue-700 */
}

.calculator-error {
    text-align: center;
    color: #ef4444;
    /* red-500 */
    font-weight: 600;
    padding: 1rem;
    background-color: #fef2f2;
    /* red-50 */
    border-radius: var(--border-radius);
}

/* ====================
   로딩 인디케이터
   ==================== */
.loading-indicator {
    text-align: center;
    margin: 2rem 0;
}

.loader {
    height: 3rem;
    width: 3rem;
    margin: 0 auto;
    border: 4px solid #e5e7eb;
    /* gray-200 */
    border-top-color: #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-indicator p {
    margin-top: 1rem;
    color: var(--color-text-muted);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ====================
   기타 유틸리티
   ==================== */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}