/* Jaettu terapiatyötaulu — perustyylit (landing + board) */

:root {
    --bg: #f4f6fb;
    --card: #ffffff;
    --ink: #21283a;
    --muted: #6b7280;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --danger: #dc2626;
    --border: #d7dce7;
    --shadow: 0 8px 24px rgba(30, 41, 59, .08);
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

/* ---------- Landing ---------- */

.landing-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.landing-card {
    width: 100%;
    max-width: 460px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.landing-card h1 {
    margin: 0 0 6px;
    font-size: 1.5rem;
}

.lead {
    color: var(--muted);
    margin: 0 0 20px;
}

.footnote {
    color: var(--muted);
    font-size: .8rem;
    text-align: center;
    margin-top: 20px;
}

.landing-block {
    margin: 12px 0;
}

.landing-block h2 {
    font-size: 1.05rem;
    margin: 0 0 10px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stack label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: .9rem;
    color: var(--muted);
}

input[type="text"] {
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    width: 100%;
}

input[type="text"]:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.btn {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    font-size: 1rem;
    cursor: pointer;
}

.btn.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.result-box {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    font-size: .95rem;
    word-break: break-word;
}

.result-box.error {
    background: #fef2f2;
    border-color: #fecaca;
    color: var(--danger);
}

/* QR-skannaus kameralla (landing) */
.join-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: .85rem;
    margin: 16px 0;
}

.join-divider::before,
.join-divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--border);
}

.scan-qr {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: #0b1020;
    text-align: center;
}

.scan-qr video {
    width: 100%;
    max-height: 260px;
    border-radius: 8px;
    background: #000;
    object-fit: cover;
}

.scan-status {
    margin: 8px 0;
    font-size: .85rem;
    color: #cbd5e1;
    min-height: 1.2em;
}

.hidden {
    display: none;
}

code.code-big {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: .3em;
    font-family: ui-monospace, Consolas, monospace;
}

/* ---------- Board ---------- */

.board-body {
    overflow: hidden;
}

.board-layout {
    display: grid;
    grid-template-rows: auto 1fr;
    height: 100vh;
}

.board-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.brand {
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.code-chip {
    background: #eef2ff;
    color: var(--primary);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: .8rem;
    letter-spacing: .2em;
    font-family: ui-monospace, Consolas, monospace;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

.spacer {
    flex: 1 1 auto;
}

.btn-sm {
    padding: 6px 10px;
    font-size: .9rem;
}

.btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.btn-danger {
    color: var(--danger);
    border-color: #fecaca;
}

.btn-danger:hover {
    background: #fef2f2;
}

.name-badge {
    font-size: .85rem;
    color: var(--muted);
}

.conn-status {
    font-size: 1.2rem;
    color: #d1d5db;
}

.conn-status.online {
    color: #22c55e;
}

.conn-status.offline {
    color: #ef4444;
}

.board-container {
    position: relative;
    overflow: hidden;
    background: #fbfbfd;
}

#board-canvas {
    display: block;
    touch-action: none;
}

.pan-hint {
    position: absolute;
    bottom: 8px;
    left: 12px;
    font-size: .72rem;
    color: var(--muted);
    background: rgba(255, 255, 255, .7);
    padding: 4px 8px;
    border-radius: 6px;
    pointer-events: none;
    z-index: 2;
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .35);
    display: grid;
    place-items: center;
    z-index: 10;
}

.overlay-box {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    max-width: 420px;
    width: 90%;
}

.overlay-box h3 {
    margin: 0 0 12px;
}

.group-name-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    font-size: .95rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    margin-bottom: 14px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-ghost {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}

.btn-ghost:hover {
    background: #e2e8f0;
}

#participants-list .part-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: .9rem;
}

#participants-list .role-host {
    color: var(--primary);
    font-weight: 600;
}

#participants-list .part-row.self {
    background: #eef2ff;
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    padding-left: 8px;
    margin-left: -8px;
    font-weight: 600;
}

#participants-list .part-row.away {
    opacity: .4;
    font-style: italic;
}

.toast {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, .85);
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: .9rem;
    z-index: 20;
}

.hidden {
    display: none !important;
}

/* ---------- Offcanvas: osallistujat & liittyminen ---------- */

