/* ==========================================================================
   Wedger — components.css
   Shared widgets: buttons, form fields, cards, banners, switches, sliders,
   popup menus, dialogs, toasts, report output (.rv-*). Used by the shell and
   by every special file.
   ========================================================================== */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .45rem .95rem; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  font-family: var(--font-ui); font-weight: 500; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--hover); border-color: var(--text-faint); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--danger { color: var(--danger); }
.btn--danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
.btn--danger-solid { background: var(--danger-fill); border-color: var(--danger-fill); color: var(--danger-fill-contrast); }
.btn--danger-solid:hover:not(:disabled) { background: var(--danger-fill-hover); border-color: var(--danger-fill-hover); filter: none; }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--small { padding: .25rem .65rem; font-size: .9rem; }
.btn.is-busy { pointer-events: none; opacity: .75; }

.link-btn { color: var(--text); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--border-strong); }
.link-btn:hover { text-decoration-color: currentColor; }

/* segmented control */
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--selected); border-radius: var(--radius); }
.seg__btn { padding: .25rem .9rem; border-radius: calc(var(--radius) - 2px); color: var(--text-muted); font-weight: 500; }
.seg__btn:hover { color: var(--text); }
.seg__btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- form fields ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field__label, legend.field__label { font-family: var(--font-read); font-weight: 600; font-size: .88rem; }
.field__hint { font-family: var(--font-read); color: var(--text-muted); font-size: .85rem; }
.field__error { font-family: var(--font-read); color: var(--danger); font-size: .9rem; white-space: pre-wrap; }
.input, .select, .textarea {
  width: 100%; padding: .45rem .65rem; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-family: var(--font-ui);
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-soft); }
.textarea { font-family: var(--font-raw); font-size: .92rem; min-height: 6rem; resize: vertical; }
.check { display: flex; align-items: center; gap: .55rem; cursor: pointer; font-family: var(--font-read); }
.check input { accent-color: var(--text); margin: 0; }
fieldset { border: 0; min-width: 0; }
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.form-row > .field { flex: 1 1 10rem; }

/* ---------- cards, banners, pills ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.card + .card { margin-top: .9rem; }
.card__title { font-family: var(--font-read); font-weight: 650; margin-bottom: .6rem; }

.banner {
  display: flex; flex-direction: column; gap: .25rem; align-items: stretch;
  padding: .65rem .85rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-family: var(--font-read);
}
.banner--error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.banner--warn  { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner--ok    { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.banner--info  { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.banner__pre { margin: .2rem 0 0; white-space: pre-wrap; font-family: var(--font-raw); font-size: .88rem; color: inherit; overflow-wrap: anywhere; }

.pill { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--selected); color: var(--text-muted); white-space: nowrap; }
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--error { background: var(--danger-soft); color: var(--danger); }

/* removable filter chip (journal + reports output) */
.jv-chip { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .35rem .15rem .65rem; border-radius: 999px; background: var(--selected); font-size: .85rem; }
.jv-chip button { display: inline-flex; width: 1.2rem; height: 1.2rem; align-items: center; justify-content: center; border-radius: 50%; color: var(--text-muted); }
.jv-chip button:hover { background: var(--border-strong); color: var(--text); }
.jv-chip button .icon { width: .75em; height: .75em; }

/* ---------- spinner ---------- */
.spinner {
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--text-muted);
  animation: spin .8s linear infinite;
}
.spinner--inline { width: 1em; height: 1em; border-width: 2px; display: inline-block; vertical-align: -.15em; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- switch ---------- */
.switch { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  position: relative; width: 2.4rem; height: 1.3rem; flex: none;
  border-radius: 999px; background: var(--border-strong); transition: background .15s;
}
.switch__track::after {
  content: ""; position: absolute; top: .15rem; left: .15rem; width: 1rem; height: 1rem;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s;
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(1.1rem); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- range slider ---------- */
input[type="range"] { -webkit-appearance: none; appearance: none; height: 18px; background: transparent; cursor: pointer; margin: 0; }
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: var(--border-strong); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 999px; background: var(--border-strong); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--surface); border: 2px solid var(--text); box-shadow: var(--shadow-sm); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--text); box-shadow: var(--shadow-sm); }
input[type="range"]:active::-webkit-slider-thumb { background: var(--text); }
input[type="range"]:active::-moz-range-thumb { background: var(--text); }

/* ---------- popup / context menu ---------- */
.popup-menu {
  position: fixed; min-width: 11rem; padding: .3rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.popup-menu__item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; width: 100%; padding: .4rem .7rem; text-align: left; border-radius: 5px; }
.popup-menu__item:hover:not(:disabled), .popup-menu__item:focus-visible { background: var(--hover); outline: none; }
.popup-menu__item--danger { color: var(--danger); }
.popup-menu__item--danger:hover:not(:disabled) { background: var(--danger-soft); }
.popup-menu__sep { height: 1px; margin: .3rem 0; background: var(--border); }

/* ---------- keyboard shortcut hints: muted text on the right of a row (VS Code / Linear), never a keycap ---------- */
.kbd {
  margin-left: auto; padding-left: 1.25rem;
  font-size: .75em; font-weight: 500; color: var(--text-faint);
  font-variant-numeric: tabular-nums; letter-spacing: .01em; white-space: nowrap;
}
.kbd[hidden] { display: none; }
/* Phones have no keyboard: hide the hints, keep every button. */
@media (hover: none) and (pointer: coarse) {
  .kbd { display: none !important; }
}

