:root {
  --bg: #f4f5f3;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #66706b;
  --line: #e1e4e0;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ec;
  --ok: #1f8a4c;
  --bad: #c2412d;
  --bad-soft: #fbe9e5;
  --warn: #9a6a00;
  --warn-soft: #fdf3d8;
  --info-soft: #e5eefb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 1px 1px rgba(20, 30, 25, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131715; --card: #1c211f; --ink: #e7ebe9; --muted: #9aa49f; --line: #2c3330;
    --accent: #4cb397; --accent-ink: #0d1411; --accent-soft: #1d3029;
    --bad-soft: #3a211c; --warn-soft: #352c14; --info-soft: #1c2638;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.warn { color: var(--warn); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* Yläpalkki */
.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-inner { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand svg { width: 24px; height: 24px; fill: var(--accent); }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
nav a:hover { color: var(--ink); background: var(--bg); }
nav a.on { color: var(--accent); background: var(--accent-soft); }
.logout { margin: 0; }
.linklike { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 6px 0; }
.linklike:hover { color: var(--ink); text-decoration: underline; }

main.page { max-width: 1180px; width: 100%; margin: 0 auto; padding: 24px 16px 48px; flex: 1; }
main.narrow { max-width: 420px; width: 100%; margin: 0 auto; padding: 10vh 16px 48px; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: .75rem; padding: 16px; }
.head { margin-bottom: 18px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.crumb { margin: 0 0 8px; font-size: .9rem; }
.crumb a { text-decoration: none; color: var(--muted); }
.section-title { margin: 28px 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.empty { text-align: center; color: var(--muted); padding: 32px 18px; }
.card.empty h2 { color: var(--ink); }
.card.notice { border-color: var(--accent); background: var(--accent-soft); }
.card.auth h1 { margin-bottom: .5rem; }

/* Lomakkeet */
label { display: block; font-size: .85rem; font-weight: 600; margin: 0 0 12px; }
input:not([type=checkbox]):not([type=file]), select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; font: inherit; font-weight: 400;
  color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; min-height: 38px;
}
input:focus, select:focus, button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin: 0; }
.inline-form input, .inline-form select { margin-top: 4px; }
.inline-form .grow { flex: 1; min-width: 220px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; min-height: 38px; font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.btn.wide { width: 100%; margin-top: 6px; }
.danger-text { color: var(--bad); }
button.icon {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 1rem; cursor: pointer; line-height: 1;
}
button.icon:hover:not(:disabled) { border-color: var(--muted); }
button.icon:disabled { opacity: .35; cursor: default; }
button.icon.danger:hover { color: var(--bad); border-color: var(--bad); }

.flashes { margin-bottom: 16px; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); border: 1px solid var(--line); }
.flash.error { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.flash.ok { background: var(--accent-soft); }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); vertical-align: middle; }
.badge.info { background: var(--info-soft); color: #2d5aa0; border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* Taulukot */
.table-card { padding: 0; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--line); }
table.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
table.list tr:last-child td { border-bottom: 0; }
table.list a { text-decoration: none; }
.num { text-align: right !important; }
table.list form { margin: 0; display: inline; }

/* Näytöt */
.pending-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--line); }
.pending-row:first-of-type { border-top: 0; }
.pending-row form { margin: 0; }
.pending-row .inline-form { flex: 1; min-width: 280px; }
.pending-row .inline-form input { flex: 1; min-width: 160px; width: auto; }
.pending-row .inline-form select { width: auto; }
.code { font: 700 1.8rem/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .12em; background: var(--card); border: 2px dashed var(--accent); border-radius: 8px; padding: 10px 14px; color: var(--accent); }
.pending-info { display: grid; min-width: 160px; }
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.device { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.shot { display: block; aspect-ratio: 16 / 9; background: #0b0d0c; }
.shot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.shot.placeholder { display: grid; place-items: center; color: #7d8782; font-size: .85rem; }
.device-body { padding: 14px 16px 16px; }
.device-title { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.device-title h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.status i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status.online { color: var(--ok); }
.status.online i { background: var(--ok); box-shadow: 0 0 0 3px rgba(31, 138, 76, .18); }
.status.offline { color: var(--bad); }
.status.offline i { background: var(--bad); }
.now { margin: 2px 0 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-form { border-top: 1px solid var(--line); padding-top: 12px; }
.tech { margin-top: 12px; font-size: .85rem; }
.tech summary { cursor: pointer; color: var(--muted); }
.tech dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; margin: 10px 0; }
.tech dt { color: var(--muted); }
.tech dd { margin: 0; }

/* Lataus */
.dropzone { position: relative; border: 2px dashed var(--line); background: transparent; box-shadow: none; text-align: center; padding: 0; transition: border-color .15s, background .15s; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-label { display: grid; gap: 2px; padding: 22px 16px; margin: 0; cursor: pointer; font-weight: 400; font-size: .95rem; }
.drop-label strong { color: var(--accent); }
.dropzone .also { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 16px; font-weight: 500; }
.dropzone .also select { width: auto; margin: 0; }
.progress { margin: 0 16px 16px; height: 26px; border-radius: 6px; background: var(--bg); position: relative; overflow: hidden; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); opacity: .25; transition: width .2s; }
.progress-text { position: relative; font-size: .82rem; line-height: 26px; }

/* Soittolistan kohteet */
.items { display: grid; gap: 10px; }
.item { display: grid; grid-template-columns: 28px 120px 1fr auto; gap: 14px; align-items: start; margin: 0; padding: 14px; }
.item-num { font-weight: 700; color: var(--muted); padding-top: 4px; text-align: center; }
.item-thumb { width: 120px; aspect-ratio: 16/9; object-fit: contain; background: #0b0d0c; border-radius: 6px; }
.item-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.item-fields { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.item-fields label { margin: 0; }
.item-fields select { width: auto; }
.dur .suffix { display: flex; align-items: center; gap: 6px; font-weight: 400; }
.dur input { width: 84px !important; }
.item-actions { display: flex; flex-direction: column; gap: 6px; }
.item.state-disabled, .item.state-expired { opacity: .6; }
.sched { margin-top: 10px; font-size: .88rem; }
.sched summary { cursor: pointer; color: var(--muted); }
.sched summary span { color: var(--ink); font-weight: 600; }
.sched[data-has] summary span { color: var(--accent); }
.sched-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; margin-top: 10px; align-items: end; }
.sched-grid label { margin: 0; }
.days { grid-column: 1 / -1; border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.days legend { font-size: .85rem; font-weight: 600; margin-bottom: 6px; padding: 0; }
.day { margin: 0; }
.day input { position: absolute; opacity: 0; }
.day span { display: inline-block; min-width: 40px; text-align: center; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-weight: 600; }
.day input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.day input:focus-visible + span { outline: 2px solid var(--accent); }
.clear-sched { justify-self: start; }
.savebar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 12px 0; background: linear-gradient(to top, var(--bg) 70%, transparent); }

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-body { position: absolute; right: 0; top: calc(100% + 6px); width: 280px; z-index: 5; display: grid; gap: 14px; }
.menu-body form { margin: 0; }

/* Kirjasto */
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.lib-item { padding: 8px; margin: 0; display: grid; gap: 6px; }
.lib-item img { width: 100%; aspect-ratio: 16/9; object-fit: contain; background: #0b0d0c; border-radius: 6px; }
.lib-meta { display: grid; min-width: 0; }
.lib-name { font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.media-card { padding: 0; overflow: hidden; margin: 0; }
.media-thumb { position: relative; display: block; aspect-ratio: 16/9; background: #0b0d0c; }
.media-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.badge.over { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.65); color: #fff; border: 0; }
.media-body { padding: 10px 12px 12px; }
.media-body form { margin: 6px 0 0; }
.rename summary { cursor: pointer; list-style: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rename summary::-webkit-details-marker { display: none; }
.rename .inline-form { margin-top: 6px; flex-wrap: nowrap; }
.user-rename summary { white-space: normal; }
.rename-hint { margin-left: 8px; text-decoration: underline dotted; }
.user-rename[open] .rename-hint { display: none; }
.user-rename .inline-form input { max-width: 240px; }

/* Verkkosivut sisältönä */
.web-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.web-form label { margin: 0; }
.web-form input, .web-form select { margin-top: 4px; }
.web-form .grow { flex: 2; min-width: 240px; }
.web-thumb { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  aspect-ratio: 16/9; background: linear-gradient(135deg, #1d3b4f, #0b0d0c); color: #dfe9ee; border-radius: 6px;
  text-decoration: none; overflow: hidden; padding: 6px; box-sizing: border-box; }
.media-thumb.web-thumb { border-radius: 0; }
.web-icon { font-size: 1.8rem; line-height: 1; }
.item-thumb.web-thumb .web-icon { font-size: 1.2rem; }
.web-host { font-size: .78rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-line { word-break: break-all; }
.audio-thumb audio { width: 92%; margin-top: 6px; }
td.nowrap { white-space: nowrap; }
.audio-item-thumb { background: linear-gradient(135deg, #4a2d5f, #0b0d0c); }
.item-fields .vol { min-width: 140px; }
.item-fields .vol input { width: 100%; }
.music-list { margin: 6px 0 12px; padding-left: 1.4em; display: grid; gap: 4px; }
.music-settings .check { margin: 6px 0; }
.sound-form h2 { margin-top: 0; }

/* Live-näkymä */
.live-link i, .live-badge i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #d64545; margin-right: 6px; vertical-align: 1px; }
.live-card { padding: 0; overflow: hidden; }
.live-screen { position: relative; background: #0b0d0c; aspect-ratio: 16 / 9; display: grid; place-items: center; }
.live-screen.portrait { aspect-ratio: 9 / 16; max-height: 80vh; margin: 0 auto; }
.live-screen img { display: none; }
.live-screen canvas { width: 100%; height: 100%; object-fit: contain; display: block; grid-area: 1 / 1; }
.live-screen canvas[hidden] { display: none; }
.live-wait { color: #9aa49f; font-size: .9rem; grid-area: 1 / 1; padding: 16px; text-align: center; }
.live-badge { position: absolute; left: 12px; top: 12px; background: rgba(0,0,0,.7); color: #fff; font-size: .78rem; font-weight: 600; padding: 4px 10px; border-radius: 99px; }
.live-badge.on i { animation: live-pulse 1.4s ease-in-out infinite; }
.live-badge.connecting i { background: #d9a13b; }
.live-badge.error i { background: #d9a13b; }
.live-badge.stopped i { background: #7d8782; }
@keyframes live-pulse { 50% { opacity: .25; } }
.live-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px 16px; margin: 0; padding: 14px 18px 4px; }
.live-stats dt { font-size: .75rem; color: var(--muted); }
.live-stats dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.live-note { padding: 0 18px 14px; margin: 8px 0 0; }
.live-controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.remote-tools { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.remote-help { padding: 8px 14px 10px; border-bottom: 1px solid var(--line); font-size: .88rem; }
.remote-help summary { cursor: pointer; font-weight: 600; }
.remote-help ol { margin: 8px 0 0; padding-left: 1.3em; display: grid; gap: 4px; }
kbd { font: 600 .78rem/1 ui-monospace, Menlo, monospace; padding: 2px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--card); }
.switch { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 600; cursor: pointer; }
.switch input { width: auto; min-height: 0; margin: 0; }
.live-screen:focus { outline: none; }
.live-screen.remote { cursor: crosshair; touch-action: none; }
.live-screen.remote:focus-within, .live-screen.remote:focus { box-shadow: inset 0 0 0 3px var(--accent); }
.click-mark { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border: 2px solid #ffd54a; border-radius: 50%; pointer-events: none; opacity: 0; }
.click-mark.pop { animation: click-pop .6s ease-out; }
@keyframes click-pop { from { opacity: 1; transform: scale(.4); } to { opacity: 0; transform: scale(1.4); } }

/* Kutsut */
.copy-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.copy-row input { flex: 1; min-width: 240px; font: .85rem ui-monospace, Menlo, monospace; }
.invite-created h2 { margin-top: 0; }

/* Käyttäjätasot ja näyttöoikeudet */
.access { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-start; margin: 10px 0; }
.access > label { margin: 0; }
.device-access { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; min-width: 240px; }
.device-access legend { font-size: .85rem; font-weight: 600; padding: 0 4px; }
.device-access .check { margin: 0; font-weight: 400; }
.device-access .check:first-of-type { flex-basis: 100%; }
.access-edit summary { white-space: normal; }
.access-form { margin-top: 6px; }
.invite-form .inline-form { margin-bottom: 4px; }
.users-table td { vertical-align: top; }
.readonly-note { border-color: var(--line); }
.inline-unlock { display: inline; margin-left: 4px; }
.audio-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px 14px; }
.audio-row label { margin: 0; }
.audio-row input[type=range] { width: 100%; }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }

/* Varmuuskopiot */
.plain-list { margin: 6px 0 0; padding-left: 1.1em; }
.steps { padding-left: 1.3em; display: grid; gap: 4px; }
.drive-step { font-size: 1rem; margin: 18px 0 6px; }
.client-form { display: grid; gap: 8px; max-width: 520px; }
.client-form label { margin: 0; }
textarea { width: 100%; box-sizing: border-box; font: .82rem ui-monospace, Menlo, monospace; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); margin-top: 4px; }

/* Ilmoitukset */
.notif-form h2 { font-size: 1.05rem; margin: 18px 0 8px; }
.notif-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; align-items: start; }
.notif-grid label { margin: 0; }
.notif-form .check { margin: 6px 0; }
.notif-off { border-color: #d9a13b; background: #fdf3e1; color: #6b4a0f; }
.test-form { display: flex; gap: 10px; align-items: center; margin: -4px 0 14px; }

/* Tapahtumat */
.event-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 12px; align-items: end; }
.event-filters label { margin: 0; }
.events-table td { vertical-align: top; }
.events-table .ev-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge.lvl-varoitus { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.lvl-virhe { background: #fde2e2; color: #a02020; border-color: transparent; }
.event-mini { list-style: none; padding: 0; margin: 6px 0; display: grid; gap: 4px; font-size: .85rem; }
.event-mini li.lvl-varoitus, .event-mini li.lvl-virhe { color: var(--warn); }

/* Esityshistoria */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { margin: 0; display: grid; gap: 2px; padding: 14px 16px; }
.stat-num { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .item { grid-template-columns: 84px 1fr; }
  .item-num { display: none; }
  .item-thumb { width: 84px; }
  .item-actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
  .devices { grid-template-columns: 1fr; }
  .top-inner { gap: 8px 16px; padding-top: 8px; padding-bottom: 8px; }
  nav { order: 3; flex-basis: 100%; }
}
