:root {
    --primary: #4361ee;
    --secondary: #3f37c9;
    --success: #4cc9f0;
    --light: #f8f9fa;
    --dark: #212529;
    --gray: #6c757d;
    --border: #dee2e6;
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --transition: all 0.3s ease;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f5f7fb;
    color: var(--dark);
    line-height: 1.6;
}

.container {
    display: flex;
    height: 100vh;
    padding: 20px;
    gap: 20px;
}

.email-list {
    width: 35%;
    background: white;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    overflow: auto;
}

.email-list-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.email-list-header h2 {
    font-size: 1.5rem;
    color: var(--dark);
    margin-bottom: 15px;
}

.data-source-selector {
    display: flex;
    gap: 30px;
}

.data-source-selector label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.data-source-selector input[type="radio"] {
    margin: 0;
}

.logout {
    position: absolute;
    top: 20px;
    right: 20px;
}

#logout-btn {
    background: #dc3545;
    color: white;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
}

#logout-btn:hover {
    background: #c82333;
}

.emails-container {
    overflow-y: auto;
    flex: 1;
}

.email-item {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
}

.email-item:hover {
    background-color: #f8fbff;
}

.email-item.active {
    background-color: #edf2ff;
    border-left: 4px solid var(--primary);
}

.email-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.email-sender {
    font-weight: 600;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.email-sender i {
    color: var(--success);
    font-size: 0.8rem;
}

.email-date {
    font-size: 0.8rem;
    color: var(--gray);
}

.email-subject {
    font-weight: 600;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-source {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#manual-text {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    resize: vertical;
    font-family: inherit;
    font-size: 0.9rem;
}

#process-text-btn {
    background: var(--primary);
    color: white;
    padding: 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#process-text-btn:hover {
    background: var(--secondary);
}

.email-viewer {
    width: 65%;
    background: white;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    overflow: auto;
}

.email-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: #f8fbff;
}

.email-header h2 {
    font-size: 1.4rem;
    margin-bottom: 10px;
}

.email-header-info {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    font-size: 0.95rem;
    color: var(--dark);
    margin-bottom: 5px;
}

.email-header-info div {
    display: flex;
    align-items: center;
    gap: 5px;
}

.email-header-info i {
    color: var(--gray);
    width: 16px;
}

.email-content {
    flex: 1;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.attachments {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
}

.attachments h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.attachments-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f1f6ff;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: var(--transition);
}

.attachment:hover {
    background: #e2ebff;
}

.attachment i {
    color: var(--primary);
}

.processing-panel {
    padding: 20px;
    background: #f8fafd;
}

.action-buttons {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

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

#process-btn:hover {
    background: var(--secondary);
}

#generate-docs {
    background: #0fa958;
    color: white;
}

#generate-docs:hover {
    background: #0c8e48;
}

.results-section {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    padding: 20px;
    margin-bottom: 20px;
}

.results-section h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    color: var(--dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.results-grid {
    display: grid;
    gap: 15px;
    margin-bottom: 20px;
}

.result-card {
    background: #f8fafd;
    border-radius: 8px;
    padding: 15px;
    border-left: 3px solid var(--primary);
}

.result-card h4 {
    font-size: 0.85rem;
    color: var(--gray);
    margin-bottom: 5px;
}

.result-card p {
    font-size: 0.95rem;
    font-weight: 500;
}

.editable-field {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: vertical;
    font-family: inherit;
    font-size: 0.9rem;
    min-height: 80px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

th,
td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: #f8fafd;
    font-weight: 600;
    color: var(--dark);
}

tr:hover {
    background-color: #f8fbff;
}

input[type="text"],
input[type="number"] {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 100%;
    transition: var(--transition);
}

input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

.documents-links {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.document-card {
    flex: 1;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: var(--transition);
}

.document-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.document-info {
    padding: 15px;
}

.document-info h4 {
    margin-bottom: 8px;
    font-size: 1rem;
}

.document-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.document-actions a {
    flex: 1;
    text-align: center;
    padding: 8px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
}

.preview-btn {
    background: #eef4ff;
    color: var(--primary);
}

.preview-btn:hover {
    background: #e2ebff;
}

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

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

.loader {
    display: none;
    text-align: center;
    padding: 30px;
}

.loader.active {
    display: block;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(67, 97, 238, 0.2);
    border-top: 5px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
    position: relative;
    /* Add to position timer inside */
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner1 {
    width: 50px;
    height: 50px;
    margin: 0 auto 0px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.timer {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 600;
    position: absolute;
    align-items: center;
    margin-top: -15px;
}

.progress-bar {
    height: 6px;
    background: #e9ecef;
    border-radius: 3px;
    margin: 20px 0;
    overflow: hidden;
}

.progress {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    width: 0%;
    transition: width 0.4s ease;
}

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

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

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 900px;
    height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray);
    transition: var(--transition);
    text-align: right;
    padding-right: 15px;
}

.close-modal:hover {
    color: var(--dark);
}

.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: #f5f7fb;
}

.login-container h2 {
    margin-bottom: 20px;
    color: var(--dark);
}

.login-container form {
    background: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    width: 100%;
    max-width: 400px;
}

.login-container input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.login-container button {
    width: 100%;
    background: var(--primary);
    color: white;
    padding: 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.login-container button:hover {
    background: var(--secondary);
}

.login-container .error {
    color: #dc3545;
    margin-top: 10px;
    text-align: center;
}

.sn_submit {
    text-align: center;
    display: block;
}

.empty-message {
    text-align: center;
    color: var(--gray);
    font-style: italic;
    padding: 40px;
}

.manual-text-source {
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
    margin-bottom: 15px;
}

.manual-text-source textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
}

.manual-text-input {
    padding: 15px;
    background: #f9f9f9;
    border-radius: 5px;
    margin-bottom: 15px;
}

.manual-text-input textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
}

