:root {
  --green: #468C37; --green-dark: #376f2b; --green-soft: #eef5ec;
  --ink: #1b1f1a; --muted: #6a716a; --line: #e4e7e2; --bg: #fafbf9; --card: #fff;
  --red: #b3261e; --amber: #8a6d00;
  --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.5; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 16px; font-weight: 650; margin: 22px 0 8px; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 8px 14px; }
button:hover { border-color: #cfd4cc; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--green-dark); }
button.primary:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; }
button.link { background: none; border: none; color: var(--muted); padding: 0; text-decoration: underline; }
button.wide { width: 100%; }
button.danger { color: var(--red); }
input, textarea, select { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink); width: 100%; }
textarea { resize: vertical; }
label { display: block; font-size: 13.5px; color: var(--muted); margin: 10px 0 0; }
label input, label textarea, label select { margin-top: 4px; }
label.check { display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; margin: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 32px; width: min(420px, 100%); }
.login-card .brand { margin-bottom: 8px; }
#dev-login { margin-top: 12px; display: flex; gap: 8px; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); display: inline-block; }

/* layout */
.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.side { border-right: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; padding: 18px 14px; gap: 14px; min-height: 0; }
.tabs { display: flex; flex-direction: column; gap: 2px; }
.tabs button { text-align: left; border: none; background: transparent; padding: 8px 10px; border-radius: 8px; color: var(--muted); }
.tabs button.active { background: var(--green-soft); color: var(--green-dark); font-weight: 600; }
#side-chat { display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.conv-list li { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; font-size: 13.5px; cursor: pointer; color: var(--ink); }
.conv-list li:hover { background: #f1f3ef; }
.conv-list li.active { background: var(--green-soft); }
.conv-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list li button { border: none; background: none; color: var(--muted); padding: 0 4px; font-size: 14px; }
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
.me img { width: 26px; height: 26px; border-radius: 50%; }
.me span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 22px 28px; overflow: auto; }
.bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

