/* ===== RESET & BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-blue: #2c5aa0;
    --primary-dark: #1e3a5f;
    --primary-light: #4a7bc8;
    --accent-green: #28a745;
    --accent-teal: #20c997;
    --neutral-light: #f8fafc;
    --neutral-white: #ffffff;
    --neutral-gray: #6c757d;
    --neutral-dark: #2c3e50;
    --success-light: #d1edff;
    --warning-light: #fff3cd;
    --error-light: #f8d7da;
    --border-radius: 12px;
    --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-medium: 0 10px 25px rgba(0, 0, 0, 0.1);
    --shadow-large: 0 20px 40px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    color: var(--neutral-dark);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== LAYOUT & CONTAINER ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--neutral-white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-large);
    overflow: hidden;
    min-height: calc(100vh - 32px);
}

/* ===== UPDATED HEADER STYLES ===== */
.header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-blue) 100%);
    color: var(--neutral-white);
    padding: clamp(20px, 3vw, 30px) clamp(24px, 4vw, 40px);
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 100" opacity="0.1"><polygon points="0,0 1000,50 1000,100 0,100" fill="white"/></svg>') no-repeat bottom;
    background-size: cover;
    z-index: 1;
}

/* Header content wrapper */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 2;
    gap: 24px;
}

/* Left side - Title and description */
.header-left {
    flex: 1;
    min-width: 0;
}

.header h1 {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    margin-bottom: 8px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--neutral-white);
}

.header-description {
    font-size: clamp(1rem, 2vw, 1.2rem);
    opacity: 0.9;
    max-width: 600px;
    margin: 0;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.9);
}

/* Right side - Buttons */
.header-right {
    flex-shrink: 0;
}

.header-buttons {
    display: flex;
    gap: clamp(12px, 2vw, 16px);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-buttons a.header-btn {
    text-decoration: none !important;
    display: inline-block;
    text-align: center;
    line-height: normal;
    color: var(--neutral-white) !important;
    cursor: pointer;
}

/* Убедитесь, что у ссылки такие же стили как у кнопки */
a.header-btn:hover {
    text-decoration: none !important;
    color: var(--neutral-white) !important;
}

/* Header buttons styles */
.header-btn {
    background: rgba(255, 255, 255, 0.15);
    color: var(--neutral-white);
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: clamp(10px, 1.5vw, 12px) clamp(16px, 2vw, 20px);
    border-radius: 8px;
    font-size: clamp(0.85rem, 1.5vw, 0.95rem);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
    min-height: 48px;
}

.header-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.6s;
}

