/* === 버튼 (Pill-shaped) === */
.btn-primary { 
    background: #4f46e5 !important; 
    color: white !important; 
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2) !important; 
    border-radius: 999px !important;
}

.m-btn-primary { 
    background: #4f46e5 !important; 
    color: white !important; 
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2) !important; 
    border-radius: 999px !important;
}

:root {
    --bg-main: #f9fafb;       
    --bg-surface: #ffffff;    
    --brand-primary: #4f46e5; 
    --brand-hover: #4338ca;   
    --brand-light: #e0e7ff;   
    
    --text-main: #111827;     
    --text-sub: #4b5563;      
    --text-muted: #9ca3af;    
    --border: #e5e7eb;        
    
    --danger: #ef4444; --danger-bg: #fef2f2;
    --success: #10b981; --success-bg: #ecfdf5;
    --warning: #f59e0b;
    
    --brand-shadow: rgba(79, 70, 229, 0.2);
    --node-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --node-shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --modal-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Pretendard', sans-serif; }
body { display: flex; height: 100vh; background: var(--bg-main); color: var(--text-main); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { outline: none; border: none; font-family: inherit; }
svg.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* === 로그인 화면 === */
#login-screen { position: fixed; inset: 0; background: var(--bg-main); z-index: 9999; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.login-card { background: var(--bg-surface); padding: 48px 40px; border-radius: 24px; box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05); border: 1px solid var(--border); width: 420px; text-align: center; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 28px; font-weight: 800; color: var(--text-main); margin-bottom: 8px; letter-spacing: -0.5px; }

.login-form { text-align: left; margin-top: 24px; }
.login-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 8px; }
.login-input { width: 100%; height: 48px; border: 1px solid var(--border); border-radius: 12px; font-size: 15px; margin-bottom: 24px; transition: 0.2s; background: #f9fafb; padding: 0 16px; }
.login-input:focus { border-color: var(--brand-primary); background: white; box-shadow: 0 0 0 3px var(--brand-light); }
.login-btn { width: 100%; height: 52px; border-radius: 12px; font-size: 15px; font-weight: 700; cursor: pointer; border: none; background: var(--brand-primary); color: white; transition: 0.2s; box-shadow: 0 4px 12px var(--brand-shadow);}
.login-btn:hover { background: var(--brand-hover); transform: translateY(-1px); }
.login-help { font-size: 12px; color: var(--text-muted); margin-top: 16px; }

/* === App Layout === */
#app-container { display: none; width: 100%; height: 100%; }

.sidebar { width: 260px; background: var(--bg-surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 24px 16px; z-index: 50; flex-shrink: 0;}
.logo { font-size: 20px; font-weight: 800; color: var(--text-main); display: flex; align-items: center; gap: 10px; margin-bottom: 32px; padding-left: 8px; letter-spacing: -0.5px;}
.nav-section { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin: 24px 0 8px 12px; letter-spacing: 0.5px; }
.nav-item { padding: 12px 14px; border-radius: 8px; color: var(--text-sub); font-weight: 600; font-size: 14px; cursor: pointer; display: flex; align-items: center; gap: 12px; transition: all 0.1s; margin-bottom: 2px; }
.nav-item:hover { background: #f3f4f6; color: var(--text-main); }
.nav-item.active { background: var(--text-main); color: white; }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-main); }
.view { display: none; height: 100%; flex-direction: column; animation: fadeIn 0.3s ease; }
.view.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.standard-header { padding: 20px 40px; border-bottom: 1px solid var(--border); background: var(--bg-surface); min-height: 80px; display: flex; justify-content: space-between; align-items: center; }
.header-title { font-size: 22px; font-weight: 800; color: var(--text-main); }
.user-profile { display: flex; align-items: center; gap: 16px; }
.user-info { text-align: right; }
.user-name { font-size: 14px; font-weight: 700; color: var(--text-main); }
.user-role { font-size: 12px; color: var(--text-muted); }
.avatar { width: 40px; height: 40px; background: linear-gradient(135deg, var(--brand-primary), #818cf8); border-radius: 50%; color: white; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px;}
.logout-btn { background: white; border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text-sub); transition: 0.2s; box-shadow: var(--shadow-sm);}
.logout-btn:hover { background: #f3f4f6; color: var(--danger); }

.standard-body { flex: 1; padding: 40px; overflow-y: auto; background: var(--bg-main); display: flex; flex-direction: column; align-items: center; }
.content-wrapper { width: 100%; max-width: 1200px; margin: 0 auto; }
.card { background: white; border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow-sm); margin-bottom: 24px; width: 100%; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 18px; font-weight: 700; margin: 0;}

.filter-bar { 
    background: #ffffff; 
    padding: 12px 20px; 
    border-radius: 12px; 
    border: 1px solid var(--border); 
    margin-bottom: 24px; 
    display: flex; 
    gap: 16px; 
    align-items: center; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); 
}
.filter-item { 
    height: 48px; 
    border: 1px solid var(--border) !important; 
    border-radius: 10px; 
    padding: 0 16px; 
    font-size: 14px; 
    font-weight: 500; 
    color: var(--text-main) !important; 
    background: #ffffff !important; 
    transition: all 0.2s; 
    outline: none;
}
.filter-item:hover { border-color: #cbd5e1; }
.filter-item:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 3px var(--brand-light); background: white; }
select.filter-item { cursor: pointer; min-width: 140px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; background-size: 18px; padding-right: 40px; }
input.filter-item { flex: 1; }

.btn { height: 48px; padding: 0 24px; border-radius: 12px; font-size: 14px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: 0.2s; border: none; }
.btn-primary { background: var(--brand-primary) !important; color: white !important; box-shadow: 0 4px 12px var(--brand-shadow) !important; }
.btn-primary:hover { background: var(--brand-hover); transform: translateY(-1px); }
.btn-outline { background: white; border: 1px solid var(--border); color: var(--text-sub); }
.btn-outline:hover { background: #f9fafb; border-color: var(--brand-primary); color: var(--brand-primary); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-radius: 12px; }
.btn-danger:hover { background: #fee2e2; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.pass { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--danger-bg); color: var(--danger); }
.badge.pending { background: #fffbeb; color: #d97706; }
.badge.reject { background: #f3f4f6; color: var(--text-muted); }

/* Table Refinement */
table { width: 100%; border-collapse: collapse; font-size: 14px; border: none; }
th, td { padding: 16px 20px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; transition: background 0.1s ease; border-top: none; }
th { font-weight: 700; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; background: #fcfcfd; border-bottom: 1px solid var(--border); text-align: center; }
tr:hover td { background-color: #f8fafc; }
tr:last-child td { border-bottom: none; }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; justify-content: center; background: #fafafa; border-radius: 12px; border: 2px dashed #cbd5e1; margin: 20px 0; }
.empty-state svg { width: 56px; height: 56px; color: #cbd5e1; margin-bottom: 16px; }
.empty-state-title { font-size: 16px; font-weight: 700; color: var(--text-main); margin-bottom: 8px; }
.empty-state-desc { font-size: 14px; color: var(--text-sub); }

/* --- Workflow Editor Specific --- */
.wf-topbar { height: 64px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0 24px; background: var(--bg-surface); flex-shrink: 0; }
.wf-title-area { display: flex; align-items: center; gap: 12px; }
.wf-title { font-size: 18px; font-weight: 700; color: var(--text-main); }
.wf-badge { font-size: 11px; font-weight: 600; background: #f3f4f6; color: var(--text-sub); padding: 4px 8px; border-radius: 12px; border: 1px solid var(--border); }
.wf-actions { display: flex; gap: 12px; }

.editor-container { flex: 1; display: flex; overflow: hidden; height: calc(100vh - 145px); }
.panel-left { width: 300px; background: var(--bg-surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; padding: 24px; }
.panel-title { font-size: 14px; font-weight: 700; color: var(--text-muted); display: flex; align-items: center; gap: 8px; margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.5px; }
.config-card { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 16px; overflow: hidden; }
.config-header { background: #f9fafb; padding: 12px 16px; font-size: 12px; font-weight: 700; color: var(--text-sub); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.config-body { padding: 16px; background: white; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-sub); margin-bottom: 8px; }
.form-input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; margin-bottom: 12px; background: #f9fafb; }
.form-input:focus { border-color: var(--brand-primary); background: white; outline: none; }

.panel-center { flex: 1; background-color: var(--bg-main); background-image: radial-gradient(#d1d5db 1px, transparent 1px); background-size: 20px 20px; position: relative; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 60px 0; gap: 50px; }
.node-vertical { width: 320px; background: white; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--node-shadow); padding: 16px; position: relative; cursor: pointer; transition: 0.2s; z-index: 10; }
.node-vertical:hover { box-shadow: var(--node-shadow-hover); border-color: #cbd5e1; transform: translateY(-2px); }
.node-vertical.selected { border-color: var(--brand-primary); box-shadow: 0 0 0 1px var(--brand-primary), var(--node-shadow); }

.nv-header { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.nv-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--text-main); margin-bottom: 8px; }
.nv-icon-box { width: 24px; height: 24px; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: white; }
.nv-desc { font-size: 12px; color: var(--text-sub); line-height: 1.5; background: #f9fafb; padding: 10px; border-radius: 6px; border: 1px solid #f3f4f6; }

.v-line { position: absolute; width: 2px; height: 50px; background: #cbd5e1; top: -50px; left: 50%; transform: translateX(-50%); z-index: 1; }
.v-line::after { content: ''; position: absolute; bottom: -2px; left: -4px; border-width: 6px 5px 0 5px; border-style: solid; border-color: #cbd5e1 transparent transparent transparent; }

.panel-right { width: 280px; background: var(--bg-surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; padding: 24px; }
.palette-group { margin-bottom: 24px; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--text-sub); cursor: grab; transition: 0.1s; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
.palette-item:hover { border-color: var(--brand-primary); color: var(--brand-primary); background: #f8fafc; }
.pi-dot { width: 8px; height: 8px; border-radius: 50%; }

/* Modals & Toasts */
.modal { 
    display: none; 
    position: fixed; 
    inset: 0; 
    background: rgba(17, 24, 39, 0.6); 
    z-index: 1000; 
    align-items: flex-start; /* Ensure modal starts from top when long */
    justify-content: center; 
    backdrop-filter: blur(8px); 
    opacity: 0; 
    transition: opacity 0.2s; 
    overflow-y: auto; /* Enable container-level scrolling */
    padding: 60px 20px;
}
.modal.show { display: flex; opacity: 1; }

/* === Simplified White Modal (Reference: Car Booking Style) === */
.modal-content { 
    background: #ffffff; 
    border-radius: 12px; 
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); 
    width: 100%; 
    max-width: 440px; 
    overflow: hidden; 
    transform: scale(0.98); 
    transition: transform 0.2s ease-out; 
}
.modal.show .modal-content { transform: scale(1); }

.m-header { 
    height: 56px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    border-bottom: 1px solid #f3f4f6; 
    position: relative; 
    padding: 0 16px;
}
.m-title { font-size: 16px; font-weight: 700; color: #111827; }
.m-close { position: absolute; right: 16px; top: 16px; color: #6b7280; cursor: pointer; transition: 0.1s; }
.m-close:hover { color: #111827; }

.m-body { padding: 0; }
.m-hero { padding: 32px 24px; text-align: center; }
.m-hero-title { font-size: 18px; font-weight: 800; margin-bottom: 4px; color: #111827; }
.m-hero-subtitle { font-size: 12px; color: var(--brand-primary); font-weight: 600; margin-bottom: 16px; }
.m-hero-img-box { width: 100%; display: flex; justify-content: center; margin-top: 8px; }
.m-hero-img { width: 220px; height: 120px; background: #f9fafb; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #9ca3af; }

.m-section { padding: 20px 24px; border-top: 1px solid #f3f4f6; }
.m-section-title { font-size: 14px; font-weight: 700; color: #111827; margin-bottom: 16px; }

.m-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 14px; }
.m-row:last-child { margin-bottom: 0; }
.m-label { color: #6b7280; font-weight: 500; }
.m-value { color: #111827; font-weight: 600; text-align: right; }

.m-footer { padding: 0 24px 24px 24px; }
.m-btn-primary { 
    width: 100%; 
    height: 52px; 
    background: var(--brand-primary) !important; 
    color: #fff !important; 
    border-radius: 12px; 
    font-size: 16px; 
    font-weight: 700; 
    cursor: pointer; 
    border: none; 
    transition: all 0.2s; 
    box-shadow: 0 4px 12px var(--brand-shadow) !important;
}
.m-btn-primary:hover { background: var(--brand-hover); transform: translateY(-1px); }

/* AI Specific Overlay in Modal */
.ai-status-overlay { 
    margin: 16px 24px; 
    padding: 16px; 
    border-radius: 8px; 
    font-size: 13px; 
    display: flex; 
    gap: 12px; 
    align-items: flex-start;
}
.ai-status-overlay.pending { background: #fffbeb; border: 1px solid #fef3c7; color: #92400e; }
.ai-status-overlay.success { background: #f0fdf4; border: 1px solid #dcfce7; color: #166534; }
.ai-status-overlay.danger { background: #fef2f2; border: 1px solid #fee2e2; color: #991b1b; }

.toast { position: fixed; bottom: -100px; left: 50%; transform: translateX(-50%); background: #1f2937; color: white; padding: 14px 28px; border-radius: 30px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 2000; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.toast.show { bottom: 40px; }

/* 모던 드롭존 */
.modern-dropzone { border: 1px dashed var(--border); border-radius: 8px; padding: 32px 24px; text-align: center; background: #ffffff; cursor: pointer; transition: all 0.2s ease; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.modern-dropzone:hover { border-color: var(--brand-primary); background: #f8fafc; }
.modern-upload-icon { width: 36px; height: 36px; background: white; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); display: flex; align-items: center; justify-content: center; margin-bottom: 12px; color: var(--text-sub); }
.inline-progress-container { display: none; border: 1px solid var(--border); border-radius: 8px; padding: 16px; background: #ffffff; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); margin-top: 16px; }
.inline-progress-container.active { display: block; }
.progress-track { width: 100%; height: 6px; background: #f3f4f6; border-radius: 3px; overflow: hidden; margin-top: 12px; }
.progress-fill { height: 100%; background: var(--brand-primary); width: 0%; transition: width 0.1s linear; border-radius: 3px; }
/* Receipt Form Enhancement */
.m-amount-large { font-size: 42px; font-weight: 800; color: var(--brand-primary); letter-spacing: -2px; width: 100%; border-bottom: 2px solid var(--border); padding: 8px 0; margin-bottom: 16px; transition: border-color 0.2s; }
.m-amount-large:focus { border-color: var(--brand-primary); }

.tag-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag-item { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); background: white; font-size: 13px; font-weight: 600; color: var(--text-sub); cursor: pointer; transition: 0.2s; }
.tag-item:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.tag-item.active { background: var(--brand-light); border-color: var(--brand-primary); color: var(--brand-primary); }

.m-label-top { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 8px; display: block; }

.m-textarea { width: 100%; min-height: 100px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); font-size: 14px; line-height: 1.5; resize: none; transition: 0.2s; background: #fcfcfd; }
.m-textarea:focus { border-color: var(--brand-primary); background: white; box-shadow: 0 0 0 3px var(--brand-light); }

.ai-badge-header { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--brand-light); color: var(--brand-primary); border-radius: 20px; font-size: 11px; font-weight: 700; margin-left: auto; }

/* Responsive adjustments */
@media (max-width: 768px) {
    .modal-content { width: 95%; height: auto; padding: 20px; }
    .m-amount-large { font-size: 32px; }
}

/* --- 앱 내 영수증 저장소 (Inbox) 스타일 --- */
.receipt-thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 16px;
    padding: 16px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.receipt-thumb-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: 0.2s;
    background: white;
    cursor: default;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.receipt-thumb-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.receipt-thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.receipt-thumb-item.processing {
    border-color: var(--brand-primary);
}

.receipt-thumb-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(0,0,0,0.5);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: 0.2s;
}

.receipt-thumb-item:hover .receipt-thumb-remove {
    opacity: 1;
}

.receipt-thumb-status {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(17, 24, 39, 0.7);
    color: white;
    font-size: 10px;
    padding: 4px;
    text-align: center;
    font-weight: 600;
}

/* 결과 테이블 이미지 미리보기 클릭 유도 스타일 */
tbody#matching-body tr {
    cursor: pointer;
}

tbody#matching-body tr:hover td {
    background: #f1f5f9;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.animate-spin {
    animation: spin 1s linear infinite;
}
