/* ===== MVC — Modern Dark Theme ===== */

/* --- Animations --- */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.3); }
    50% { box-shadow: 0 0 20px 4px rgba(99,102,241,0.15); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.animate-fade-in {
    animation: fade-in 0.6s ease-out both;
}
.animate-fade-in-up {
    animation: fade-in-up 0.6s ease-out both;
    animation-delay: 0.15s;
}

/* --- Navigation --- */
.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #94a3b8;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}
.nav-btn:hover {
    color: #e2e8f0;
    background: rgba(255,255,255,0.05);
}
.nav-btn.active {
    color: #fff;
    background: rgba(99,102,241,0.12);
}
.nav-btn.active i {
    color: #818cf8;
}

/* --- Feature Cards (Hero) --- */
.feature-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding: 1.5rem;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}
.feature-card:hover {
    background: #253347;
    border-color: rgba(99,102,241,0.2);
    transform: translateY(-2px);
}
.feature-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    font-size: 1rem;
    transition: background 0.2s ease;
}

/* --- Cards --- */
.card {
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 1rem;
    padding: 1.5rem;
}

/* --- Search Bar --- */
.search-bar {
    display: flex;
    align-items: center;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 1rem;
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search-bar:focus-within {
    border-color: rgba(99,102,241,0.5);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

/* --- Input Fields --- */
.input-field {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 0.5rem;
    color: #e2e8f0;
    font-size: 0.875rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
}
.input-field:focus {
    border-color: rgba(99,102,241,0.5);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}
.input-field::placeholder {
    color: #475569;
}

.field-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: #94a3b8;
    margin-bottom: 0.375rem;
}

/* --- Buttons --- */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    background: #4f46e5;
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.btn-primary:hover {
    background: #4338ca;
}
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    background: rgba(255,255,255,0.06);
    color: #cbd5e1;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.btn-secondary:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}
.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    background: transparent;
    color: #94a3b8;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.btn-ghost:hover {
    background: rgba(255,255,255,0.05);
    color: #e2e8f0;
}
.btn-ghost:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Status Badges --- */
.status-verified {
    background: rgba(16,185,129,0.1);
    border: 1px solid rgba(16,185,129,0.2);
    color: #6ee7b7;
}
.status-conflict {
    background: rgba(245,158,11,0.1);
    border: 1px solid rgba(245,158,11,0.2);
    color: #fcd34d;
}
.status-error {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    color: #fca5a5;
}
.status-pending {
    background: rgba(148,163,184,0.1);
    border: 1px solid rgba(148,163,184,0.15);
    color: #94a3b8;
}

/* --- Result Cards --- */
.result-card {
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 0.75rem;
    padding: 1.25rem;
}
.result-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #fff;
}
.result-label {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.25rem;
}

/* --- Source Items --- */
.source-item {
    padding: 0.875rem 1rem;
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 0.75rem;
    transition: border-color 0.15s ease;
}
.source-item.confirmed {
    border-color: rgba(16,185,129,0.3);
    background: rgba(16,185,129,0.04);
}

/* --- Cache Badge --- */
.cache-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    background: rgba(16,185,129,0.08);
    color: #6ee7b7;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    border: 1px solid rgba(16,185,129,0.15);
}

