/* =====================================================================
   Style options (Style › Options, js/theme.js). Each block is switched on by its key in
   <html data-fx="…">, so turning an option off restores the style exactly. Loaded after
   the theme sheets; works in every style unless the block says otherwise.
   ===================================================================== */

/* ---- dlganim: dialogs, menus and their backdrop ease in (no JS: @starting-style) ---- */

@media (prefers-reduced-motion: no-preference) {
  html[data-fx~="dlganim"] .dlg { transition: opacity .14s ease-out, scale .14s ease-out; }
  html[data-fx~="dlganim"] .dlg-overlay { transition: background-color .14s ease-out; }
  html[data-fx~="dlganim"] .cm { transition: opacity .1s ease-out, translate .1s ease-out; }
  @starting-style {
    html[data-fx~="dlganim"] .dlg { opacity: 0; scale: .96; }
    html[data-fx~="dlganim"] .dlg-overlay { background-color: transparent; }
    html[data-fx~="dlganim"] .cm { opacity: 0; translate: 0 -4px; }
  }
}

/* ---- rowstripe: a state colour on the row's left edge, still there when the row is selected ---- */

html[data-fx~="rowstripe"] .dg-row:is(.row-ok, .row-warn, .row-bad, .row-info, .grp-red, .grp-approved, .grp-pre)::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; z-index: 3;
  background: var(--fx-stripe); pointer-events: none;
}
html[data-fx~="rowstripe"] .dg-row.row-ok { --fx-stripe: var(--ok-strong); }
html[data-fx~="rowstripe"] .dg-row.row-warn { --fx-stripe: var(--warn-strong); }
html[data-fx~="rowstripe"] .dg-row.row-bad { --fx-stripe: var(--danger); }
html[data-fx~="rowstripe"] .dg-row.row-info { --fx-stripe: var(--accent); }
html[data-fx~="rowstripe"] .dg-row.grp-red { --fx-stripe: #b00020; }
html[data-fx~="rowstripe"] .dg-row.grp-approved { --fx-stripe: #2e7d32; }
html[data-fx~="rowstripe"] .dg-row.grp-pre { --fx-stripe: #0e7c76; }

/* ---- tabnums: every digit the same width, so amounts line up ---- */

html[data-fx~="tabnums"] :is(.dg-cell, .dg-fcell, .dg-footer, .statusbar, .wf-statusstrip, .inv-rc-table td, .kv) {
  font-variant-numeric: tabular-nums;
}

/* ---- focusring: a clear ring on whatever the keyboard is on ---- */

html[data-fx~="focusring"] :is(button, a, [tabindex]:not(.dg-root):not(.dg), .wf-tab, .tab):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
html[data-fx~="focusring"] :is(input, select, textarea):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 0;
}
html[data-fx~="focusring"] .dg-root:focus-visible, html[data-fx~="focusring"] .dg:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -2px;
}

/* ---- autogrow: free-standing text boxes grow with what is typed (not the fixed WinForms layouts) ---- */

html[data-fx~="autogrow"] :is(.dlg-body, .form-input, .misc-chat-bottom) textarea:not(.wf):not(.notes-editor) {
  field-sizing: content; min-block-size: 3lh; max-block-size: 50vh;
}

/* ---- themefx: the new style spreads in a circle from the click (js/theme.js starts it) ---- */

html[data-fx~="themefx"]::view-transition-old(root),
html[data-fx~="themefx"]::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html[data-fx~="themefx"]::view-transition-new(root) { animation: fx-reveal .5s cubic-bezier(.4, 0, .2, 1); }
@keyframes fx-reveal {
  from { clip-path: circle(0 at var(--fx-x, 100%) var(--fx-y, 0)); }
  to   { clip-path: circle(150vmax at var(--fx-x, 100%) var(--fx-y, 0)); }
}

/* ---- print: only the work goes on paper — no menus, tool or status bars; an open dialog prints alone ---- */

@media print {
  html[data-fx~="print"] :is(.menubar, .toolbar, .statusbar, .tabstrip, .splitter-v, .splitter-h,
    .wf-MenuStrip, .wf-toolstrip, .wf-statusstrip, .wf-tabheader, .cm, .toast, .dlg-x, .dlg-buttons) { display: none !important; }
  html[data-fx~="print"] body { background: #fff !important; color: #000; }
  html[data-fx~="print"] * { box-shadow: none !important; rotate: none !important; }
  html[data-fx~="print"] .dg-row, html[data-fx~="print"] .dg-cell { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  html[data-fx~="print"] body:has(> .dlg-overlay) > :not(.dlg-overlay) { display: none !important; }
  html[data-fx~="print"] .dlg-overlay { position: static; background: none; display: block; }
  html[data-fx~="print"] .dlg { max-width: none; max-height: none; border: 0; }
}

/* ---- Original style: accent colour. light-dark() gives each accent a light and a dark tone;
        selection and hover are mixed from it and the panel, so they follow the mode too. ---- */

:root[data-accent]:not([data-theme="papercut"]):not([data-theme="windows"]) {
  --accent: var(--fx-accent);
  --sel-strong: var(--fx-accent);
  --sel: color-mix(in oklab, var(--fx-accent) 30%, var(--panel));
  --hover: color-mix(in oklab, var(--fx-accent) 14%, var(--panel));
  --info: color-mix(in oklab, var(--fx-accent) 12%, var(--panel));
  accent-color: var(--fx-accent);
}
:root[data-accent="green"]  { --fx-accent: light-dark(#1f7a3a, #6fcf8e); }
:root[data-accent="teal"]   { --fx-accent: light-dark(#0e7c76, #5fd0c8); }
:root[data-accent="purple"] { --fx-accent: light-dark(#6a3fb5, #b49cff); }
:root[data-accent="orange"] { --fx-accent: light-dark(#b35300, #ffa260); }
:root[data-accent="rose"]   { --fx-accent: light-dark(#b0264f, #ff8fb1); }

/* =====================================================================
   Paper cut-out extras (only in that style)
   ===================================================================== */

/* ---- grain: a faint paper fibre on the paper surfaces ---- */

html[data-theme="papercut"][data-fx~="grain"] :is(.dlg, .cm, .hpanel, .statusbar, .login-box, .wf-tabpage) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .30 0 0 0 0 .2 .16 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- tape: a strip of masking tape holds each dialog and toast down ---- */

html[data-theme="papercut"][data-fx~="tape"] :is(.dlg, .toast)::before {
  content: ''; position: absolute; top: -10px; left: 50%; width: 84px; height: 20px; translate: -50% 0; rotate: -3deg;
  background: var(--tape); box-shadow: 0 1px 2px rgba(0, 0, 0, .18); pointer-events: none; z-index: 2;
}
html[data-theme="papercut"][data-fx~="tape"] .toast::before { width: 46px; height: 14px; top: -8px; rotate: 4deg; }

/* ---- torn: the dialog's title banner has a ragged, torn bottom edge ---- */

html[data-theme="papercut"][data-fx~="torn"] .dlg-title {
  padding-bottom: 8px; border-radius: 3px 3px 0 0;
  mask:
    linear-gradient(#000 0 0) top / 100% calc(100% - 5px) no-repeat,
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='6' preserveAspectRatio='none'%3E%3Cpath d='M0 0H60V3L57 5 53 2 49 6 46 3 41 5 38 1 34 4 30 2 27 6 22 3 19 5 15 1 12 4 8 2 5 6 2 3 0 4Z'/%3E%3C/svg%3E") bottom / 60px 6px repeat-x;
}