/* ---------- CodeMirror (colours come from the theme in codemirror/entry.js, which reads the tokens) ---------- */
.cm-textarea-proxy { display: none; }
.cm-wrapper { display: flex; flex: 1; min-height: 0; min-width: 0; height: 100%; }
.cm-wrapper > .cm-editor { flex: 1; min-width: 0; height: 100%; }
.cm-editor { height: 100%; }
.cm-scroller { overflow: auto; height: 100%; }
.cm-wrapper.cm-disabled { opacity: .6; }

/* ---------- dialogs ---------- */
dialog.dialog {
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  width: min(32rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem);
  margin: auto; overflow: auto;
}
dialog.dialog--wide { width: min(40rem, calc(100vw - 2rem)); }
dialog.dialog::backdrop { background: rgba(10, 12, 18, .5); }
.dialog__body { padding: 1.25rem 1.4rem .5rem; display: flex; flex-direction: column; gap: .8rem; }
.dialog__title { font-size: 1.15rem; font-weight: 650; }
.dialog__message { font-family: var(--font-read); color: var(--text-muted); }
.dialog__actions { display: flex; justify-content: flex-end; gap: .5rem; padding: .9rem 1.4rem 1.2rem; }

/* ---------- toasts ---------- */
.toast-stack { position: fixed; right: 1rem; bottom: 2.4rem; display: flex; flex-direction: column; gap: .5rem; align-items: flex-end; }
.toast {
  max-width: 24rem; padding: .6rem .9rem; border-radius: var(--radius-sm);
  background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  font-family: var(--font-read);
}
.toast--ok { background: var(--text); }
.toast--error { background: var(--danger); color: #fff; }
html.dark-mode .toast--error { color: #1a0b0a; }

/* ==========================================================================
   Report output (shared by Reports output and anything else that shows a report)
   ========================================================================== */
.rv-empty { font-family: var(--font-read); color: var(--text-muted); text-align: center; padding: 1.2rem 0; }
.rv-text { margin: 0; padding: .7rem .85rem; max-height: 32rem; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); font-family: var(--font-raw); font-size: .9rem; line-height: 1.5; font-variant-numeric: tabular-nums; white-space: pre; }

.rv-table-wrap { overflow: auto; max-height: 34rem; border: 1px solid var(--border); border-radius: var(--radius); }
.rv-table { border-collapse: separate; border-spacing: 0; width: 100%; font-family: var(--font-read); font-size: .92rem; }
.rv-table th { position: sticky; top: 0; z-index: 1; padding: .45rem .75rem; text-align: left; background: var(--surface-2); border-bottom: 1px solid var(--border-strong); font-weight: 600; white-space: nowrap; }
.rv-table td { padding: .4rem .75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rv-table tbody tr:last-child td { border-bottom: 0; }
.rv-table tbody tr:hover td { background: var(--hover); }
.rv-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.rv-table .is-neg { color: var(--neg); }

.rv-table tfoot td { position: sticky; bottom: 0; padding: .45rem .75rem; background: var(--surface-2); border-top: 1px solid var(--border-strong); font-weight: 650; }
.rv-block { display: flex; flex-direction: column; gap: .6rem; }
.rv-notes { margin: 0; padding-left: 1.1rem; font-family: var(--font-read); font-size: .88rem; color: var(--text-muted); }
.rv-notes li + li { margin-top: .15rem; }

.rv-tree { font-family: var(--font-read); }
.rv-tree__section + .rv-tree__section { margin-top: 1.1rem; }
.rv-tree__title { font-size: .8rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: .3rem; }
.rv-tree__row { display: flex; align-items: center; gap: .5rem; padding: .22rem .5rem .22rem calc(.5rem + var(--depth, 0) * 1.3rem); border-radius: 5px; list-style: none; cursor: default; }
.rv-tree__branch > summary { cursor: pointer; }
.rv-tree__branch > summary::-webkit-details-marker { display: none; }
.rv-tree__row:hover { background: var(--hover); }
.rv-tree__caret { flex: none; width: .5rem; height: .5rem; margin-right: .15rem; border-right: 2px solid var(--text-faint); border-bottom: 2px solid var(--text-faint); transform: rotate(-45deg); transition: transform .12s; }
.rv-tree__branch[open] > summary .rv-tree__caret { transform: rotate(45deg); }
.rv-tree__leaf { padding-left: calc(.5rem + var(--depth, 0) * 1.3rem + 1.05rem); }
.rv-tree__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-tree__amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.rv-tree__amount.is-neg { color: var(--neg); }
.rv-tree__total { margin-top: .2rem; border-top: 1px solid var(--border-strong); border-radius: 0; font-weight: 650; }
.rv-tree__grand { border-top-width: 2px; }


/* ---- Reveal: the record Activity just took you to (see js/shell/reveal.js) ---- */
.is-revealed {
  outline: 2px solid var(--text);
  outline-offset: -2px;
  background: var(--selected);
  animation: reveal-flash 3.2s ease-out;
}
@keyframes reveal-flash {
  0%, 35% { background: var(--accent-soft); }
  100% { background: var(--selected); }
}
@media (prefers-reduced-motion: reduce) { .is-revealed { animation: none; } }