#products-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

#products-table th {
    background-color: #f5f5f5;
    padding: 8px;
    text-align: left;
    font-weight: bold;
    border-bottom: 2px solid #ddd;
}

#products-table .sub-header th {
    background-color: #e9e9e9;
    font-weight: normal;
    font-size: 0.9em;
}

#products-table td {
    padding: 4px;
    border-bottom: 1px solid #eee;
}

.product-main-row td {
    background-color: #f9f9f9;
}

.product-source-row td {
    background-color: #f0f0f0;
}

.product-number {
    text-align: center;
    font-weight: bold;
    background-color: #e0e0e0 !important;
}

/* Контейнеры для цены */
.price-container {
    display: flex;
    align-items: center;
    gap: 5px;
}

.price-input {
    flex: 1;
    width: 80%;
}

.copy-price-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #007bff;
    font-size: 14px;
    padding: 4px;
}

.copy-price-btn:hover {
    color: #0056b3;
}

.source-price-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.source-price-display {
    font-weight: 500;
    color: #28a745;
    line-height: .8;
}

.currency {
    color: #6c757d;
    font-size: 0.9em;
}

.source-select {
    width: 100%;
    padding: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.document-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    overflow: hidden;
}

.document-info {
    padding: 15px;
}

.document-info h4 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 16px;
}

.document-preview {
    position: relative;
    margin-bottom: 15px;
    border: 1px solid #eee;
    border-radius: 4px;
    overflow: hidden;
    background: #f9f9f9;
}

.pdf-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.preview-loader {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
}

.preview-loader p {
    margin: 10px 0 0 0;
    font-size: 12px;
    color: #666;
}

.document-actions {
    display: flex;
    gap: 10px;
}

.preview-btn,
.download-btn {
    flex: 1;
    padding: 8px 12px;
    text-align: center;
    border-radius: 4px;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.2s;
}

.preview-btn {
    background-color: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
}

.preview-btn:hover {
    background-color: #e0e0e0;
}

.download-btn {
    background-color: #007bff;
    color: white;
    border: 1px solid #007bff;
}

.download-btn:hover {
    background-color: #0069d9;
}

/* Маленький спиннер для превью */
.spinner.small {
    width: 30px;
    height: 30px;
}

.spinner.small:after {
    width: 20px;
    height: 20px;
}

.source-price-container {
    display: flex;
    align-items: center;
    gap: 5px;
}

.currency {
    font-size: 0.9rem;
    color: var(--primary);
}

.source-link-icon {
    cursor: pointer;
    color: var(--primary);
    font-size: 0.9rem;
    margin-left: 5px;
    transition: color 0.2s;
}

.source-link-icon:hover {
    color: var(--primary-dark);
    /* Adjust to a darker shade of your primary color */
}

.attachment-errors {
    margin-top: 15px;
    padding: 10px;
    background-color: #fff3f3;
    border: 1px solid #ffcdd2;
    border-radius: 5px;
}

.attachment-error {
    color: #d32f2f;
    margin: 5px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.attachment-error i {
    color: #d32f2f;
}

.show_ver {
    position: absolute;
    right: 18px;
    bottom: 18px;
}

.citations-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.citation-item a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 6px 10px;
    background-color: #f0f4ff;
    border-radius: 4px;
    transition: var(--transition);
}

.citation-item a:hover {
    background-color: #e2ebff;
    text-decoration: underline;
}

.citation-item i {
    font-size: 0.8rem;
}