/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 32px;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 4px;
}

.subtitle {
    color: var(--gray-500);
    font-size: 1rem;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    padding: 8px 16px;
    background: white;
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gray-400);
    animation: pulse 2s infinite;
}

.status-dot.online {
    background: var(--success);
}

.status-dot.offline {
    background: var(--danger);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Cards */
.card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--gray-900);
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: var(--gray-50);
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--gray-400);
    margin-bottom: 16px;
}

.upload-area .link {
    color: var(--primary);
    font-weight: 500;
}

.upload-hint {
    font-size: 0.875rem;
    color: var(--gray-400);
    margin-top: 8px;
}

/* Model Selector */
.model-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.model-selector label {
    font-weight: 500;
    color: var(--gray-600);
}

.model-selector select {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.875rem;
    background: white;
    cursor: pointer;
}

/* File Queue */
.queue {
    margin-top: 16px;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--gray-50);
    border-radius: 8px;
    margin-bottom: 8px;
}

.queue-item-preview {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--gray-200);
}

.queue-item-info {
    flex: 1;
}

.queue-item-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--gray-800);
}

.queue-item-size {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.queue-item-remove {
    padding: 4px 8px;
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    font-size: 1.25rem;
}

.queue-item-remove:hover {
    color: var(--danger);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
    margin-top: 16px;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.875rem;
}

.spinner {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

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

/* Results */
.results-container {
    display: grid;
    gap: 16px;
}

.result-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.result-thumbnail {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
}

.result-meta {
    flex: 1;
}

.result-filename {
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 4px;
}

.result-stats {
    display: flex;
    gap: 16px;
    font-size: 0.875rem;
    color: var(--gray-500);
}

.result-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.result-body {
    padding: 16px;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.result-field {
    padding: 12px;
    background: var(--gray-50);
    border-radius: 8px;
}

.result-field-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.result-field-value {
    font-weight: 500;
    color: var(--gray-900);
    word-break: break-word;
}

.result-field-value.highlight {
    color: var(--primary);
    font-size: 1.25rem;
}

/* Party Sections (Sender/Receiver) */
.party-section {
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

.party-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.party-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sender-section .party-header {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.sender-section .party-title {
    color: #166534;
}

.receiver-section .party-header {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.receiver-section .party-title {
    color: #1e40af;
}

.transaction-section .party-header {
    background: #faf5ff;
    border-color: #e9d5ff;
}

.transaction-section .party-title {
    color: #6b21a8;
}

.party-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    padding: 12px 16px;
}

.transaction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 12px 16px;
}

.party-field {
    font-size: 0.875rem;
}

.party-label {
    color: var(--gray-500);
    font-size: 0.75rem;
}

.party-value {
    color: var(--gray-900);
    font-weight: 500;
}

.party-value.empty {
    color: var(--gray-400);
    font-weight: 400;
}

/* Receiver validation badges */
.receiver-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-formula {
    background: #d1fae5;
    color: #065f46;
}

.badge-warning-receiver {
    background: #fef3c7;
    color: #92400e;
}

.receiver-warning {
    padding: 8px 16px;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.875rem;
    border-top: 1px solid #fde68a;
}

/* History */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h2 {
    margin-bottom: 0;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:hover {
    background: var(--gray-50);
}

.history-item:last-child {
    border-bottom: none;
}

.history-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--gray-200);
}

.history-info {
    flex: 1;
}

.history-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--gray-800);
}

.history-time {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.history-value {
    font-weight: 600;
    color: var(--success);
}

.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--gray-400);
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--gray-400);
    font-size: 0.875rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--gray-800);
    color: white;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    margin-top: 8px;
    animation: slideIn 0.3s ease;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1001;
}

.modal:not([hidden]) {
    display: flex;
}

.modal[hidden] {
    display: none !important;
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
}

/* Quality Control Options */
.quality-options {
    margin: 24px 0;
    padding: 20px;
    background: var(--gray-50);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.quality-options h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 16px;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.option-group label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--gray-700);
}

.option-group small {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.option-input {
    display: flex;
    align-items: center;
    gap: 12px;
}

.option-input input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--gray-300);
    border-radius: 3px;
    cursor: pointer;
}

.option-input input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

.option-input input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.option-input input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.option-input span {
    min-width: 60px;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--primary);
    text-align: right;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .result-grid {
        grid-template-columns: 1fr;
    }

    .result-header {
        flex-direction: column;
        text-align: center;
    }
}
