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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 0;
    margin: 0;
    height: 100vh;
}

body.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100%;
}

.login-box {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    color: #3F3F3F;
    margin-bottom: 30px;
    font-size: 32px;
}

.login-logo {
    display: block;
    margin: 0 auto 30px;
    height: 80px;
    max-width: 300px;
    object-fit: contain;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.btn-login {
    background: #3F3F3F;
    color: white;
    padding: 14px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 10px;
}

.btn-login:hover {
    background: #2a2a2a;
    transform: translateY(-2px);
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    border-left: 4px solid #c62828;
}

.login-footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
    color: #999;
    font-size: 13px;
}

.login-footer p {
    margin: 8px 0;
}

/* Full Screen Frame */
.phone-frame {
    width: 100%;
    height: 100vh;
    background: white;
    border-radius: 0;
    overflow: hidden;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    position: relative;
}

.phone-header {
    background: #3F3F3F;
    color: white;
    padding: 20px;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.phone-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 0;
    flex: 1;
}

.header-logo {
    height: 50px;
    max-width: 200px;
    object-fit: contain;
    flex: 1;
}

.user-info {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    font-size: 13px;
    gap: 15px;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.3);
}

.phone-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f9f9f9;
}

/* Tabs */
.tab-container {
    display: flex;
    background: white;
    border-bottom: 1px solid #e0e0e0;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    font-size: 16px;
    font-weight: 600;
    color: #999;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
}

.tab-btn.active {
    color: #3F3F3F;
    border-bottom-color: #3F3F3F;
}

/* Tab Content */
.tab-content {
    flex: 1;
    overflow-y: auto;
    display: none;
}

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

/* Contracts Header */
.contracts-header {
    padding: 10px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: all 0.3s ease;
    background: white;
}

.search-input:focus {
    outline: none;
    border-color: #3F3F3F;
    box-shadow: 0 0 0 3px rgba(63, 63, 63, 0.1);
}

.search-input::placeholder {
    color: #999;
}

.btn-create {
    width: 100%;
    padding: 14px;
    background: #3F3F3F;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(63, 63, 63, 0.3);
}

.btn-create:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(63, 63, 63, 0.4);
}

.btn-create:active {
    transform: translateY(0);
}

