/* Kalkulator Płytek - Główne style CSS */
/* Mobile First Approach */

:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --light-bg: #f8f9fa;
    --dark-text: #333;
    --border-radius: 8px;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

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

/* Base styles - Mobile first */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--dark-text);
    background-color: #fff;
    padding: 0;
    position: relative;
    min-height: 100vh;
    padding-bottom: 60px; /* miejsce na stopkę */
    overflow-x: hidden; /* FIXED: Prevent horizontal scroll */
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
    box-sizing: border-box; /* FIXED: Ensure padding doesn't cause overflow */
}

/* Mobile container fix */
@media (max-width: 767px) {
    .container {
        padding: 0.75rem;
        max-width: 100vw; /* Never exceed viewport width */
    }
}

/* Header Styles - FIXED: Smaller height with logo */
header {
    background-color: var(--light-bg);
    padding: 0.75rem 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--primary-color);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 50%;
}

/* Mobile header adjustments */
@media (max-width: 767px) {
    header {
        padding: 0.5rem 0;
        margin-bottom: 1rem;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .logo-icon {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
}

/* Calculator Styles - Naprawione i responsywne */
.calculator-section {
    background-color: white;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin-bottom: 2rem;
}

.calculator-section h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    text-align: center;
}

.form-group {
    margin-bottom: 1rem;
}

label {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    text-align: left;
}

input, select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
    height: 44px;
    line-height: 1.2;
}

input:focus, select:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-color: var(--primary-color);
}

.input-hint {
    color: #666;
    font-size: 0.87rem;
    display: block;
    margin-top: 0.25rem;
}

fieldset {
    border: 1px solid #e7ebef;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
}

legend {
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0 0.5rem;
    color: var(--primary-color);
}

/* Przyciski kalkulatora - NAPRAWIONE */
.calc-btn {
    background-color: var(--primary-color);
    border: none;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: var(--transition);
    margin: 0.25rem 0.25rem 0.25rem 0;
    display: inline-block;
    min-width: 120px;
    text-align: center;
    text-decoration: none;
    /* Naprawka dla przycisków */
    border: 2px solid var(--primary-color);
}

.calc-btn:hover, 
.calc-btn:focus {
    background-color: #0056b3;
    border-color: #0056b3;
    outline: 2px solid #0056b3;
    outline-offset: 2px;
    transform: translateY(-1px);
}

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

.calc-btn:disabled {
    background-color: #6c757d;
    border-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Container dla przycisków */
.button-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 1rem;
}

.results-container {
    min-height: 200px;
    padding: 1.5rem;
    border-top: 1px solid #e7ebef;
    margin-top: 1rem;
    background-color: var(--light-bg);
    border-radius: var(--border-radius);
    display: none; /* Ukryty domyślnie, pokazuje się po kliknięciu "Oblicz" */
}

.result-block {
    margin-bottom: 1rem;
    padding: 1rem;
    background-color: white;
    border-radius: 4px;
    border-left: 4px solid var(--primary-color);
}

.row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: stretch;
    margin-bottom: 1rem;
}

.col-sm {
    flex: 1 1 100%; /* Mobile first - pełna szerokość */
    min-width: 200px;
}

/* Radio buttons - NAPRAWIONE */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 12px;
}

.radio-option input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.radio-option label {
    margin-bottom: 0;
    cursor: pointer;
    font-weight: 500;
}

/* Price table - FIXED for mobile */
.price-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.price-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 300px; /* Minimum width to prevent crushing */
    margin: 0;
    font-size: 0.85rem;
}

.price-table th, 
.price-table td {
    border: 1px solid #dbe2ea;
    padding: 0.5rem;
    text-align: center;
    white-space: nowrap; /* Prevent text wrapping */
}

.price-table th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    font-size: 0.8rem;
}

.price-table td {
    font-size: 0.8rem;
}