.btn-participants {
    flex-shrink: 0;
}

.offcanvas-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease;
    z-index: 30;
}

.offcanvas-backdrop.show {
    opacity: 1;
    visibility: visible;
}

.offcanvas {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 360px;
    max-width: 100vw;
    background: #fff;
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 31;
    display: flex;
    flex-direction: column;
}

.offcanvas.show {
    transform: translateX(0);
}

.offcanvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.offcanvas-title {
    margin: 0;
    font-size: 1.1rem;
}

.offcanvas-close {
    border: 0;
    background: transparent;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    padding: 0 4px;
}

.offcanvas-close:hover {
    color: var(--ink);
}

.offcanvas-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.offcanvas-body h3 {
    margin: 0 0 10px;
    font-size: 1rem;
    color: var(--muted);
}

.panel-divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 14px 0;
}

#host-code {
    text-align: center;
    margin-bottom: 10px;
}

/* QR-koodi klikattavana suurennokseen */
.qr-box {
    display: grid;
    place-items: center;
    margin-bottom: 10px;
}

.qr-open-btn {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    padding: 8px;
    cursor: pointer;
    transition: box-shadow .15s, transform .15s;
    line-height: 0;
}

.qr-open-btn:hover {
    box-shadow: var(--shadow);
    transform: scale(1.02);
}

.qr-open-btn img,
.qr-open-btn canvas,
.qr-open-btn svg {
    display: block;
    border-radius: 8px;
}

/* ---------- QR-suurennusmodal ---------- */

#modal-qr {
    z-index: 40;
    /* offcanvas (30) ja sen backdrop yläpuolella */
}

#modal-qr .overlay-box {
    text-align: center;
    position: relative;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    max-width: 460px;
    width: 90%;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    border: 0;
    background: transparent;
    font-size: 1.8rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    padding: 0 4px;
}

.modal-close:hover {
    color: var(--ink);
}

.qr-modal-title {
    margin: 0 0 4px;
}

.qr-modal-sub {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: .9rem;
}

.qr-modal-canvas {
    display: grid;
    place-items: center;
    margin-bottom: 14px;
}

.qr-modal-canvas img,
.qr-modal-canvas canvas,
.qr-modal-canvas svg {
    max-width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.qr-modal-code {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: .35em;
    text-align: center;
    font-family: ui-monospace, Consolas, monospace;
    margin-bottom: 8px;
}

.url-box {
    font-size: .8rem;
    color: var(--muted);
    word-break: break-all;
    text-align: center;
}

.cap-badge {
    font-size: .72rem;
    color: var(--muted);
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px 6px;
    margin-left: auto;
}

.cap-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.cap-check {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: .72rem;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
}

.host-only {
    display: none;
}

body.is-host .host-only {
    display: flex;
}

/* ---------- Projektit-modali ---------- */
.project-list {
    max-height: 240px;
    overflow-y: auto;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px;
}

.project-empty {
    color: var(--muted);
    font-size: .9rem;
    padding: 10px;
    text-align: center;
}

.project-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background .15s;
}

   .project-row:hover {
       background: #f1f5f9;
   }

.project-row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.project-export {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: 6px;
    font-size: .75rem;
    padding: 2px 8px;
    cursor: pointer;
    color: var(--ink);
}

.project-export:hover {
    background: #eef2ff;
    border-color: #c7d2fe;
}

.project-import {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 10px 0;
    padding: 10px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    font-size: .85rem;
}

.project-import input[type=file] {
    font-size: .8rem;
}

.import-open-label {
    font-size: .8rem;
    color: var(--muted);
}

.project-row.selected {
    background: #eef2ff;
    outline: 1px solid #c7d2fe;
}

.project-name {
    font-size: .95rem;
    font-weight: 500;
}

.project-date {
    font-size: .75rem;
    color: var(--muted);
}

.project-label {
    display: block;
    font-size: .85rem;
    color: var(--muted);
    margin-bottom: 4px;
}

.create-qr {
    display: grid;
    place-items: center;
    margin-bottom: 12px;
}

.create-qr img,
.create-qr svg,
.create-qr canvas {
    border-radius: 8px;
    border: 1px solid var(--border);
}

.cap-check input {
    cursor: pointer;
}