/* Contracts List */
.contracts-list {
    padding: 10px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.contract-row {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border-left: 4px solid #ddd;
    transition: all 0.3s ease;
}

.contract-row:hover:not(.complete) {
    background: #f5f5f5;
    transform: translateX(4px);
}

.contract-row.complete {
    background: white;
    opacity: 1;
    border-left-color: #ddd;
    cursor: default;
}

.contract-row.closed {
    background: #e8f5e9;
    opacity: 0.7;
    border-left-color: #4CAF50;
    cursor: default;
}

.contract-row.complete .contract-info,
.contract-row.closed .contract-info {
    flex: 1;
    min-width: 0;
}

.contract-row.complete .contract-actions,
.contract-row.closed .contract-actions {
    margin-left: 12px;
    display: flex;
    flex-direction: row;
    gap: 12px;
    flex-shrink: 0;
    width: 100%;
    max-width: none;
}

.contract-row.pending {
    border-left-color: #CCCCCC;
}

.contract-info {
    flex: 1;
}

.contract-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.contract-type {
    font-size: 13px;
    color: #808080;
    font-weight: 500;
    margin-bottom: 4px;
}

.contract-details {
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
}

.prepaid-badge {
    background: #e8f5e9;
    color: #4CAF50;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 11px;
}

.contract-price {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.price {
    font-weight: 700;
    color: #3F3F3F;
}

.contract-price-line {
    font-size: 13px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    white-space: nowrap;
}

.contract-phone {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
    user-select: text;
    cursor: pointer;
    word-break: break-all;
}

.contract-address {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
    user-select: text;
    cursor: pointer;
    word-break: break-all;
}

.contract-lifts {
    font-size: 12px;
    color: #4CAF50;
    margin-top: 4px;
    font-weight: 500;
}

.contract-stairs {
    font-size: 12px;
    color: #FF9800;
    margin-top: 4px;
    font-weight: 500;
}

.selectable {
    padding: 4px 0;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.selectable:hover {
    background: rgba(200, 200, 200, 0.2);
    color: #666;
    font-weight: 500;
}

.contract-row.complete .contract-price {
    color: #333;
    font-weight: 400;
}

.contract-row.closed .contract-price {
    color: #4CAF50;
    font-weight: 700;
}

.contract-actions {
    margin-left: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.actions-row-top {
    display: flex;
    align-items: center;
    gap: 6px;
}

.actions-row-bottom {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.action-spacer {
    flex: 1;
}

.btn-edit {
    background: #808080;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    min-width: 40px;
    text-align: center;
}

.btn-edit:hover {
    background: #696969;
    transform: scale(1.05);
}

.btn-edit:active {
    transform: scale(0.95);
}

/* Table view emoji-only buttons */
.view-table .btn-edit,
.view-table .btn-delete,
.view-table .btn-download,
.view-table .btn-cancel-completion,
.view-table .btn-close-order {
    font-size: 18px;
    padding: 6px 8px;
    width: auto;
    min-width: auto;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-delete {
    background: transparent !important;
    color: #333 !important;
    border: 1px solid #333 !important;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.btn-delete:hover {
    background: rgba(51, 51, 51, 0.05) !important;
    transform: scale(1.1);
}

.btn-delete:active {
    transform: scale(0.95);
}

.btn-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #2196F3;
    border: 1px solid #2196F3;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    flex-shrink: 0;
    gap: 4px;
    white-space: nowrap;
}

.btn-download:hover {
    background: #E3F2FD;
    border-color: #1976D2;
    color: #1976D2;
    transform: scale(1.05);
}

.btn-download:active {
    transform: scale(0.95);
}

.btn-cancel-completion {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #2196F3;
    border: 1px solid #2196F3;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    flex-shrink: 0;
    gap: 4px;
    white-space: nowrap;
    margin-left: 8px;
}

.btn-cancel-completion:hover {
    background: #E3F2FD;
    border-color: #1976D2;
    color: #1976D2;
    transform: scale(1.05);
}

.btn-cancel-completion:active {
    transform: scale(0.95);
}

.btn-close-order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #4CAF50;
    border: 1px solid #4CAF50;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    flex-shrink: 0;
    gap: 4px;
    white-space: nowrap;
}

.btn-close-order:hover {
    background: #E8F5E9;
    border-color: #388E3C;
    color: #388E3C;
    transform: scale(1.05);
}

.btn-close-order:active {
    transform: scale(0.95);
}

.btn-close-order:disabled {
    color: #BDBDBD;
    border-color: #BDBDBD;
    cursor: not-allowed;
    background: transparent;
}

.btn-close-order:disabled:hover {
    background: transparent;
    border-color: #BDBDBD;
    color: #BDBDBD;
    transform: none;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 16px;
}

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    padding: 15px;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-label {
    font-size: 12px;
    color: #999;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: #3F3F3F;
}

.chart-container {
    flex: 1;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#statsChart {
    max-width: 300px;
    max-height: 300px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 350px;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 101;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content {
    padding: 24px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 16px;
}

.modal-header h2 {
    font-size: 22px;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    transition: color 0.3s ease;
}

.modal-close:hover {
    color: #333;
}

/* Form */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.price-hint {
    font-size: 12px;
    font-weight: 400;
    color: #ccc;
    margin-left: 8px;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="tel"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus,
.form-group input[type="number"]:focus,
.form-group input[type="tel"]:focus,
.form-group input[type="date"]:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #808080;
    box-shadow: 0 0 0 3px rgba(128, 128, 128, 0.1);
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 36px;
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.form-group.checkbox {
    display: flex;
    align-items: center;
    margin-bottom: 24px;
}

.form-group.checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 10px;
    cursor: pointer;
}

.form-group.checkbox label {
    margin-bottom: 0;
    cursor: pointer;
    flex: 1;
}

.btn-complete {
    display: block;
    width: 100%;
    padding: 16px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    margin-bottom: 0;
}

.btn-complete:hover {
    border-color: #4CAF50;
    color: #4CAF50;
    background: #f9f9f9;
}

#is_complete:checked + .btn-complete {
    background: #c8e6c9;
    border-color: #4CAF50;
    color: #2e7d32;
    font-weight: 700;
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
}

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

.btn-cancel {
    flex: 1;
    padding: 12px;
    background: #f0f0f0;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-cancel:hover {
    background: #e0e0e0;
}

.btn-save {
    flex: 1;
    padding: 12px;
    background: #E3F2FD;
    color: #000;
    border: 1px solid #BBDEFB;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-save:hover {
    background: #BBDEFB;
    transform: scale(1.02);
}

.btn-save:active {
    transform: scale(0.98);
}

/* Scrollbar styling */
.contracts-list::-webkit-scrollbar,
.modal::-webkit-scrollbar {
    width: 6px;
}

.contracts-list::-webkit-scrollbar-track,
.modal::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.contracts-list::-webkit-scrollbar-thumb,
.modal::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.contracts-list::-webkit-scrollbar-thumb:hover,
.modal::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.contract-row {
    animation: slideIn 0.3s ease;
}

/* Responsive */
@media (max-width: 480px) {
    .phone-frame {
        border-radius: 0;
        height: 100vh;
        max-height: 100vh;
    }

    .modal {
        width: 95%;
        border-radius: 16px;
    }

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

/* Project Image Styles */
.project-image-container {
    position: relative;
    margin: 10px 0;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    max-width: 150px;
}

.project-thumbnail {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #ddd;
    transition: transform 0.2s, border-color 0.2s;
}

.project-image-container:hover .project-thumbnail {
    transform: scale(1.05);
    border-color: #3F3F3F;
}

.image-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    opacity: 0;
    transition: opacity 0.2s;
}

.project-image-container:hover .image-overlay {
    opacity: 1;
}

/* Image Preview in Modal */
.image-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 6px;
}

.preview-thumbnail {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.image-name {
    font-size: 12px;
    color: #666;
    word-break: break-all;
    flex: 1;
}

.btn-delete-image {
    background: #ff4444;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.3s ease;
}

.btn-delete-image:hover {
    background: #cc0000;
    transform: translateY(-1px);
}

/* Facade Material Display */
.facade-material-info {
    font-size: 13px;
    color: #666;
    margin-top: 6px;
    padding: 6px 8px;
    background: #f0f0f0;
    border-radius: 4px;
    display: inline-block;
}

/* Lightbox for full image */
.image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: pointer;
    animation: fadeIn 0.2s ease;
}

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

.lightbox-image {
    width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    color: #333;
    font-size: 28px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 10001;
}

.lightbox-close:hover {
    background: white;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Loading state */
.htmx-swapping {
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.htmx-settling {
    opacity: 1;
}

/* Admin Panel */
.admin-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: white;
    min-height: 100vh;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    margin-top: 20px;
}

.admin-header h1 {
    font-size: 24px;
    color: #333;
    margin: 0;
}

.btn-back {
    background: #E3F2FD;
    color: #000;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 14px;
    transition: all 0.3s ease;
    border: 1px solid #BBDEFB;
}

.btn-back:hover {
    background: #BBDEFB;
    transform: translateY(-2px);
}

.admin-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
}

.admin-section {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.admin-section h2 {
    font-size: 20px;
    color: #3F3F3F;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #3F3F3F;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.form-row .form-group {
    margin-bottom: 0;
}

.users-table {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 20px;
    border-radius: 6px;
    border: 1px solid #ddd;
    transition: all 0.3s ease;
    gap: 20px;
    margin-bottom: 10px;
}

.user-row:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.user-info {
    flex: 1;
}

.user-username {
    font-size: 16px;
    font-weight: 600;
    color: #3F3F3F;
    margin-bottom: 10px;
}

.user-role {
    margin-bottom: 10px;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}

.badge-manager {
    background: #e3f2fd;
    color: #1976d2;
}

.badge-collector {
    background: #f3e5f5;
    color: #7b1fa2;
}

.user-email {
    font-size: 13px;
    color: #666;
}

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

.btn-reset-password {
    background: #E3F2FD;
    color: #000;
    border: 1px solid #BBDEFB;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-reset-password:hover {
    background: #BBDEFB;
    transform: translateY(-1px);
}

.btn-delete-user {
    background: #ff4444;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-delete-user:hover {
    background: #cc0000;
    transform: translateY(-1px);
}

/* Collector View Styles */
.collector-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #ddd;
}

.tab-button {
    background: none;
    border: none;
    padding: 12px 20px;
    font-size: 16px;
    cursor: pointer;
    color: #999;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    font-weight: 500;
}

.tab-button.active {
    color: #333;
    border-bottom-color: #3498DB;
}

.tab-button:hover {
    color: #555;
}

.tab-content {
    display: none;
}

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

.collector-contract-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 20px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    align-items: start;
}

.collector-contract-row .contract-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.collector-contract-row .contract-name {
    font-weight: bold;
    font-size: 16px;
    color: #333;
}

.collector-contract-row .contract-client {
    font-size: 14px;
    color: #555;
}

.collector-contract-row .contract-phone,
.collector-contract-row .contract-address {
    font-size: 13px;
    color: #666;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.collector-contract-row .contract-phone:hover,
.collector-contract-row .contract-address:hover {
    background: #f0f0f0;
}

.rating-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.rating-buttons {
    display: flex;
    gap: 15px;
}

.emoji-btn {
    font-size: 40px;
    background: none;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 10px 15px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.emoji-btn:hover {
    transform: scale(1.15);
    border-color: #3498DB;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.emoji-btn:active {
    transform: scale(0.95);
}

.rating-display {
    font-size: 14px;
    color: #666;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 6px;
    text-align: center;
    min-width: 120px;
}

/* Admin Collectors Ratings View */
.collectors-ratings-section {
    margin-top: 8px;
    padding: 0;
    background: transparent;
    border-radius: 0;
    border-left: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ratings-label {
    display: none;
}

.collectors-rating-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.collector-rating-btn {
    background: white;
    border: 1px solid #ddd;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.collector-rating-btn:hover {
    background: #3498DB;
    color: white;
    border-color: #3498DB;
    transform: translateY(-2px);
    box-shadow: 0 3px 8px rgba(52, 152, 219, 0.3);
}

.collector-rating-btn:active {
    transform: translateY(0);
}

.collector-rating-btn.assigned {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
    font-weight: 600;
}

.collector-rating-btn.assigned:hover {
    background: #45a049;
}

.collector-rating-btn.assigned.disabled {
    background: #ccc;
    color: #666;
    border-color: #999;
    cursor: not-allowed;
    opacity: 0.6;
}

.collector-rating-btn.assigned.disabled:hover {
    background: #ccc;
    color: #666;
    border-color: #999;
    transform: none;
    box-shadow: none;
}

.collector-rating-btn.disabled {
    background: #f0f0f0;
    color: #999;
    border-color: #ddd;
    cursor: not-allowed;
    opacity: 0.5;
}

.collector-rating-btn.disabled:hover {
    background: #f0f0f0;
    color: #999;
    border-color: #ddd;
    transform: none;
    box-shadow: none;
}

.collector-rating-btn:disabled {
    cursor: not-allowed;
}

.assigned-collector-info {
    display: none;
}

.btn-unassign {
    display: none;
}

.btn-unassign:hover {
    background: #e53935;
    border-color: #e53935;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(239, 83, 80, 0.3);
}

.btn-unassign:active {
    transform: translateY(0);
}

/* Hide Details button for collectors only */
.collector-contract-row .btn-download {
    display: none !important;
}

.collector-contract-row.assigned {
    background: #e8f5e9 !important;
    border-left: 4px solid #4CAF50;
}

.assigned-badge {
    display: inline-block;
    background: #4CAF50;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 6px;
}

.collector-contract-row.assigned-other {
    background: #f5f5f5 !important;
    border-left: 4px solid #999;
    display: none; /* Hide by default */
}

#rated-tab .collector-contract-row.assigned-other.visible {
    display: flex;
}

.rated-tab-header {
    padding: 8px 10px;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 8px;
}

.show-all-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    user-select: none;
}

.show-all-checkbox input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.assigned-other-badge {
    display: inline-block;
    background: #ef5350;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 6px;
}

.dispute-warning {
    display: none;
}

.matches-badge {
    display: inline-block;
    background: #2196F3;
    color: white;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 4px;
}

/* View Toggle Buttons */
.view-toggle-btn {
    background: #f0f0f0;
    border: 1px solid #ddd;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.view-toggle-btn:hover {
    background: #e0e0e0;
    border-color: #999;
}

.view-toggle-btn.active {
    background: #3F3F3F;
    color: white;
    border-color: #3F3F3F;
}

/* Table View */
.contracts-list.view-table {
    display: flex;
    flex-direction: column;
    padding: 0;
}

.contracts-list.view-table .contract-row {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    margin-bottom: 0;
    border-bottom: 1px solid #eee;
    border-radius: 0;
    background: white;
    gap: 6px;
    min-height: 32px;
}

.contracts-list.view-table .contract-row:first-child {
    background: #f5f5f5;
    font-weight: 600;
    border-bottom: 2px solid #ddd;
    padding: 8px 8px;
}

/* Flatten contract-left and contract-right for table view */
.contracts-list.view-table .contract-left {
    display: contents;
}

.contracts-list.view-table .contract-right {
    display: contents;
}

.contracts-list.view-table .contract-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

/* 1. Contract Number */
.contracts-list.view-table .contract-name {
    font-size: 10px;
    margin-bottom: 0;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 55px;
    flex-shrink: 0;
}

/* 2. Client Name (in contract-type) */
.contracts-list.view-table .contract-type {
    font-size: 10px;
    margin-bottom: 0;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #666;
    display: block !important;
    flex: 2;
    min-width: 120px;
}

/* Hide price span, show cost-price-badge and make price visible */
.contracts-list.view-table .contract-price-line {
    display: contents;
}

.contracts-list.view-table .contract-price-line > div {
    display: contents;
}

.contracts-list.view-table .contract-price-line span.price {
    font-size: 11px;
    color: #7B68EE;
    font-weight: 600;
    white-space: nowrap;
    width: 85px;
    flex-shrink: 0;
    font-family: 'Courier New', monospace;
    text-align: right;
    display: inline-block;
}

/* 3. Phone Number - positioned after price */
.contracts-list.view-table .contract-phone {
    display: block !important;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0 !important;
    color: #999;
    min-width: 90px;
    flex-shrink: 0;
    order: 3;
}

/* 4. Cost price display in table view */
.contracts-list.view-table .cost-price-badge {
    font-size: 11px !important;
    margin-left: 0 !important;
    text-align: right;
    white-space: nowrap;
    width: 85px;
    flex-shrink: 0;
    display: inline-block !important;
    color: #FF9944;
    font-family: 'Courier New', monospace;
    text-decoration: underline;
}

.contracts-list.view-table .cost-price-badge::before {
    display: none;
}

/* 5. Container for remaining badge in table view */
.contracts-list.view-table .contract-info > div:has(.remaining-badge) {
    text-align: right;
    margin: 0;
    white-space: nowrap;
    font-size: 11px;
    width: 85px;
    flex-shrink: 0;
}

.contracts-list.view-table .remaining-badge {
    font-size: 11px;
    color: #66BB6A;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    display: inline-block;
    white-space: nowrap;
    width: 85px;
    text-align: right;
}

.contracts-list.view-table .remaining-badge::before {
    display: none;
}

/* Hide all buttons in table view */
.contracts-list.view-table .contract-actions {
    display: none;
}

.contracts-list.view-table .btn-edit,
.contracts-list.view-table .btn-delete,
.contracts-list.view-table .btn-download,
.contracts-list.view-table .btn-cancel-completion,
.contracts-list.view-table .btn-close-order {
    display: none;
}

/* Hide unnecessary elements in table view */
.contracts-list.view-table .contract-address,
.contracts-list.view-table .contract-details-expandable,
.contracts-list.view-table .project-image-container,
.contracts-list.view-table .facade-material-info,
.contracts-list.view-table .contract-lifts,
.contracts-list.view-table .contract-stairs,
.contracts-list.view-table .collectors-ratings-section {
    display: none;
}

/* Cards View (default) */
.contracts-list.view-cards .contract-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 24px;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 12px;
    align-items: start;
}

/* Left column: Image + Buttons (1/3 width) */
.contracts-list.view-cards .contract-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 120px;
    flex-shrink: 0;
    overflow: hidden;
}

/* Show and position project image */
.contracts-list.view-cards .project-image-container {
    display: block !important;
    flex-shrink: 0;
    width: 100%;
    margin: 0;
    padding: 0;
}

.contracts-list.view-cards .project-thumbnail {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    object-fit: cover;
}

/* Right column: Text information (2/3 width) */
.contracts-list.view-cards .contract-right {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-width: 0;
}

/* ВАЖНО: все строки правой колонки начинаются от одной вертикали.
   Никаких margin/padding слева у прямых потомков — иначе отступы "плавают". */
.contracts-list.view-cards .contract-right > * {
    margin: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    text-indent: 0;
    align-self: stretch;
    min-width: 0;
}

/* Номер договора — вспомогательная информация: светло-серый, не жирный */
.contracts-list.view-cards .contract-name {
    font-size: 11px;
    font-weight: 400;
    color: #b5b5b5;
    letter-spacing: 0.2px;
}

.contracts-list.view-cards .contract-type {
    font-size: 10px;
    color: #666;
    display: block;
}

.contracts-list.view-cards .contract-price-line {
    font-size: 10px;
    display: block;
}

.contracts-list.view-cards .contract-price-line > div {
    display: block;
}

.contracts-list.view-cards .remaining-line {
    font-size: 11px;
    display: block;
}

.contracts-list.view-cards .contract-price-line span.price {
    font-size: 11px;
    color: #7B68EE;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.contracts-list.view-cards .contract-price-line span.price::after {
    content: " ₽";
}

.contracts-list.view-cards .contract-phone {
    font-size: 10px;
    display: block;
    color: #999;
}

.contracts-list.view-cards .contract-address {
    font-size: 10px;
    display: block;
    color: #999;
}

/* Facade material */
.contracts-list.view-cards .facade-material-info {
    display: block !important;
    font-size: 0;
    color: #666;
    background: none;
    padding: 0;
}

.contracts-list.view-cards .facade-material-info::before {
    content: "Фасад: ";
    font-size: 10px;
}

.contracts-list.view-cards .facade-material-info > strong {
    font-size: 10px;
    font-weight: 400;
}

/* Hide lifts/stairs */
.contracts-list.view-cards .contract-lifts,
.contracts-list.view-cards .contract-stairs {
    display: none;
}

/* Show collectors ratings in cards view */
.contracts-list.view-cards .collectors-ratings-section {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px !important;
}

/* Buttons under image - vertical layout */
.contracts-list.view-cards .contract-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    margin-left: 0;
}

