/* Reset ja perustyylit */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fafafa;
    display: flex;
    min-height: 100vh;
    flex-direction: column;
    overflow-x: hidden;
}

a {
    color: #0066cc;
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: #0052a3;
}

button, input[type="button"], input[type="submit"] {
    cursor: pointer;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Navigointibaari */
.navbar {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    position: relative;
}

/* Hide hamburger by default (desktop), show on mobile via media query */
.navbar-toggle { display: none; }

.navbar-brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.navbar-brand a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: white;
    font-weight: bold;
}

.logo {
    height: 45px;
    width: auto;
}

.site-name {
    font-size: 1.1rem;
    white-space: nowrap;
}

.navbar-menu {
    display: flex;
    list-style: none;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Ensure anchors are styled, current markup uses <a> directly under .navbar-menu */
.navbar-menu a {
    display: block;
    padding: 0.75rem 1rem;
    color: #ffffff;
    transition: background-color 0.2s ease, color 0.2s ease;
    border-radius: 4px;
    font-weight: 600;
}

.navbar-menu a:hover,
.navbar-menu a:focus {
    background-color: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    outline: none;
}

/* Improve focus visibility for keyboard navigation */
.navbar-menu a:focus-visible {
    box-shadow: 0 0 0 3px rgba(255,255,255,0.4);
}

.navbar-menu .btn {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 500;
}

.btn-login {
    background-color: #0066cc;
    color: white;
}

.btn-login:hover {
    background-color: #0052a3;
    color: white;
}

.btn-logout {
    background-color: #dc3545;
    color: white;
}

.btn-logout:hover {
    background-color: #c82333;
    color: white;
}

/* Hero page styles */
.has-hero .navbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.8);
    color: #333;
}

.has-hero .navbar-brand a,
.has-hero .navbar-menu a {
    color: #333;
}

.has-hero .navbar-menu a:hover,
.has-hero .navbar-menu a:focus {
    background-color: rgba(255, 255, 255, 0.18);
    color: #333;
}

.has-hero .main-content {
    padding-top: 0;
}

.has-hero .hero {
    position: relative;
    width: 100vw;
    left: 50%;
    transform: translateX(-50%);
    height: 600px;
    background: url('/kuvat/hero.webp') center top / cover no-repeat;
    margin-bottom: 0;
}

.has-hero .hero::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: linear-gradient(to top, #fafafa, transparent);
    pointer-events: none;
}

/* Mobiili has-hero */
.has-hero .navbar-toggle {
    color: #333;
    border-color: rgba(0, 0, 0, 0.4);
}

.has-hero .navbar-menu {
    background: transparent
}

.has-hero .navbar-menu a {
    color: #333;
}

/* Main content */
.main-content {
    padding: 1.5rem 1rem;
    flex: 1;
}

/* Hero-osio */
.hero {
    position: relative;
    background: url('/kuvat/hero.webp') center/auto no-repeat;
    color: white;
    padding: clamp(2.5rem, 4vw + 1rem, 3.5rem) 1rem;
    text-align: center;
    border-radius: 8px;
    margin-bottom: 2rem;
    overflow: hidden;
    min-height: 300px;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    font-weight: 700;
}

.hero p {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    opacity: 0.95;
}

.btn-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Painikkeet */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: #0066cc;
    color: white;
    border: none;
    border-radius: 4px;
    font-weight: 500;
    font-size: 1rem;
    line-height: 1.5;
    text-align: center;
    vertical-align: middle;
    transition: all 0.3s ease;
}

.btn:hover {
    background-color: #0052a3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background-color: #e3f2fd;
    color: #1976d2;
}

.btn-secondary:hover {
    background-color: #bbdefb;
    color: #1565c0;
}

.btn-danger {
    background-color: #dc3545;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-success {
    background-color: #28a745;
}

.btn-success:hover {
    background-color: #218838;
}

/* Kortit */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin: 1.5rem 0;
}

.card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.card-header {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-bottom: 1px solid #dee2e6;
}

.card-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.card-body h3 {
    margin-top: 0;
    color: #1a1a2e;
}

.card-body p {
    color: #666;
    margin: 0.5rem 0;
}

