/* Certego ovihallinta – sama tyylitiedosto työpöydälle ja mobiilille */
:root {
  --brand: #e8700a;
  --brand-ink: #ffffff;
  --brand-soft: #fdf0e3;
  --navy: #0d4a72;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #dde2e8;
  --text: #17212b;
  --muted: #5d6b79;
  --ok: #1d7f4e;
  --ok-soft: #e3f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info-soft: #e5f0f8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #f08a2c;
    --brand-ink: #1a1006;
    --brand-soft: #3a2614;
    --navy: #7cb8e0;
    --bg: #0f1419;
    --surface: #171e25;
    --surface-2: #1d252e;
    --line: #2c3742;
    --text: #e6ebf0;
    --muted: #97a4b1;
    --ok: #4cc38a;
    --ok-soft: #14301f;
    --warn: #e6b450;
    --warn-soft: #33290f;
    --bad: #f07a6e;
    --bad-soft: #3a1714;
    --info-soft: #14283a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--navy); }
h1 { font-size: 24px; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* --- Työpöytä: sivupalkki ------------------------------------------------ */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; color: var(--text);
  text-decoration: none; padding: 0 8px 18px; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 900; }
.logo small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 600; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.nav .sep { margin: 14px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-foot { margin-top: auto; font-size: 13px; color: var(--muted); padding: 0 10px; }
.side-foot form { display: inline; }
.main { padding: 26px 32px 60px; max-width: 1200px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

/* --- Kortit, taulukot ----------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; }
.card + .card { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  text-decoration: none; color: var(--text); }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.hot { border-color: var(--brand); background: var(--brand-soft); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
tr.link-row { cursor: pointer; }
tr.link-row:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* --- Tilat ja merkit ------------------------------------------------------ */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.st-kokoonpano { background: var(--info-soft); color: var(--navy); border-color: transparent; }
.st-riskiarvio, .st-testaus { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.st-koodi { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.st-hyvaksyttavana { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.st-julkaistu { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.res-ok { color: var(--ok); font-weight: 700; }
.res-huom { color: var(--warn); font-weight: 700; }
.res-vika { color: var(--bad); font-weight: 700; }
.res-eis { color: var(--muted); }
.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-weight: 800; letter-spacing: .08em; }
.code-big { font-size: 40px; text-align: center; padding: 16px; border: 3px dashed var(--brand); border-radius: 14px;
  background: var(--brand-soft); color: var(--text); margin: 12px 0; }

.steps { display: flex; gap: 4px; margin: 10px 0 0; flex-wrap: wrap; }
.steps span { flex: 1; min-width: 70px; font-size: 11px; font-weight: 700; text-align: center; padding: 6px 4px;
  border-radius: 6px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.steps span.done { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.steps span.now { background: var(--brand); color: var(--brand-ink); border-color: transparent; }

/* --- Ilmoitukset ---------------------------------------------------------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.note { padding: 10px 14px; border-radius: 8px; background: var(--info-soft); font-size: 14px; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--bad-soft); }
.errors { margin: 0 0 14px; padding: 10px 14px 10px 30px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); }

/* --- Lomakkeet ------------------------------------------------------------ */
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search],
select, textarea {
  width: 100%; font: inherit; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 16px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 2px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.inline { display: inline; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--navy); text-decoration: underline; cursor: pointer; }

/* Riski- ja testilomakkeen valintanapit */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { margin: 0; padding: 7px 12px; font-size: 13px; font-weight: 700; cursor: pointer; background: var(--surface);
  border-left: 1px solid var(--line); color: var(--muted); }
.seg label:first-of-type { border-left: 0; }
.seg input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: -2px; }
.seg input:checked + label.v-ok, .seg input:checked + label.v-0 { background: var(--ok); color: #fff; }
.seg input:checked + label.v-huom { background: var(--warn); color: #fff; }
.seg input:checked + label.v-vika, .seg input:checked + label.v-1 { background: var(--bad); color: #fff; }
.seg input:checked + label.v-eis { background: var(--muted); color: #fff; }
.q { padding: 14px 0; border-bottom: 1px solid var(--line); }
.q:last-child { border-bottom: 0; }
.q-text { font-weight: 600; margin-bottom: 4px; }
.q-ctrl { margin-top: 10px; }
.titem { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding: 10px 0;
  border-bottom: 1px solid var(--line); }
.titem:last-child { border-bottom: 0; }
.titem .tnote { grid-column: 1 / -1; }
.titem .tnote[hidden] { display: none; }

/* --- Kirjautuminen -------------------------------------------------------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 400px; }
.auth .logo { padding: 0 0 18px; }

/* --- Mobiili: asentajan tila ---------------------------------------------- */
.m-top { position: sticky; top: 0; z-index: 5; background: var(--navy); color: #fff; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px; min-height: 52px; }
@media (prefers-color-scheme: dark) { .m-top { background: #0b2233; } }
.m-top a { color: #fff; text-decoration: none; }
.m-top .back { font-size: 22px; line-height: 1; padding: 4px 8px 4px 0; }
.m-top .title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-top .logo-mark { width: 26px; height: 26px; font-size: 14px; }
.m-main { padding: 14px 16px 90px; max-width: 640px; margin: 0 auto; }
.m-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; }
.m-list li + li { border-top: 1px solid var(--line); }
.m-list a, .m-list .m-item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; color: var(--text); text-decoration: none; }
.m-list a:active { background: var(--surface-2); }
.m-list .grow { flex: 1; min-width: 0; }
.m-list .t { font-weight: 700; }
.m-list .d { font-size: 13px; color: var(--muted); }
.m-list .chev { color: var(--muted); font-size: 20px; }
.m-section { margin: 20px 0 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.m-section a { text-transform: none; letter-spacing: 0; font-size: 14px; }
.m-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line); z-index: 5; }
.m-bar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 8px; }
.m-bar .btn { flex: 1; padding: 12px; }
.m-foot { text-align: center; font-size: 13px; color: var(--muted); margin-top: 28px; }
.m-foot form { display: inline; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
  margin-bottom: 14px; }
.tabs a { flex: 1; text-align: center; padding: 8px; border-radius: 7px; font-weight: 700; font-size: 14px;
  color: var(--muted); text-decoration: none; }
.tabs a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.comp-actions { display: flex; gap: 6px; padding: 0 14px 12px; }
.comp-actions form { display: inline; }
.photo { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.chips a { flex: none; padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); text-decoration: none; font-size: 13px; font-weight: 600; }
.chips a.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.big-action { display: block; padding: 18px; border-radius: 12px; background: var(--brand); color: var(--brand-ink);
  text-decoration: none; font-weight: 800; font-size: 17px; text-align: center; border: 0; width: 100%; cursor: pointer; font-family: inherit; }
details.more { margin-top: 12px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--navy); }

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .cols, .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 18px 16px 50px; }
  .grid3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .titem { grid-template-columns: 1fr; }
  .seg label { padding: 8px 10px; }
  .code-big { font-size: 34px; }
}
/* Kapealla näytöllä vaihepalkki tiivistyy: vain nykyinen vaihe nimellä */
@media (max-width: 760px) {
  .steps { flex-wrap: nowrap; align-items: center; }
  .steps span { min-width: 0; font-size: 0; padding: 0; height: 8px; border-radius: 99px; }
  .steps span.now { flex: 0 0 auto; font-size: 12px; padding: 4px 10px; height: auto; }
}
