/* PDF Document Extractor - Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --success-color: #10b981;
    --success-hover: #059669;
    --secondary-color: #6b7280;
    --error-color: #ef4444;
    --bg-color: #f9fafb;
    --card-bg: #ffffff;
    --text-color: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 2rem 1rem;
    color: var(--text-color);
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

header p {
    font-size: 1.125rem;
    opacity: 0.95;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.tab-button {
    flex: 1;
    padding: 0.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.tab-button.active {
    background: white;
    color: var(--primary-color);
    border-color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Processing Tab Sections */
.processing-section {
    margin-bottom: 1.5rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-color);
}

main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

/* Extraction Mode Selector */
.extraction-mode-select {
    margin-bottom: 1.5rem;
}

.extraction-mode-select label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}

.mode-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
}

.mode-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--primary-color);
    background: #f0f4ff;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.file-info {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 8px;
}

.file-info p {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.file-info strong {
    color: var(--text-color);
}

/* Company Input Section */
.company-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.company-input-group input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.company-input-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.help-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

/* Extraction Mode Selector */
.extraction-mode {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 8px;
}

.extraction-mode label {
    display: block;
    margin-bottom: 0.75rem;
    color: var(--text-color);
}

.mode-options {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.mode-option {
    flex: 1;
    min-width: 200px;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
}

.mode-option:hover {
    border-color: var(--primary-color);
    background: #f0f4ff;
}

.mode-option input[type="radio"] {
    margin-right: 0.5rem;
}

.mode-option input[type="radio"]:checked+span {
    color: var(--primary-color);
    font-weight: 600;
}

.mode-option span {
    display: block;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.mode-option small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    margin-left: 1.5rem;
}


/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-success {
    background: var(--success-color);
    color: white;
    width: 100%;
    margin-top: 1rem;
}

.btn-success:hover {
    background: var(--success-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Processing */
.progress-container {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f4f6;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#status-text {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Results */
.summary-download {
    margin-bottom: 1.5rem;
}

.documents-grid {
    display: grid;
    gap: 1rem;
}

.document-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.document-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.doc-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.doc-info {
    flex: 1;
}

.doc-info h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    color: var(--text-color);
}

.doc-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Error */
.error-card {
    border-left: 4px solid var(--error-color);
}

#error-message {
    color: var(--error-color);
    margin-bottom: 1rem;
}

/* Training Section */
.training-upload,
.training-data-summary,
.training-controls {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.training-controls {
    border-bottom: none;
}

.training-upload h3,
.training-data-summary h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.training-upload-form {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.doc-type-input {
    flex: 1;
    min-width: 200px;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
}

.typeahead-container {
    flex: 1;
    position: relative;
}

#training-file-selected {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: 8px;
}

.training-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.stat-item {
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: 8px;
    border-left: 3px solid var(--primary-color);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-error {
    color: var(--error-color);
}

.text-success {
    color: var(--success-color);
}

#training-result {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 8px;
    background: #f9fafb;
}

/* Extraction Summary Table */
.extraction-summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.extraction-summary-table th,
.extraction-summary-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.extraction-summary-table th {
    background: #f9fafb;
    font-weight: 600;
    color: var(--text-color);
}

.extraction-summary-table tbody tr:hover {
    background: #f9fafb;
}

.extraction-summary-table .doc-link {
    color: var(--primary-color);
    cursor: pointer;
    text-decoration: underline;
}

.extraction-summary-table .doc-link:hover {
    color: var(--primary-hover);
}

/* History Table */
.history-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.history-table th,
.history-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.history-table th {
    background: #f9fafb;
    font-weight: 600;
    color: var(--text-color);
}

.history-table tbody tr {
    cursor: pointer;
}

.history-table tbody tr:hover {
    background: #f0f4ff;
}

/* Popover */
.popover {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popover-content {
    position: relative;
    width: 90%;
    max-width: 1200px;
    height: 90%;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

.popover-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
    background: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.popover-close:hover {
    background: #f9fafb;
}

/* Popover document viewer */
.popover-body {
    display: flex;
    height: calc(100% - 80px);
    overflow: hidden;
}

.left-panel {
    width: 350px;
    background: #f9fafb;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}

.panel-header h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.count-badge {
    background: #3b82f6;
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 600;
}

.document-info-summary {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.info-item {
    display: flex;
    font-size: 0.875rem;
}

.info-item .label {
    font-weight: 600;
    color: #6b7280;
    min-width: 80px;
}

.info-item .value {
    color: #1f2937;
}

.documents-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.document-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    position: relative;
    user-select: none;
}

.document-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    background: #fafafa;
}

.document-item:active {
    transform: translateY(0);
}

.document-item.active {
    background: #eff6ff;
    border: 2px solid #3b82f6;
}

.doc-number {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    background: #3b82f6;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
}

.doc-info {
    flex: 1;
    min-width: 0;
}

.doc-type {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.doc-name {
    color: #6b7280;
    font-size: 0.875rem;
    margin-top: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-meta {
    color: #9ca3af;
    font-size: 0.75rem;
    margin-top: 0.125rem;
}

.empty-documents {
    text-align: center;
    color: #9ca3af;
    padding: 2rem;
    font-style: italic;
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

.pdf-viewer-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.viewer-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
}

.viewer-header h4 {
    margin: 0;
    font-size: 1rem;
    color: #1f2937;
    font-weight: 600;
}

.viewer-controls {
    display: flex;
    gap: 0.5rem;
}

#pdf-viewer, #pdf-viewer-popover {
    flex: 1;
    width: 100%;
    height: 100%;
    border: none;
    background: #f3f4f6;
}

#popover-iframe {
    border: none;
}

/* Footer */
footer {
    text-align: center;
    color: white;
    margin-top: 2rem;
    opacity: 0.8;
}

/* Responsive */
@media (max-width: 640px) {
    header h1 {
        font-size: 2rem;
    }

    .card {
        padding: 1.5rem;
    }

    .document-card {
        flex-direction: column;
        text-align: center;
    }
}

/* Document Type Badge */
.doc-type-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    white-space: nowrap;
}
/* Training Module Styles */
.training-batch-upload {
    margin-bottom: 2rem;
}

.batch-upload-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.batch-file-list {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--bg-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.batch-file-list h4 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

#file-items {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.file-item {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.file-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.file-name {
    font-weight: 500;
    color: var(--text-color);
}

.btn-remove {
    background: var(--error-color);
    color: white;
    border: none;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-remove:hover {
    background: #dc2626;
}

.file-item-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-group select {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
    background: white;
}

.form-group select:disabled {
    background: var(--bg-color);
    cursor: not-allowed;
}

.training-examples-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-color);
}

.training-examples-section h3 {
    margin-bottom: 1rem;
}

#examples-container {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--bg-color);
    border-radius: 8px;
}

.examples-grouped {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.category-group {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.category-group h4 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.category-group ul {
    list-style: none;
    padding-left: 0;
}

.category-group li {
    padding: 0.5rem 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.category-group li strong {
    color: var(--text-color);
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}
