/* Glazetor – ulkoasu (vastaa työpöytäversion tyylejä) */
:root {
  --navy: #0F172A; --navy-soft: #1E293B; --accent: #2563EB; --accent-dark: #1D4ED8; --accent-soft: #EFF6FF;
  --ink: #0F172A; --slate: #475569; --muted: #64748B; --line: #E2E8F0; --line-strong: #CBD5E1; --bg: #F1F5F9;
  --amber-bg: #FFFBEB; --amber-line: #FCD34D; --amber-ink: #92400E; --red: #B91C1C;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- yläpalkki ja välilehdet ---------- */
.top { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 14px; padding: 12px 22px; }
.top-logo { width: 44px; height: 44px; }
.brand { font-size: 21px; font-weight: 700; }
.brand .app-ver { font-size: 12.5px; font-weight: 600; color: #94A3B8; margin-left: 4px; }
.sub { color: #94A3B8; font-size: 13px; margin-top: 1px; }
.badge { margin-left: auto; background: var(--navy-soft); border: 1px solid #334155; color: #FCD34D; font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 8px; }
.seg-dark { display: flex; gap: 2px; background: var(--navy-soft); border: 1px solid #334155; border-radius: 9px; padding: 3px; }
.seg-dark button { width: 48px; height: 32px; border: 0; border-radius: 7px; background: transparent; color: #fff; font-weight: 600; cursor: pointer; }
.seg-dark button.on { background: var(--accent); }
.tabs { background: #fff; border-bottom: 1px solid var(--line); padding: 0 22px; display: flex; gap: 26px; }
.tab { border: 0; background: none; padding: 12px 4px 10px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- asettelu ---------- */
.page { padding: 18px 22px 0; min-height: calc(100vh - 118px); display: flex; flex-direction: column; }
.grid-calc { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; flex: 1; }
.grid-set { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.row2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; }
.grow { flex: 1; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(15, 23, 42, .05); padding: 4px 18px 18px; display: flex; flex-direction: column; min-width: 0; }
.card h2 { font-size: 14.5px; font-weight: 600; margin: 0; padding: 14px 0 10px; display: flex; align-items: center; }
.card h2::before { content: ""; width: 4px; height: 15px; border-radius: 2px; background: var(--accent); margin-right: 9px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
label > span, .lbl { font-size: 12.5px; font-weight: 600; color: var(--slate); }
.lbl { margin-bottom: 6px; }
.help { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; line-height: 1.45; }
.help.prev-summary { margin-top: 14px; }
.page-end { height: 18px; }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: 11.5px; word-break: break-all; }

/* ---------- kentät ---------- */
input:not([type]), input[type=text], select {
  height: 40px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; font-size: 15px; background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
input:disabled { background: #F8FAFC; color: var(--muted); }
input::placeholder { color: #94A3B8; font-style: italic; font-size: 13.5px; }
input.bad { border-color: var(--red); }

.seg { display: inline-flex; background: #E2E8F0; border-radius: 9px; padding: 3px; gap: 2px; align-self: flex-start; margin-bottom: 12px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 8px 15px; border-radius: 7px; font-weight: 600; color: var(--slate); cursor: pointer; }
.seg button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(15, 23, 42, .12); }

.switch { flex-direction: row; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i { width: 40px; height: 23px; border-radius: 12px; background: var(--line-strong); position: relative; flex: none; transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: left .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { left: 20px; }
.switch input:focus-visible + i { box-shadow: 0 0 0 3px rgba(37, 99, 235, .3); }
.switch > span { font-size: 14px; font-weight: 500; color: var(--ink); }

.edge-row { display: flex; gap: 18px; align-items: flex-end; }
.edge-row .switch { margin-bottom: 20px; }
.side-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.lbl-inline { font-size: 13px; color: var(--slate); margin-bottom: 12px; }

.canvas { background: #F8FAFC; border: 1px solid var(--line); border-radius: 10px; flex: 1; min-height: 220px; display: flex; align-items: center; justify-content: center; padding: 8px; }
.canvas svg { width: 100%; height: auto; max-height: 330px; }
/* laskimessa kaavio täyttää vapaan tilan, mutta ei kasvata saraketta */
.c-elec .canvas { flex: 1 1 0; min-height: 210px; position: relative; padding: 0; }
.c-elec .canvas svg { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); max-height: none; }
.chip { margin: 0 0 12px auto; background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; font-size: 13px; padding: 6px 14px; border-radius: 8px; }

/* tiivis kortti (laskimen vasen sarake) */
.col-left { gap: 14px; }
.col-left .row2 { gap: 14px; }
.card.compact { padding: 2px 16px 12px; }
.card.compact h2 { padding: 11px 0 8px; }
.card.compact label { margin-bottom: 8px; gap: 4px; }
.card.compact input:not([type]), .card.compact select { height: 36px; font-size: 14.5px; }
.card.compact .help { margin-bottom: 4px; }
.card.compact .pair { gap: 10px; }
.quad { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.editing { display: flex; align-items: center; gap: 12px; background: var(--accent-soft); color: var(--accent-dark); border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600; margin-top: 2px; }
.editing .linkish { margin-left: auto; }

/* ---------- tulokset ---------- */
.results { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 12px; align-items: stretch; }
.results .tiles { margin-top: 0; }
.results .hero { display: flex; flex-direction: column; justify-content: center; }
.hero { background: linear-gradient(135deg, #2563EB, #1E40AF); color: #fff; border-radius: 12px; padding: 16px 20px; }
.hero-lbl { font-size: 13px; opacity: .85; }
.hero-val { font-size: 30px; font-weight: 700; margin-top: 2px; }
.hero-sub { font-size: 13px; opacity: .85; margin-top: 2px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; display: flex; flex-direction: column; gap: 3px; }
.tile span { font-size: 12.5px; color: var(--slate); }
.tile b { font-size: 19px; }
.tile.accent { background: var(--accent-soft); }
.tile.accent b { color: var(--accent); }
.error { margin-top: 12px; color: var(--red); font-size: 13px; background: #FEF2F2; border: 1px solid #FECACA; border-radius: 8px; padding: 9px 12px; }

/* ---------- alapalkki ---------- */
.bar { display: flex; align-items: center; gap: 16px; padding: 14px 0 16px; flex-wrap: wrap; }
/* laskimen ja asetusten alapalkki pysyy näkyvissä myös matalalla näytöllä */
#calc > .bar, #settings > .bar { position: sticky; bottom: 0; z-index: 5; background: var(--bg); margin-top: 4px; box-shadow: 0 -10px 12px -10px rgba(15, 23, 42, .18); }
.warn { display: flex; align-items: center; gap: 10px; background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-ink); border-radius: 10px; padding: 9px 14px; font-size: 13px; flex: 1 1 380px; }
.warn b { width: 22px; height: 22px; border-radius: 50%; background: #F59E0B; color: #fff; display: flex; align-items: center; justify-content: center; flex: none; font-size: 13px; }
.warn a { margin-left: auto; color: var(--amber-ink); font-weight: 600; white-space: nowrap; }
.bar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.switch.small { margin: 0; gap: 7px; }
.switch.small > span { font-weight: 600; color: var(--slate); margin-right: 4px; }
.switch.small em { font-style: normal; font-size: 12.5px; color: var(--muted); }
.pn { flex-direction: row; align-items: center; gap: 10px; margin: 0; }
.pn input { width: 190px; }
button.primary { height: 44px; padding: 0 26px; border: 0; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; cursor: pointer; }
button.primary:hover { background: var(--accent-dark); }
button.primary:disabled { background: #94A3B8; cursor: default; }
button.outline { height: 44px; padding: 0 22px; border: 2px solid var(--accent); border-radius: 9px; background: transparent; color: var(--accent); font-weight: 600; font-size: 15px; cursor: pointer; }
button.outline:hover { background: var(--accent-soft); }
button.outline:disabled { border-color: #94A3B8; color: #94A3B8; cursor: default; }
html[data-theme="dark"] button.outline { color: #93C5FD; border-color: #3B82F6; }
button.secondary { height: 38px; padding: 0 15px; border: 0; border-radius: 8px; background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; cursor: pointer; }
button.secondary:hover { background: #DBEAFE; }

/* ---------- asetukset ---------- */
.subtabs { display: flex; gap: 4px; flex-wrap: nowrap; overflow-x: auto; background: #E2E8F0; border-radius: 10px; padding: 4px; align-self: flex-start; max-width: 100%; margin-bottom: 16px; scrollbar-width: thin; }
.subtab { border: 0; background: transparent; padding: 9px 16px; border-radius: 7px; font-weight: 600; color: var(--slate); cursor: pointer; white-space: nowrap; }
.subtab:hover { color: var(--ink); }
.subtab.on { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(15, 23, 42, .12); }
html[data-theme="dark"] .subtabs { background: #1E293B; }
html[data-theme="dark"] .subtab.on { background: #0F172A; color: #93C5FD; box-shadow: none; }
.set-switch { align-self: end; margin-bottom: 20px; }
.set-one { width: min(860px, 100%); flex: 1; }
.set-bar { gap: 12px; }
.set-bar .status { color: var(--slate); font-size: 13px; margin-left: auto; }
/* Asetukset keskitetään: alivälilehdet, sisältö ja alapalkki samalla leveydellä ruudun keskellä */
#settings { align-items: center; }
#settings > .subtabs { align-self: center; }
#settings > .set-bar { width: min(860px, 100%); }
.note-small { color: var(--muted); font-size: 12px; }
.logo-row { display: flex; gap: 14px; align-items: center; margin-bottom: 6px; }
.logo-box { width: 200px; height: 64px; border: 1px dashed var(--line-strong); border-radius: 8px; display: flex; align-items: center; justify-content: center; background: #F8FAFC; color: var(--muted); font-size: 12.5px; overflow: hidden; }
.logo-box img { max-width: 100%; max-height: 100%; }
.logo-btns { display: flex; flex-direction: column; gap: 8px; }

/* ---------- käyttöehdot ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.dialog { background: var(--bg); border-radius: 14px; width: min(760px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.dlg-head { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 14px; padding: 14px 20px; }
.dlg-head img { width: 42px; height: 42px; }
.dlg-head .seg-dark { margin-left: auto; }
.dlg-title { font-size: 19px; font-weight: 700; }
.dlg-sub { color: #94A3B8; font-size: 12.5px; margin-top: 2px; }
.dlg-body { background: #fff; margin: 16px 18px 0; border: 1px solid var(--line); border-radius: 12px; padding: 4px 22px 16px; overflow-y: auto; line-height: 1.5; color: var(--slate); }
.dlg-body h3 { color: var(--ink); font-size: 16px; margin: 16px 0 8px; }
.dlg-body p { margin: 0 0 8px; }
.dlg-body ul { margin: 0 0 8px; padding-left: 20px; }
.dlg-body .note { background: #F8FAFC; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; font-size: 12.5px; font-style: italic; color: var(--muted); margin-top: 10px; }
.dlg-foot { padding: 14px 18px 18px; }
.check { flex-direction: row; align-items: flex-start; gap: 10px; margin-bottom: 8px; font-weight: 600; font-size: 13.5px; cursor: pointer; }
.check input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.dlg-btns { display: flex; justify-content: flex-end; margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); z-index: 60; max-width: calc(100% - 40px); font-size: 14px; }

/* ---------- kapeat näytöt (tabletti, puhelin) ---------- */
@media (max-width: 1100px) {
  .grid-calc, .grid-set { grid-template-columns: 1fr; }
  /* kapealla näytöllä kortit numerojärjestyksessä: 1, 2–3, 4, 5, 6 */
  .grid-calc .col { display: contents; }
  .c-job { order: 1; } .c-dims { order: 2; } .c-elec { order: 3; } .c-inputs { order: 4; } .c-results { order: 5; }
}
@media (max-width: 1300px) {
  .results { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .top { padding: 10px 14px; gap: 10px; }
  .sub, .badge { display: none; }
  .seg-dark { margin-left: auto; }
  .page { padding: 12px 12px 0; }
  .row2, .pair, .quad, .tiles { grid-template-columns: 1fr; }
  .edge-row { flex-direction: column; align-items: stretch; gap: 0; }
  .bar-right { width: 100%; flex-direction: column; align-items: stretch; gap: 12px; }
  .pn { width: 100%; } .pn span { white-space: nowrap; } .pn input { flex: 1; width: auto; }
  button.primary, button.outline { width: 100%; }
  .set-bar { flex-direction: column; align-items: stretch; }
  .set-bar .status { margin-left: 0; }
}

/* ======================================================================
   TUMMA TILA  (html[data-theme="dark"])
   Kaavio ja tuloste pysyvät vaaleina, jotta ne näyttävät samalta kuin Word-tulosteessa.
   ====================================================================== */
html[data-theme="dark"] {
  --bg: #0B1120; --ink: #E2E8F0; --slate: #CBD5E1; --muted: #94A3B8; --line: #1E293B; --line-strong: #334155;
  --accent: #3B82F6; --accent-dark: #93C5FD; --accent-soft: #172554;
  --amber-bg: #231A06; --amber-line: #78590F; --amber-ink: #FCD34D; --red: #F87171;
  color-scheme: dark;
}
html[data-theme="dark"] body { background: var(--bg); color: var(--ink); }
html[data-theme="dark"] .tabs,
html[data-theme="dark"] .card,
html[data-theme="dark"] .dlg-body { background: #111A2E; border-color: var(--line); box-shadow: none; }
html[data-theme="dark"] input:not([type]), html[data-theme="dark"] input[type=text],
html[data-theme="dark"] input[type=search], html[data-theme="dark"] select { background: #0F172A; border-color: var(--line-strong); color: var(--ink); }
html[data-theme="dark"] input:disabled { background: #0B1324; color: var(--muted); }
html[data-theme="dark"] input::placeholder { color: #64748B; }
html[data-theme="dark"] .seg { background: #1E293B; }
html[data-theme="dark"] .seg button.on { background: #0F172A; color: #93C5FD; box-shadow: none; }
html[data-theme="dark"] .tile { border-color: var(--line); }
html[data-theme="dark"] .tile.accent b { color: #93C5FD; }
html[data-theme="dark"] .error { background: #2A1215; border-color: #7F1D1D; }
html[data-theme="dark"] .dialog { background: var(--bg); }
html[data-theme="dark"] .dlg-body .note, html[data-theme="dark"] .logo-box { background: #0F172A; border-color: var(--line-strong); }
html[data-theme="dark"] button.secondary:hover { background: #1E3A8A; }
html[data-theme="dark"] .canvas { background: #F8FAFC; border-color: #334155; }
html[data-theme="dark"] .switch input:not(:checked) + i { background: #475569; }

/* ohje */
.help-btn { margin-left: 4px; height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 13px 0 8px; border-radius: 9px; border: 1px solid #334155; background: var(--navy-soft); color: #fff; font-weight: 600; cursor: pointer; }
.help-btn b { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 13px; }
.help-btn:hover { background: #334155; }
.dialog.wide { width: min(1000px, 100%); height: calc(100vh - 40px); }
.help-wrap { display: flex; gap: 0; flex: 1; min-height: 0; margin: 16px 18px 0; }
.help-toc { width: 220px; flex: none; overflow-y: auto; padding: 4px 12px 4px 0; display: flex; flex-direction: column; gap: 2px; }
.help-toc a { color: var(--slate); text-decoration: none; font-size: 13.5px; font-weight: 600; padding: 7px 10px; border-radius: 7px; }
.help-toc a:hover { background: var(--accent-soft); color: var(--accent-dark); }
.help-body { margin: 0; flex: 1; }
.help-body h2 { color: var(--ink); font-size: 18px; margin: 18px 0 8px; padding-top: 4px; }
.help-body h2:first-child { margin-top: 10px; }
.help-body h3 { font-size: 15px; margin: 14px 0 6px; }
@media (max-width: 760px) { .help-toc { display: none; } .help-wrap { margin: 12px 10px 0; } }
@media (max-width: 640px) { .help-btn span { display: none; } .help-btn { padding: 0 8px; } }

/* pikanappi yläpalkissa */
.theme-btn { width: 38px; height: 38px; border-radius: 9px; border: 1px solid #334155; background: var(--navy-soft); color: #fff; font-size: 17px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.theme-btn:hover { background: #334155; }

/* ======================================================================
   TULOSTEET-VÄLILEHTI
   ====================================================================== */
.hist-top { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.hist-top input[type=search] { height: 40px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; font-size: 15px; width: min(360px, 100%); background: #fff; }
.hist-top .count { color: var(--muted); font-size: 13px; }
.hist-note { color: var(--muted); font-size: 12px; margin-left: auto; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table.hist { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 820px; }
table.hist th { text-align: left; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--accent-soft); }
table.hist td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.hist tr:last-child td { border-bottom: 0; }
table.hist td.num { font-variant-numeric: tabular-nums; }
table.hist th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.hist th.sortable:hover { color: var(--accent-dark); }
table.hist th.sortable::after { content: "↕"; opacity: .35; margin-left: 5px; font-size: 10px; }
table.hist th.sort-asc::after { content: "▲"; opacity: 1; color: var(--accent); }
table.hist th.sort-desc::after { content: "▼"; opacity: 1; color: var(--accent); }
table.hist td.acts { white-space: nowrap; text-align: right; }
table.hist td.acts button { height: 32px; padding: 0 11px; margin-left: 6px; font-size: 12.5px; }
button.danger { color: #B91C1C; }
html[data-theme="dark"] button.danger { color: #F87171; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.pn-cell { font-weight: 600; }
.lang-pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-dark); }

/* ======================================================================
   LISÄYKSET: materiaalit, raja-arvot, mittaukset, esikatselu
   ====================================================================== */
button.linkish { background: none; border: 0; padding: 0; color: var(--accent-dark); font-size: 12.5px; font-weight: 600; text-decoration: underline; cursor: pointer; align-self: flex-start; }
button.linkish:disabled { color: var(--muted); text-decoration: none; cursor: default; }

.callout { background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-ink); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.45; }
.limitwarn { margin-top: 12px; background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-ink); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.limitwarn b { display: block; margin-bottom: 4px; }
.limitwarn ul { margin: 0; padding-left: 18px; }
.limitwarn.hard { background: #FEF2F2; border-color: #FECACA; color: #991B1B; }
html[data-theme="dark"] .limitwarn.hard { background: #2A1215; border-color: #7F1D1D; color: #FCA5A5; }

.mat-add { display: grid; grid-template-columns: 1fr 140px auto; gap: 8px; margin-top: 12px; }
.mat-add input { height: 38px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 10px; background: #fff; }
html[data-theme="dark"] .mat-add input { background: #0F172A; color: var(--ink); }

table.hist th.chk, table.hist td.chk { width: 34px; text-align: center; padding-left: 8px; padding-right: 0; }
table.hist input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.meas-yes { color: #16A34A; font-weight: 700; }
html[data-theme="dark"] .meas-yes { color: #4ADE80; }
.meas-over { color: #B91C1C; font-weight: 700; cursor: help; }
html[data-theme="dark"] .meas-over { color: #F87171; }
.pair-help { align-self: end; margin: 0 0 6px; }

table.meas { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.meas th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.meas td { padding: 7px 10px; border-bottom: 1px solid var(--line); }
table.meas td:first-child { font-weight: 600; white-space: nowrap; }
table.meas td.calc { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.meas td.dev { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
table.meas input { height: 36px; width: 130px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 10px; background: #fff; }
html[data-theme="dark"] table.meas input { background: #0F172A; color: var(--ink); }
table.meas input.auto { font-style: italic; color: var(--accent); border-style: dashed; }
html[data-theme="dark"] table.meas input.auto { color: #93C5FD; }

.dialog.narrow { width: min(620px, 100%); }
/* Huomiot: pieni ikkuna ja keltainen painike rivin perässä */
.dialog.small { width: min(460px, 100%); }
.notes-body { background: var(--amber-bg); border-color: var(--amber-line); color: var(--ink); padding: 12px 16px; }
.notes-body p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; }
html[data-theme="dark"] .notes-body { background: var(--amber-bg); border-color: var(--amber-line); }
table.hist td.acts button.notes { background: var(--amber-bg); color: var(--amber-ink); border: 1px solid var(--amber-line); }
table.hist td.acts button.notes:hover { filter: brightness(0.97); }
table.hist td.acts button.notes.placeholder { visibility: hidden; }
.dlg-btns { gap: 10px; }

/* esikatselu */
.prev-head { display: flex; align-items: flex-start; gap: 14px; border-bottom: 2px solid var(--accent); padding-bottom: 10px; margin: 10px 0 14px; }
.prev-head img { max-width: 150px; max-height: 48px; }
.prev-title { font-size: 19px; font-weight: 700; color: var(--ink); }
.prev-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 14px; }
.prev-meta div { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.prev-meta span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.prev-meta b { font-size: 13.5px; color: var(--ink); }
.prev-sec { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); margin: 16px 0 6px; }
.prev-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.prev-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.prev-table td:first-child { color: var(--muted); }
.prev-table td:nth-child(2) { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.prev-table td:nth-child(n+3) { text-align: right; font-variant-numeric: tabular-nums; }
.prev-diagram { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-top: 8px; }
.prev-diagram svg { width: 100%; height: auto; max-height: 260px; }
.prev-file { font-family: Consolas, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }

@media (max-width: 640px) {
  .mat-add { grid-template-columns: 1fr; }
  table.meas input { width: 100%; }
}

/* Tarra-asetukset */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }
#lbCustom[hidden] { display: none; }

/* Puhelin: alapalkissa yksi rivi (Tallenna, Tulosta, ⋯). ⋯ avaa kielen, Tyhjennä, Esikatselu ja Tulosta tarra.
   Varoitus näytetään sivun lopussa (.warn-mobile), ei kiinteässä palkissa. */
.bar-more, .warn-mobile { display: none; }
@media (max-width: 640px) {
  .seg-dark button { width: 42px; }
  .warn-mobile { display: flex; flex: none; margin: 4px 0 12px; }
  #calcBar { padding: 8px 0 10px; gap: 8px; }
  #calcBar > .warn { display: none; }
  #calcBar .bar-right { display: grid; grid-template-columns: 1fr 1fr 48px; gap: 8px; }
  #calcBar .bar-right > * { order: 2; }
  #calcBar #saveJob, #calcBar #createReport, #calcBar .bar-more { order: 1; }
  #calcBar .bar-more { display: block; width: 48px; padding: 0; font-size: 20px; line-height: 1; }
  #calcBar .bar-right > .switch, #calcBar #clearBtn, #calcBar #previewBtn, #calcBar #printLabel { display: none; }
  #calcBar.more-open .bar-right > .switch { display: flex; grid-column: 1 / -1; justify-content: center; }
  #calcBar.more-open #clearBtn, #calcBar.more-open #previewBtn { display: block; }
  #calcBar.more-open #printLabel { display: block; grid-column: 1 / -1; }
  #calcBar.more-open .bar-more { background: var(--accent-soft); }
  /* Asetukset: Tallenna ja ⋯; tilaviesti näkyy vain, kun siinä on tekstiä */
  #setBar { display: grid; grid-template-columns: 1fr 48px; gap: 8px; padding: 8px 0 10px; }
  #setBar > * { order: 2; grid-column: 1 / -1; }
  #setBar #sSave { order: 1; grid-column: 1; }
  #setBar .bar-more { display: block; order: 1; grid-column: 2; width: 48px; padding: 0; font-size: 20px; line-height: 1; }
  #setBar #sReset, #setBar #sApply, #setBar .note-small { display: none; }
  #setBar .status:empty { display: none; }
  #setBar.more-open #sReset, #setBar.more-open #sApply, #setBar.more-open .note-small { display: block; }
  #setBar.more-open .bar-more { background: var(--accent-soft); }
}

/* ---------- tili (vain kun tilit ovat käytössä, ks. js/account.js) ---------- */
a.acct-badge { margin-left: 8px; text-decoration: none; color: #BFDBFE; }
a.acct-badge:hover { border-color: #60A5FA; }
.acct-block { border: 0; padding: 0; background: transparent; max-width: 440px; width: calc(100% - 32px); }
.acct-block::backdrop { background: rgba(15, 23, 42, .72); }
.acct-box { background: #fff; color: var(--ink); border-radius: var(--radius); max-width: 440px; padding: 22px 24px; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.acct-box h2 { margin: 0 0 8px; font-size: 18px; }
.acct-box p { margin: 0 0 16px; color: var(--slate); line-height: 1.5; }
.acct-btn { display: inline-flex; align-items: center; height: 44px; padding: 0 22px; border-radius: 9px; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; }
html[data-theme="dark"] .acct-box { background: #1E293B; color: #E2E8F0; }
html[data-theme="dark"] .acct-box p { color: #CBD5E1; }