/* --- Search History --- */
.history-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: rgba(255,255,255,0.04);
    color: #94a3b8;
    font-size: 0.8125rem;
    border-radius: 9999px;
    border: 1px solid rgba(255,255,255,0.06);
    cursor: pointer;
    transition: all 0.15s ease;
}
.history-item:hover {
    background: rgba(255,255,255,0.08);
    color: #e2e8f0;
    border-color: rgba(255,255,255,0.12);
}
.history-status {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 9999px;
    flex-shrink: 0;
}
.history-status.verified { background: #10b981; }
.history-status.conflict { background: #f59e0b; }
.history-status.unknown { background: #64748b; }
.history-weight {
    font-size: 0.6875rem;
    color: #64748b;
}

/* --- Settings Panel --- */
.settings-group {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.settings-group:last-of-type {
    border-bottom: none;
}
.settings-group-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #e2e8f0;
    margin-bottom: 0.75rem;
}

/* --- Top Loading Bar --- */
.top-loader {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #4f46e5, #818cf8, #4f46e5);
    background-size: 200% 100%;
    animation: shimmer 1s linear infinite;
    z-index: 100;
    transition: width 0.3s ease, opacity 0.3s ease;
    border-radius: 0 2px 2px 0;
}

/* --- Keyboard Shortcut Hint --- */
.kbd-hint {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.375rem;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 0.25rem;
    font-family: monospace;
    font-size: 0.625rem;
    color: #64748b;
    line-height: 1;
}

/* --- Toast Notifications --- */
.toast {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transform: translateX(0);
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    overflow: hidden;
    position: relative;
}
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: rgba(255,255,255,0.3);
    transition: width linear;
}
.toast-success {
    background: rgba(16,185,129,0.9);
    color: #fff;
}
.toast-error {
    background: rgba(239,68,68,0.9);
    color: #fff;
}
.toast-warning {
    background: rgba(245,158,11,0.9);
    color: #fff;
}
.toast-info {
    background: rgba(99,102,241,0.9);
    color: #fff;
}

/* --- Tab transition --- */
.tab-content {
    transition: opacity 0.2s ease;
}

/* --- Spinner --- */
.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* --- Drop Zone --- */
.drop-zone {
    position: relative;
    border: 2px dashed rgba(255,255,255,0.08);
    border-radius: 1rem;
    padding: 2rem;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
}
.drop-zone:hover {
    border-color: rgba(99,102,241,0.3);
    background: rgba(99,102,241,0.02);
}
.drop-zone.dragover {
    border-color: rgba(99,102,241,0.5);
    background: rgba(99,102,241,0.05);
    transform: scale(1.01);
}
.drop-zone-icon {
    font-size: 2rem;
    color: #4f46e5;
    margin-bottom: 0.75rem;
    opacity: 0.6;
}
.drop-zone-text {
    font-size: 0.875rem;
    color: #94a3b8;
}
.drop-zone-hint {
    font-size: 0.75rem;
    color: #475569;
    margin-top: 0.5rem;
}

/* --- Sortable Column --- */
.sortable-th {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s ease;
}
.sortable-th:hover {
    color: #e2e8f0;
}
.sort-icon {
    font-size: 0.625rem;
    opacity: 0.4;
    margin-left: 0.25rem;
    transition: opacity 0.15s ease;
}
.sortable-th.active .sort-icon {
    opacity: 1;
    color: #818cf8;
}

/* --- Summary Row --- */
.summary-row td {
    padding: 0.75rem 1rem !important;
    font-weight: 600;
    color: #e2e8f0 !important;
    border-top: 1px solid rgba(255,255,255,0.08);
    background: rgba(99,102,241,0.04);
}

/* --- Search Toggles --- */
.search-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.625rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1.5px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.03);
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}
.search-toggle-icon {
    font-size: 0.75rem;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}
.search-toggle-check {
    font-size: 0.625rem;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s ease;
    margin-left: -0.125rem;
}
.search-toggle:hover {
    border-color: rgba(99,102,241,0.3);
    background: rgba(99,102,241,0.05);
    color: #94a3b8;
}
.search-toggle:hover .search-toggle-icon {
    opacity: 0.8;
}
.search-toggle.active {
    background: rgba(99,102,241,0.12);
    border-color: rgba(99,102,241,0.45);
    color: #c7d2fe;
    box-shadow: 0 0 12px rgba(99,102,241,0.08);
}
.search-toggle.active .search-toggle-icon {
    color: #818cf8;
    opacity: 1;
}
.search-toggle.active .search-toggle-check {
    opacity: 1;
    transform: scale(1);
    color: #34d399;
}

/* --- Batch Table --- */
#batch-tbody tr {
    transition: background 0.15s ease;
}
#batch-tbody tr:hover {
    background: rgba(255,255,255,0.03);
}
#batch-tbody td {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    color: #cbd5e1;
}

/* --- Shortlist Table --- */
#shortlist-tbody tr {
    transition: background 0.15s ease;
}
#shortlist-tbody tr:hover {
    background: rgba(255,255,255,0.03);
}
#shortlist-tbody td {
    font-size: 0.8125rem;
    color: #cbd5e1;
}

/* --- Waterfall (Price breakdown) --- */
.waterfall-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.8125rem;
    color: #94a3b8;
}
.waterfall-row .bar {
    height: 4px;
    border-radius: 2px;
    flex: 1;
    margin: 0 0.75rem;
    background: rgba(255,255,255,0.05);
    overflow: hidden;
}
.waterfall-row .bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease;
}
.waterfall-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    margin-top: 0.5rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-weight: 700;
    color: #fff;
    font-size: 0.9375rem;
}

/* --- Skeleton Loader --- */
@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.skeleton {
    background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
    background-size: 800px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 0.5rem;
}
.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
}
.skeleton-text.sm { height: 0.75rem; }
.skeleton-text.lg { height: 1.5rem; width: 60%; }
.skeleton-card {
    padding: 1.25rem;
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 0.75rem;
}

