:root {
  --accent: #0B5D73;
  --accent-ink: #08465A;
  --ink: #14202B;
  --text: #3E4954;
  --muted: #5A6672;
  --line: #E1E6EB;
  --line-strong: #C5CDD5;
  --surface: #F4F6F8;
  --danger: #A12828;
  --ok: #1E6B3A;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.pad { padding: 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Kirjautuminen */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 100%; max-width: 380px; background: #FFFFFF; border: 1px solid var(--line); border-radius: 16px; padding: 32px; display: flex; flex-direction: column; gap: 16px; }
.login h1 { font-size: 22px; }

/* Runko: leveällä näytöllä sivupalkki, kapealla yläpalkki ja avattava valikko */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.topbar { display: none; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: #FFFFFF; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; }
.brand { font-weight: 700; font-size: 16px; padding: 0 8px; }
.brand span { display: block; font-weight: 500; font-size: 13px; color: var(--muted); }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: block; padding: 10px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.side nav a:hover { background: var(--surface); color: var(--ink); }
.side nav a[aria-current="page"] { background: color-mix(in srgb, var(--accent) 12%, #FFFFFF); color: var(--accent-ink); font-weight: 600; }
.side .grow { flex: 1; }
.side .me { padding: 0 8px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.main { min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
.pagehead h1 { font-size: 24px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 30; height: 56px; padding: 0 8px 0 16px;
    background: #FFFFFF; border-bottom: 1px solid var(--line);
  }
  .topbar .brand { padding: 0; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .menu-btn { width: 44px; height: 44px; border: none; background: none; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex: 0 0 auto; }
  .menu-btn:hover { background: var(--surface); }
  .side {
    display: none; position: fixed; top: 56px; left: 0; right: 0; bottom: 0; z-index: 29; height: auto;
    border-right: none; box-shadow: 0 12px 24px rgba(20,32,43,0.12);
  }
  .side > .brand { display: none; }
  .shell.menu-open .side { display: flex; }
  .main { padding: 20px 16px 40px; gap: 16px; }
  .pagehead h1 { font-size: 22px; }
}

/* Osat */
.card { background: #FFFFFF; border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card h2 { font-size: 17px; }
.card .head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.stat { font-size: 32px; font-weight: 700; line-height: 1; }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--text); }
label.f .hint { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="url"], select, textarea {
  height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: #FFFFFF; font-weight: 400; font-size: 15px; width: 100%;
}
textarea { height: auto; min-height: 90px; padding: 8px 12px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type="color"] { width: 56px; height: 40px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 8px; background: #FFFFFF; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 32px; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn { height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #FFFFFF; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--accent-ink); color: #FFFFFF; }
.btn.secondary { background: #FFFFFF; color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--surface); color: var(--ink); }
.btn.danger { background: #FFFFFF; color: var(--danger); border-color: #E3B5B5; }
.btn.danger:hover { background: #FBEDED; }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; background: #FFFFFF; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: #FAFBFC; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; }
td.actions > .btn { margin: 2px 0; }
td.nowrap { white-space: nowrap; }
.empty { padding: 20px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface); color: var(--text); }
.pill.on { background: #E3F1E8; color: var(--ok); }
.pill.off { background: #F1F1F1; color: var(--muted); }

/* Puhelimessa taulukon rivit näytetään kortteina; sarakeotsikko tulee solun eteen (data-label). */
@media (max-width: 900px) {
  .table-wrap { border: none; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap table { background: transparent; }
  .table-wrap tr { background: #FFFFFF; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; margin-bottom: 10px; }
  .table-wrap tr[hidden] { display: none; }
  .table-wrap td { border: none; padding: 5px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 16px; text-align: right; overflow-wrap: anywhere; }
  .table-wrap td::before { content: attr(data-label); flex: 0 0 auto; font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; }
  .table-wrap td:empty, .table-wrap td[data-empty] { display: none; }
  .table-wrap td.actions { justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding-top: 10px; white-space: normal; }
  .table-wrap td.actions::before { content: none; }
  .table-wrap td.nowrap { white-space: normal; }
  .table-wrap .empty { background: #FFFFFF; border: 1px solid var(--line); border-radius: 10px; }
  .card { padding: 16px; }
  .card .head form.row { width: 100%; }
  .card .head form.row > * { flex: 1 1 140px; }
  .btn { justify-content: center; }
}

code.key { font-size: 13px; background: var(--surface); padding: 4px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.secret { background: #FFF8E1; border: 1px solid #EBD38A; border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.secret code { font-size: 16px; font-weight: 600; }

.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; }
video.preview { width: 100%; max-width: 480px; border-radius: 10px; background: #000000; }
img.logo-preview { max-height: 48px; max-width: 220px; }

dialog { border: none; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(20,32,43,0.25); }
dialog::backdrop { background: rgba(20,32,43,0.45); }
dialog form { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { font-size: 19px; }
dialog .row.end { justify-content: flex-end; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: none; padding: 12px 20px; border-radius: 10px; background: var(--ink); color: #FFFFFF; font-weight: 500; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { display: block; }
#toast.err { background: var(--danger); }
.error { color: var(--danger); font-size: 14px; }
.ok { color: var(--ok); font-weight: 600; }

@media print {
  .side, .no-print, #toast { display: none !important; }
  body { background: #FFFFFF; }
  .main { padding: 0; }
  .card { border: none; padding: 0; }
}