.contracts-list.view-cards .actions-row-top {
    display: none;
}

.contracts-list.view-cards .actions-row-bottom {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.contracts-list.view-cards .action-spacer {
    display: none;
}

.contracts-list.view-cards .btn-edit,
.contracts-list.view-cards .btn-delete,
.contracts-list.view-cards .btn-download,
.contracts-list.view-cards .btn-cancel-completion,
.contracts-list.view-cards .btn-close-order {
    padding: 6px 8px;
    font-size: 11px;
    white-space: nowrap;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

/* Close button in right column - отдельная строка с отступом от кнопок сборщиков */
.contracts-list.view-cards .contract-right .btn-close-order {
    margin-top: 10px !important;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 6px;
    background: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    display: block;
    width: 100%;
    flex: 0 0 auto;
    align-self: stretch;
}

.contracts-list.view-cards .contract-right .btn-close-order:hover:not(:disabled) {
    background: #45a049;
}

.contracts-list.view-cards .contract-right .btn-close-order:disabled {
    background: #cccccc;
    color: #666666;
    cursor: not-allowed;
    opacity: 1;
}

/* View Toggle */
.view-toggle-btn {
    background: #f0f0f0;
    border: 1px solid #ddd;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
    margin-bottom: 10px;
}

.view-toggle-btn:hover {
    background: #e0e0e0;
    border-color: #999;
}

.view-toggle-btn.active {
    background: #3F3F3F;
    color: white;
    border-color: #3F3F3F;
}

/* Minimal View */
.contracts-list.view-minimal .contract-row {
    padding: 10px 12px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.contracts-list.view-minimal .contract-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    flex-wrap: wrap;
}

.contracts-list.view-minimal .contract-name {
    font-size: 13px;
    margin-bottom: 0;
    flex: 0 0 auto;
    min-width: 80px;
    font-weight: 600;
}

.contracts-list.view-minimal .contract-type {
    font-size: 11px;
    margin-bottom: 0;
    flex: 0 0 auto;
    color: #999;
}

.contracts-list.view-minimal .contract-phone {
    font-size: 11px;
    margin-top: 0;
    flex: 0 0 auto;
    color: #999;
}

.contracts-list.view-minimal .contract-price {
    font-size: 13px;
    margin: 0;
    flex: 0 0 auto;
    font-weight: 600;
}

.contracts-list.view-minimal .contract-details-expandable {
    display: none !important;
}

.contracts-list.view-minimal .contract-actions {
    margin-left: 0;
    display: flex;
    flex-direction: row;
    gap: 4px;
    flex-shrink: 0;
}

/* Expanded View */
.contracts-list.view-expanded .contract-row {
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.contracts-list.view-expanded .contract-info {
    width: 100%;
    margin-bottom: 12px;
}

.contracts-list.view-expanded .contract-actions {
    width: 100%;
    display: flex;
    flex-direction: row;
    gap: 8px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.contracts-list.view-expanded .contract-name {
    font-size: 16px;
    margin-bottom: 8px;
    font-weight: 700;
}

.contracts-list.view-expanded .contract-type {
    font-size: 14px;
    margin-bottom: 8px;
    color: #666;
}

.contracts-list.view-expanded .contract-details-expandable {
    display: block !important;
    width: 100%;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

.contracts-list.view-expanded .contract-details-expandable > div {
    margin-bottom: 8px;
    display: inline-block;
    margin-right: 24px;
}

/* ==========================================================================
   ЕДИНАЯ СЕТКА КАРТОЧКИ ДОГОВОРА  (v20260823)
   Работает БЕЗ класса .view-cards (он нигде не добавляется в коде).
   Левая колонка — фиксированная ширина, поэтому информация у ВСЕХ
   договоров начинается строго на одном уровне.
   ========================================================================== */

.contracts-list:not(.view-table) .contract-row {
    display: grid !important;
    grid-template-columns: 140px minmax(0, 1fr);
    column-gap: 24px;
    row-gap: 0;
    align-items: start;
    justify-items: stretch;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 12px;
}

/* --- Левая колонка: картинка + кнопки, всегда ровно 140px --- */
.contracts-list:not(.view-table) .contract-left {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 140px;
    max-width: 140px;
    min-width: 140px;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.contracts-list:not(.view-table) .contract-left .project-image-container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

.contracts-list:not(.view-table) .contract-left .project-thumbnail {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    object-fit: cover;
}

/* Кнопки — строго внутри 140px, одинаковые у всех договоров */
.contracts-list:not(.view-table) .contract-left .contract-actions,
.contracts-list:not(.view-table) .contract-row.complete .contract-actions,
.contracts-list:not(.view-table) .contract-row.closed .contract-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 100%;
    margin: 0 !important;
    padding: 0;
}

.contracts-list:not(.view-table) .contract-left .actions-row-top,
.contracts-list:not(.view-table) .contract-left .actions-row-bottom {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    margin: 0;
}

.contracts-list:not(.view-table) .contract-left .action-spacer {
    display: none;
}

.contracts-list:not(.view-table) .contract-left .btn-edit,
.contracts-list:not(.view-table) .contract-left .btn-delete,
.contracts-list:not(.view-table) .contract-left .btn-download,
.contracts-list:not(.view-table) .contract-left .btn-cancel-completion {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    margin: 0 !important;
    padding: 6px 4px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

/* --- Правая колонка: вся информация от одной вертикали --- */
.contracts-list:not(.view-table) .contract-right {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-width: 0;
    margin: 0;
    padding: 0;
}

/* Ни у одной строки текста нет собственного бокового отступа */
.contracts-list:not(.view-table) .contract-right > * {
    margin: 0 !important;
    padding-left: 0 !important;
    text-indent: 0;
    align-self: stretch;
    min-width: 0;
    display: block;
}

/* --- Кнопки сборщиков (админ) --- */
.contracts-list:not(.view-table) .contract-right .collectors-ratings-section {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px !important;
}

/* --- Кнопка "Закрыть": отдельная строка с отступом от сборщиков --- */
.contracts-list:not(.view-table) .contract-right .btn-close-order {
    display: block !important;
    width: 100%;
    box-sizing: border-box;
    margin-top: 10px !important;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 6px;
    background: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
}

.contracts-list:not(.view-table) .contract-right .btn-close-order:hover:not(:disabled) {
    background: #45a049;
}

.contracts-list:not(.view-table) .contract-right .btn-close-order:disabled {
    background: #cccccc;
    color: #666666;
    cursor: not-allowed;
    opacity: 1;
}

/* Карточка не должна "прыгать" вбок при наведении */
.contracts-list:not(.view-table) .contract-row:hover:not(.complete) {
    transform: none;
}

/* ==========================================================================
   ЧАСТИ ДОГОВОРА (поддоговоры) — таблица внутри карточки договора
   ========================================================================== */

.items-wrap {
    margin-top: 8px !important;
    overflow-x: auto;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    background: #fcfcfc;
}

.items-table {
    display: grid;
    min-width: 100%;
    max-width: 780px;   /* на широком экране колонки не расползаются */
    font-size: 11px;
}

/* Наборы колонок по ролям */
/* У админа в колонке файлов три кнопки: детализация, файлы, проектировка */
.items-table.cols-admin {
    grid-template-columns: 74px minmax(70px, 1.1fr) minmax(60px, 0.9fr) 84px 106px minmax(120px, 1.6fr);
    min-width: 610px;
}

.items-table.cols-manager {
    grid-template-columns: 74px minmax(80px, 1.2fr) minmax(70px, 1fr) 90px 78px;
    min-width: 422px;
}

.items-table.cols-collector {
    grid-template-columns: 74px minmax(90px, 1.3fr) minmax(80px, 1fr) 78px 96px;
    min-width: 428px;
}

/* Проектировщик: фото, тип, фасад, файлы — без денег */
.items-table.cols-designer {
    grid-template-columns: 74px minmax(90px, 1.3fr) minmax(80px, 1fr) 96px;
    min-width: 350px;
}

.items-row {
    display: contents;
}

.items-row > span {
    padding: 6px 6px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.items-row.items-head > span {
    background: #f2f2f2;
    font-weight: 600;
    color: #555;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid #ddd;
    position: sticky;
    top: 0;
}

.items-table > .items-row:last-child > span {
    border-bottom: none;
}

.items-row.item-mine > span {
    background: #e8f5e9;
}

.ta-right  { justify-content: flex-end; text-align: right; }
.ta-center { justify-content: center; text-align: center; }

.item-thumbs {
    display: flex;
    gap: 3px;
    align-items: center;
}

.item-thumb {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #ddd;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.item-thumb:hover {
    transform: scale(1.12);
    border-color: #3F3F3F;
}

.item-thumb-empty {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed #ddd;
    border-radius: 4px;
    color: #bbb;
    font-size: 12px;
}

.item-type   { font-weight: 600; color: #444; }
.item-facade { color: #777; }
.item-price  { color: #7B68EE; font-weight: 600; font-family: 'Courier New', monospace; }
.item-muted  { color: #bbb; font-size: 10px; }

.btn-item-doc {
    background: transparent;
    border: 1px solid #2196F3;
    border-radius: 4px;
    color: #2196F3;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    padding: 4px 6px;
    transition: all 0.2s ease;
}

.btn-item-doc:hover {
    background: #E3F2FD;
    transform: scale(1.1);
}

.item-collectors {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 2px 0;
    white-space: normal;
}

.item-collectors .collector-rating-btn {
    font-size: 10px;
    padding: 3px 6px;
}

.emoji-btn-sm {
    font-size: 18px;
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 2px 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1.1;
}

.emoji-btn-sm:hover {
    transform: scale(1.15);
    border-color: #3498DB;
}

.item-rate { gap: 5px; }

.item-rated  { font-size: 16px; }
.mine-badge  { font-size: 13px; }

.items-empty {
    margin-top: 8px !important;
    padding: 10px;
    font-size: 11px;
    color: #aaa;
    text-align: center;
    border: 1px dashed #e0e0e0;
    border-radius: 8px;
}

/* Карточка договора: левая колонка теперь только кнопки, картинки в ней нет */
.contracts-list:not(.view-table) .contract-row {
    grid-template-columns: 92px minmax(0, 1fr);
}

.contracts-list:not(.view-table) .contract-left {
    width: 92px;
    min-width: 92px;
    max-width: 92px;
}

/* ==========================================================================
   Карточки частей в модалке «Создать новый договор»
   ========================================================================== */

.items-section-title {
    font-size: 15px;
    font-weight: 700;
    color: #333;
    margin: 22px 0 10px;
    padding-top: 16px;
    border-top: 2px solid #eee;
}

.item-card {
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 14px;
    background: #fafafa;
}

.item-card-head {
    font-size: 13px;
    font-weight: 700;
    color: #3F3F3F;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e6e6e6;
}

.item-card .form-group:last-child { margin-bottom: 0; }

.photo-hint {
    font-weight: 400;
    font-size: 11px;
    color: #999;
}

.item-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.item-preview:empty { margin-top: 0; }

.photo-thumb {
    position: relative;
    width: 84px;
}

.photo-thumb img {
    width: 84px;
    height: 84px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #ddd;
    display: block;
    background: #f0f0f0;
}

/* Крестик в правом верхнем углу миниатюры */
.photo-remove {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #e53935;
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s, background 0.15s;
    padding: 0;
}

.photo-remove:hover {
    background: #c62828;
    transform: scale(1.15);
}

.photo-name {
    display: block;
    margin-top: 4px;
    font-size: 10px;
    color: #888;
    line-height: 1.3;
    word-break: break-all;
    max-height: 26px;
    overflow: hidden;
}

/* Сверка суммы частей с суммой договора */
.items-balance {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
    border-left: 4px solid #ccc;
}

.items-balance.ok {
    background: #e8f5e9;
    border-left-color: #4CAF50;
    color: #2e7d32;
}

.items-balance.bad {
    background: #fff3e0;
    border-left-color: #FF9800;
    color: #e65100;
}

.btn-save:disabled {
    background: #f0f0f0;
    color: #aaa;
    border-color: #e0e0e0;
    cursor: not-allowed;
    transform: none;
}

.btn-save:disabled:hover {
    background: #f0f0f0;
    transform: none;
}

/* Пояснение о составе договора в модалке редактирования */
.edit-items-note {
    padding: 10px 12px;
    background: #f5f5f5;
    border-radius: 8px;
    font-size: 13px;
    color: #444;
}

.edit-items-note small {
    display: block;
    margin-top: 6px;
    color: #999;
    font-size: 11px;
    line-height: 1.5;
}

/* ==========================================================================
   Галерея фото частей договора
   ========================================================================== */

.gallery-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    font-size: 13px;
    text-align: center;
    border-radius: 0 0 8px 8px;
}

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.gallery-nav:hover { background: #fff; }
.gallery-prev { left: -56px; }
.gallery-next { right: -56px; }

@media (max-width: 600px) {
    .gallery-prev { left: 6px; }
    .gallery-next { right: 6px; }

    /* На телефоне таблица не прокручивается вбок, а раскладывается
       в компактные строки: фото слева, под типом — фасад, справа цена
       и детализация, сборщики отдельной строкой снизу. */
    .items-wrap { overflow-x: visible; }

    /* Подсветку «моей» части на телефоне красим по строке целиком,
       иначе между ячейками остаются белые промежутки. */
    .items-row.item-mine { background: #e8f5e9; }
    .items-row.item-mine > span { background: transparent; }

    .items-table.cols-admin,
    .items-table.cols-manager,
    .items-table.cols-designer,
    .items-table.cols-collector {
        display: block;
        min-width: 0;
        font-size: 11px;
    }

    .items-row.items-head { display: none; }

    .items-row {
        display: grid;
        gap: 2px 8px;
        padding: 7px 8px;
        border-bottom: 1px solid #eee;
        align-items: center;
    }

    .items-table > .items-row:last-child { border-bottom: none; }

    .items-row > span {
        padding: 0;
        border-bottom: none;
        white-space: normal;
    }

    /* admin / manager: фото | тип+фасад | цена | 📄 */
    .cols-admin .items-row,
    .cols-manager .items-row {
        grid-template-columns: 70px minmax(0, 1fr) auto auto;
    }

    .cols-admin .items-row > span:nth-child(1),
    .cols-manager .items-row > span:nth-child(1) { grid-row: 1 / span 2; grid-column: 1; }

    .cols-admin .items-row > span:nth-child(2),
    .cols-manager .items-row > span:nth-child(2) { grid-row: 1; grid-column: 2; }

    .cols-admin .items-row > span:nth-child(3),
    .cols-manager .items-row > span:nth-child(3) { grid-row: 2; grid-column: 2; font-size: 10px; }

    .cols-admin .items-row > span:nth-child(4),
    .cols-manager .items-row > span:nth-child(4) { grid-row: 1 / span 2; grid-column: 3; }

    .cols-admin .items-row > span:nth-child(5),
    .cols-manager .items-row > span:nth-child(5) { grid-row: 1 / span 2; grid-column: 4; }

    /* Сборщики — во всю ширину под строкой */
    .cols-admin .items-row > span:nth-child(6) {
        grid-row: 3;
        grid-column: 1 / -1;
        margin-top: 4px;
    }

    /* collector: фото | тип+фасад | файлы | оценка */
    .cols-collector .items-row {
        grid-template-columns: 70px minmax(0, 1fr) auto auto;
    }

    .cols-collector .items-row > span:nth-child(1) { grid-row: 1 / span 2; grid-column: 1; }
    .cols-collector .items-row > span:nth-child(2) { grid-row: 1; grid-column: 2; }
    .cols-collector .items-row > span:nth-child(3) { grid-row: 2; grid-column: 2; font-size: 10px; }
    .cols-collector .items-row > span:nth-child(4) { grid-row: 1 / span 2; grid-column: 3; }
    .cols-collector .items-row > span:nth-child(5) { grid-row: 1 / span 2; grid-column: 4; }

    /* designer: фото | тип+фасад | файлы */
    .cols-designer .items-row {
        grid-template-columns: 70px minmax(0, 1fr) auto;
    }

    .cols-designer .items-row > span:nth-child(1) { grid-row: 1 / span 2; grid-column: 1; }
    .cols-designer .items-row > span:nth-child(2) { grid-row: 1; grid-column: 2; }
    .cols-designer .items-row > span:nth-child(3) { grid-row: 2; grid-column: 2; font-size: 10px; }
    .cols-designer .items-row > span:nth-child(4) { grid-row: 1 / span 2; grid-column: 3; }

    /* Карточка договора в один столбец — таблице достаётся вся ширина */
    .contracts-list:not(.view-table) .contract-row {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 10px;
    }

    .contracts-list:not(.view-table) .contract-left {
        grid-column: 1;
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .contracts-list:not(.view-table) .contract-left .actions-row-bottom {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .contracts-list:not(.view-table) .contract-left .btn-edit,
    .contracts-list:not(.view-table) .contract-left .btn-delete,
    .contracts-list:not(.view-table) .contract-left .btn-cancel-completion {
        width: auto;
        flex: 1 1 auto;
    }

    .contracts-list:not(.view-table) .contract-right { grid-column: 1; }
}

/* ==========================================================================
   Поиск: кнопка «Новый договор по этому клиенту»
   ========================================================================== */

.btn-repeat-client {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: #E8F5E9;
    color: #2E7D32;
    border: 1px solid #A5D6A7;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    box-sizing: border-box;
}

.btn-repeat-client:hover {
    background: #C8E6C9;
    border-color: #66BB6A;
    transform: scale(1.03);
}

.btn-repeat-client:active {
    transform: scale(0.97);
}

/* В табличном виде кнопка не нужна — там кнопки скрыты целиком */
.contracts-list.view-table .btn-repeat-client {
    display: none;
}

/* Подсказка в модалке о том, откуда скопированы данные клиента */
.prefill-note {
    padding: 10px 12px;
    margin-bottom: 16px;
    background: #E8F5E9;
    border-left: 4px solid #4CAF50;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.5;
    color: #2E7D32;
}

/* ==========================================================================
   Вкладка «Закрытые»: отмена закрытия договора (только администратор)
   ========================================================================== */

.contracts-list:not(.view-table) .contract-right .btn-reopen-order {
    display: block !important;
    width: 100%;
    box-sizing: border-box;
    margin-top: 10px !important;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    background: #FFF3E0;
    color: #E65100;
    border: 1px solid #FFB74D;
    cursor: pointer;
    transition: all 0.2s ease;
}

.contracts-list:not(.view-table) .contract-right .btn-reopen-order:hover {
    background: #FFE0B2;
    border-color: #FB8C00;
}

.contracts-list:not(.view-table) .contract-right .btn-reopen-order:active {
    transform: scale(0.98);
}

/* Закрытая карточка приглушена (opacity: .7) — кнопку оставляем контрастной */
.contract-row.closed .btn-reopen-order {
    opacity: 1;
}

.contracts-list.view-table .btn-reopen-order {
    display: none;
}

/* ==========================================================================
   Кнопка «Навигатор» рядом с адресом
   ========================================================================== */

/* Адрес и кнопка навигатора — всегда в одной строке.
   nowrap не даёт кнопке перескочить вниз: длинный адрес переносится
   внутри своего блока, а кнопка остаётся справа от первой строки. */
.contract-address-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}

.contract-address-row .contract-address {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.btn-navigator {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #E3F2FD;
    color: #1565C0;
    border: 1px solid #90CAF9;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.btn-navigator:hover {
    background: #BBDEFB;
    border-color: #42A5F5;
}

.btn-navigator:active {
    transform: scale(0.96);
}

/* Закрытая карточка приглушена — кнопку оставляем читаемой */
.contract-row.closed .btn-navigator {
    opacity: 1;
}

/* Навигатор нужен только там, где он установлен — на телефоне.
   Проверяем не ширину экрана, а способ ввода: если у устройства есть мышь
   (компьютер, ноутбук), кнопку прячем. Телефон и планшет с сенсорным
   экраном её видят при любой ширине, в том числе в альбомной ориентации. */
@media (hover: hover) and (pointer: fine) {
    .btn-navigator {
        display: none;
    }
}

/* В карточке сборщика адрес с кнопкой тоже в одну строку */
.collector-contract-row .contract-address-row {
    gap: 6px;
}

/* В табличном виде кнопка не нужна */
.contracts-list.view-table .contract-address-row,
.contracts-list.view-table .btn-navigator {
    display: none;
}

/* ============================================================
   Строка поиска + переключатель режима отображения
   ============================================================ */
.search-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.search-row .search-input {
    flex: 1;
    min-width: 0;
}

.search-row .view-toggle-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

/* ============================================================
   Кнопка «Себестоимость» в карточке договора
   ============================================================ */
.btn-cost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: #FF9944;
    border: 1px solid #FF9944;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-cost:hover {
    background: #FFF3E0;
    border-color: #F57C00;
    color: #F57C00;
    transform: scale(1.05);
}

.btn-cost:active {
    transform: scale(0.95);
}

/* ============================================================
   Окно «Себестоимость»: все операции по договору
   ============================================================ */
.cost-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s ease;
}

.cost-modal {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 460px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.cost-modal-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #eee;
}

.cost-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #333;
}

.cost-modal-sub {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
}

.cost-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: #999;
    cursor: pointer;
    padding: 0;
}

.cost-modal-close:hover {
    color: #333;
}

.cost-totals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: #eee;
    border-bottom: 1px solid #eee;
}

.cost-total {
    background: #fafafa;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
    color: #666;
}

.cost-total b {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #333;
    white-space: nowrap;
}

.cost-total.income b { color: #4CAF50; }
.cost-total.expense b { color: #E57373; }
.cost-total.profit b { color: #1565C0; }

.cost-hint {
    padding: 10px 20px;
    font-size: 12px;
    color: #999;
    background: #fffdf5;
    border-bottom: 1px solid #eee;
}

.cost-ops {
    overflow-y: auto;
    padding: 8px 12px 14px;
}

.cost-op {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    border-bottom: 1px solid #f2f2f2;
}

.cost-op:last-child {
    border-bottom: none;
}

.cost-op-main {
    flex: 1;
    min-width: 0;
}

.cost-op-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.cost-op-date {
    font-size: 11px;
    color: #999;
    font-family: 'Courier New', monospace;
}

.cost-op-cat {
    font-size: 13px;
    color: #333;
    font-weight: 500;
}

.cost-op-pending {
    font-size: 10px;
    color: #F57C00;
    background: #FFF3E0;
    border-radius: 4px;
    padding: 1px 5px;
}

.cost-op-note {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
    word-break: break-word;
}

.cost-op-sum {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.cost-op.income .cost-op-sum { color: #4CAF50; }
.cost-op.expense .cost-op-sum { color: #E57373; }

.cost-op-del {
    background: transparent;
    border: 1px solid #ddd;
    color: #999;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.cost-op-del:hover {
    border-color: #E57373;
    color: #E57373;
    background: #ffebee;
}

.cost-empty {
    text-align: center;
    color: #999;
    font-size: 14px;
    padding: 30px 10px;
}

/* ============================================================
   Минималистичный табличный режим списка договоров
   ============================================================ */
.contracts-list.mini-mode .contract-row {
    display: none !important;
}

table.contracts-mini {
    width: 100%;
    /* Фиксированная раскладка: ширины столбцов берутся из объявленных,
       а длинный заголовок «Себестоимость» больше не растягивает столбец
       и не отбирает место у ФИО. */
    table-layout: fixed;
    border-collapse: collapse;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

table.contracts-mini th {
    background: #f5f5f5;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #999;
    font-weight: 600;
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid #e0e0e0;
}

table.contracts-mini td {
    padding: 9px 8px;
    border-bottom: 1px solid #f2f2f2;
    font-size: 13px;
    color: #333;
    vertical-align: middle;
}

table.contracts-mini tr:last-child td {
    border-bottom: none;
}

table.contracts-mini tr.closed td {
    background: #f3faf4;
}

table.contracts-mini .col-num {
    width: 44px;
    text-align: right;
    color: #999;
    font-family: 'Courier New', monospace;
}

/* Рабочие дни в работе — обычным чёрным текстом, как просили */
table.contracts-mini .col-workdays {
    width: 78px;
    text-align: right;
    white-space: nowrap;
    color: #333;
    font-family: 'Courier New', monospace;
}

/* Заголовок в верхнем регистре шире значений — иначе наезжает на ФИО */
table.contracts-mini th.col-workdays {
    font-family: inherit;
    font-weight: 600;
    text-align: right;
    padding-right: 8px;
    letter-spacing: 0;
}

table.contracts-mini .col-client {
    width: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

table.contracts-mini .col-money {
    text-align: right;
    white-space: nowrap;
    font-family: 'Courier New', monospace;
    width: 104px;
}

/* «Себестоимость» не влезает в узкий столбец на телефоне,
   поэтому там показывается короткий вариант заголовка. */
table.contracts-mini th.col-money {
    white-space: normal;
    line-height: 1.2;
    overflow: hidden;
}

table.contracts-mini th .narrow-only {
    display: none;
}

table.contracts-mini .col-act {
    width: 44px;
    text-align: right;
}

/* Прибыль = стоимость − себестоимость. Минус показываем чёрным,
   а не красным — как и отрицательный баланс на «Финансах». */
table.contracts-mini .col-profit {
    color: #4CAF50;
    font-weight: 600;
}

table.contracts-mini .col-profit.negative {
    color: #000;
}

.mini-cost {
    background: transparent;
    border: none;
    color: #FF9944;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    text-decoration: underline;
    white-space: nowrap;
}

.mini-cost:hover {
    background: #FFF3E0;
    color: #F57C00;
}

table.contracts-mini .btn-edit.mini-edit {
    padding: 5px 8px;
    font-size: 14px;
    min-width: 0;
    background: transparent;
    color: #666;
    border: 1px solid #ddd;
}

table.contracts-mini .btn-edit.mini-edit:hover {
    background: #f0f0f0;
    color: #333;
    transform: none;
}

@media (max-width: 480px) {
    table.contracts-mini th,
    table.contracts-mini td {
        padding: 8px 4px;
        font-size: 12px;
    }

    table.contracts-mini th {
        font-size: 9px;
        letter-spacing: 0;
    }

    table.contracts-mini th .wide-only {
        display: none;
    }

    table.contracts-mini th .narrow-only {
        display: inline;
    }

    table.contracts-mini .col-money {
        width: 70px;
        font-size: 11px;
    }

    table.contracts-mini .col-num {
        width: 30px;
    }

    table.contracts-mini .col-workdays {
        width: 38px;
        font-size: 11px;
        padding-left: 2px;
        padding-right: 4px;
    }

    table.contracts-mini th.col-workdays {
        padding-right: 4px;
    }

    table.contracts-mini .col-act {
        width: 40px;
    }

    table.contracts-mini .btn-edit.mini-edit {
        padding: 4px 5px;
        font-size: 13px;
    }

    .cost-totals {
        grid-template-columns: 1fr;
    }
}


/* ==========================================================================
   Карточка договора: шапка, суммы, значки
   ========================================================================== */

/* Первая строка — ФИО и тип мебели */
.contract-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.client-name {
    /* В полтора раза крупнее прежних 15px — ФИО главное в карточке */
    font-size: 22px;
    font-weight: 700;
    color: #2b2b2b;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.client-name.expandable {
    cursor: pointer;
    border-bottom: 1px dashed #d0d0d0;
}

.client-name.expandable:hover {
    border-bottom-color: #999;
}

/* Полное ФИО лежит рядом с сокращённым и показывается по нажатию */
.cn-full {
    display: none;
}

.client-name.expanded .cn-short {
    display: none;
}

.client-name.expanded .cn-full {
    display: inline;
}

/* Тип мебели виден всегда */
.type-badge {
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 500;
    color: #6b6b6b;
    background: #f0f0f0;
    border-radius: 10px;
    padding: 2px 8px;
    white-space: nowrap;
}

.contract-row.closed .type-badge {
    background: #dbeedd;
}

/* Суммы: подписи слева, значения справа, все одного серого цвета */
.contract-sums {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px !important;
}

.sum-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    line-height: 1.4;
}

.sum-label {
    color: #9a9a9a;
    font-weight: 400;
}

.sum-value {
    color: #6b6b6b;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    white-space: nowrap;
}

/* Себестоимость — единственная выделенная цветом строка */
.sum-row.cost .sum-label {
    color: #C05621;
}

.sum-row.cost .sum-value {
    color: #C05621;
    text-decoration: underline;
    cursor: pointer;
}

.sum-row.cost .sum-value:hover {
    color: #97400f;
}

/* Значок подъёма — в конце строки с адресом */
.lift-badge {
    flex: 0 0 auto;
    font-size: 14px;
    line-height: 1;
    cursor: help;
    white-space: nowrap;
}

/* Пометка у маленького лифта: сам лифт есть, но мебель в него не входит */
.lift-mini {
    font-size: 9px;
    font-weight: 600;
    color: #9a9a9a;
    vertical-align: super;
    margin-left: 1px;
    letter-spacing: -0.2px;
}

/* ==========================================================================
   Кнопка «Навигатор» в цветах Яндекс Навигатора
   ========================================================================== */

.btn-navigator {
    background: #FFDB4D;
    color: #21201F;
    border: 1px solid #F0C400;
    gap: 5px;
    padding: 4px 9px;
    font-weight: 600;
    align-self: flex-start;
}

/* На узком экране подпись прячем — остаётся один узнаваемый значок */
@media (max-width: 380px) {
    .btn-navigator span {
        display: none;
    }

    .btn-navigator {
        padding: 5px 7px;
    }
}

.btn-navigator:hover {
    background: #FFCC00;
    border-color: #E0B800;
}

.navi-icon {
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    display: block;
}

/* В карточке сборщика суммы не показываются */
.collector-contract-row .contract-sums {
    display: none;
}

@media (max-width: 480px) {
    .client-name {
        font-size: 14px;
    }

    .sum-row {
        font-size: 11px;
    }
}


/* --------------------------------------------------------------------------
   Правило «.contract-right > * { display: block }» (см. выше) делает блочными
   ВСЕ прямые блоки правой колонки. Возвращаем flex тем, кому он нужен:
   без этого кнопка навигатора уезжала под адрес, а шапка теряла выравнивание.
   -------------------------------------------------------------------------- */
.contracts-list:not(.view-table) .contract-right > .contract-head,
.contracts-list:not(.view-table) .contract-right > .contract-address-row {
    display: flex;
}

.contracts-list:not(.view-table) .contract-right > .contract-sums {
    display: flex;
    flex-direction: column;
}


/* Короткое уведомление внизу экрана */
.app-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    max-width: calc(100vw - 32px);
    background: #333;
    color: #fff;
    font-size: 13px;
    line-height: 1.35;
    padding: 10px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    z-index: 10050;
    text-align: center;
    animation: toastIn 0.2s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ====================================================================
   ФАЙЛЫ ЧАСТИ ДОГОВОРА
   Колонка «Файлы» в карточке, окно «Остальные файлы»
   и плитки файлов в форме создания/редактирования.
   ==================================================================== */

/* Увеличенная картинка и просмотр текста открываются ПОВЕРХ окна файлов */
#file-lightbox { z-index: 12200; }
#file-text-viewer { z-index: 12100; }

.item-files-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.item-file-none {
    color: #bbb;
    font-size: 12px;
}

.btn-item-files {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 5px;
    border: 1px solid #d7d7d7;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
}

.btn-item-files:hover {
    background: #f2f6ff;
    border-color: #9db9ee;
}

.btn-item-files .files-count {
    font-size: 10px;
    font-weight: 600;
    color: #4a6fa5;
}

/* ---- Мини-окно со списком файлов ---- */

.files-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 12000;
    padding: 16px;
}

.files-window {
    background: #fff;
    border-radius: 12px;
    width: min(760px, 100%);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
}

.files-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
}

.files-title {
    font-weight: 600;
    font-size: 15px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.files-close {
    border: none;
    background: transparent;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: #888;
    padding: 2px 6px;
}

.files-close:hover { color: #222; }

/* Панель «скачать архивом» под шапкой окна */
.files-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid #eee;
    background: #fff;
}

.btn-archive {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: #2e7d32;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn-archive:hover { background: #256428; }
.btn-archive:disabled { opacity: 0.6; cursor: default; }

.btn-archive .archive-note {
    font-weight: 400;
    font-size: 11px;
    opacity: 0.85;
}

.btn-archive-alt {
    background: #fff;
    color: #2e7d32;
    border: 1px solid #b6d7b8;
}

.btn-archive-alt:hover { background: #f1f8f1; }

.files-group-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #8a8a8a;
    margin: 4px 0 8px;
}

.files-group-title + .files-grid { margin-bottom: 18px; }

.files-body {
    padding: 14px 16px 18px;
    overflow-y: auto;
}

.files-empty {
    color: #888;
    text-align: center;
    padding: 24px 0;
}

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

.file-cell {
    border: 1px solid #e6e6e6;
    border-radius: 10px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #fcfcfc;
}

.file-preview {
    height: 96px;
    border-radius: 8px;
    overflow: hidden;
    background: #f1f1f1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.file-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.file-preview-icon {
    flex-direction: column;
    gap: 2px;
    background: #f4f6fa;
}

.file-preview-icon .file-ico { font-size: 30px; line-height: 1; }
.file-preview-icon .file-ext {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #6b7c99;
}

.file-preview:hover { filter: brightness(0.96); }

.file-name {
    font-size: 11px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta {
    font-size: 10px;
    color: #999;
}

.file-dl {
    border: 1px solid #d7d7d7;
    background: #fff;
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 11px;
    cursor: pointer;
    color: #444;
}

.file-dl:hover { background: #f2f6ff; border-color: #9db9ee; }

/* Просмотр текстового файла */
.files-window.text-window { width: min(880px, 100%); }

.file-text {
    margin: 0;
    padding: 14px 16px 18px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    color: #222;
}

/* ---- Плитки файлов в форме ---- */

.file-thumb .file-thumb-ico {
    width: 84px;
    height: 84px;
    border-radius: 8px;
    border: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: #f4f6fa;
    color: #6b7c99;
}

.file-thumb .file-thumb-ico span { font-size: 26px; line-height: 1; }
.file-thumb .file-thumb-ico b {
    font-size: 9px;
    letter-spacing: 0.04em;
}

@media (max-width: 768px) {
    .files-overlay { padding: 0; }

    .files-window {
        width: 100%;
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
    }

    .files-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

/* ====================================================================
   ПРОЕКТИРОВКА
   Кнопка в карточке, окно загрузки, группа файлов и бейдж роли.
   ==================================================================== */

.btn-item-design {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 5px;
    border: 1px solid #d7d7d7;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
}

.btn-item-design:hover {
    background: #f3effb;
    border-color: #b9a4e0;
}

/* Проектировка уже загружена */
.btn-item-design.has-design {
    background: #efe7fb;
    border-color: #b9a4e0;
}

.design-window { width: min(680px, 100%); }

.design-block {
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid #eee;
}

.design-block:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 4px;
}

.design-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.design-actions {
    border-bottom: none;
    border-top: 1px solid #eee;
}

.design-status {
    font-size: 13px;
    color: #666;
    min-height: 18px;
}

.design-status.bad {
    color: #c62828;
    background: #fdecea;
    border-radius: 6px;
    padding: 8px 10px;
}

.btn-archive-design {
    background: #6b4fa0;
}

.btn-archive-design:hover { background: #573f83; }

/* Фурнитура в списке файлов заметно выделена */
.file-cell-hw {
    border-color: #c9b6e8;
    background: #faf7ff;
}

.file-badge {
    font-size: 10px;
    font-weight: 700;
    color: #6b4fa0;
    letter-spacing: 0.02em;
}

.badge-designer {
    background: #efe7fb;
    color: #5a3f8a;
}

/* ====================================================================
   ЗАКУПКА ФУРНИТУРЫ
   Кнопка под таблицей частей и окно со списком позиций.
   ==================================================================== */

.purchase-row {
    margin-top: 8px;
}

.btn-purchase {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid #ffd9a0;
    border-radius: 6px;
    background: #fff6e8;
    color: #a35b06;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn-purchase:hover {
    background: #ffedd4;
    border-color: #f0b968;
}

.purchase-window { width: min(720px, 100%); }

/* Полоса общего прогресса под шапкой */
.purchase-summary {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    background: #fff;
}

.purchase-progress {
    height: 6px;
    border-radius: 3px;
    background: #eee;
    overflow: hidden;
}

.purchase-progress-bar {
    height: 100%;
    background: #2e7d32;
    border-radius: 3px;
    transition: width 0.25s ease;
}

.purchase-progress-text {
    margin-top: 6px;
    font-size: 12px;
    color: #666;
}

.purchase-part {
    margin-bottom: 20px;
}

.purchase-part:last-child { margin-bottom: 0; }

.purchase-part-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}

.purchase-part-name {
    font-size: 13px;
    font-weight: 700;
    color: #444;
}

.purchase-part-count {
    font-size: 11px;
    color: #999;
    white-space: nowrap;
}

.purchase-part-count.all-done {
    color: #2e7d32;
    font-weight: 600;
}

.purchase-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
}

.purchase-line td {
    padding: 8px 10px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    color: #333;
    vertical-align: middle;
}

.purchase-line:last-child td { border-bottom: none; }

.purchase-check {
    width: 1%;
    padding-right: 0 !important;
}

/* Палец должен попадать по галочке уверенно */
.purchase-check input {
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
    accent-color: #2e7d32;
}

.purchase-text {
    word-break: break-word;
    white-space: normal;
}

/* Закупленная позиция гасится, но остаётся читаемой */
.purchase-line.done {
    background: #f4faf4;
}

.purchase-line.done .purchase-text {
    color: #8a9a8a;
    text-decoration: line-through;
}

@media (max-width: 768px) {
    .purchase-line td {
        padding: 10px 8px;
        font-size: 13px;
    }
}

/* Счётчик «закуплено/всего» прямо на кнопке */
.btn-purchase .purchase-count {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

/* Всё закуплено — кнопка перестаёт привлекать внимание */
.btn-purchase.all-done {
    background: #eef7ee;
    border-color: #c3e0c3;
    color: #2e7d32;
}

.btn-purchase.all-done:hover {
    background: #e2f1e2;
    border-color: #a5d0a5;
}


/* ====================================================================
   «В РАБОТЕ: N РАБ. ДНЕЙ»
   Подпись после номера договора в карточке.
   ==================================================================== */

.work-days {
    margin-left: 8px;
    font-size: 11px;
    font-weight: 400;
    color: #c4c4c4;
    white-space: nowrap;
}

/* В карточке номер договора и так светло-серый — счётчик чуть светлее,
   чтобы не спорить с самим номером */
.contracts-list.view-cards .contract-name .work-days {
    color: #c4c4c4;
}

/* В табличном режиме карточки не видны, но подпись есть в разметке:
   там её показывает отдельная колонка «(раб. дни)» */
.contracts-list.view-table .work-days {
    display: none;
}

@media (max-width: 480px) {
    .work-days {
        margin-left: 6px;
        font-size: 10px;
    }
}

/* ====================================================================
   ПРЕДПРОСМОТР ТАБЛИЦ EXCEL
   Оформление повторяет саму программу: буквы столбцов, номера строк,
   строка формул сверху и вкладки листов снизу.
   ==================================================================== */

.sheet-window {
    width: min(1140px, 100%);
    max-height: 92vh;
}

/* Высота шапки с буквами — по ней же считается прилипание */
.sheet-window {
    --sheet-head-h: 24px;
}

/* Строка формул */
.sheet-formula {
    display: flex;
    align-items: stretch;
    gap: 0;
    border-bottom: 1px solid #d0d0d0;
    background: #fff;
    flex: 0 0 auto;
}

.sheet-addr {
    flex: 0 0 84px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #d0d0d0;
    background: #f8f8f8;
    font-size: 12px;
    font-weight: 600;
    color: #444;
    font-family: 'Courier New', monospace;
}

.sheet-value {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    font-size: 12px;
    color: #222;
    white-space: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Сетка */
.sheet-body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
    background: #fff;
}

.sheet-table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.sheet-table td,
.sheet-table th {
    border-right: 1px solid #d9d9d9;
    border-bottom: 1px solid #d9d9d9;
    padding: 4px 7px;
    height: var(--sheet-head-h);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
    background: #fff;
    color: #222;
    font-weight: 400;
    text-align: left;
    vertical-align: middle;
}

/* Буквы столбцов — прилипают сверху */
.sheet-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f2f2f2;
    color: #666;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid #b8b8b8;
    min-width: 64px;
}

/* Номера строк — прилипают слева */
.sheet-table .sheet-rownum {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #f2f2f2;
    color: #888;
    font-size: 11px;
    text-align: center;
    min-width: 42px;
    width: 42px;
    border-right: 1px solid #b8b8b8;
}

/* Угол над номерами строк */
.sheet-table .sheet-corner {
    position: sticky;
    left: 0;
    top: 0;
    z-index: 5;
    min-width: 42px;
    width: 42px;
    background: #eaeaea;
    border-right: 1px solid #b8b8b8;
}

/* Заголовок столбца и номер строки текущей ячейки подсвечены */
.sheet-table .sheet-colname.active,
.sheet-table .sheet-rownum.active {
    background: #d6e4f7;
    color: #1a4a8a;
}

/* Закреплённая первая строка — идёт сразу под буквами столбцов */
.sheet-table tbody tr.sheet-frozen td,
.sheet-table tbody tr.sheet-frozen th {
    position: sticky;
    top: var(--sheet-head-h, 24px);
    z-index: 2;
    background: #fbfbfb;
    font-weight: 600;
    color: #333;
    border-bottom: 1px solid #b8b8b8;
}

.sheet-table tbody tr.sheet-frozen th.sheet-rownum {
    z-index: 4;
    background: #f2f2f2;
    font-weight: 400;
}

.sheet-table .sheet-num {
    text-align: right;
    font-family: 'Courier New', monospace;
}

.sheet-table tbody td {
    cursor: cell;
}

.sheet-table tbody td:hover {
    background: #f7f9fc;
}

/* Текущая ячейка — рамкой, как в Excel */
.sheet-table td.selected {
    outline: 2px solid #217346;
    outline-offset: -2px;
    background: #fff;
}

.sheet-empty {
    padding: 30px;
    color: #999;
    text-align: center;
    cursor: default !important;
}

/* Низ окна: вкладки листов слева, сведения и скачивание справа */
.sheet-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-top: 1px solid #d0d0d0;
    background: #f6f6f6;
    flex: 0 0 auto;
}

.sheet-tabs {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    min-width: 0;
}

.sheet-tabs.single {
    font-size: 12px;
    color: #666;
    padding: 4px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-tab {
    flex: 0 0 auto;
    padding: 5px 14px;
    border: 1px solid #d0d0d0;
    border-top: none;
    border-radius: 0 0 5px 5px;
    background: #eaeaea;
    color: #666;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sheet-tab:hover { background: #e0e0e0; }

.sheet-tab.active {
    background: #fff;
    color: #217346;
    font-weight: 600;
    border-top: 2px solid #217346;
    padding-top: 3px;
}

.sheet-foot-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
}

.sheet-note {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .sheet-window { max-height: 100vh; }

    .sheet-table td,
    .sheet-table th {
        padding: 5px 6px;
        font-size: 11px;
        max-width: 150px;
    }

    .sheet-table thead th { min-width: 52px; }

    .sheet-addr { flex-basis: 60px; font-size: 11px; }

    .sheet-foot {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .sheet-foot-right {
        justify-content: space-between;
    }

    .sheet-note { white-space: normal; }
}

/* ====================================================================
   КАРТОЧКА: НОМЕР ДОГОВОРА, ТИП МЕБЕЛИ, ПЕРЕХОД ИЗ ТАБЛИЦЫ
   ==================================================================== */

/* Номер договора — такой же неброский текст, как «В работе: N раб. дней»,
   и стоит сразу за ним */
.contract-no {
    font-size: 11px;
    font-weight: 400;
    color: #c4c4c4;
    letter-spacing: 0.2px;
    margin-left: 8px;
    white-space: nowrap;
}

/* Если счётчика дней нет (договор не заключён), отступ слева не нужен */
.contract-name > .contract-no:first-child {
    margin-left: 0;
}

/* Тип мебели — своей строкой под фамилией */
.type-line {
    margin-top: 2px;
}

.contracts-list.view-cards .contract-right > .type-line {
    display: block;
}

/* Карточка, к которой перешли из таблицы: подсвечивается на пару секунд */
@keyframes cardFlash {
    0%   { background: #fff8dc; box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.45); }
    70%  { background: #fff8dc; box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.25); }
    100% { background: inherit;  box-shadow: none; }
}

.contract-row.card-flash {
    animation: cardFlash 2.4s ease-out;
}

/* Фамилия в табличном режиме кликабельна — ведёт к карточке */
table.contracts-mini .col-client {
    cursor: pointer;
    color: #1a4a8a;
}

table.contracts-mini .col-client:hover {
    text-decoration: underline;
}

/* Подпись под найденным договором: в каком файле совпало */
.match-note {
    font-size: 10px;
    color: #8a7a3a;
    background: #fffbe8;
    border: 1px solid #f0e6bd;
    border-radius: 5px;
    padding: 4px 7px;
    margin-top: 4px !important;
    overflow-wrap: anywhere;
}

.match-note:empty { display: none; }

/* ====================================================================
   ПРЕДПРОСМОТР WORD
   ==================================================================== */

.doc-window {
    width: min(900px, 100%);
    max-height: 92vh;
}

.doc-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 20px 24px;
    background: #fff;
    font-size: 13px;
    line-height: 1.5;
    color: #222;
}

.doc-p {
    margin: 0 0 10px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.doc-p:last-child { margin-bottom: 0; }

.doc-table-wrap {
    overflow-x: auto;
    margin: 0 0 16px;
}

.doc-table {
    border-collapse: collapse;
    width: 100%;
}

.doc-table td {
    border: 1px solid #d9d9d9;
    padding: 5px 8px;
    vertical-align: top;
    overflow-wrap: anywhere;
    min-width: 70px;
}

.doc-row-head td {
    background: #f4f6f8;
    font-weight: 600;
}

@media (max-width: 768px) {
    .doc-window { max-height: 100vh; }
    .doc-body { padding: 14px; font-size: 12px; }
    .doc-table td { padding: 5px 6px; font-size: 11px; }
}

/* ====================================================================
   ДОГОВОР В PDF
   Строка «В работе: N раб. дней  A15-318» служит кнопкой скачивания.
   Оформление строки не меняется: кнопка прозрачная и наследует всё —
   шрифт, размер, цвет, межбуквенное расстояние. Единственное, что
   добавлено, — кружок перед текстом.
   ==================================================================== */

.contract-pdf-line {
    display: inline;
    padding: 0;
    margin: 0;
    border: 0;
    background: none;
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
    line-height: inherit;
    text-align: left;
    cursor: pointer;
}

/* Кружок не должен утаскивать за собой цвет и размер соседних подписей */
.pdf-dot {
    margin-right: 4px;
    font-size: 9px;
    vertical-align: middle;
    line-height: 1;
}

/* Файла нет — нажимать нечего */
.contract-pdf-line.no-pdf {
    cursor: default;
}

/* Кнопка с файлом чуть подсвечивается, но цвет текста остаётся прежним */
.contract-pdf-line.has-pdf:hover .contract-no,
.contract-pdf-line.has-pdf:hover .work-days {
    text-decoration: underline;
}

.contract-pdf-line:focus-visible {
    outline: 1px solid #b5b5b5;
    outline-offset: 2px;
}

/* В табличном режиме карточек не видно, но на всякий случай */
.contracts-list.view-table .pdf-dot {
    display: none;
}

/* Приложенный файл в форме: по нему можно кликнуть и скачать */
.photo-thumb.pdf-downloadable {
    cursor: pointer;
}

.photo-thumb.pdf-downloadable:hover {
    border-color: #b03a2e;
}

/* ====================================================================
   МАСТЕР ДОГОВОРА: ЭТАПЫ, ЧАСТИ, ЗАГРУЗКА
   ==================================================================== */

.wizard-step {
    border: 1px solid #e6e6e6;
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 16px;
    background: #fff;
}

.wizard-step-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    color: #333;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    flex-wrap: wrap;
}

.wizard-step-no {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #3F3F3F;
    color: #fff;
    font-size: 12px;
    flex-shrink: 0;
}

.wizard-step-note {
    font-size: 11px;
    font-weight: 400;
    color: #999;
    flex-basis: 100%;
}

/* Второй этап до сохранения первого: виден, но недоступен —
   так понятно, что будет дальше, но нельзя начать не с того конца */
.wizard-step.step-locked {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(0.6);
}

.wizard-save {
    width: 100%;
    margin-top: 4px;
}

/* Сообщения: ошибку показываем целиком, она может быть длинной */
.wizard-message {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.45;
    margin-bottom: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

.wizard-message.error {
    background: #fdecea;
    color: #b3261e;
    border-left: 4px solid #b3261e;
}

.wizard-message.ok {
    background: #e8f5e9;
    color: #2e7d32;
    border-left: 4px solid #4CAF50;
}

.wizard-message.info {
    background: #f2f4f7;
    color: #555;
    border-left: 4px solid #b5b5b5;
}

/* ---- Карточка части ---- */
.item-card {
    border: 1px solid #e6e6e6;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fafafa;
}

.item-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.item-card-title {
    font-weight: 700;
    font-size: 14px;
    color: #333;
}

.item-saved {
    font-size: 11px;
    color: #2e7d32;
    background: #e8f5e9;
    border-radius: 10px;
    padding: 2px 8px;
}

.item-unsaved {
    font-size: 11px;
    color: #8a6d00;
    background: #fff6d8;
    border-radius: 10px;
    padding: 2px 8px;
}

.item-remove {
    margin-left: auto;
    background: none;
    border: 1px solid #ddd;
    color: #b3261e;
    border-radius: 6px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    line-height: 1;
}

.item-remove:hover {
    background: #fdecea;
    border-color: #f0b4ae;
}

.btn-save-item {
    width: 100%;
    padding: 10px;
    border: 1px solid #BBDEFB;
    border-radius: 8px;
    background: #E3F2FD;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-save-item:hover:not(:disabled) { background: #BBDEFB; }
.btn-save-item:disabled { opacity: 0.6; cursor: default; }

.btn-add-item {
    width: 100%;
    padding: 12px;
    border: 1px dashed #bbb;
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    color: #555;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-add-item:hover { border-color: #3F3F3F; color: #3F3F3F; }

.item-files {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed #ddd;
}

.item-files-hint {
    margin-top: 10px;
    font-size: 12px;
    color: #999;
    text-align: center;
    padding: 8px;
    background: #f2f4f7;
    border-radius: 8px;
}

.items-balance.ok { color: #2e7d32; }
.items-balance.warn { color: #8a6d00; }

/* ---- Круговой индикатор загрузки ----
   Круг заполняется по часовой стрелке: conic-gradient рисует
   ровно тот «пирог», который просили. Как только файл долетел,
   плитка перерисовывается уже без него. */
.photo-thumb.is-uploading img,
.photo-thumb.is-uploading .file-thumb-ico {
    opacity: 0.45;
    filter: blur(1px);
}

.upload-pie {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: conic-gradient(#4CAF50 0deg 0deg, rgba(255, 255, 255, 0.35) 0deg 360deg);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
}

/* Белая серединка — чтобы это читалось как круговая шкала,
   а не как сплошной кружок */
.upload-pie::after {
    content: "";
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
}

.upload-percent {
    position: relative;
    z-index: 1;
    font-size: 9px;
    font-weight: 700;
    color: #2e7d32;
}

/* Пометка договора, у которого сохранена только общая информация */
.draft-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    color: #8a6d00;
    background: #fff6d8;
    border: 1px solid #f0e0a8;
    border-radius: 10px;
    padding: 1px 8px;
    white-space: nowrap;
}

/* Подсветка договора после смены статуса: он переезжает на другую
   вкладку, и без метки его пришлось бы искать глазами. Светло-оранжевый
   держится три секунды и плавно гаснет. */
@keyframes cardHighlight {
    0%   { background: #FFE0B2; box-shadow: 0 0 0 3px rgba(255, 152, 0, 0.45); }
    80%  { background: #FFE0B2; box-shadow: 0 0 0 3px rgba(255, 152, 0, 0.35); }
    100% { background: inherit; box-shadow: none; }
}

.contract-row.card-highlight {
    animation: cardHighlight 3s ease-out;
}