.header-btn:hover::before {
    left: 100%;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.header-btn:active {
    transform: translateY(0);
}

/* Specific button styles */
.header-btn.btn-primary {
    background: linear-gradient(135deg, var(--accent-green) 0%, var(--accent-teal) 100%);
    border-color: rgba(255, 255, 255, 0.4);
}

.header-btn.btn-primary:hover {
    background: linear-gradient(135deg, #239b3d 0%, #1bb184 100%);
    box-shadow: 0 8px 25px rgba(40, 167, 69, 0.4);
}

.header-btn.btn-secondary {
    background: linear-gradient(135deg, rgba(108, 117, 125, 0.8) 0%, rgba(90, 98, 104, 0.8) 100%);
    border-color: rgba(255, 255, 255, 0.2);
}

.header-btn.btn-secondary:hover {
    background: linear-gradient(135deg, #5a6268 0%, #4a5258 100%);
}

/* ===== MOBILE ADAPTATION FOR HEADER ===== */
@media (max-width: 992px) {
    .header-content {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        gap: 20px;
    }
    
    .header-left {
        margin-bottom: 0;
    }
    
    .header-buttons {
        justify-content: center;
    }
    
    .header-description {
        margin: 0 auto;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 20px 16px;
    }
    
    .header-content {
        gap: 16px;
    }
    
    .header-buttons {
        flex-direction: column;
        width: 100%;
        gap: 12px;
    }
    
    .header-btn {
        width: 100%;
        justify-content: center;
        white-space: normal;
        min-height: 44px;
        padding: 12px 16px;
    }
    
    .header h1 {
        font-size: 1.6rem;
        margin-bottom: 6px;
    }
    
    .header-description {
        font-size: 0.95rem;
        line-height: 1.3;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 16px 12px;
    }
    
    .header h1 {
        font-size: 1.4rem;
    }
    
    .header-description {
        font-size: 0.9rem;
    }
    
    .header-btn {
        font-size: 0.85rem;
        min-height: 42px;
    }
    
    /* Fix для Facebook плагина */
    .header-btn {
        position: relative !important;
        z-index: 2147483647 !important;
        pointer-events: auto !important;
    }
}

/* ===== FIX FOR Z-INDEX ISSUES ===== */
.header-content,
.header-left,
.header-right,
.header-buttons,
.header-btn {
    position: relative;
    z-index: 2;
}

/* ===== ANIMATION FOR BUTTONS ===== */
@keyframes buttonPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

/* Optional: Add pulse animation to primary button */
.header-btn.btn-primary.pulse {
    animation: buttonPulse 2s infinite;
}

/* ===== MAIN CONTENT GRID ===== */
.content {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(400px, 1.2fr);
    gap: clamp(20px, 3vw, 32px);
    padding: clamp(20px, 3vw, 32px);
    align-items: start;
}

@media (max-width: 1024px) {
    .content {
        grid-template-columns: 1fr;
        gap: 24px;
    }
}

/* ===== SECTIONS ===== */
.form-section,
.results-section {
    background: var(--neutral-light);
    padding: clamp(20px, 3vw, 28px);
    border-radius: var(--border-radius);
    border: 1px solid #e9ecef;
    box-shadow: var(--shadow-soft);
}

/* ===== TYPOGRAPHY ===== */
h2 {
    color: var(--primary-dark);
    margin-bottom: clamp(16px, 2vw, 24px);
    padding-bottom: 12px;
    border-bottom: 3px solid var(--primary-blue);
    font-size: clamp(1.3rem, 2.5vw, 1.6rem);
    font-weight: 600;
}

h3 {
    color: var(--primary-dark);
    margin-bottom: clamp(12px, 1.5vw, 20px);
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    font-weight: 600;
}

/* ===== FORM ELEMENTS ===== */
.form-group {
    margin-bottom: clamp(16px, 2vw, 24px);
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--neutral-dark);
    font-size: clamp(0.9rem, 1.5vw, 1rem);
}

input,
select,
textarea {
    width: 100%;
    padding: clamp(10px, 1.5vw, 14px);
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: clamp(0.9rem, 1.5vw, 1rem);
    transition: var(--transition);
    background: var(--neutral-white);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.1);
}

textarea {
    height: 120px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.5;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.checkbox-group input {
    width: auto;
    transform: scale(1.2);
}

/* ===== BUTTONS (для контента, не хедера) ===== */
.btn {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-light) 100%);
    color: var(--neutral-white);
    border: none;
    padding: clamp(12px, 2vw, 16px) clamp(20px, 3vw, 32px);
    border-radius: 8px;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.btn:active {
    transform: translateY(0);
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
}

.btn-success {
    background: linear-gradient(135deg, var(--accent-green) 0%, #218838 100%);
}

.btn-danger {
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.btn-small {
    padding: clamp(6px, 1vw, 8px) clamp(12px, 2vw, 16px);
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    width: auto;
}

/* ===== RESULTS GRID ===== */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    gap: clamp(12px, 1.5vw, 16px);
    margin-bottom: clamp(20px, 2.5vw, 32px);
}

.result-card {
    background: var(--neutral-white);
    padding: clamp(16px, 2vw, 20px);
    border-radius: 8px;
    border-left: 4px solid var(--primary-blue);
    box-shadow: var(--shadow-soft);
    transition: var(--transition);
}

.result-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.result-card h3 {
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    color: var(--neutral-gray);
    margin-bottom: 8px;
    font-weight: 500;
}

.result-card .value {
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    font-weight: 700;
    color: var(--neutral-dark);
    line-height: 1.2;
}

.result-card.highlight {
    border-left-color: var(--accent-green);
    background: linear-gradient(135deg, #f8fff9 0%, #e8f5e8 100%);
}

.result-card.warning {
    border-left-color: #ffc107;
    background: linear-gradient(135deg, #fffbf0 0%, #fff3cd 100%);
}

/* ===== TABLES ===== */
.schedule-table,
.payments-table,
.calculations-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    box-shadow: var(--shadow-soft);
    border-radius: 8px;
    overflow: hidden;
}

.schedule-table th,
.schedule-table td,
.payments-table th,
.payments-table td,
.calculations-table th,
.calculations-table td {
    padding: clamp(8px, 1.2vw, 12px);
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

.schedule-table th,
.payments-table th,
.calculations-table th {
    background-color: var(--primary-blue);
    color: var(--neutral-white);
    font-weight: 600;
    position: sticky;
    top: 0;
}

.schedule-table tr:hover,
.payments-table tr:hover,
.calculations-table tr:hover {
    background-color: #f8f9fa;
}

.extra-payment {
    background-color: var(--warning-light) !important;
}

.regular-payment {
    background-color: var(--success-light) !important;
}

/* ===== LOADING & MESSAGES ===== */
.loading {
    display: none;
    text-align: center;
    padding: 40px 20px;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-blue);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.error {
    background-color: var(--error-light);
    color: #721c24;
    padding: clamp(12px, 2vw, 16px);
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #f5c6cb;
    font-size: clamp(0.9rem, 1.5vw, 1rem);
}

.success {
    background-color: var(--success-light);
    color: #155724;
    padding: clamp(12px, 2vw, 16px);
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #c3e6cb;
    font-size: clamp(0.9rem, 1.5vw, 1rem);
}

/* ===== MODAL STYLES ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--neutral-white);
    margin: 5% auto;
    padding: clamp(20px, 3vw, 32px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-large);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    animation: modalSlideIn 0.3s ease-out;
    z-index: 10001;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(16px, 2vw, 24px);
    padding-bottom: clamp(12px, 1.5vw, 16px);
    border-bottom: 2px solid var(--primary-blue);
}

.modal-title {
    font-size: clamp(1.2rem, 2.5vw, 1.5rem);
    color: var(--neutral-dark);
    margin: 0;
    font-weight: 600;
}

.close {
    color: var(--neutral-gray);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
}

.close:hover {
    color: var(--neutral-dark);
    background-color: #f8f9fa;
}

/* ===== FEEDBACK FORM ===== */
.feedback-form {
    margin: clamp(16px, 2vw, 24px) 0;
}

.form-row {
    margin-bottom: clamp(16px, 2vw, 20px);
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--neutral-dark);
    font-size: clamp(0.9rem, 1.5vw, 1rem);
}

.agreement-label {
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    color: var(--neutral-gray);
    line-height: 1.4;
}

/* ===== SAVED CALCULATIONS ===== */
.saved-calculations {
    margin-top: clamp(32px, 4vw, 48px);
    padding: clamp(20px, 3vw, 28px);
    background: var(--neutral-light);
    border-radius: var(--border-radius);
    border: 1px solid #e9ecef;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(16px, 2vw, 24px);
    flex-wrap: wrap;
    gap: clamp(12px, 1.5vw, 16px);
}

.section-title {
    color: var(--neutral-dark);
    margin: 0;
    font-size: clamp(1.2rem, 2.5vw, 1.5rem);
    font-weight: 600;
}

.export-buttons {
    display: flex;
    gap: clamp(8px, 1vw, 12px);
    flex-wrap: wrap;
}

/* ===== CALCULATIONS TABLE ===== */
.calculations-table-container {
    overflow-x: auto;
    margin: clamp(16px, 2vw, 24px) 0;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: var(--neutral-white);
    max-height: 400px;
    overflow-y: auto;
    box-shadow: var(--shadow-soft);
}

.calculations-table {
    min-width: 600px;
}

.calculations-table th:first-child,
.calculations-table td:first-child {
    position: sticky;
    left: 0;
    background-color: inherit;
    z-index: 5;
}

.calculations-table th:first-child {
    background-color: var(--primary-dark);
    z-index: 10;
}

.calculations-table .calculation-name {
    font-weight: 600;
    min-width: 150px;
}

.calculations-table .calculation-value {
    text-align: right;
    min-width: 120px;
}

/* ===== ACTIONS & UTILITIES ===== */
.actions {
    display: flex;
    gap: clamp(8px, 1.5vw, 12px);
    margin-top: clamp(16px, 2vw, 24px);
    flex-wrap: wrap;
}

.actions .btn {
    flex: 1;
    min-width: 120px;
}

.button-group {
    display: flex;
    gap: clamp(8px, 1.5vw, 12px);
    margin: clamp(16px, 2vw, 24px) 0;
    flex-wrap: wrap;
}

.button-group .btn {
    flex: 1;
    min-width: 150px;
}

.table-input {
    width: 100%;
    padding: clamp(8px, 1.2vw, 10px);
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: clamp(0.8rem, 1.2vw, 0.9rem);
    transition: var(--transition);
}

.table-input:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px rgba(44, 90, 160, 0.1);
}

.empty-message {
    text-align: center;
    padding: clamp(24px, 3vw, 40px);
    color: var(--neutral-gray);
    font-style: italic;
    font-size: clamp(0.9rem, 1.5vw, 1.1rem);
}

/* ===== SCROLLBAR STYLING ===== */
.calculations-table-container::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.calculations-table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.calculations-table-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.calculations-table-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ===== ANIMATIONS ===== */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== MOBILE OPTIMIZATIONS (общие) ===== */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }

    .container {
        border-radius: 8px;
    }

    .content {
        padding: 16px;
        gap: 16px;
    }

    .form-section,
    .results-section {
        padding: 16px;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .actions,
    .button-group {
        flex-direction: column;
    }

    .actions .btn,
    .button-group .btn {
        width: 100%;
    }

    .modal-content {
        margin: 5% auto;
        width: 95%;
        padding: 20px;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
}

/* ===== EMERGENCY FIX FOR FACEBOOK (если ничего не помогает) ===== */
@media (max-width: 480px) {
    /* Ядерный вариант - переопределяем всё для старого хедера */
    body .header .header-actions .contact-btn {
        all: unset !important;
        display: block !important;
        width: 90% !important;
        max-width: 280px !important;
        margin: 0 auto !important;
        background: linear-gradient(135deg, #28a745 0%, #20c997 100%) !important;
        color: white !important;
        border: none !important;
        padding: 14px 24px !important;
        border-radius: 25px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        text-align: center !important;
        cursor: pointer !important;
        position: fixed !important;
        bottom: 20px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 2147483647 !important;
        pointer-events: auto !important;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07) !important;
        transition: all 0.3s ease !important;
        min-height: 48px !important;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    body {
        background: white !important;
        padding: 0;
    }

    .container {
        box-shadow: none;
        border-radius: 0;
    }

    .header-actions,
    .btn:not(.btn-print) {
        display: none;
    }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --neutral-light: #1a1a1a;
        --neutral-white: #2d2d2d;
        --neutral-dark: #f8f9fa;
        --neutral-gray: #adb5bd;
    }

    body {
        background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%);
    }
    
    /* Dark mode для нового хедера */
    .header {
        background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%);
    }
    
    .header-btn {
        background: rgba(0, 0, 0, 0.2);
        border-color: rgba(255, 255, 255, 0.2);
    }
    
    .header-btn:hover {
        background: rgba(0, 0, 0, 0.3);
        border-color: rgba(255, 255, 255, 0.3);
    }
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.header-btn:focus-visible {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-blue: #0000ff;
        --primary-dark: #000000;
        --accent-green: #008000;
    }
}