:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dde1e6;
  --text: #1c2129; --muted: #5d6673; --accent: #1f5fbf; --accent-text: #ffffff;
  --ok: #2f8a4c; --low: #c98a0b; --crit: #c23b33; --unknown: #9aa3ae;
  --k: #2b2b2b; --c: #00a3d9; --m: #d6007e; --y: #f2c500;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --surface: #1c2027; --surface-2: #232831; --border: #323844;
    --text: #e6e9ee; --muted: #9ba4b1; --accent: #5b9bff; --accent-text: #0b1220;
    --ok: #4fbf72; --low: #e2a93a; --crit: #ef6b62; --unknown: #6b7480;
    --k: #c9ccd1; --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }

/* Yläpalkki */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 1.5rem; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 650; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand svg { width: 22px; height: 22px; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: .4rem .7rem; border-radius: 6px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--text); background: var(--surface-2); font-weight: 550; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.userbox form { margin: 0; }

main { max-width: 1280px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* Kortit ja taulukot */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 600; background: var(--surface-2); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Lomakkeet */
form.inline { display: inline; }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .9rem; }
.filters .field { margin-bottom: 0; }
.field label, .filters label { font-size: .85rem; color: var(--muted); }
.field .hint { font-size: .8rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: .45rem .6rem; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .25rem 1rem; }
.form-narrow { max-width: 560px; }
.btn { display: inline-flex; align-items: center; gap: .35rem; font: inherit; font-weight: 550; padding: .45rem .9rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, var(--border)); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Ilmoitukset */
.flash { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; overflow-wrap: anywhere; }
.flash.ok { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.flash.warn { background: color-mix(in srgb, var(--low) 14%, var(--surface)); border-color: color-mix(in srgb, var(--low) 45%, transparent); }
.flash.error { background: color-mix(in srgb, var(--crit) 12%, var(--surface)); border-color: color-mix(in srgb, var(--crit) 45%, transparent); }

/* Tilat */
.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.warn { color: var(--low); background: color-mix(in srgb, var(--low) 16%, transparent); }
.badge.crit { color: var(--crit); background: color-mix(in srgb, var(--crit) 14%, transparent); }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .35rem; vertical-align: baseline; }
.dot.ok { background: var(--ok); } .dot.off { background: var(--crit); } .dot.never { background: var(--unknown); }

/* Tarvikepalkit */
.toners { display: flex; gap: 6px; align-items: flex-end; }
.toner { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.toner .tube { width: 14px; height: 34px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 3px; position: relative; overflow: hidden; }
.toner .fill { position: absolute; left: 0; right: 0; bottom: 0; }
.c-Black { background: var(--k); } .c-Cyan { background: var(--c); } .c-Magenta { background: var(--m); } .c-Yellow { background: var(--y); }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; border-radius: 999px; }
.lvl-ok > span, span.lvl-ok { background: var(--ok); }
.lvl-low > span, span.lvl-low { background: var(--low); }
.lvl-crit > span, span.lvl-crit { background: var(--crit); }
.lvl-unknown > span { background: var(--unknown); }
.pct.lvl-low { color: var(--low); font-weight: 600; } .pct.lvl-crit { color: var(--crit); font-weight: 600; }

/* Päiväkäyttö-kaavio */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column-reverse; min-width: 4px; height: 100%; position: relative; }
.chart .col span { display: block; width: 100%; }
.chart .mono { background: var(--muted); border-radius: 0 0 2px 2px; }
.chart .color { background: var(--accent); border-radius: 2px 2px 0 0; }
.chart .col:hover { background: var(--surface-2); }
.chart-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.copy { display: flex; gap: .5rem; align-items: stretch; }
.copy input { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.status-msg { white-space: pre-line; font-size: .9rem; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-wrap .card { width: 100%; max-width: 380px; padding: 28px; }
.login-wrap input { width: 100%; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .userbox { margin-left: 0; width: 100%; justify-content: space-between; padding-bottom: .5rem; }
  h1 { font-size: 1.3rem; }
}

/* Hallinta-pudotusvalikko */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; color: var(--muted); padding: .4rem .7rem; border-radius: 6px; user-select: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::after { content: ""; display: inline-block; margin-left: .4rem; border: 4px solid transparent; border-top-color: currentColor; vertical-align: -1px; }
.menu > summary:hover, .menu[open] > summary { background: var(--surface-2); color: var(--text); }
.menu > summary.active { color: var(--text); background: var(--surface-2); font-weight: 550; }
.menu .dropdown { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; min-width: 220px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; display: flex; flex-direction: column; }
.menu .dropdown a { color: var(--text); padding: .45rem .7rem; border-radius: 6px; display: flex; justify-content: space-between; gap: 1rem; }
.menu .dropdown a:hover { background: var(--surface-2); text-decoration: none; }
.menu .dropdown a.active { background: var(--surface-2); font-weight: 550; }
.menu .dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* Hallinnan välilehdet */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 550; }
.tabs .count { font-size: .75rem; background: var(--low); color: #fff; border-radius: 999px; padding: 0 .4rem; margin-left: .3rem; }

/* Haku ja sivutus */
input[type=search] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; min-width: 220px; }
.filters .grow { flex: 1 1 240px; }
.filters .grow input { width: 100%; }
.result-meta { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: .5rem 0; font-size: .85rem; color: var(--muted); }
.pager { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }
.pager a, .pager span { padding: .2rem .55rem; border-radius: 6px; border: 1px solid var(--border); font-size: .85rem; }
.pager span.current { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.pager span.gap { border: 0; }
.htmx-request #results, #results.htmx-request { opacity: .55; transition: opacity .15s; }
details.create { margin-bottom: 1rem; }
details.create > summary { cursor: pointer; display: inline-flex; list-style: none; }
details.create > summary::-webkit-details-marker { display: none; }
details.create[open] > summary { margin-bottom: .75rem; }
details.row-edit > summary { cursor: pointer; list-style: none; display: inline-flex; }
details.row-edit > summary::-webkit-details-marker { display: none; }
details.row-edit[open] { margin-top: .5rem; }
.inline-fields { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; }
.inline-fields .field { margin-bottom: 0; }
mark { background: color-mix(in srgb, var(--low) 35%, transparent); color: inherit; border-radius: 2px; }
