/* Keskitetty teemapaletti. Tumma teema säilyttää sivuston nykyisen ulkoasun. */
:root {
    color-scheme: dark;
    --background: #0b0d13;
    --surface: #191f2d;
    --surface-elevated: #11141d;
    --input: #0b0d13;
    --text: #e2e8f0;
    --text-secondary: #cbd5e1;
    --text-muted: #a0aec0;
    --accent: #ffaa00;
    --accent-hover: #ffb726;
    --accent-contrast: #11141d;
    --heading: #f8fafc;
    --input-text: #f8fafc;
    --placeholder: #64748b;
    --link-muted: #94a3b8;
    --border: #2d3748;
    --border-strong: #4a5568;
    --success: #4ade80;
    --danger: #f87171;
    --card-shadow: rgba(0, 0, 0, 0.55);
    --inset-shadow: rgba(0, 0, 0, 0.2);
}

:root[data-theme="light"] {
    color-scheme: light;
    --background: #f4f6f8;
    --surface: #ffffff;
    --surface-elevated: #eef1f5;
    --input: #f8fafc;
    --text: #1f2937;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --accent: #a86100;
    --accent-hover: #8b4d00;
    --accent-contrast: #ffffff;
    --heading: #1f2937;
    --input-text: #1f2937;
    --placeholder: #64748b;
    --link-muted: #64748b;
    --border: #d7dde6;
    --border-strong: #aab4c2;
    --success: #15803d;
    --danger: #b91c1c;
    --card-shadow: rgba(15, 23, 42, 0.12);
    --inset-shadow: rgba(15, 23, 42, 0.05);
}

/* =========================================================
   PERUSASETUKSET (Reset & Base)
========================================================= */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: #0b0d13;
    color: #e2e8f0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
    min-width: 0;
    min-height: 100vh;
}

img, svg, video, canvas {
    max-width: 100%;
    height: auto;
}

button, input, select, textarea {
    max-width: 100%;
    font: inherit;
}

pre, code {
    max-width: 100%;
    overflow-wrap: anywhere;
}

/* =========================================================
   ASETTELU (Layout)
========================================================= */
.laatikko {
    width: calc(100% - 32px);
    max-width: 800px;
    margin: 40px auto;
    padding: 32px;
    background-color: #191f2d;
    border-radius: 14px;
    border: 1px solid #2d3748;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.55);
    overflow-wrap: anywhere;
}

.osion-tausta {
    background-color: #11141d;
    padding: 22px;
    border-radius: 10px;
    margin-bottom: 20px;
    border: 1px solid #2d3748;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.osion-tausta:last-child {
    margin-bottom: 0;
}

/* =========================================================
   TYPOGRAFIA
========================================================= */
.otsikko {
    text-align: center;
    color: #ffaa00;
    margin-top: 0;
    margin-bottom: 24px;
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.45rem;
    color: #f8fafc;
    margin-top: 0;
    margin-bottom: 12px;
    font-weight: 700;
}

h3 {
    font-size: 1.15rem;
    color: #cbd5e1;
    margin-top: 0;
    margin-bottom: 10px;
    font-weight: 600;
}

p {
    margin-top: 0;
    margin-bottom: 14px;
}

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

