/* BM Office – ulkoasu. Biomitan värit kuten BM Maastossa. */

:root {
  --brand: #285836;
  --brand-dark: #1c3f27;
  --brand-soft: #e6efe8;
  --blue: #0e427e;
  --red: #b23a2e;
  --bg: #eef1ee;
  --surface: #ffffff;
  --text: #17201a;
  --muted: #5d685f;
  --line: #d5dbd6;
  --sel: rgba(14, 66, 126, .14);
  --shadow: 0 1px 6px rgba(0, 0, 0, .18);
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #2c6a40;
    --brand-dark: #23573a;
    --brand-soft: #1f3326;
    --blue: #7fb0ea;
    --bg: #111613;
    --surface: #1b221d;
    --text: #e9efea;
    --muted: #9eaaa1;
    --line: #2f3a32;
    --sel: rgba(127, 176, 234, .22);
    --shadow: 0 1px 8px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text);
}
button, select, input, textarea { font: inherit; color: inherit; }
button, select {
  min-height: 32px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--brand); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-dark); }
button.on { background: var(--brand-soft); border-color: var(--brand); font-weight: 600; }
input[type="search"], input:not([type]), .pageno {
  min-height: 32px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
.muted { color: var(--muted); }
.grow { flex: 1; }
.right { margin-left: auto; }

/* Yläpalkki */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 6px 16px;
  background: var(--brand); color: #fff; flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; font-size: 16px; }
.brand img { border-radius: 6px; background: #fff; }
.apps { display: flex; gap: 4px; }
.apps a { color: #fff; text-decoration: none; padding: 6px 12px; border-radius: 6px; opacity: .85; }
.apps a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.apps a.on { background: rgba(255,255,255,.2); opacity: 1; font-weight: 600; }
.docname { margin-left: auto; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* Koti */
.home { max-width: 960px; margin: 0 auto; padding: 32px 16px; overflow: auto; width: 100%; }
.home h1 { margin: 0 0 8px; color: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .home h1 { color: #6cc189; } }
.lead { font-size: 16px; color: var(--muted); max-width: 640px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 24px 0 8px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  padding: 16px; min-height: 96px; border-radius: 10px; white-space: normal; box-shadow: var(--shadow);
}
.tile b { font-size: 16px; }
.tile span { color: var(--muted); }
.hint { color: var(--muted); }
.recent { list-style: none; padding: 0; margin: 0; }
.recent li { display: flex; gap: 12px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.recent button { border: none; background: none; padding: 0; color: var(--blue); text-decoration: underline; min-height: 0; }
.recent .kind { font-size: 12px; padding: 2px 6px; border-radius: 4px; background: var(--brand-soft); }
body.dragging::after {
  content: "Pudota tiedosto avataksesi"; position: fixed; inset: 12px; border: 3px dashed var(--brand);
  border-radius: 16px; background: rgba(40,88,54,.12); display: grid; place-items: center;
  font-size: 22px; font-weight: 700; color: var(--brand); pointer-events: none; z-index: 100;
}

/* Työkalurivit */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 6px 12px; align-items: center;
  background: var(--surface); border-bottom: 1px solid var(--line); flex: none;
}
.toolbar .group { display: flex; gap: 4px; align-items: center; }
.toolbar .group.grow { flex: 1; min-width: 180px; }
.toolbar .group.grow input { flex: 1; min-width: 0; }
.mini { display: inline-flex; align-items: center; }
.mini input[type="color"] { width: 34px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.pageno { width: 52px; text-align: center; }
.statusbar {
  display: flex; gap: 12px; padding: 4px 12px; font-size: 12px; color: var(--muted);
  background: var(--surface); border-top: 1px solid var(--line); flex: none;
}

/* PDF */
.pdf-body { flex: 1; display: flex; min-height: 0; }
.thumbs { width: 190px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); }
.thumbbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); }
.thumbbar button { min-height: 28px; padding: 2px 6px; font-size: 12px; }
.thumblist { list-style: none; margin: 0; padding: 8px; overflow: auto; flex: 1; }
.thumblist li {
  position: relative; margin: 0 auto 10px; padding: 4px; border: 2px solid transparent; border-radius: 6px;
  cursor: pointer; text-align: center; font-size: 12px; color: var(--muted); width: fit-content;
}
.thumblist li.sel { border-color: var(--blue); background: var(--sel); }
.thumblist li.cur .num { color: var(--text); font-weight: 700; }
.thumblist li.dropbefore { box-shadow: 0 -4px 0 var(--brand); }
.thumblist li.dropafter { box-shadow: 0 4px 0 var(--brand); }
.thumblist canvas { display: block; background: #fff; box-shadow: var(--shadow); max-width: 150px; }
.pdf-scroll { flex: 1; overflow: auto; position: relative; outline: none; background: var(--bg); }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px; min-width: fit-content; }
.page { position: relative; background: #fff; box-shadow: var(--shadow); flex: none; }
.page canvas.render { position: absolute; inset: 0; width: 100%; height: 100%; }
.page .textLayer { z-index: 1; }
.page .anns { position: absolute; inset: 0; z-index: 2; }
.page .hits { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.page .hits div { position: absolute; background: rgba(255, 170, 0, .35); outline: 1px solid rgba(200, 120, 0, .7); }
.page .hits div.cur { background: rgba(255, 90, 0, .45); }
.pdf-pages[data-tool="select"] .anns { pointer-events: none; }
.pdf-pages[data-tool="select"] .ann { pointer-events: auto; }
.pdf-pages:not([data-tool="select"]) .anns { cursor: crosshair; }
.pdf-pages[data-tool="text"] .anns { cursor: text; }
.ann { position: absolute; transform-origin: 0 100%; }
.ann.sel { outline: 2px dashed var(--blue); outline-offset: 2px; }
.pdf-pages[data-tool="select"] .ann { cursor: move; }
.ann.text { white-space: pre; line-height: 1.2; font-family: Helvetica, Arial, sans-serif; padding: 0; min-width: 4px; }
.ann.text[contenteditable="true"] { outline: 1px solid var(--blue); background: rgba(255,255,255,.6); cursor: text; }
.ann.img img { width: 100%; height: 100%; display: block; pointer-events: none; }
.ann .handle {
  position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--blue); border: 2px solid #fff; cursor: nwse-resize; display: none;
}
.ann.sel .handle { display: block; }
.anns svg.ink { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.anns svg.ink path { pointer-events: stroke; }
.pdf-pages[data-tool="select"] svg.ink path { cursor: move; }
.anns svg.ink path.sel { stroke-dasharray: 6 3; }
.drawbox { position: absolute; border: 1px dashed var(--blue); pointer-events: none; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center; color: var(--muted); }
.side { width: 280px; flex: none; overflow: auto; padding: 12px; background: var(--surface); border-left: 1px solid var(--line); }
.side h3 { margin: 0 0 12px; font-size: 15px; }
.side label.field { display: block; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.side label.field input, .side label.field select, .side label.field textarea {
  display: block; width: 100%; margin-top: 2px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 14px;
}
.check { display: flex; gap: 6px; align-items: center; }

/* Asiakirja */
.doc-scroll { flex: 1; overflow: auto; padding: 24px 16px 64px; }
.paper {
  width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto; padding: 25mm 20mm 25mm 25mm;
  background: #fff; color: #111; box-shadow: var(--shadow); outline: none;
  font: 11pt/1.5 Poppins, Calibri, Arial, sans-serif;
}
.paper h1, .paper h2 { color: #285836; font-weight: 600; line-height: 1.25; }
.paper h1 { font-size: 18pt; margin: 18pt 0 8pt; }
.paper h2 { font-size: 14pt; margin: 14pt 0 6pt; }
.paper h3 { font-size: 12pt; margin: 12pt 0 4pt; color: #0e427e; font-weight: 600; }
.paper p { margin: 0 0 8pt; }
.paper blockquote { margin: 8pt 0; padding-left: 12pt; border-left: 3px solid #285836; color: #444; }
.paper table { border-collapse: collapse; width: 100%; margin: 8pt 0; }
.paper td, .paper th { border: 1px solid #999; padding: 4px 6px; vertical-align: top; min-width: 30px; }
.paper th { background: #0e427e; color: #fff; text-align: left; }
.paper img { max-width: 100%; height: auto; }
.paper a { color: #0e427e; }
.paper hr.pagebreak { border: none; border-top: 1px dashed #aaa; margin: 16pt 0; break-after: page; page-break-after: always; }
.paper hr.pagebreak::after { content: "Sivunvaihto"; }

/* Taulukko */
.formulabar { display: flex; gap: 6px; padding: 4px 8px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.formulabar .addr { min-width: 72px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; text-align: center; font-variant-numeric: tabular-nums; }
.formulabar input { flex: 1; font-family: ui-monospace, Consolas, monospace; }
.grid-wrap { flex: 1; overflow: auto; position: relative; outline: none; background: var(--surface); }
.grid-sizer { position: absolute; top: 0; left: 0; width: 1px; height: 1px; pointer-events: none; }
.grid { position: sticky; top: 0; left: 0; width: 0; height: 0; overflow: visible; }
.grid .c {
  position: absolute; height: 24px; padding: 0 4px; line-height: 23px; overflow: hidden; white-space: nowrap;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 13px;
  background: var(--surface); text-overflow: clip;
}
.grid .c.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .c.err { color: var(--red); }
.grid .h { background: var(--bg); color: var(--muted); text-align: center; font-size: 12px; z-index: 2; user-select: none; }
.grid .h.on { background: var(--brand-soft); color: var(--text); font-weight: 600; }
.grid .corner { z-index: 3; }
.grid .selbox { position: absolute; border: 2px solid var(--blue); background: var(--sel); pointer-events: none; z-index: 1; }
.cell-editor {
  position: absolute; z-index: 5; resize: none; border: 2px solid var(--blue); padding: 1px 3px; margin: 0;
  font: 13px/20px system-ui, sans-serif; background: var(--surface); color: var(--text); outline: none; overflow: hidden;
}
.sheettabs { display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: var(--surface); border-top: 1px solid var(--line); flex: none; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { border-radius: 0 0 6px 6px; border-top: none; min-height: 28px; }
.tabs button.on { background: var(--brand-soft); border-color: var(--brand); font-weight: 600; }

/* Ikkunat ja ilmoitukset */
.dialog { border: none; border-radius: 12px; padding: 20px; box-shadow: var(--shadow); background: var(--surface); color: var(--text); max-width: calc(100vw - 32px); }
.dialog h3 { margin: 0 0 4px; }
.dialog canvas { display: block; width: 100%; max-width: 600px; aspect-ratio: 3 / 1; border: 1px solid var(--line); border-radius: 8px; background: #fff; touch-action: none; margin: 12px 0; }
.dialog .row { display: flex; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 200;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast.err { background: var(--red); }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .docname { display: none; }
  .thumbs { display: none; }
  .side { position: absolute; right: 0; top: 0; bottom: 0; z-index: 10; }
  .paper { padding: 12mm; min-height: 0; }
}

@media print {
  body > *:not(#view-asiakirja) { display: none !important; }
  #view-asiakirja > *:not(.doc-scroll) { display: none !important; }
  .doc-scroll { padding: 0; overflow: visible; }
  .paper { box-shadow: none; width: auto; min-height: 0; padding: 0; margin: 0; }
  .paper hr.pagebreak { border: none; margin: 0; }
  .paper hr.pagebreak::after { content: none; }
  @page { size: A4; margin: 25mm 20mm 25mm 25mm; }
}
