/* ========== СБРОС И БАЗОВЫЕ СТИЛИ ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

/* ========== ШАПКА ПРИЛОЖЕНИЯ ========== */
.app-header {
    background: linear-gradient(135deg, #2c3e50, #3498db);
    color: white;
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.app-header h1 { font-size: 1.5rem; font-weight: 600; }
.app-header .version { font-size: 0.8rem; opacity: 0.7; }

/* ========== НАВИГАЦИЯ ========== */
.nav-tabs {
    background: white;
    display: flex;
    border-bottom: 2px solid #e0e0e0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.nav-tabs button {
    padding: 15px 30px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1rem;
    color: #666;
    transition: all 0.3s ease;
    position: relative;
}

.nav-tabs button:hover { background: #f0f4f8; color: #3498db; }
.nav-tabs button.active { color: #3498db; font-weight: 600; }

.nav-tabs button.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 3px;
    background: #3498db;
}

/* ========== КОНТЕЙНЕР ========== */
.content-container {
    max-width: 1400px;
    margin: 30px auto;
    padding: 0 20px;
}

.tab-content { display: none; }
.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== КАРТОЧКИ ========== */
.card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.08);
    padding: 25px;
    margin-bottom: 25px;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e8ecf1;
}

/* ========== ФОРМЫ ========== */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #555;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

/* ========== КНОПКИ ========== */
.btn {
    padding: 12px 25px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary { background: #3498db; color: white; }
.btn-primary:hover {
    background: #2980b9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.35);
}

.btn-success { background: #27ae60; color: white; }
.btn-success:hover { background: #219a52; }

.btn-danger { background: #e74c3c; color: white; }
.btn-danger:hover { background: #c0392b; }

.btn-warning { background: #f39c12; color: white; }
.btn-warning:hover { background: #d68910; }

.btn-sm { padding: 8px 15px; font-size: 0.875rem; }

.btn-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

/* ========== ТАБЛИЦЫ ========== */
.table-container { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #e8ecf1;
}

th {
    background: #f8fafc;
    font-weight: 600;
    color: #2c3e50;
    white-space: nowrap;
}

tr:hover { background: #f8fafc; }

td input, td select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

td input:focus, td select:focus {
    outline: none;
    border-color: #3498db;
}

td input[readonly] { background: #f8fafc; color: #666; }

.col-name { width: 40%; }
.col-unit { width: 12%; }
.col-qty { width: 12%; }
.col-price { width: 15%; }
.col-sum { width: 15%; }
.col-action { width: 6%; text-align: center; }

.btn-delete {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 5px;
    transition: transform 0.2s;
}

.btn-delete:hover { transform: scale(1.2); }

/* ========== АВТОДОПОЛНЕНИЕ ========== */
.autocomplete-wrapper { position: relative; }

.autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    display: none;
}

.autocomplete-list.show { display: block; }

.autocomplete-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.autocomplete-item:hover,
.autocomplete-item.selected { background: #e8f4fc; }

.autocomplete-item .item-name { font-weight: 500; }
.autocomplete-item .item-info { font-size: 0.85rem; color: #888; }

/* ========== ГРУППЫ РАБОТ ========== */
.work-group {
    border: 2px solid #e8ecf1;
    border-radius: 10px;
    margin-bottom: 20px;
    overflow: hidden;
}

.group-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.group-header input {
    background: rgba(255,255,0.2);
    border: 1px solid rgba(255,255,0.3);
    color: white;
    padding: 8px 15px;
    border-radius: 5px;
    font-size: 1rem;
    flex: 1;
    max-width: 400px;
}

.group-header input::placeholder { color: rgba(255,255,0.7); }
.group-header input:focus { outline: none; background: rgba(255,255,0.3); }

.group-body { padding: 20px; }

.group-footer {
    background: #f8fafc;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #e8ecf1;
}

.group-total { font-size: 1.1rem; font-weight: 600; color: #2c3e50; }

/* ========== ИТОГОВЫЙ БЛОК ========== */
.totals-card {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
}

.totals-card .card-title {
    color: white;
    border-bottom-color: rgba(255,255,255,0.2);
}

.totals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.total-item {
    text-align: center;
    padding: 20px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
}

.total-item .label { font-size: 0.9rem; opacity: 0.8; margin-bottom: 5px; }
.total-item .value { font-size: 1.5rem; font-weight: 700; }

.total-item.grand-total {
    background: rgba(46, 204, 113, 0.3);
    border: 2px solid #2ecc71;
}

.total-item.grand-total .value { font-size: 2rem; color: #2ecc71; }

/* ========== ДОПОЛНИТЕЛЬНЫЕ РАСХОДЫ ========== */
.extra-costs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.extra-cost-item {
    display: flex;
    align-items: center;
    gap: 15px;
}

.extra-cost-item label { white-space: nowrap; font-weight: 500; }

.extra-cost-item input[type="number"] {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

.extra-cost-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* ========== УВЕДОМЛЕНИЯ ========== */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #27ae60;
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transform: translateX(150%);
    transition: transform 0.4s ease;
    z-index: 1000;
}

.toast.show { transform: translateX(0); }

/* ========== ПЕЧАТНАЯ ФОРМА ========== */
.print-document {
    background: white;
    padding: 40px;
    max-width: 210mm;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    line-height: 1.4;
    color: #000;
}

.print-header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid #333;
    padding-bottom: 20px;
}

.print-company-name {
    font-size: 16pt;
    font-weight: bold;
    margin-bottom: 5px;
}

.print-company-info {
    font-size: 10pt;
    color: #555;
}

.print-title {
    font-size: 18pt;
    font-weight: bold;
    text-align: center;
    margin: 30px 0 10px;
    text-transform: uppercase;
}

.print-subtitle {
    text-align: center;
    font-size: 11pt;
    margin-bottom: 25px;
}

.print-info-block {
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
    gap: 40px;
}

.print-info-col {
    flex: 1;
}

.print-info-row {
    margin-bottom: 8px;
}

.print-info-label {
    font-weight: bold;
}

.print-section-title {
    background: #f0f0f0;
    padding: 8px 15px;
    font-weight: bold;
    font-size: 11pt;
    margin: 20px 0 10px;
    border-left: 4px solid #333;
}

.print-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    font-size: 10pt;
}

.print-table th,
.print-table td {
    border: 1px solid #333;
    padding: 8px 10px;
    text-align: left;
}

.print-table th {
    background: #e8e8e8;
    font-weight: bold;
    text-align: center;
}

.print-table .col-num { width: 5%; text-align: center; }
.print-table .col-name { width: 45%; }
.print-table .col-unit { width: 10%; text-align: center; }
.print-table .col-qty { width: 10%; text-align: center; }
.print-table .col-price { width: 15%; text-align: right; }
.print-table .col-sum { width: 15%; text-align: right; }

.print-table .subtotal-row {
    background: #f5f5f5;
    font-weight: bold;
}

.print-table .subtotal-row td {
    text-align: right;
}

.print-totals {
    margin-top: 30px;
    border-top: 2px solid #333;
    padding-top: 20px;
}

.print-total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 12pt;
}

.print-total-row.grand {
    font-size: 14pt;
    font-weight: bold;
    border-top: 2px solid #333;
    margin-top: 10px;
    padding-top: 15px;
}

.print-signatures {
    margin-top: 50px;
    display: flex;
    justify-content: space-between;
}

.print-signature-block {
    width: 45%;
}

.print-signature-title {
    font-weight: bold;
    margin-bottom: 10px;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}

.print-signature-line {
    margin-top: 40px;
    border-bottom: 1px solid #333;
    position: relative;
}

.print-signature-label {
    font-size: 9pt;
    color: #666;
    margin-top: 5px;
}

.print-footer {
    margin-top: 40px;
    text-align: center;
    font-size: 9pt;
    color: #888;
    border-top: 1px solid #ddd;
    padding-top: 15px;
}

/* ========== СТИЛИ ДЛЯ ПЕЧАТИ ========== */
@media print {
    body {
        background: white;
        margin: 0;
        padding: 0;
    }

    .app-header, .nav-tabs, .no-print,
    .btn, .btn-group, .btn-delete,
    .autocomplete-list, .toast {
        display: none !important;
    }

    .content-container {
        margin: 0;
        padding: 0;
        max-width: 100%;
    }

    .tab-content {
        display: none !important;
    }

    .tab-content#print {
        display: block !important;
    }

    .card {
        box-shadow: none;
        padding: 0;
        margin: 0;
    }

    .print-document {
        box-shadow: none;
        padding: 15mm;
        max-width: 100%;
    }

    .print-table {
        page-break-inside: auto;
    }

    .print-table tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    .print-signatures {
        page-break-inside: avoid;
    }
}

/* ========== АВТОРИЗАЦИЯ ========== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.auth-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.auth-btn {
    background: rgba(255,255,0.15);
    border: 1px solid rgba(255,255,0.3);
    color: white;
    padding: 8px 20px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.auth-btn:hover {
    background: rgba(255,255,0.25);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-email {
    color: rgba(255,255,0.9);
    font-size: 0.9rem;
}

.btn-logout {
    background: rgba(231, 76, 60, 0.8);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-logout:hover {
    background: #e74c3c;
}

.sync-indicator {
    font-size: 0.75rem;
    color: rgba(255,255,0.7);
    display: none;
}

.sync-indicator.show {
    display: block;
}

/* ========== МОДАЛЬНОЕ ОКНО ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-box {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    overflow: hidden;
    transform: translateY(-20px);
    transition: transform 0.3s;
}

.modal-overlay.show .modal-box {
    transform: translateY(0);
}

.modal-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.modal-close {
    background: rgba(255,255,0.2);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
}

.modal-body {
    padding: 25px;
}

.modal-body .form-group {
    margin-bottom: 20px;
}

.modal-body .form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #333;
}

.modal-body .form-group input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 1rem;
}

.modal-body .form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.modal-error {
    background: #fee;
    color: #c00;
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 15px;
    display: none;
    font-size: 0.9rem;
}

.modal-error.show {
    display: block;
}

.modal-footer {
    text-align: center;
    padding-top: 15px;
    border-top: 1px solid #eee;
    color: #666;
}

.modal-footer a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}


/* ========== АДАПТИВНОСТЬ ========== */
@media (max-width: 768px) {
    .nav-tabs { flex-wrap: wrap; }
    .nav-tabs button { padding: 12px 15px; font-size: 0.9rem; flex: 1 1 50%; }
    .app-header { flex-direction: column; text-align: center; gap: 5px; }
    .group-header { flex-direction: column; gap: 10px; }
    .group-header input { max-width: 100%; }
    .print-info-block { flex-direction: column; gap: 15px; }
    .print-signatures { flex-direction: column; gap: 30px; }
    .print-signature-block { width: 100%; }
}