/* ===== CSS 변수 (테마) ===== */
:root {
    /* 라이트 모드 */
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --accent-color: #4299e1;
    --accent-hover: #3182ce;
    --success-color: #48bb78;
    --danger-color: #f56565;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-card: #2d3748;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-muted: #a0aec0;
    --border-color: #4a5568;
    --accent-color: #63b3ed;
    --accent-hover: #4299e1;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* ===== 기본 스타일 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* ===== 앱 컨테이너 ===== */
.app-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container .main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* 메인 푸터 */
.main-footer {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ===== 헤더 ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.header-centered {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
}

.header-spacer {
    min-width: 44px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo:first-child {
    justify-content: flex-start;
}

.logo:nth-child(2) {
    justify-content: center;
}

.logo-icon {
    font-size: 2rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-color), #805ad5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 홈버튼 */
.home-btn {
    font-size: 1.5rem;
    text-decoration: none;
    margin-right: 8px;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s, transform 0.2s;
}

.home-btn:hover {
    background: var(--bg-secondary);
    transform: scale(1.1);
}

.theme-toggle {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--bg-secondary);
    cursor: pointer;
    font-size: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
    justify-self: end;
}

.theme-toggle:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow);
}

/* ===== 메뉴 선택 페이지 ===== */
.menu-section {
    text-align: center;
    padding: 40px 20px;
}

.menu-container {
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 48px 32px;
}

.menu-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 40px;
}

.menu-cards {
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
}

.menu-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 40px 32px;
    width: 280px;
    text-decoration: none;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    border: 2px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.menu-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-color);
}

.menu-card-icon {
    font-size: 3rem;
    margin-bottom: 8px;
}

.menu-card h3 {
    font-size: 1.3rem;
    font-weight: 600;
}

.menu-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.menu-card-arrow {
    color: var(--accent-color);
    font-weight: 500;
    font-size: 0.9rem;
    margin-top: 8px;
}

/* ===== 섹션 스타일 ===== */
.input-section,
.preview-section {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border-color);
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== 버튼 스타일 ===== */
.btn {
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-color), #805ad5);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-delete {
    background: transparent;
    color: var(--danger-color);
    padding: 6px 10px;
    font-size: 1rem;
}

.btn-delete:hover {
    background: rgba(245, 101, 101, 0.1);
}

.btn-add-item {
    background: transparent;
    color: var(--accent-color);
    border: 1px dashed var(--accent-color);
    padding: 8px 14px;
}

.btn-add-item:hover {
    background: rgba(66, 153, 225, 0.1);
}

/* ===== 카테고리 카드 ===== */
.categories-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.category-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.category-name {
    font-size: 1.1rem;
    font-weight: 600;
    padding: 8px 12px;
    border: 2px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    width: 300px;
    transition: border-color 0.2s;
}

.category-name:focus {
    outline: none;
    border-color: var(--accent-color);
    background: var(--bg-card);
}

.category-name::before {
    content: '📁 ';
}

/* 카테고리 셀렉트박스 */
.category-select {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.category-select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.category-select option {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 8px;
}

/* 회계처리용 계정과목 입력/셀렉트 */
.account-input,
.account-select {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
}

.account-input:focus,
.account-select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.account-input::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

/* ===== 항목 테이블 ===== */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
}

.items-table th,
.items-table td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.items-table th {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.items-table input,
.items-table select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
}

.items-table input:focus,
.items-table select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.items-table input[type="number"] {
    width: 80px;
}

.item-date {
    width: 70px !important;
}

.item-card {
    width: 80px !important;
}

/* ===== 카테고리 푸터 ===== */
.category-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
}

.category-subtotal {
    font-weight: 600;
    color: var(--accent-color);
    font-size: 1rem;
}

/* ===== 엑셀 미리보기 ===== */
.excel-preview {
    overflow-x: auto;
    margin-bottom: 20px;
}

.excel-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

.excel-table th,
.excel-table td {
    padding: 12px 16px;
    text-align: left;
    border: 1px solid var(--border-color);
}

