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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

/* Navbar */
.navbar {
    background-color: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 1rem 0;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar h1 {
    color: #667eea;
    font-size: 1.5rem;
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-links a {
    color: #333;
    text-decoration: none;
    transition: color 0.3s;
}

.nav-links a:hover {
    color: #667eea;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
}

/* Authentication Card */
.auth-card {
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 3rem;
    max-width: 450px;
    margin: 4rem auto;
}

.auth-card h1 {
    color: #667eea;
    text-align: center;
    margin-bottom: 0.5rem;
    font-size: 2rem;
}

.auth-card h2 {
    text-align: center;
    color: #555;
    margin-bottom: 2rem;
    font-weight: 400;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #555;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: #888;
    font-size: 0.85rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.btn-primary {
    background-color: #667eea;
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background-color: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    background-color: #667eea;
    color: white;
}

.btn-small:hover {
    background-color: #5568d3;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 5px;
    margin-bottom: 1.5rem;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.alert-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Dashboard */
.dashboard {
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    padding: 2rem;
}

.dashboard h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
}

.upload-section {
    background-color: #f8f9fa;
    padding: 2rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.documents-section {
    margin-top: 2rem;
}

.documents-section h3 {
    color: #555;
    margin-bottom: 1rem;
}

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

.documents-table thead {
    background-color: #667eea;
    color: white;
}

.documents-table th,
.documents-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.documents-table tbody tr:hover {
    background-color: #f8f9fa;
}

/* Status Badges */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-block;
}

.status-pending {
    background-color: #ffeaa7;
    color: #856404;
}

.status-processing {
    background-color: #74b9ff;
    color: #0c5460;
}

.status-completed {
    background-color: #00b894;
    color: white;
}

.status-failed {
    background-color: #d63031;
    color: white;
}

/* Radio Button Cards */
.radio-group {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.radio-label {
    flex: 1;
    cursor: pointer;
}

.radio-label input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.radio-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    transition: all 0.2s;
    background: white;
}

.radio-label input[type="radio"]:checked + .radio-card {
    border-color: #667eea;
    background: #f0f2ff;
}

.radio-label:hover .radio-card {
    border-color: #667eea;
}

.radio-indicator {
    width: 20px;
    height: 20px;
    min-width: 20px;
    border: 2px solid #ccc;
    border-radius: 50%;
    margin-top: 2px;
    position: relative;
    transition: border-color 0.2s;
}

.radio-label input[type="radio"]:checked + .radio-card .radio-indicator {
    border-color: #667eea;
}

.radio-label input[type="radio"]:checked + .radio-card .radio-indicator::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 10px;
    height: 10px;
    background: #667eea;
    border-radius: 50%;
}

.radio-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.radio-content strong {
    color: #333;
    font-size: 0.95rem;
}

.radio-content small {
    color: #888;
    font-size: 0.8rem;
    line-height: 1.3;
}

/* Quality Badges */
.quality-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-block;
}

.quality-good {
    background-color: #d4edda;
    color: #155724;
}

.quality-poor {
    background-color: #fff3cd;
    color: #856404;
}

/* Settings */
.settings {
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    padding: 2rem;
}

.settings h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
}

.settings-section {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid #e0e0e0;
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h3 {
    color: #555;
    margin-bottom: 1rem;
}

.info-row {
    display: flex;
    padding: 0.75rem 0;
}

.info-row label {
    font-weight: 500;
    width: 150px;
    color: #666;
}

.info-row span {
    color: #333;
}

/* QR Code */
.qr-code-container {
    text-align: center;
    margin: 1.5rem 0;
}

.qr-code {
    max-width: 250px;
    height: auto;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.5rem;
    background-color: white;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #888;
}

/* Text Utilities */
.text-center {
    text-align: center;
    margin-top: 1.5rem;
}

.text-error {
    color: #e74c3c;
}

/* Links */
a {
    color: #667eea;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    .nav-container {
        flex-direction: column;
        gap: 1rem;
    }
    
    .auth-card {
        margin: 2rem 1rem;
        padding: 2rem;
    }
    
    .documents-table {
        font-size: 0.875rem;
    }
    
    .documents-table th,
    .documents-table td {
        padding: 0.5rem;
    }

    .radio-group {
        flex-direction: column;
    }
}

/* Inline classification results, expanded from a document row */
.result-row td {
    background-color: #f8f9fa;
    padding: 0;
}

.result-block {
    margin: 0;
    padding: 15px 20px;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #2c3e50;
    white-space: pre-wrap;
    word-break: break-word;
    border-left: 4px solid #667eea;
}

.result-block-error {
    color: #c0392b;
    border-left-color: #c0392b;
}

/* Expanded row: thumbnail beside the classification text */
.result-panel {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    padding: 15px 20px;
}

.result-preview {
    flex: 0 0 auto;
    text-align: center;
}

.preview-thumb {
    display: block;
    max-width: 180px;
    height: auto;
    border: 1px solid #dfe3e8;
    border-radius: 4px;
    background-color: white;
    margin-bottom: 8px;
}

.preview-missing {
    max-width: 180px;
    padding: 30px 10px;
    margin-bottom: 8px;
    color: #7f8c8d;
    font-size: 0.85rem;
    border: 1px dashed #cfd6dd;
    border-radius: 4px;
}

.result-panel .result-block {
    flex: 1 1 auto;
    padding: 0;
    border-left: none;
}

/* Dedicated document page */
.document-layout {
    display: flex;
    gap: 25px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.document-viewer {
    flex: 1 1 520px;
    min-width: 300px;
}

.pdf-frame {
    width: 100%;
    height: 70vh;
    min-height: 420px;
    border: 1px solid #dfe3e8;
    border-radius: 6px;
    background-color: white;
}

.document-side {
    flex: 1 1 300px;
    min-width: 280px;
}

.document-side .result-block {
    border-left: 4px solid #667eea;
    background-color: #f8f9fa;
    border-radius: 4px;
}

/* Logout is a state change, so it must be a POST carrying the CSRF token —
   a plain <a> issues a GET, which LogoutFilter rejects and CsrfFilter exempts.
   These rules make the required submit button look like the links beside it. */
.logout-form {
    display: inline-flex;
    align-items: center;
    margin: 0;
}

.link-button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: #333;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.3s;
}

.link-button:hover {
    color: #667eea;
}
