/* =========================================================================
   Pure Home laskuri – ulkoasu
   Värit: syvä metsänvihreä (pääväri) + oliivi (Pure Home -logon sävy).
   Mobiili: ≤ 860 px valikko tiivistyy, ≤ 760 px taulukot muuttuvat korteiksi.
   ========================================================================= */

:root {
  --bg: #f3f4ef;
  --bg-deep: #e9ece4;
  --surface: #ffffff;
  --surface-muted: #f8f9f6;
  --text: #17231c;
  --text-soft: #3a4740;
  --muted: #6b766f;
  --border: #e1e5dd;
  --border-strong: #cdd4ca;

  --primary: #1f5b3f;
  --primary-dark: #163a2a;
  --primary-soft: #e5efe8;
  --accent: #93b33a;
  --accent-soft: #f0f5df;

  --danger: #b3261e;
  --danger-soft: #fbecea;
  --warning: #8a5a00;
  --warning-soft: #fff5dc;
  --warning-border: #efd38f;
  --info-soft: #e9f1f8;
  --violet: #4f3a7a;
  --violet-soft: #efeaf8;
  --blue: #24527a;
  --blue-soft: #e4eef8;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 34, 24, .05), 0 4px 16px rgba(16, 34, 24, .05);
  --shadow-lg: 0 10px 30px rgba(16, 34, 24, .12);
  --focus: 0 0 0 3px rgba(147, 179, 58, .35);

  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "SF Pro Text", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 80px; }
body { margin: 0; background: var(--bg); min-height: 100vh; }
a { color: var(--primary); text-underline-offset: 2px; }
a:hover { color: var(--primary-dark); }
h1 { font-size: 1.65rem; line-height: 1.25; margin: 0 0 1rem; letter-spacing: -.015em; font-weight: 700; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; letter-spacing: -.005em; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9em; }
.icon { flex: none; vertical-align: -3px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }

/* ---------- Yläpalkki ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(180deg, #1a4532 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.06) inset, 0 2px 10px rgba(0,0,0,.12);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 1.25rem;
  display: flex; align-items: center; gap: 1.5rem; min-height: 60px;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand:hover { color: #fff; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: var(--primary-dark);
}
.brand-text em { font-style: normal; font-weight: 500; color: #c9dc8f; }
.mainnav { display: flex; gap: .25rem; flex: 1; }
.mainnav a {
  display: flex; align-items: center; gap: .45rem;
  padding: .45rem .8rem; border-radius: 8px; color: rgba(255,255,255,.78); text-decoration: none; font-weight: 500;
}
.mainnav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.mainnav a[aria-current="page"] { color: #fff; background: rgba(255,255,255,.14); box-shadow: inset 0 -2px 0 var(--accent); }
.usermenu { display: flex; align-items: center; gap: .35rem; font-size: .92rem; }
.who { display: flex; align-items: center; gap: .5rem; font-weight: 600; margin-right: .35rem; }
.avatar {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.15); color: #fff; font-weight: 700; font-size: .85rem;
}
.usermenu-link {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  color: rgba(255,255,255,.8); background: none; border: 0; cursor: pointer;
}
.usermenu-link:hover { background: rgba(255,255,255,.1); color: #fff; }
form.inline { display: inline; margin: 0; }
.role-badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .08rem .5rem; border-radius: 999px; letter-spacing: .01em; }
.role-admin { background: var(--violet-soft); color: var(--violet); }
.role-laskija { background: var(--blue-soft); color: var(--blue); }
.role-myyja { background: #fdecd9; color: #8a4b12; }
.topbar .role-badge { background: rgba(255,255,255,.14); color: #e8f0d0; }

/* Mobiilivalikko (details/summary, ei JavaScriptiä) */
.mobile-menu { display: none; margin-left: auto; }
.mobile-menu summary {
  list-style: none; cursor: pointer; display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 10px; color: #fff;
}
.mobile-menu summary::-webkit-details-marker { display: none; }
.mobile-menu summary:hover { background: rgba(255,255,255,.1); }
.mobile-menu .close-icon { display: none; }
.mobile-menu[open] .close-icon { display: block; }
.mobile-menu[open] .open-icon { display: none; }
.mobile-menu-panel {
  position: absolute; left: 0; right: 0; top: 100%;
  background: var(--primary-dark); padding: .5rem 1rem 1.25rem;
  box-shadow: var(--shadow-lg); border-top: 1px solid rgba(255,255,255,.08);
}
.mobile-menu-panel nav { display: grid; gap: .15rem; }
.mobile-menu-panel a, .mobile-menu-panel button {
  display: flex; align-items: center; gap: .75rem; width: 100%;
  padding: .85rem .75rem; border-radius: 10px; color: #fff; text-decoration: none;
  font: inherit; font-size: 1.02rem; background: none; border: 0; cursor: pointer; text-align: left;
}
.mobile-menu-panel a[aria-current="page"] { background: rgba(255,255,255,.12); }
.mobile-menu-panel a:hover, .mobile-menu-panel button:hover { background: rgba(255,255,255,.08); color: #fff; }
.mobile-user { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid rgba(255,255,255,.12); }
.mobile-user .who { padding: .5rem .75rem; color: #fff; }
.mobile-user form { margin: 0; }

/* ---------- Sivupohja ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.container.narrow { max-width: 460px; padding-top: 3rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head > div:first-child { min-width: 0; }
.page-head .actions { margin: 0; }
.breadcrumb { margin: 0 0 .4rem; color: var(--muted); font-size: .88rem; }
.breadcrumb a { text-decoration: none; color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }
.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--muted); font-weight: 600; letter-spacing: -.02em; }
.small { font-size: .85rem; }

.subnav { display: flex; gap: .25rem; margin-bottom: 1.5rem; overflow-x: auto; scrollbar-width: none; background: var(--surface); padding: .3rem; border-radius: 10px; border: 1px solid var(--border); width: fit-content; max-width: 100%; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a { padding: .45rem .9rem; text-decoration: none; color: var(--text-soft); border-radius: 7px; white-space: nowrap; font-weight: 500; }
.subnav a:hover { background: var(--surface-muted); }
.subnav a[aria-current="page"] { background: var(--primary); color: #fff; }

.card, fieldset.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.5rem; margin: 0 0 1.25rem;
}
fieldset.card { min-width: 0; }
fieldset.card legend { font-weight: 700; font-size: 1.05rem; padding: 0 .4rem; margin-left: -.4rem; }
.card h2 { display: flex; align-items: center; gap: .5rem; }
.form-card { max-width: 600px; }
.wide-form { max-width: 920px; }

/* ---------- Kirjautuminen ---------- */
body.auth-page { background: radial-gradient(1200px 600px at 10% -10%, #2a6b4b 0%, transparent 60%), linear-gradient(160deg, #163a2a 0%, #0f2a1e 100%); }
body.auth-page .container.narrow { padding-top: 8vh; }
.login-card { padding: 2.25rem 2rem; border: 0; box-shadow: var(--shadow-lg); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin-bottom: 1.75rem; text-align: center; }
.login-brand .brand-mark { width: 52px; height: 52px; border-radius: 14px; }
.brand-title { margin: 0; font-size: 1.5rem; }
.brand-title span { color: var(--accent); font-weight: 500; }
.login-brand p { margin: 0; color: var(--muted); font-size: .92rem; }
body.auth-page .flash { box-shadow: var(--shadow); }

/* ---------- Etusivu ---------- */
.hero {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.hero h1 { margin: 0 0 .2rem; font-size: 1.9rem; }
.hero p { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; gap: .2rem; position: relative; overflow: hidden;
}
a.stat:hover { border-color: var(--border-strong); color: var(--text); transform: translateY(-1px); transition: transform .15s; }
.stat .stat-icon { position: absolute; right: 1rem; top: 1rem; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-muted); color: var(--muted); }
.stat .stat-label { color: var(--muted); font-size: .85rem; font-weight: 500; padding-right: 2.6rem; }
.stat .stat-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.stat .stat-sub { color: var(--text-soft); font-size: .88rem; font-variant-numeric: tabular-nums; }
.stat.stat-primary { background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%); color: #fff; border: 0; }
.stat.stat-primary .stat-label, .stat.stat-primary .stat-sub { color: rgba(255,255,255,.78); }
.stat.stat-primary .stat-icon { background: rgba(255,255,255,.12); color: var(--accent); }
.stat.stat-accent .stat-icon { background: var(--accent-soft); color: #5f7a14; }
.stat.stat-warning .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat.stat-blue .stat-icon { background: var(--blue-soft); color: var(--blue); }

.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.panel-head h2 { margin: 0; }
.panel-head a { font-size: .9rem; text-decoration: none; font-weight: 500; }
.recent { list-style: none; margin: 0 -1.5rem -1.5rem; padding: 0; }
.recent li { border-top: 1px solid var(--border); }
.recent a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem 1rem; padding: .85rem 1.5rem; text-decoration: none; color: var(--text); }
.recent a:hover { background: var(--surface-muted); }
.recent .r-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .r-meta { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .r-amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.recent .r-status { text-align: right; }
.quicklinks { display: grid; gap: .5rem; }
.quicklink {
  display: flex; align-items: center; gap: .85rem; padding: .8rem .9rem; border-radius: 10px;
  border: 1px solid var(--border); text-decoration: none; color: var(--text); background: var(--surface);
}
.quicklink:hover { border-color: var(--primary); color: var(--text); }
.quicklink .ql-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.quicklink strong { display: block; }
.quicklink span.ql-sub { color: var(--muted); font-size: .84rem; }
.quicklink .icon:last-child { margin-left: auto; color: var(--muted); }

/* Vanhat ruudut (käytössä mm. tyhjissä tiloissa) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.tile { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
a.tile:hover { border-color: var(--primary); }
.tile p { color: var(--muted); margin: 0; }

/* ---------- Lomakkeet ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .9rem; color: var(--text-soft); }
.field input[type="text"], .field input[type="email"], .field input[type="password"], .field input[type="number"],
.field input[type="date"], .field input:not([type]), .field select, .field textarea, .filters input, .filters select {
  width: 100%; padding: .6rem .75rem; font: inherit; color: var(--text);
  background: #fff; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s; min-height: 42px;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .filters input:focus, .filters select:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--focus);
}
.field input[readonly] { background: var(--surface-muted); color: var(--muted); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field label.check { display: flex; align-items: center; gap: .55rem; font-weight: 500; cursor: pointer; color: var(--text); }
.field label.check input, .filters .check input { width: 1.15rem; height: 1.15rem; accent-color: var(--primary); }
.with-suffix { display: flex; align-items: stretch; }
.with-suffix input { border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; text-align: right; }
.with-suffix .suffix {
  display: flex; align-items: center; padding: 0 .7rem; background: var(--surface-muted); color: var(--muted);
  border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; white-space: nowrap; font-size: .9rem;
}
.hint { color: var(--muted); font-size: .85rem; margin: .35rem 0 0; }
.hint.centered { text-align: center; margin-top: 1.25rem; }
legend + .hint, h1 + .hint, h2 + .hint { margin: 0 0 1rem; }
.error { color: var(--danger); font-size: .87rem; margin: .35rem 0 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.grid-2.tight { gap: 0 .75rem; grid-template-columns: 2fr 3fr; }
.grid-2.tight-equal { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 1rem; align-items: start; }
.grid-2.tight-equal .check { margin-top: 2rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 1.25rem; }
.grid-code-name { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 0 1.25rem; }
.grid-add { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: 0 1rem; }
.actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }

/* ---------- Painikkeet ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 40px; padding: .5rem 1.05rem; font: inherit; font-weight: 600; font-size: .93rem;
  border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; text-align: center;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.button:hover { border-color: var(--primary); color: var(--primary-dark); }
.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(31,91,63,.25); }
.button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.button.accent { background: var(--accent); border-color: var(--accent); color: var(--primary-dark); }
.button.accent:hover { background: #86a332; color: var(--primary-dark); }
.button.wide { width: 100%; margin-top: .5rem; min-height: 46px; }
.button.danger { color: var(--danger); border-color: #efc2bf; }
.button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.linkbutton { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
button.icon { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; font-size: .6rem; line-height: 1; padding: .3rem .4rem; cursor: pointer; color: var(--muted); }
button.icon:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
button.icon:disabled { opacity: .3; cursor: default; }

/* ---------- Ilmoitukset ---------- */
.flash { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; background: var(--surface); }
.flash-success { background: var(--primary-soft); border-color: #bcd8c9; color: #143a28; }
.flash-error { background: var(--danger-soft); border-color: #efc2bf; color: #7d1a14; }
.flash-info { background: var(--info-soft); border-color: #c6d7e8; }
.flash-warning { background: var(--warning-soft); border-color: var(--warning-border); color: #5c3d00; }
.notice { background: var(--warning-soft); border: 1px solid var(--warning-border); padding: .75rem 1rem; border-radius: var(--radius-sm); color: #5c3d00; }

/* ---------- Taulukot ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-muted); font-weight: 600; }
.table th small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fbfcfa; }
.table tr.muted td { color: #9aa39e; }
.table tr.draft td { background: #fcfcfb; }
.table .right, .right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.tag { font-size: .72rem; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 999px; padding: .05rem .5rem; color: var(--muted); white-space: nowrap; }
.log .details { font-size: .85rem; color: var(--muted); }
.log .details .k { color: var(--text); font-weight: 600; margin-right: .3rem; }
.show-sm { display: none; }
.row-link { font-weight: 600; text-decoration: none; }
.row-link:hover { text-decoration: underline; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; margin: 0 0 1.25rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.secret { font-size: 1.2rem; background: var(--surface-muted); padding: .2rem .6rem; border-radius: 6px; border: 1px solid var(--border); user-select: all; letter-spacing: .05em; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--border-strong); margin: 0; }
.empty { text-align: center; padding: 2.75rem 1.5rem; }
.empty p { color: var(--muted); max-width: 560px; margin: .5rem auto 1.25rem; }

/* ---------- Tilat ---------- */
.status { display: inline-flex; align-items: center; gap: .35rem; font-size: .76rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.status-ok, .status-accepted { background: var(--primary-soft); color: var(--primary); }
.status-draft { background: #eef0ec; color: var(--muted); }
.status-error, .status-rejected { background: var(--danger-soft); color: #9a2019; }
.status-sent { background: var(--blue-soft); color: var(--blue); }
.status-superseded { background: #f2f2f2; color: #8a8a8a; text-decoration: line-through; }
.status-expired { background: var(--warning-soft); color: var(--warning); }
.page-head .status { margin-top: .45rem; }

/* ---------- Rakennekirjasto ---------- */
.catalog-section { margin-bottom: 2rem; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.section-head h2 { margin: 0; }
.section-head .actions { margin: 0; font-size: .92rem; }
.section-head .actions a { text-decoration: none; font-weight: 500; }
.muted-section { opacity: .6; }
.structure-top { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }
.cost-headline { display: flex; flex-direction: column; gap: .15rem; padding-bottom: 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.cost-headline .label { color: var(--muted); font-size: .85rem; }
.cost-headline .value { font-size: 2rem; font-weight: 700; color: var(--primary); letter-spacing: -.02em; }
.description { white-space: pre-line; margin: 0 0 .5rem; }
.internal-notes { white-space: pre-line; color: var(--muted); font-size: .9rem; margin: 0; }
.image-card img { display: block; width: 100%; max-height: 280px; object-fit: contain; background: var(--surface-muted); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.image-placeholder { display: flex; align-items: center; justify-content: center; gap: .5rem; height: 160px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); color: var(--muted); background: var(--surface-muted); }
.image-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .75rem 0 .25rem; }
.image-form input[type="file"] { flex: 1; min-width: 0; font-size: .85rem; }
.components .sub, .quote-lines .sub { color: var(--muted); font-size: .82rem; font-weight: 400; }
.components tr.not-default td { color: #8d9691; background: var(--surface-muted); }
.components tfoot td { font-weight: 700; background: var(--surface-muted); border-top: 2px solid var(--border); border-bottom: 0; }
.components td.move, .quote-lines td.move { width: 1%; white-space: nowrap; padding-right: 0; }
.components td.move form, .quote-lines td.move form { display: flex; flex-direction: column; gap: 3px; }
.mode { display: inline-block; font-size: .78rem; padding: .08rem .55rem; border-radius: 6px; background: #eef0ec; color: var(--text-soft); }
.mode-removable { background: var(--blue-soft); color: var(--blue); }
.mode-addable { background: #fdecd9; color: #8a4b12; }
.mode-choice { background: var(--violet-soft); color: var(--violet); font-weight: 600; }
.danger-zone { border-color: #f1d4d1; }
.danger-zone h2 { color: var(--danger); }
.logo-row { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; }
.logo-preview { max-width: 240px; max-height: 90px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem; background: #fff; }
.logo-placeholder { width: 240px; height: 90px; }

/* ---------- Tarjoukset ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem .75rem; align-items: center; margin-bottom: 1.1rem; }
.filters .search { position: relative; flex: 1; min-width: 220px; }
.filters .search .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.filters .search input { padding-left: 2.4rem; }
.filters select { width: auto; }
.filters .check { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.quote-top { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.quote-top .facts { margin: 0; }
.quote-top .card > p.small { margin: 1rem 0 0; }
.new-customer { border-top: 1px dashed var(--border); padding-top: .75rem; margin-top: .25rem; }
.quote-lines .variation { color: var(--violet); }
.muted-num { color: var(--muted); }
.totals-wrap { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin-top: 1.25rem; }
.totals.internal { background: var(--surface-muted); }
.totals.customer { border-color: #cfe0d5; }
dl.sum { display: grid; grid-template-columns: 1fr auto; gap: .45rem 1rem; margin: 0; }
dl.sum dt { color: var(--muted); }
dl.sum dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
dl.sum .grand { font-size: 1.2rem; color: var(--text); border-top: 1px solid var(--border); padding-top: .55rem; margin-top: .15rem; }
dl.sum dd.grand { color: var(--primary); font-weight: 700; }
.add-lines { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; margin-top: 1.25rem; align-items: start; }
.line-now { background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .65rem .85rem; font-size: .93rem; }
.selection { display: flex; flex-direction: column; gap: .45rem; }
.option { display: grid; grid-template-columns: auto 1fr auto; gap: .75rem; align-items: center; padding: .7rem .85rem; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface); min-height: 48px; }
.option:hover { border-color: var(--primary); }
.option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.option.fixed { cursor: default; background: var(--surface-muted); }
.option.fixed:hover { border-color: var(--border); }
.option input { width: 1.15rem; height: 1.15rem; accent-color: var(--primary); }
.option .sub { color: var(--muted); font-size: .82rem; margin-left: .35rem; }
.option-cost { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.choice-group { border: 1px solid #ddd3ee; border-radius: var(--radius); padding: .55rem .8rem .8rem; margin: .25rem 0; display: flex; flex-direction: column; gap: .45rem; background: #fcfbfe; }
.choice-group legend { font-weight: 700; padding: 0 .35rem; color: var(--violet); }
.choice-group legend .sub { font-weight: 400; color: var(--muted); font-size: .82rem; }
.mobile-total { display: none; }
[hidden] { display: none !important; }
/* Tarjousrivin hinta pysyy näkyvissä valintoja selatessa ja päivittyy heti */
.live-bar { position: sticky; bottom: 0; z-index: 30; margin: 0 0 1rem; padding: .5rem 0 calc(.5rem + env(safe-area-inset-bottom)); background: linear-gradient(to bottom, transparent, var(--bg, #f6f7f4) 30%); }
.live-bar .line-now { background: var(--surface); box-shadow: 0 -4px 18px rgba(16,34,24,.10); transition: opacity .15s; }
.live-bar .line-now.is-preview { border-color: var(--primary); }
.live-errors .flash { margin: 0 0 .4rem; }
form.is-updating .line-now, form.is-updating [data-live="section"] .section-drawing { opacity: .55; }

/* ---------- Leikkauskuva ---------- */
.section-figure { margin: 0; display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }
.section-drawing { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .75rem; }
.section-svg { display: block; width: 100%; height: auto; max-height: 340px; }
.section-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.section-legend li { display: grid; grid-template-columns: 22px 1fr auto; gap: .55rem; align-items: baseline; font-size: .92rem; }
.legend-num { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .72rem; font-weight: 700; }
.legend-mm { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.section-total { margin: .75rem 0 0; padding-top: .6rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .9rem; }
.section-total strong { color: var(--text); }
/* U-arvo */
.thermal-headline { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; margin: .25rem 0 .5rem; }
.thermal-headline .value { font-size: 2rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.thermal-headline .unit { color: var(--muted); font-weight: 600; }
.thermal-headline .sub { margin-left: .75rem; }
.thermal-details summary { cursor: pointer; font-weight: 600; color: var(--primary); margin: .25rem 0 .5rem; }
.thermal-table td, .thermal-table th { padding: .35rem .5rem; font-size: .88rem; }
.thermal-table tr.sub td { color: var(--muted); }
.u-badge { display: inline-block; padding: .1rem .5rem; border-radius: 6px; background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.u-ok { color: var(--primary); font-weight: 600; }
.u-fail { color: #9a2019; }
.suggest-form .grid-4 { align-items: end; }
.suggest-group { margin-bottom: 1.25rem; }
.suggest-group h2 { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.suggest-group h2 .sub { font-size: .9rem; font-weight: 400; }
tr.suggest-miss td { opacity: .55; }
/* Materiaalikirjasto */
.material-picker { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: .75rem .9rem; margin-bottom: 1rem; background: var(--surface-muted); }
.material-results { list-style: none; margin: .35rem 0 0; padding: 0; max-height: 18rem; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.material-results li + li { border-top: 1px solid var(--border); }
.material-results button { display: flex; flex-direction: column; align-items: flex-start; gap: .1rem; width: 100%; text-align: left; background: none; border: 0; padding: .45rem .6rem; cursor: pointer; font: inherit; color: inherit; }
.material-results button:hover, .material-results button:focus { background: var(--primary-soft); outline: none; }
.material-results .empty { padding: .45rem .6rem; color: var(--muted); }
.material-selected { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin: .25rem 0 .5rem; }
.refresh-prices { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin: .5rem 0; }
.builder-cta { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-left: 4px solid var(--accent); }
.builder-cta h2 { margin: 0 0 .25rem; }
.builder-cta .hint { margin: 0; max-width: 60ch; }
.site-form h3 { margin: 1rem 0 .5rem; font-size: 1rem; }
.site-parts select { width: 100%; min-width: 16rem; }
.site-parts .with-suffix input { max-width: 8rem; text-align: right; }
.site-parts .small-input { margin-top: .35rem; width: 100%; }
.quantities dd strong { color: var(--primary); }
.plain-list { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.plain-list li + li { margin-top: .15rem; }
.grid-layer { display: grid; grid-template-columns: 110px minmax(0, 2fr) 150px minmax(0, 1.4fr); gap: 0 1rem; }
.fill-chip { display: inline-flex; align-items: center; gap: .45rem; }
.fill-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); display: inline-block; background: #dcdcdc; }
.fill-eriste_puukuitu { background: #efd8b4; } .fill-eriste_mineraali { background: #fff59a; } .fill-eriste_muovi { background: #e3eaf2; } .fill-eriste_finnfoam { background: #ffd94a; }
.fill-olki { background: #ecd99c; } .fill-puu { background: #f2dbb0; } .fill-lauta { background: #e8c48c; }
.fill-levy_kipsi { background: #eef0f2; } .fill-levy_kuitukipsi { background: #dfe4e8; } .fill-levy_puukuitu { background: #a9794c; }
.fill-levy_puu { background: #e4c088; } .fill-kalvo { background: #3f5f8f; } .fill-ilma { background: #fff; }
.fill-betoni { background: #d2d2d2; } .fill-lattia { background: #b9a58c; } .fill-kate { background: #4b4f54; } .fill-muu { background: #dcdcdc; }

/* =========================================================================
   Tabletti ja puhelin
   ========================================================================= */
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .usermenu .who > span:not(.avatar) { display: none; }
}

@media (max-width: 860px) {
  .mainnav, .usermenu { display: none; }
  .mobile-menu { display: block; }
  .topbar-inner { min-height: 56px; padding: 0 .75rem 0 1rem; gap: .75rem; }
  .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { font-size: 15px; }
  .container { padding: 1.1rem .9rem 6rem; }
  h1 { font-size: 1.4rem; }
  .hero h1 { font-size: 1.55rem; }
  .card, fieldset.card { padding: 1.1rem; border-radius: 10px; }
  .recent { margin: 0 -1.1rem -1.1rem; }
  .recent a { padding: .8rem 1.1rem; }

  /* iOS ei zoomaa, kun kentän fonttikoko on vähintään 16 px */
  .field input, .field select, .field textarea, .filters input, .filters select { font-size: 16px; min-height: 46px; }
  .button { min-height: 44px; }

  .grid-2, .grid-3, .grid-4, .grid-code-name, .grid-add, .structure-top, .quote-top, .totals-wrap, .add-lines, .section-figure, .grid-layer { grid-template-columns: 1fr; }
  .grid-2.tight { grid-template-columns: 2fr 3fr; }
  .grid-2.tight-equal .check { margin-top: 0; }
  .stats { gap: .65rem; }
  .stat { padding: .9rem; }
  .stat .stat-value { font-size: 1.5rem; }
  .stat .stat-icon { width: 30px; height: 30px; right: .7rem; top: .7rem; }

  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-head .actions > *, .page-head .actions form, .page-head .actions form .button { width: 100%; }
  .filters { display: grid; grid-template-columns: 1fr auto; }
  .filters .search { grid-column: 1 / -1; }
  .filters select { width: 100%; }
  .facts { grid-template-columns: minmax(90px, max-content) 1fr; }

  /* Taulukot kortteina */
  .table-wrap.responsive-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tfoot { display: block; }
  .table.responsive tr {
    display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow); padding: .8rem .95rem; margin-bottom: .6rem;
  }
  .table.responsive tbody tr:hover td { background: none; }
  .table.responsive td { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; border: 0; padding: .18rem 0; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: left; font-weight: 500; flex: none; }
  .table.responsive td.cell-main { display: block; text-align: left; font-size: 1rem; padding-bottom: .45rem; margin-bottom: .2rem; border-bottom: 1px solid var(--border); }
  .table.responsive td.cell-main::before, .table.responsive td:not([data-label])::before { content: none; }
  .table.responsive tr { display: flex; flex-direction: column; }
  .table.responsive td.cell-tools { order: 20; justify-content: flex-end; align-items: center; gap: .6rem; padding-top: .5rem; }
  .table.responsive td.cell-tools form { flex-direction: row; }
  .table.responsive td.cell-tools a { font-weight: 600; }
  .table.responsive td.move { width: auto; padding-right: 0; }
  .table.responsive td.move button.icon { padding: .45rem .6rem; font-size: .7rem; }
  .table.responsive .hide-sm { display: none; }
  .show-sm { display: inline; }
  .table.responsive td.details { display: block; text-align: left; padding-top: .35rem; }
  .table.responsive tr.not-default { opacity: .75; }
  .table.responsive tfoot tr { background: var(--primary-soft); border-color: #cfe0d5; }
  .table.responsive tfoot td { background: none; border: 0; }

  /* Tarjousnäkymän kiinteä summapalkki */
  .mobile-total {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: .7rem 1rem calc(.7rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 20px rgba(16,34,24,.08);
  }
  .mobile-total .mt-label { color: var(--muted); font-size: .8rem; display: block; }
  .mobile-total .mt-value { font-size: 1.2rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
}

@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .page-head .actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