/* --- Confidence Bar --- */
.confidence-bar {
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.confidence-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s ease;
}
.confidence-high { background: #10b981; }
.confidence-mid { background: #f59e0b; }
.confidence-low { background: #ef4444; }

/* --- Source Card Expand --- */
.source-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}
.source-details.open {
    max-height: 200px;
    opacity: 1;
}
.source-item {
    cursor: pointer;
}
.source-toggle {
    transition: transform 0.2s ease;
}
.source-toggle.open {
    transform: rotate(180deg);
}

/* --- KB Badge --- */
.kb-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.6rem;
    background: rgba(139,92,246,0.1);
    color: #a78bfa;
    font-size: 0.6875rem;
    font-weight: 600;
    border-radius: 9999px;
    border: 1px solid rgba(139,92,246,0.2);
}

/* --- Add to Shortlist Button --- */
.btn-shortlist {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: rgba(99,102,241,0.1);
    color: #a5b4fc;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 1px solid rgba(99,102,241,0.2);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-shortlist:hover {
    background: rgba(99,102,241,0.2);
    border-color: rgba(99,102,241,0.3);
}

/* --- Use in Calc Button --- */
.btn-use-calc {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: rgba(245,158,11,0.1);
    color: #fbbf24;
    font-size: 0.8125rem;
    font-weight: 600;
    border: 1px solid rgba(245,158,11,0.2);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-use-calc:hover {
    background: rgba(245,158,11,0.2);
    border-color: rgba(245,158,11,0.3);
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}
.empty-state-icon {
    width: 5rem;
    height: 5rem;
    margin: 0 auto 1.5rem;
    background: rgba(99,102,241,0.06);
    border: 1px solid rgba(99,102,241,0.1);
    border-radius: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: #6366f1;
}
.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #e2e8f0;
    margin-bottom: 0.5rem;
}
.empty-state-text {
    font-size: 0.875rem;
    color: #64748b;
    max-width: 24rem;
    margin: 0 auto;
    line-height: 1.5;
}

/* --- Pallet Diagram --- */
.pallet-diagram {
    position: relative;
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-top: 1rem;
}
.pallet-grid {
    display: grid;
    gap: 2px;
    margin: 0 auto;
    max-width: 200px;
    aspect-ratio: 1.5 / 1;
}
.pallet-box {
    background: rgba(99,102,241,0.2);
    border: 1px solid rgba(99,102,241,0.3);
    border-radius: 2px;
    transition: all 0.2s ease;
    min-height: 8px;
}
.pallet-box.filled {
    background: rgba(99,102,241,0.35);
    border-color: rgba(99,102,241,0.5);
}
.pallet-label {
    text-align: center;
    font-size: 0.6875rem;
    color: #64748b;
    margin-top: 0.5rem;
}

/* --- Live calc indicator --- */
.calc-auto-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    background: rgba(16,185,129,0.08);
    color: #6ee7b7;
    font-size: 0.625rem;
    font-weight: 600;
    border-radius: 9999px;
    border: 1px solid rgba(16,185,129,0.15);
}

/* --- Stacked Bar --- */
.stacked-bar {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: rgba(255,255,255,0.04);
}
.stacked-bar-segment {
    height: 100%;
    transition: width 0.4s ease;
}

/* --- Quick Search Buttons --- */
.quick-search-btn {
    padding: 0.375rem 0.875rem;
    background: rgba(255,255,255,0.04);
    color: #94a3b8;
    font-size: 0.8125rem;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.quick-search-btn:hover {
    background: rgba(99,102,241,0.1);
    color: #a5b4fc;
    border-color: rgba(99,102,241,0.2);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

/* --- Selection --- */
::selection {
    background: rgba(99,102,241,0.3);
    color: #fff;
}

/* --- Responsive --- */
@media (max-width: 640px) {
    .search-bar {
        flex-wrap: wrap;
    }
    .search-bar input {
        width: 100%;
        padding: 0.875rem 1rem;
        font-size: 1rem;
    }
    .search-bar .btn-primary {
        width: 100%;
        margin: 0.5rem;
        padding: 0.75rem;
    }
    .search-bar > i:first-child {
        display: none;
    }
}

/* --- Batch Chat (Clarification) --- */
.chat-msg {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    animation: fade-in-up 0.3s ease-out both;
}
.chat-msg-system { align-self: flex-start; }
.chat-msg-user { align-self: flex-end; margin-left: auto; flex-direction: row-reverse; }

.chat-bubble {
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.5;
}
.chat-bubble-system {
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.05);
    color: #cbd5e1;
}
.chat-bubble-user {
    background: rgba(99,102,241,0.15);
    border: 1px solid rgba(99,102,241,0.2);
    color: #e2e8f0;
}

.chat-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
}
.chat-avatar-bot { background: rgba(99,102,241,0.1); color: #818cf8; }
.chat-avatar-user { background: rgba(16,185,129,0.1); color: #6ee7b7; }

.chat-items-list {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(255,255,255,0.03);
    border-radius: 0.5rem;
    font-family: monospace;
    font-size: 0.75rem;
    color: #94a3b8;
    max-height: 6rem;
    overflow-y: auto;
}

.chat-suggestion-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.5rem;
}
.chat-suggestion-btn {
    padding: 0.25rem 0.625rem;
    background: rgba(99,102,241,0.08);
    color: #a5b4fc;
    font-size: 0.75rem;
    border: 1px solid rgba(99,102,241,0.15);
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.chat-suggestion-btn:hover {
    background: rgba(99,102,241,0.2);
    border-color: rgba(99,102,241,0.3);
}

.chat-searching {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
    font-size: 0.75rem;
}