/* Mobile-specific table styles */
@media (max-width: 767px) {
    .price-table {
        font-size: 0.75rem;
        min-width: 280px;
    }
    
    .price-table th, 
    .price-table td {
        padding: 0.4rem;
        font-size: 0.7rem;
    }
    
    .price-table th {
        font-size: 0.65rem;
    }
}

.recommendations {
    background-color: #ddeffa;
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 4px;
    font-size: 0.95rem;
}

.alert {
    background-color: #ffecb3;
    color: #795548;
    padding: 0.75rem;
    border-radius: 4px;
    font-size: 0.93rem;
    margin: 1rem 0;
}

.copy-alert {
    background-color: #e0ffe3;
    color: #278613;
    padding: 0.5rem;
    border-radius: 3px;
    font-size: 0.94rem;
    display: none;
    margin-top: 0.5rem;
}

/* Article styles */
h2.article-title {
    font-size: 1.75rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    text-align: center;
}

.intro {
    font-size: 1.05rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background-color: var(--light-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

/* Navigation */
.toc-container {
    background-color: var(--light-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    box-shadow: var(--box-shadow);
}

.toc-title {
    font-size: 1.4rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.toc-list {
    list-style: none;
}

.toc-list li {
    margin-bottom: 0.5rem;
}

.toc-list a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.toc-list a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Main Content */
main {
    margin-bottom: 3rem;
}

section {
    margin-bottom: 3rem;
    padding: 1.5rem;
    background-color: #fff;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

h3 {
    font-size: 1.6rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--light-bg);
}

h4 {
    font-size: 1.3rem;
    color: var(--secondary-color);
    margin: 1.5rem 0 1rem;
}

p {
    margin-bottom: 1rem;
    font-size: 1rem;
}

ul, ol {
    margin: 1rem 0 1rem 2rem;
}

li {
    margin-bottom: 0.5rem;
}

strong {
    font-weight: 600;
}

/* Charts - NAPRAWIONE dla lepszej responsywności */
.chart-container {
    margin: 2rem 0;
    padding: 1rem;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    position: relative;
    height: 300px; /* Zmniejszona wysokość dla mobile */
    clear: both;
}

.chart-container canvas {
    max-height: 100% !important;
    width: 100% !important;
}

.chart-description {
    margin-top: 1rem;
    padding: 1rem;
    font-size: 0.9rem;
    background-color: var(--light-bg);
    border-radius: 4px;
    max-width: 100%;
    overflow-wrap: break-word;
    border: 1px solid #e7ebef;
    line-height: 1.5;
}

/* Mobile chart descriptions */
@media (max-width: 767px) {
    .chart-description {
        font-size: 0.85rem;
        padding: 0.75rem;
        margin-top: 0.75rem;
        line-height: 1.4;
    }
}

/* Tables - IMPROVED for mobile */
.responsive-table {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 300px; /* Prevent table crushing */
}

/* Table captions - IMPROVED for mobile */
.responsive-table caption {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-align: left;
    color: var(--dark-text);
    line-height: 1.4;
}

.responsive-table th,
.responsive-table td {
    padding: 0.5rem;
    text-align: left;
    border: 1px solid #ddd;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.responsive-table th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    white-space: nowrap; /* Keep headers on one line */
}

.responsive-table tr:nth-child(even) {
    background-color: var(--light-bg);
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 2rem 0;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    max-width: 100%; /* FIXED: Prevent overflow */
}

/* Mobile table improvements */
@media (max-width: 767px) {
    .table-wrapper,
    .price-table-wrapper {
        margin: 1rem 0;
        font-size: 0.8rem;
    }
    
    .responsive-table,
    .price-table {
        min-width: 280px;
        font-size: 0.75rem;
    }
    
    /* Larger captions on mobile for better readability */
    .responsive-table caption {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }
    
    .responsive-table th,
    .responsive-table td,
    .price-table th,
    .price-table td {
        padding: 0.4rem 0.3rem;
        font-size: 0.7rem;
    }
    
    /* Add scroll indicator */
    .table-wrapper::after,
    .price-table-wrapper::after {
        content: "← Przesuń poziomo →";
        display: block;
        text-align: center;
        font-size: 0.7rem;
        color: #666;
        padding: 0.5rem;
        background-color: var(--light-bg);
        border-top: 1px solid #ddd;
    }
}

.table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

/* Quiz Styles - NAPRAWIONE */
.quiz-container {
    background-color: var(--light-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    margin: 3rem 0;
    box-shadow: var(--box-shadow);
}

.quiz-title {
    font-size: 1.6rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    text-align: center;
}

.quiz-question {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.quiz-question h4 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--dark-text);
    text-align: left;
}

.quiz-options {
    list-style: none;
    padding: 0;
    margin: 0;
}

.quiz-option {
    margin-bottom: 0.75rem;
}

.quiz-option label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 0.75rem;
    background-color: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: var(--border-radius);
    transition: var(--transition);
    width: 100%;
    box-sizing: border-box;
    text-align: left;
    margin-bottom: 0;
}

.quiz-option label:hover {
    background-color: #e9ecef;
    border-color: var(--primary-color);
}

.quiz-option input[type="radio"] {
    margin-right: 15px;
    transform: scale(1.2);
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.quiz-option label span {
    flex: 1;
}

.submit-btn {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 2rem auto;
    padding: 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.submit-btn:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

.quiz-result {
    display: none;
    margin-top: 2rem;
    padding: 1.5rem;
    background-color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    text-align: center;
}

.result-text {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.explanation {
    font-size: 0.9rem;
    line-height: 1.4;
}

.correct {
    color: var(--success-color);
    font-weight: 600;
}

.incorrect {
    color: var(--danger-color);
    font-weight: 600;
}

/* FAQ Styles */
.faq-container {
    margin: 3rem 0;
}

.faq-title {
    font-size: 1.6rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    text-align: center;
}

details {
    margin-bottom: 1rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    background-color: white;
    box-shadow: var(--box-shadow);
}

summary {
    padding: 1rem 1.5rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    outline: none;
    background-color: var(--light-bg);
    border-bottom: 1px solid #ddd;
    transition: var(--transition);
}

summary:hover {
    background-color: #e9ecef;
}

details[open] summary {
    background-color: #e9ecef;
    border-bottom: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

details p {
    padding: 1.5rem;
    margin: 0;
    font-size: 1rem;
}

/* Glossary Styles */
.glossary-container {
    margin: 3rem 0;
}

.glossary-title {
    font-size: 1.6rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    text-align: center;
}

.glossary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.glossary-item {
    padding: 1rem;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.glossary-term {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-size: 1.05rem;
}

.glossary-definition {
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Sources Section */
.sources-container {
    margin: 3rem 0;
    padding: 2rem;
    background-color: var(--light-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.sources-title {
    font-size: 1.6rem;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    text-align: center;
}

.sources-list {
    list-style: none;
}

.sources-list li {
    margin-bottom: 0.75rem;
    padding-left: 1rem;
    border-left: 3px solid var(--primary-color);
}

.sources-list a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

.sources-list a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 70px;
    right: 20px;
    background-color: var(--primary-color);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 1.5rem;
    box-shadow: var(--box-shadow);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    z-index: 1000;
}

.back-to-top.show {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background-color: #0056b3;
    transform: translateY(-2px);
}

/* Footer */
footer {
    background-color: var(--light-bg);
    padding: 1.5rem 0;
    text-align: center;
    border-top: 1px solid #ddd;
    position: absolute;
    bottom: 0;
    width: 100%;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus styles for accessibility */
a:focus, 
button:focus, 
input:focus, 
select:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Smooth scrolling for anchor links */
html {
    scroll-behavior: smooth;
}

/* Media Queries - Progressive Enhancement */

/* Tablet - 768px and up */
@media (min-width: 768px) {
    .container {
        padding: 2rem;
    }
    
    .logo {
        font-size: 1.5rem;
    }
    
    .calculator-section {
        padding: 2rem;
    }
    
    .calculator-section h1 {
        font-size: 2rem;
    }
    
    .col-sm {
        flex: 1 1 calc(50% - 0.75rem);
    }
    
    .row {
        flex-direction: row;
    }
    
    .calc-btn {
        width: auto;
    }
    
    .button-container {
        flex-direction: row;
    }
    
    .chart-container {
        height: 400px;
    }
    
    .responsive-table {
        font-size: 0.9rem;
    }
    
    .responsive-table th,
    .responsive-table td {
        padding: 0.75rem;
    }
    
    h2.article-title {
        font-size: 2rem;
    }
    
    .intro {
        font-size: 1.1rem;
    }
    
    h3 {
        font-size: 1.8rem;
    }
    
    h4 {
        font-size: 1.4rem;
    }
    
    .toc-title {
        font-size: 1.5rem;
    }
    
    .quiz-title {
        font-size: 1.8rem;
    }
    
    .quiz-question h4 {
        font-size: 1.2rem;
    }
    
    .faq-title {
        font-size: 1.8rem;
    }
    
    summary {
        font-size: 1.1rem;
    }
    
    .glossary-title {
        font-size: 1.8rem;
    }
    
    .glossary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .sources-title {
        font-size: 1.8rem;
    }
}

/* Desktop - 1025px and up */
@media (min-width: 1025px) {
    .glossary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .chart-container {
        height: 500px;
    }
    
    .col-sm {
        min-width: 200px;
    }
}

/* Large Desktop - 1400px and up */
@media (min-width: 1400px) {
    .container {
        padding: 3rem;
    }
}

/* Mobile-specific enhancements */
@media (max-width: 767px) {
    /* FIXED: Prevent horizontal scrolling */
    html, body {
        overflow-x: hidden;
        max-width: 100%;
    }
    
    /* Ensure all containers stay within viewport */
    .container,
    .calculator-section,
    section,
    .row,
    .form-group {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Better touch targets */
    button, .calc-btn, .submit-btn {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }
    
    /* Improved form inputs for mobile */
    input, select {
        font-size: 16px; /* Prevents zoom on iOS */
        -webkit-appearance: none;
        border-radius: 4px;
        max-width: 100%;
        width: 100%;
    }
    
    /* Better radio buttons for touch */
    .radio-option input[type="radio"] {
        width: 24px;
        height: 24px;
        margin-right: 12px;
    }
    
    /* Improved quiz options */
    .quiz-option label {
        min-height: 44px;
        padding: 12px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* Better spacing for mobile */
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    /* Improved table scrolling */
    .table-wrapper,
    .price-table-wrapper {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        max-width: calc(100vw - 2rem); /* Ensure it fits in viewport */
    }
    
    /* Ensure text doesn't overflow */
    p, li, span, div {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
    
    /* Charts container mobile fix */
    .chart-container {
        max-width: 100%;
        overflow: hidden;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .calc-btn:hover,
    .submit-btn:hover,
    .quiz-option label:hover,
    .back-to-top:hover {
        transform: none;
        background-color: var(--primary-color);
    }
    
    /* Larger touch targets */
    .quiz-option input[type="radio"] {
        width: 28px;
        height: 28px;
    }
    
    /* Better focus for touch */
    button:focus,
    input:focus,
    select:focus {
        outline: 3px solid var(--primary-color);
        outline-offset: 2px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
    /* Crisp text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Landscape mobile optimization */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .calculator-section h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    .chart-container {
        height: 250px;
    }
    
    .quiz-question {
        padding: 1rem;
        margin-bottom: 1rem;
    }
}

/* Print styles */
@media print {
    .back-to-top,
    .calc-btn,
    .submit-btn,
    .button-container {
        display: none;
    }
    
    .chart-container {
        break-inside: avoid;
    }
    
    section {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
}