/**
 * erp-purchase.css
 * AutoParts Pro ERP - 구매 관리 모듈 전용 스타일
 * AI 파싱 대시보드 / 단가 히스토리 / 시장 가격 분석
 */

/* ── Page Layout ── */
.purchase-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    align-items: start;
}
.purchase-main { display: flex; flex-direction: column; gap: 1.5rem; }
.purchase-side { display: flex; flex-direction: column; gap: 1.5rem; position: sticky; top: 5rem; }

/* ── Stats Bar ── */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: white; border-radius: 14px; padding: 1.25rem 1.5rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-3px); }
.stat-card .val { font-size: 1.7rem; font-weight: 800; color: #111827; letter-spacing: -0.5px; }
.stat-card .lbl { font-size: 0.78rem; color: #6b7280; font-weight: 500; margin-top: 0.2rem; }
.stat-card .trend { font-size: 0.75rem; font-weight: 600; margin-top: 0.5rem; }
.stat-card .trend.up { color: #ef4444; }
.stat-card .trend.down { color: #10b981; }
.stat-card .trend.neutral { color: #6b7280; }

/* ── Panel Cards ── */
.panel {
    background: white; border-radius: 16px; padding: 1.5rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.panel-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.25rem; padding-bottom: 0.75rem;
    border-bottom: 1px solid #f3f4f6;
}
.panel-title {
    font-size: 1rem; font-weight: 700; color: #111827;
    display: flex; align-items: center; gap: 0.5rem;
}
.panel-title .icon { font-size: 1.2rem; }

/* ── AI Parser Panel ── */
.ai-parser-panel {
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
    border-radius: 16px; padding: 1.75rem;
    color: white; position: relative; overflow: hidden;
}
.ai-parser-panel::before {
    content: ''; position: absolute; top: -30%; right: -10%;
    width: 300px; height: 300px;
    background: radial-gradient(circle, rgba(99,102,241,0.4) 0%, transparent 70%);
    border-radius: 50%;
}
.ai-parser-panel h3 {
    font-size: 1.1rem; font-weight: 700; color: #e0e7ff;
    margin-bottom: 0.5rem; position: relative;
    display: flex; align-items: center; gap: 0.5rem;
}
.ai-parser-panel p { color: #a5b4fc; font-size: 0.85rem; margin-bottom: 1.25rem; position: relative; }

.parse-textarea {
    width: 100%; min-height: 160px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 10px; padding: 0.85rem;
    color: white; font-family: inherit; font-size: 0.85rem;
    resize: vertical; line-height: 1.6; position: relative;
    transition: border-color 0.2s;
}
.parse-textarea::placeholder { color: rgba(255,255,255,0.35); }
.parse-textarea:focus { outline: none; border-color: rgba(99,102,241,0.8); background: rgba(255,255,255,0.12); }

.btn-parse {
    width: 100%; padding: 0.85rem;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white; border: none; border-radius: 10px;
    font-weight: 700; font-size: 0.95rem; cursor: pointer;
    transition: all 0.2s; margin-top: 0.85rem; position: relative;
    box-shadow: 0 4px 15px rgba(99,102,241,0.4);
}
.btn-parse:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(99,102,241,0.5); }
.btn-parse:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* AI Thinking Animation */
.ai-thinking {
    display: none; align-items: center; gap: 0.6rem;
    margin-top: 0.75rem; color: #a5b4fc; font-size: 0.85rem;
}
.ai-thinking.active { display: flex; }
.dot-pulse { display: flex; gap: 0.3rem; }
.dot-pulse span {
    width: 6px; height: 6px; background: #6366f1;
    border-radius: 50%; animation: pulse 1.2s ease-in-out infinite;
}
.dot-pulse span:nth-child(2) { animation-delay: 0.2s; }
.dot-pulse span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 100% { transform: scale(0.6); opacity: 0.4; } 50% { transform: scale(1); opacity: 1; } }

/* ── Review Queue ── */
.review-queue-item {
    border: 1px solid #fde68a; background: #fffbeb;
    border-radius: 10px; padding: 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s;
}
.review-queue-item:hover { border-color: #f59e0b; box-shadow: 0 4px 12px rgba(245,158,11,0.15); }
.review-queue-item .rq-header { display: flex; justify-content: space-between; align-items: flex-start; }
.review-queue-item .rq-vendor { font-weight: 700; font-size: 0.9rem; color: #92400e; }
.review-queue-item .rq-date { font-size: 0.75rem; color: #b45309; }
.review-queue-item .rq-confidence {
    font-size: 0.75rem; font-weight: 700;
    padding: 0.2rem 0.6rem; border-radius: 20px;
    background: #fef3c7; color: #d97706;
}
.review-queue-item .rq-confidence.low { background: #fee2e2; color: #dc2626; }
.review-queue-item .rq-amount { font-size: 1.1rem; font-weight: 800; color: #111827; margin: 0.4rem 0; }
.review-queue-item .rq-actions { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.btn-approve { background: #10b981; color: white; border: none; border-radius: 6px; padding: 0.35rem 0.75rem; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.btn-reject { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; border-radius: 6px; padding: 0.35rem 0.75rem; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.btn-edit-review { background: #6366f1; color: white; border: none; border-radius: 6px; padding: 0.35rem 0.75rem; font-size: 0.8rem; font-weight: 600; cursor: pointer; }

/* ── Parsed Result Card ── */
.parse-result {
    background: white; border: 2px solid #6366f1;
    border-radius: 14px; padding: 1.25rem;
    display: none;
}
.parse-result.active { display: block; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: translateY(0); } }
.parse-result .pr-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1rem;
}
.parse-result .pr-title { font-weight: 700; color: #4f46e5; }
.confidence-badge {
    font-size: 0.75rem; font-weight: 700; padding: 0.2rem 0.7rem; border-radius: 20px;
}
.confidence-badge.high { background: #d1fae5; color: #065f46; }
.confidence-badge.medium { background: #fef3c7; color: #92400e; }
.confidence-badge.low { background: #fee2e2; color: #991b1b; }

.pr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-bottom: 1rem; }
.pr-field label { font-size: 0.72rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em; display: block; margin-bottom: 0.2rem; }
.pr-field input, .pr-field textarea {
    width: 100%; padding: 0.45rem 0.65rem;
    border: 1px solid #e5e7eb; border-radius: 6px;
    font-size: 0.85rem; font-family: inherit;
    transition: border-color 0.2s;
}
.pr-field input:focus, .pr-field textarea:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,0.1); }

/* ── Table Responsiveness ── */
.erp-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.erp-table {
    min-width: 800px;
    width: 100%;
    border-collapse: collapse;
}

.pr-items-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; margin-bottom: 1rem; }
.pr-items-table th { background: #f8fafc; color: #475569; font-weight: 600; padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid #e5e7eb; }
.pr-items-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid #f3f4f6; }
.pr-items-table input { width: 100%; padding: 0.3rem; border: 1px solid #e5e7eb; border-radius: 4px; font-size: 0.82rem; }

.pr-actions { display: flex; gap: 0.75rem; }
.btn-save-invoice { flex: 1; background: #6366f1; color: white; border: none; border-radius: 8px; padding: 0.6rem 1rem; font-weight: 700; font-size: 0.9rem; cursor: pointer; transition: background 0.2s; }
.btn-save-invoice:hover { background: #4f46e5; }
.btn-discard { background: #f3f4f6; color: #6b7280; border: 1px solid #e5e7eb; border-radius: 8px; padding: 0.6rem 1rem; font-weight: 600; font-size: 0.9rem; cursor: pointer; }

/* ── Invoice List Table ── */
.invoice-status-badge {
    display: inline-block; font-size: 0.72rem; font-weight: 700;
    padding: 0.2rem 0.6rem; border-radius: 20px; white-space: nowrap;
}
.badge-received { background: #d1fae5; color: #065f46; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-review { background: #fee2e2; color: #991b1b; }
.badge-transit { background: #dbeafe; color: #1e40af; }

/* ── Chart Container ── */
.chart-wrapper {
    position: relative; height: 280px;
    background: #f9fafb; border-radius: 12px;
    padding: 0.5rem;
}
.chart-wrapper canvas { border-radius: 8px; }

/* ── Cost History ── */
.sku-search-bar {
    display: flex; gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.sku-search-bar input {
    flex: 1; padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb; border-radius: 10px;
    font-size: 0.95rem; transition: border-color 0.2s;
}
.sku-search-bar input:focus { outline: none; border-color: #6366f1; }
.btn-search-sku {
    background: #6366f1; color: white; border: none;
    border-radius: 10px; padding: 0.75rem 1.5rem;
    font-weight: 700; font-size: 0.95rem; cursor: pointer;
    transition: background 0.2s;
}
.btn-search-sku:hover { background: #4f46e5; }

.price-kpi-row {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
    margin-bottom: 1.5rem;
}
.price-kpi {
    text-align: center; padding: 1rem;
    background: white; border-radius: 12px; border: 1px solid #e5e7eb;
}
.price-kpi .val { font-size: 1.5rem; font-weight: 800; }
.price-kpi .lbl { font-size: 0.75rem; color: #6b7280; margin-top: 0.25rem; }
.price-kpi.lowest .val { color: #10b981; }
.price-kpi.avg .val { color: #3b82f6; }
.price-kpi.highest .val { color: #ef4444; }

/* ── Market Analyzer ── */
.action-item-badge {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.85rem 1rem; border-radius: 10px;
    margin-bottom: 0.6rem; font-size: 0.875rem; font-weight: 500;
}
.action-item-badge.warning {
    background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
}
.action-item-badge.danger {
    background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
}
.action-item-badge.success {
    background: #f0fdf4; border: 1px solid #bbf7d0; color: #14532d;
}
.action-item-badge .ai-icon { font-size: 1.2rem; }

.margin-slider-row { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
.margin-slider { flex: 1; -webkit-appearance: none; height: 6px; border-radius: 3px; background: #e5e7eb; }
.margin-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 18px; height: 18px;
    background: #6366f1; border-radius: 50%; cursor: pointer; box-shadow: 0 2px 6px rgba(99,102,241,0.4);
}
.margin-display { font-size: 1.2rem; font-weight: 800; color: #6366f1; min-width: 60px; text-align: right; }

/* ── Alert Notification Banner ── */
.alert-banner {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white; border-radius: 12px; padding: 1rem 1.25rem;
    display: flex; align-items: center; gap: 0.75rem;
    margin-bottom: 1rem; animation: slideIn 0.3s ease;
}
.alert-banner.warning { background: linear-gradient(135deg, #d97706, #b45309); }
.alert-banner.info { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.alert-banner p { margin: 0; font-size: 0.875rem; }
.alert-banner strong { font-weight: 700; }

/* ── Gmail Connect ── */
.gmail-connect-card {
    background: white; border: 2px dashed #d1d5db;
    border-radius: 14px; padding: 1.5rem; text-align: center;
}
.gmail-connect-card h4 { color: #374151; margin-bottom: 0.5rem; }
.gmail-connect-card p { color: #6b7280; font-size: 0.85rem; margin-bottom: 1rem; }
.btn-connect-gmail {
    background: white; border: 2px solid #e5e7eb; border-radius: 10px;
    padding: 0.65rem 1.25rem; font-weight: 600; font-size: 0.9rem;
    cursor: pointer; display: inline-flex; align-items: center; gap: 0.5rem;
    transition: all 0.2s; color: #374151;
}
.btn-connect-gmail:hover { border-color: #6366f1; color: #4f46e5; background: #f5f3ff; }
.btn-connect-gmail.connected { background: #f0fdf4; border-color: #10b981; color: #065f46; }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .purchase-layout { display: flex; flex-direction: column-reverse; gap: 1rem; }
    .purchase-side { position: relative; top: 0; width: 100%; }
    .purchase-main { width: 100%; overflow: hidden; }
    
    .stats-bar { grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem; }
    .stat-card { padding: 1rem; border-radius: 10px; }
    .stat-card .val { font-size: 1.4rem; }
    .price-kpi-row { grid-template-columns: 1fr 1fr; }
    
    .mobile-accordion summary { 
        display: block; padding: 0.85rem 1.25rem; 
        background: #f8fafc; border: 1px solid #cbd5e1; 
        border-radius: 10px; font-weight: 700; cursor: pointer; 
        color: #1e293b; font-size: 0.95rem; margin-bottom: 0.5rem;
    }
    .mobile-accordion[open] summary { background: #6366f1; color: white; border-color: #6366f1; }
    .mobile-accordion > .panel, .mobile-accordion > .ai-parser-panel, .mobile-accordion > .gmail-panel {
        margin-top: 0.5rem;
    }
}

@media (min-width: 1025px) {
    .mobile-accordion summary { display: none; }
}

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .erp-header h1 { font-size: 1.3rem; }
    .erp-header p { font-size: 0.8rem; }
    
    .stats-bar { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
    .stat-card { padding: 0.75rem; border-radius: 8px; }
    .stat-card .val { font-size: 1.2rem; }
    .stat-card .lbl { font-size: 0.65rem; }
    .stat-card .trend { font-size: 0.65rem; margin-top: 0.2rem; }
    
    .panel-header { flex-direction: column; align-items: flex-start; gap: 0.3rem; padding-bottom: 0.5rem; margin-bottom: 0.5rem; }
    .panel-header > div { width: 100%; flex-direction: column; align-items: stretch; gap: 0.3rem; }
    #invoiceSearch, #invoiceStatusFilter { width: 100% !important; margin-top: 2px; }
    .panel { padding: 0.5rem; border-radius: 8px; }
    
    .erp-table { min-width: auto !important; width: 100%; }
    .erp-table th, .erp-table td { padding: 0.4rem; font-size: 0.75rem; }
    .erp-table th { white-space: nowrap; }
    .invoice-status-badge { padding: 0.15rem 0.4rem; font-size: 0.65rem; }
}