.excel-table thead {
    background: linear-gradient(135deg, var(--accent-color), #805ad5);
}

.excel-table th {
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
}

.excel-table tbody tr:nth-child(even) {
    background: var(--bg-card);
}

.excel-table tbody tr:hover {
    background: rgba(66, 153, 225, 0.1);
}

.excel-table .subtotal-row {
    background: rgba(66, 153, 225, 0.15) !important;
    font-weight: 600;
}

.excel-table .total-row {
    background: linear-gradient(135deg, var(--accent-color), #805ad5) !important;
    color: white;
    font-weight: 700;
}

/* ===== 컬럼 옵션 체크박스 ===== */
.column-options {
    display: flex;
    gap: 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.checkbox-label span {
    user-select: none;
}

/* ===== 미리보기 액션 ===== */
.preview-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ===== 빈 상태 ===== */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 1rem;
    margin-top: 12px;
}

/* ===== 토스트 알림 ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 16px 24px;
    background: var(--success-color);
    color: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    animation: slideIn 0.3s ease;
    z-index: 1000;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ===== 반응형 ===== */
@media (max-width: 768px) {
    .app-container {
        padding: 12px;
    }

    .header {
        padding: 16px 20px;
    }

    .section-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .category-name {
        width: 100%;
    }

    .items-table {
        font-size: 0.8rem;
    }

    .preview-actions {
        flex-direction: column;
    }

    .preview-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ===== 자동 입력 페이지 스타일 ===== */
.back-link {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
}

.back-link:hover {
    text-decoration: underline;
}

/* API 키 입력 */
.api-key-form {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.api-key-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
}

.api-key-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.api-key-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.api-key-hint a {
    color: var(--accent-color);
}

/* 업로드 영역 */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 16px;
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-secondary);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent-color);
    background: rgba(66, 153, 225, 0.05);
}

.upload-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 16px;
}

.upload-area p {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 8px;
}

.upload-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.upload-actions {
    margin-top: 20px;
    text-align: center;
}

/* 이미지 미리보기 */
.image-preview-container {
    text-align: center;
    margin-bottom: 16px;
}

.image-preview {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.image-preview-container .btn-delete {
    margin-top: 12px;
}

/* 로딩 오버레이 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-content {
    background: var(--bg-card);
    padding: 40px 60px;
    border-radius: 20px;
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-content p {
    color: var(--text-primary);
    font-weight: 500;
}

/* ===== 여러 이미지 업로드 스타일 ===== */
.images-preview-container {
    margin-bottom: 16px;
}

.images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.image-thumb {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1;
}

.image-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-remove:hover {
    background: var(--danger-color);
}

.image-count {
    font-size: 0.9rem;
    color: var(--accent-color);
    font-weight: 500;
}

/* ===== 편집 가능한 결과 테이블 ===== */
.excel-table input[type="text"],
.excel-table input[type="number"],
.excel-table select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
}

.excel-table input:focus,
.excel-table select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.excel-table .edit-category,
.excel-table .edit-account {
    min-width: 120px;
}

.excel-table .edit-date {
    width: 80px;
}

.excel-table .edit-quantity {
    width: 60px;
    text-align: center;
}

.excel-table .edit-amount {
    width: 90px;
    text-align: right;
}

.excel-table .edit-payment {
    min-width: 90px;
}

.excel-table .delete-item {
    padding: 4px 8px;
    font-size: 0.9rem;
}

/* ===== 수정하기 버튼 ===== */
.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-edit {
    padding: 8px 16px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.btn-edit:hover {
    background: #8b5cf6;
    transform: translateY(-1px);
}

.btn-edit.btn-active {
    background: #10b981;
}

.btn-edit.btn-active:hover {
    background: #059669;
}

/* ===== 문의하기 버튼 (메인) ===== */
.contact-link {
    margin-top: 32px;
    text-align: center;
}

.btn-contact {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-muted);
    border-radius: 12px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-contact:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    transform: translateY(-2px);
}

/* ===== 문의하기 페이지 ===== */
.contact-hero {
    text-align: center;
    margin-bottom: 24px;
}

.contact-hero h2 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.contact-hero p {
    color: var(--text-muted);
}

.contact-help {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 32px;
    text-align: center;
    margin-bottom: 32px;
    box-shadow: var(--shadow-sm);
}

.contact-help h3 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.contact-help p {
    color: var(--text-muted);
}

.contact-content {
    display: grid;
    grid-template-columns: 1fr 3fr;
    gap: 24px;
    align-items: stretch;
}

@media (max-width: 768px) {
    .contact-content {
        grid-template-columns: 1fr;
    }
}

/* 정보 카드 */
.contact-info {
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
}

.info-card {
    flex: 1;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.info-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.info-icon {
    width: 48px;
    height: 48px;
    background: var(--accent-color);
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto 12px;
}

.info-card h4 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.info-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.info-link {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.info-link:hover {
    text-decoration: underline;
}

.info-text {
    color: var(--accent-color);
    font-weight: 500;
}

/* 문의 폼 */
.contact-form-container {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 32px;
    box-shadow: var(--shadow-sm);
}

.contact-form-container h3 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 24px;
}

.contact-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 500px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-group textarea {
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-color);
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
}

.btn-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    font-size: 1rem;
}

/* 푸터 */
.contact-footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.contact-footer p {
    color: var(--text-muted);
    font-size: 0.9rem;
}