/* =========================================================
   LOMAKKEET JA SYÖTTEET (Forms & Inputs)
========================================================= */
.syote {
    width: 100%;
    padding: 12px 14px;
    background-color: #0b0d13;
    border: 1px solid #4a5568;
    border-radius: 8px;
    color: #f8fafc;
    font-size: 16px; /* Estää iOS-safarin automaattisen zoomaamisen */
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.syote:focus {
    outline: none;
    border-color: #ffaa00;
    box-shadow: 0 0 0 3px rgba(255, 170, 0, 0.18);
}

.syote::placeholder {
    color: #64748b;
}

.flex-form {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.flex-form > * {
    flex: 1 1 auto;
}

/* =========================================================
   PAINIKKEET JA LINKIT (Buttons & Links)
========================================================= */
.nappula, .nappula1 {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.98rem;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: opacity 0.2s, transform 0.1s, background-color 0.2s, box-shadow 0.2s;
    min-height: 48px;
    user-select: none;
}

.nappula {
    background-color: #ffaa00;
    color: #11141d;
    box-shadow: 0 4px 12px rgba(255, 170, 0, 0.2);
}

.nappula:hover {
    background-color: #ffb726;
    box-shadow: 0 6px 16px rgba(255, 170, 0, 0.3);
}

.nappula:active {
    transform: scale(0.98);
}

.nappula:focus-visible,
.nappula1:focus-visible,
.linkki-takaisin:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(255, 170, 0, 0.65);
    outline-offset: 3px;
}

.nappula1 {
    background-color: #3b82f6;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.nappula1:hover {
    background-color: #2563eb;
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.nappula1:active {
    transform: scale(0.98);
}

/* Nappilistat etusivulla ja ohjesivuilla */
.nappilista,
.nappilista-ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.nappilista li,
.nappilista-ul li {
    width: 100%;
    max-width: 340px;
}

.nappilista li .nappula1,
.nappilista-ul li .nappula1 {
    margin-bottom: 0;
    width: 100%;
}

.linkki-takaisin {
    display: block;
    width: fit-content;
    max-width: 100%;
    text-align: center;
    color: #94a3b8;
    text-decoration: none;
    margin-top: 24px;
    padding: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    transition: color 0.2s ease;
    margin-left: auto;
    margin-right: auto;
}

.linkki-takaisin:hover {
    color: #ffaa00;
}

/* Saavutettavuus: Hyppää sisältöön linkki */
.skip-to-content {
    position: absolute;
    top: -50px;
    left: 16px;
    background: #ffaa00;
    color: #11141d;
    padding: 10px 16px;
    border-radius: 6px;
    z-index: 1000;
    transition: top 0.2s ease;
    font-weight: 700;
    text-decoration: none;
}

.skip-to-content:focus {
    top: 16px;
}

/* =========================================================
   TAULUKOT (Admin-paneeli ym.)
========================================================= */
.table-container {
    width: 100%;
    overflow-x: auto;
    margin-top: 16px;
    border-radius: 8px;
    border: 1px solid #2d3748;
    background: #0b0d13;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.92rem;
}

th, td {
    padding: 12px 14px;
    border-bottom: 1px solid #1e293b;
}

th {
    background-color: #11141d;
    color: #cbd5e1;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* =========================================================
   MOBIILIOPTIMOINTI (Media Queries)
========================================================= */
@media (max-width: 650px) {
    .laatikko {
        width: calc(100% - 24px);
        margin: 20px auto;
        padding: 22px 18px;
        border-radius: 12px;
    }

    .osion-tausta {
        padding: 16px;
        margin-bottom: 16px;
    }

    .otsikko {
        font-size: 1.75rem;
        margin-bottom: 18px;
    }

    h2 {
        font-size: 1.3rem;
    }

    h3 {
        font-size: 1.05rem;
    }

    .flex-form {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .flex-form > * {
        width: 100%;
        min-width: 0 !important;
    }

    .nappilista li,
    .nappilista-ul li {
        max-width: 100%;
    }

    .toiminto-rivi {
        flex-wrap: wrap;
    }

    .toiminto-rivi > *,
    [style*="min-width: 200px"],
    [style*="min-width: 230px"] {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
    }

    #qr-tulos-laatikko {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1;
    }

    th, td {
        padding: 10px;
    }
}

@media (max-width: 360px) {
    .laatikko {
        width: calc(100% - 16px);
        padding: 18px 14px;
    }

    .osion-tausta {
        padding: 14px;
    }

    .otsikko {
        font-size: 1.55rem;
    }
}

/* =========================================================
   TEEMA JA TEEMANVAIHTO
========================================================= */
html,
body {
    background-color: var(--background);
    color: var(--text);
}

body {
    transition: background-color 0.2s ease, color 0.2s ease;
}

.laatikko {
    background-color: var(--surface);
    border-color: var(--border);
    box-shadow: 0 10px 35px var(--card-shadow);
}

.osion-tausta {
    background-color: var(--surface-elevated);
    border-color: var(--border);
    box-shadow: inset 0 2px 4px var(--inset-shadow);
}

.otsikko,
.linkki-takaisin:hover {
    color: var(--accent);
}

h2 {
    color: var(--heading);
}

h3 {
    color: var(--text-secondary);
}

.syote {
    background-color: var(--input);
    border-color: var(--border-strong);
    color: var(--input-text);
}

.syote:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.syote::placeholder,
.linkki-takaisin {
    color: var(--placeholder);
}

.linkki-takaisin {
    color: var(--link-muted);
}

.nappula {
    background-color: var(--accent);
    color: var(--accent-contrast);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 20%, transparent);
}

.nappula:hover {
    background-color: var(--accent-hover);
    box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 30%, transparent);
}

.nappula1:focus-visible,
.nappula:focus-visible,
.linkki-takaisin:focus-visible,
button:focus-visible,
a:focus-visible {
    outline-color: color-mix(in srgb, var(--accent) 65%, transparent);
}

.table-container {
    border-color: var(--border);
    background: var(--input);
}

th,
td {
    border-bottom-color: var(--border);
}

th {
    background-color: var(--surface-elevated);
    color: var(--text-secondary);
}

#theme-toggle {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    z-index: 1000;
    width: auto;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface-elevated);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.16);
}

#theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Sivujen omat inline-tyylit saavat käyttää samaa palettia teemaa vaihdettaessa. */
[data-theme="light"] [style*="#191f2d"] { background-color: var(--surface) !important; }
[data-theme="light"] [style*="#11141d"] { background-color: var(--surface-elevated) !important; }
[data-theme="light"] [style*="#0b0d13"] { background-color: var(--input) !important; }
[data-theme="light"] [style*="#ffaa00"] { color: var(--accent) !important; border-color: var(--accent) !important; }
[data-theme="light"] [style*="#a0aec0"] { color: var(--text-muted) !important; }
[data-theme="light"] [style*="#ddd"] { color: var(--text-secondary) !important; }
[data-theme="light"] [style*="#2d3748"] { border-color: var(--border) !important; }

/* Työkalujen omissa head-tyyleissä määritellyt tekstialueet. */
#b64-syote,
#b64-tulos,
#json-syote,
#json-tulos {
    background: var(--input) !important;
    color: var(--input-text) !important;
}

#b64-tulos,
#json-tulos {
    color: var(--success) !important;
}

#b64-tulos.virhe,
#json-tulos.virhe {
    color: var(--danger) !important;
}

@media (prefers-reduced-motion: reduce) {
    body {
        transition: none;
    }
}