/* Keep card buttons at the bottom and centered */
.card-body .btn {
    margin-top: auto;
    align-self: center;
}

/* Lomakkeet */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #333;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #0066cc;
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

/* Taulukot */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Horizontal scroll wrapper for wide tables on small screens */
.responsive-table {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

thead {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: #333;
}

td {
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

tbody tr:hover {
    background-color: #f8f9fa;
}

/* Hälytykset */
.alert {
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: 4px;
    border-left: 4px solid;
}

.alert-danger {
    background-color: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}

.alert-success {
    background-color: #d4edda;
    border-color: #28a745;
    color: #155724;
}

.alert-info {
    background-color: #d1ecf1;
    border-color: #17a2b8;
    color: #0c5460;
}

/* Sisällön osio */
.content-section {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.content-section h2 {
    margin-top: 0;
    color: #1a1a2e;
    border-bottom: 2px solid #667eea;
    padding-bottom: 1rem;
}

.results-status {
    margin-top: 1rem;
    text-align: center;
    color: #555;
    font-size: 0.95rem;
}

#results-sentinel {
    height: 1px;
}

/* Hakuosio */
.search-form {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 2rem;
}

.search-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Footer */
.footer {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    padding: 3rem 1rem 1rem;
    margin-top: 2rem;
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.footer-section h3,
.footer-section h4 {
    margin-top: 0;
    margin-bottom: 1rem;
    color: #fff;
}

.footer-section p {
    color: #bbb;
    margin: 0.5rem 0;
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin: 0.5rem 0;
}

.footer-section a {
    color: #bbb;
    transition: color 0.3s ease;
}

.footer-section a:hover {
    color: white;
}

.footer-bottom {
    text-align: center;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: #bbb;
}

/* News Section */
.news-section {
    margin: 2rem 0;
}

.news-section h2 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 2rem;
    color: #1a1a2e;
}

.news-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.news-card {
    background-color: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.news-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.news-date {
    color: #0066cc;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.news-card h3 {
    color: #1a1a2e;
    font-size: 1.05rem;
    margin-bottom: 1rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.news-content {
    color: #555;
    line-height: 1.6;
    flex-grow: 1;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.news-content-clamped {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 8;
    line-clamp: 8;
    overflow: hidden;
}

.news-read-more {
    display: none;
    margin-top: 1rem;
    align-self: flex-start;
    color: #0066cc;
    font-weight: 600;
    text-decoration: none;
}

.news-card.has-overflow .news-read-more {
    display: inline-block;
}

.news-read-more:hover {
    text-decoration: underline;
}

/* Keep rich text content inside the card on small screens */
.news-content table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.news-content iframe,
.news-content video {
    width: 100%;
    max-width: 100%;
}

.news-content pre,
.news-content code {
    white-space: pre-wrap;
    word-break: break-word;
}

.news-content * {
    max-width: 100%;
    box-sizing: border-box;
}

.news-content a,
.news-content span,
.news-content p,
.news-content li {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.news-content :not(pre):not(code) {
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
}

.news-content p:last-child,
.news-content ul:last-child,
.news-content ol:last-child {
    margin-bottom: 0;
}

.news-pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
}

.news-pagination-link {
    display: inline-block;
    min-width: 2.25rem;
    padding: 0.45rem 0.75rem;
    border: 1px solid #d0d7e2;
    border-radius: 6px;
    background: #fff;
    color: #1a1a2e;
    font-weight: 600;
    text-align: center;
}

.news-pagination-link:hover {
    border-color: #0066cc;
    color: #0066cc;
}

.news-pagination-link.is-active {
    background: #0066cc;
    border-color: #0066cc;
    color: #fff;
}

.news-pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    color: #666;
    font-weight: 600;
    padding: 0 0.25rem;
}

/* Kuvat responsiiviseksi */
img {
    max-width: 100%;
    height: auto;
}

/* Responsiivisuus */
@media (max-width: 768px) {
    .navbar,
    .has-hero .navbar {
        width: 100dvw;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }

    /* Mobile: brand + toggle visible, menu collapses into dropdown */
    .navbar .container {
        flex-direction: row;
        gap: 0.5rem;
    }

    .navbar-toggle {
        display: inline-block;
        background: transparent;
        color: #ffffff;
        border: 1px solid rgba(255,255,255,0.4);
        border-radius: 4px;
        padding: 0.4rem 0.6rem;
        font-size: 1rem;
        line-height: 1;
    }

    .navbar-menu {
        position: absolute;
        top: 100%;
        left: 50%;
        right: auto;
        width: 100dvw;
        max-width: 100dvw;
        transform: translateX(-50%);
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
        display: none;
        flex-direction: column;
        gap: 0;
        padding: 0.5rem 0;
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    }

    .navbar-menu.is-open {
        display: flex;
        background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    }

    .has-hero .navbar-menu.is-open {
        background: rgba(255, 255, 255, 0.96);
    }

    .has-hero .navbar-menu.is-open a {
        color: #333;
    }

    .navbar-menu a {
        padding: 0.75rem 1rem;
        border-radius: 0;
    }

    .site-name {
        display: none;
    }

    .hero {
        padding: 2rem 1rem;
    }

    .has-hero .hero {
        width: 100dvw;
        left: 50%;
        transform: translateX(-50%);
        height: 280px;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .hero p {
        font-size: 1rem;
    }

    .btn-group {
        flex-direction: column;
    }

    .btn-group .btn {
        width: 100%;
    }

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

    .content-section {
        padding: 1.5rem;
    }

    table {
        font-size: 0.9rem;
    }

    th, td {
        padding: 0.75rem;
    }

    .news-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .news-section h2 {
        font-size: 1.75rem;
    }

    .news-content-clamped {
        -webkit-line-clamp: 6;
        line-clamp: 6;
    }
}

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

    .logo {
        height: 35px;
    }

    .site-name {
        display: none;
    }

    .hero h1 {
        font-size: 1.5rem;
    }

    .has-hero .hero {
        height: 220px;
    }

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

    .news-pagination-link {
        padding: 0.4rem 0.6rem;
        min-width: 2rem;
    }
}

/* Global opt-in mobile stacked table pattern */
@media (max-width: 480px) {
    .table-stack-mobile thead { display: none; }
    .table-stack-mobile tbody tr { 
        display: block; 
        border-bottom: 1px solid #ddd; 
        padding: 1rem 0; 
        margin-bottom: 0.5rem; 
    }
    .table-stack-mobile tbody tr td { 
        display: block;
        padding: 0.5rem 0;
        border: none;
    }
    .table-stack-mobile tbody tr td::before {
        content: attr(data-label);
        font-weight: bold;
        color: #333;
        display: block;
        margin-bottom: 0.25rem;
    }
    .table-stack-mobile tbody tr td:first-child { 
        font-weight: bold;
        font-size: 1.1em;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid #e0e0e0;
        margin-bottom: 0.5rem;
    }
    .table-stack-mobile td.num { text-align: right; }
}

/* Statistics page helpers (generic enough for reuse) */
.stats-info {
        color: #666;
        font-size: 0.95rem;
        margin-bottom: 1rem;
}
.charts-grid { 
        display: grid; 
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); 
        gap: 1.5rem; 
        margin: 2rem 0; 
}
.chart-card { min-height: 400px; }
.chart-canvas-wrap { width: 100%; }
.chart-canvas { max-height: 300px; width: 100% !important; height: auto !important; }
.table-block { margin-top: 1.5rem; }
.stats-table { width: 100%; font-size: 0.95rem; }
.stats-table .col-left { text-align: left; }
.stats-table .col-right, .stats-table td.num { text-align: right; }

@media (max-width: 480px) {
    .chart-card {
        min-height: auto;
    }

    .chart-card h2 {
        font-size: 1.05rem;
        line-height: 1.3;
        margin-bottom: 0.4rem;
    }

    .chart-card .stats-info {
        font-size: 0.9rem;
        margin-bottom: 0.65rem;
    }

    .chart-card .chart-canvas {
        max-height: 240px;
    }

    .chart-card .table-block {
        margin-top: 0.75rem;
    }

    .chart-card .stats-table {
        font-size: 0.9rem;
    }

    .chart-card .table-stack-mobile tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        align-items: baseline;
        gap: 0.2rem 0.75rem;
        padding: 0.45rem 0;
        margin-bottom: 0;
    }

    .chart-card .table-stack-mobile tbody tr td {
        display: block;
        padding: 0;
        border: none;
        min-width: 0;
    }

    .chart-card .table-stack-mobile tbody tr td::before {
        content: none;
        display: none;
    }

    .chart-card .table-stack-mobile tbody tr td.num {
        text-align: right;
        white-space: nowrap;
    }

    .chart-card .table-stack-mobile tbody tr td.num::before {
        content: "";
        display: inline;
        font-size: 0.75rem;
        color: #666;
        font-weight: 600;
    }

    .chart-card .table-stack-mobile tbody tr td.num[data-label="Määrä"]::before {
        content: "Määrä: ";
    }

    .chart-card .table-stack-mobile tbody tr td:first-child {
        font-size: 0.98rem;
        padding-bottom: 0;
        margin-bottom: 0;
        border-bottom: none;
    }
}

/* Print styles: hide navigation, footer, buttons */
@media print {
    .navbar, .footer, .search-form, .btn, button { display: none !important; }
    body { background: white; margin: 0; padding: 0; }
    .container { max-width: 100%; padding: 0 !important; margin: 0 !important; }
    .content-section { box-shadow: none; page-break-inside: avoid; margin-bottom: 1rem; padding: 1rem; }
    .content-section h2 { border-bottom: 1px solid #333; page-break-after: avoid; }
    h1, h2, h3 { page-break-after: avoid; }
    table { page-break-inside: avoid; font-size: 0.9rem; }
    thead { display: table-header-group; }
    tbody tr { page-break-inside: avoid; }
}

/* CKEditor sisältötyylit - listat ja muotoilu */
.content-section ul,
.content-section ol,
.news-content ul,
.news-content ol,
article ul,
article ol {
    margin: 1em 0;
    padding-left: 2em;
}

.content-section ul,
.news-content ul,
article ul {
    list-style-type: disc;
}

.content-section ol,
.news-content ol,
article ol {
    list-style-type: decimal;
}

.content-section ul li,
.content-section ol li,
.news-content ul li,
.news-content ol li,
article ul li,
article ol li {
    margin: 0.5em 0;
    line-height: 1.6;
}

.content-section ul ul,
.content-section ol ul,
.news-content ul ul,
.news-content ol ul,
article ul ul,
article ol ul {
    list-style-type: circle;
}

.content-section ul ul ul,
.content-section ol ul ul,
.news-content ul ul ul,
.news-content ol ul ul,
article ul ul ul,
article ol ul ul {
    list-style-type: square;
}

/* Mobile: keep list markers inside card padding */
@media (max-width: 600px) {
    .content-section ul,
    .content-section ol,
    .news-content ul,
    .news-content ol,
    article ul,
    article ol {
        padding-left: 1.25rem;
        list-style-position: inside;
        margin-left: 0;
    }

    .content-section li,
    .news-content li,
    article li {
        margin-left: 0;
    }
}

/* Kuvatyylit sisällössä */
.content-section img,
.news-content img,
article img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Kuvan oletusmarginaalit, jos ei inline-tyylejä */
.content-section img:not([style*="margin"]),
.news-content img:not([style*="margin"]),
article img:not([style*="margin"]) {
    margin: 1em 0;
}

/* Keskitetyt kuvat - käytetään luokkaa */
.content-section img.img-center,
.news-content img.img-center,
article img.img-center {
    display: block;
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: 1em;
    margin-bottom: 1em;
}

/* Varmista että inline margin-tyylit toimivat (vanha tapa) */
.content-section img[style*="margin-left: auto"],
.news-content img[style*="margin-left: auto"],
article img[style*="margin-left: auto"] {
    display: block;
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: 1em;
    margin-bottom: 1em;
}

/* Linkit sisällössä */
.content-section a,
.news-content a,
article a {
    color: #0066cc;
    text-decoration: underline;
}

.content-section a:hover,
.news-content a:hover,
article a:hover {
    color: #0052a3;
}