/* chat */
#view-chat { padding: 0; }
.messages { flex: 1; overflow: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 18px; }
.welcome { max-width: 680px; margin: 8vh auto 0; }
.welcome h1 { font-size: 26px; margin-bottom: 6px; }
.examples { display: grid; gap: 8px; margin-top: 16px; }
.examples .ex { text-align: left; background: var(--card); }
.msg { max-width: 860px; width: 100%; margin: 0 auto; }
.msg.user .bubble { background: var(--green-soft); border-radius: 12px; padding: 10px 14px; display: inline-block; max-width: 80%; white-space: pre-wrap; }
.msg.user { text-align: right; }
.msg.assistant .bubble { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.thinking { font-size: 13px; color: var(--muted); font-style: italic; white-space: pre-wrap; max-height: 90px; overflow: hidden; margin-bottom: 8px; }
.steps { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; }
.step { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.step .st { width: 8px; height: 8px; border-radius: 50%; background: #d3d8d0; flex: none; position: relative; top: -1px; }
.step.ok .st { background: var(--green); } .step.err .st { background: var(--red); } .step.run .st { background: var(--amber); animation: blink 1s infinite; }
.step details { display: inline; } .step summary { cursor: pointer; color: var(--muted); }
.step pre { font-family: var(--mono); font-size: 12px; background: #f5f6f4; padding: 8px; border-radius: 6px; overflow: auto; white-space: pre-wrap; margin: 6px 0 0; width: 100%; }
@keyframes blink { 50% { opacity: .3; } }
.content :is(h1,h2,h3) { margin: 12px 0 6px; font-size: 16px; }
.content h1 { font-size: 18px; }
.content p { margin: 6px 0; }
.content ul, .content ol { margin: 6px 0; padding-left: 22px; }
.content table { border-collapse: collapse; margin: 8px 0; font-size: 13.5px; width: 100%; }
.content th, .content td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.content th { background: #f4f7f3; font-weight: 600; }
.content td.num, .content th.num { text-align: right; font-variant-numeric: tabular-nums; }
.content code { font-family: var(--mono); font-size: 12.5px; background: #f2f3f0; padding: 1px 4px; border-radius: 4px; }
.content pre { background: #f2f3f0; padding: 10px; border-radius: 8px; overflow: auto; }
.content pre code { background: none; padding: 0; }
.content blockquote { border-left: 3px solid var(--green); margin: 8px 0; padding-left: 12px; color: var(--muted); }
.cursor::after { content: "▍"; color: var(--green); animation: blink 1s infinite; }
.composer { border-top: 1px solid var(--line); background: var(--card); padding: 12px 28px 16px; }
.composer textarea { max-width: 860px; margin: 0 auto; display: block; }
.composer-actions { max-width: 860px; margin: 8px auto 0; display: flex; justify-content: flex-end; gap: 8px; }

/* cards & tables */
.cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); margin-top: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.card.active { border-color: var(--green); }
.card h3 { margin: 0; font-size: 15px; }
.card .prompt { font-size: 13.5px; color: var(--muted); white-space: pre-wrap; max-height: 4.5em; overflow: hidden; }
.card .sched { font-size: 12.5px; color: var(--muted); }
.card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.card .actions button { padding: 5px 10px; font-size: 13px; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: #eef0ec; color: var(--muted); }
.badge.on { background: var(--green-soft); color: var(--green-dark); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; table-layout: auto; }
.table th, .table td { padding: 6px 7px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: #f4f7f3; font-weight: 600; font-size: 12px; line-height: 1.25; }
.table th.num { white-space: normal; }
.table td { font-size: 12.5px; }
@media (max-width: 1100px) { .table { font-size: 12px; } .table th, .table td { padding: 5px 5px; } .delta { display: none; } }
.table td.mono { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; max-width: 520px; }
.table tr.err td { color: var(--red); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 10px 0 6px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-weight: 650; }
.stat span { font-size: 12.5px; color: var(--muted); }
.run-view { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin-top: 12px; }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; width: min(640px, 92vw); }
dialog::backdrop { background: rgba(20, 30, 20, .35); }
dialog h2 { margin: 0 0 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .side { border-right: none; border-bottom: 1px solid var(--line); }
  .tabs { flex-direction: row; flex-wrap: wrap; }
  #side-chat .conv-list { max-height: 140px; }
}

/* v2: logo, kojelauta, palaute */
.logo-lg { height: 44px; width: auto; display: block; margin-bottom: 6px; }
.logo-sm { height: 26px; width: auto; }
.brand-sub { font-weight: 600; font-size: 15px; color: var(--ink); }
.side .brand { gap: 10px; }
.small { font-size: 12.5px; }
.row-inline { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row-inline select, .row-inline input { width: auto; }
label.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
label.inline select { margin: 0; width: auto; }
.table-wrap { width: 100%; }  /* ei koskaan vaakaskrollausta: taulukot tiivistetään sopimaan leveyteen */
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.click { cursor: pointer; } .table tr.click:hover td { background: #f6f8f5; }
.table td.good { color: var(--green-dark); font-weight: 600; } .table td.bad { color: var(--red); font-weight: 600; }
.delta { font-size: 11.5px; font-weight: 500; margin-left: 3px; }
.delta.up { color: var(--green-dark); } .delta.down { color: var(--red); } .delta.flat { color: var(--muted); }
.stat b .delta { font-size: 12px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin: 8px 0 4px; }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.chart-title { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
svg.chart { display: block; overflow: visible; }
svg.chart .grid { stroke: #ecefea; stroke-width: 1; } svg.chart .tick { font-size: 10.5px; fill: var(--muted); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.hbars { display: grid; gap: 5px; }
.hbar { display: grid; grid-template-columns: 220px 1fr 50px; gap: 8px; align-items: center; font-size: 13px; }
.hbar .hb { height: 10px; background: #eef0ec; border-radius: 5px; overflow: hidden; } .hbar .hb i { display: block; height: 100%; }
.hbar .hv { text-align: right; font-variant-numeric: tabular-nums; }
.wide-dialog { width: min(1000px, 94vw); max-height: 92vh; overflow: auto; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; text-align: center; margin-left: 4px; }
.badge.warn { background: #fdecea; color: var(--red); }
h3 { font-size: 15px; font-weight: 650; margin: 18px 0 6px; }
/* palautekupla */
.fb-bubble { position: fixed; right: 18px; bottom: 18px; width: 48px; height: 48px; border-radius: 50%; background: var(--green); color: #fff; border: none; font-size: 22px; box-shadow: 0 4px 14px rgba(0,0,0,.18); z-index: 20; padding: 0; }
.fb-bubble:hover { background: var(--green-dark); }
.fb-panel { position: fixed; right: 18px; bottom: 76px; width: min(360px, calc(100vw - 36px)); max-height: 70vh; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.16); z-index: 20; }
.fb-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.fb-panel select, .fb-panel textarea { margin-bottom: 8px; }
.fb-omat h4 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); }
.fb-item { border-top: 1px solid var(--line); padding: 8px 0; font-size: 13.5px; }
.fb-reply { color: var(--green-dark); margin-top: 4px; font-size: 13px; }
/* käynnit */
.btn-link { display: inline-block; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); font-size: 14px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.vahva { background: var(--green-soft); color: var(--green-dark); } .pill.kohtalainen { background: #fff4d6; color: var(--amber); } .pill.riski { background: #fdecea; color: var(--red); } .pill.none { background: #eef0ec; color: var(--muted); }
.krit { display: inline-flex; gap: 3px; }
.krit i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; background: #e3e6e0; }
.krit i.k1 { background: #b7d3a8; } .krit i.k2 { background: var(--green); } .krit i.k0 { background: #f1c4c0; }
.krit-list { display: grid; gap: 8px; margin: 8px 0; }
.krit-row { display: grid; grid-template-columns: 210px 60px 1fr; gap: 10px; align-items: baseline; font-size: 13.5px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.krit-row .kv { font-weight: 700; } .krit-row .kp { color: var(--muted); } .krit-row .tulk { font-size: 11px; color: var(--amber); margin-left: 6px; }
.riski-tag { display: inline-block; background: #fdecea; color: var(--red); padding: 1px 7px; border-radius: 6px; font-size: 12px; margin: 2px 4px 2px 0; }
.huomio { background: #f6f8f5; border-left: 3px solid var(--green); padding: 8px 12px; border-radius: 6px; margin: 10px 0; }

/* latausindikaattori: peittää sisällön, estää turhat klikkaukset */
.loading { position: fixed; inset: 0; background: rgba(250,251,249,.72); z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-weight: 600; color: var(--green-dark); cursor: progress; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid #d9e6d4; border-top-color: var(--green); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
