/* Dialogs and form controls. */

/* Scrollbar inset: the dialog is its own scroller, and browsers draw its
   scrollbar as a straight strip along the padding box — with a plain 1px
   border it ran through the rounded corners. A transparent border (painted
   by the background, origin border-box) moves the padding box inward so the
   whole track sits inside the curve; the visible edge is a 1px shadow ring.
   Padding gives back the inset, so content sits exactly where it did.
   Rule: (radius - gut-x)^2 + (radius - gut-y)^2 < radius^2, with margin. */
dialog {
  --dlg-gut-x: 8px;
  --dlg-gut-y: 12px;
  background: var(--surface-2);
  background-origin: border-box;
  color: var(--text);
  border-style: solid;
  border-color: transparent;
  border-width: var(--dlg-gut-y) var(--dlg-gut-x);
  border-radius: 24px;
  padding: calc(1.5rem - var(--dlg-gut-y)) calc(1.5rem - var(--dlg-gut-x));
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-pop);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.66); backdrop-filter: blur(10px) saturate(0.6); -webkit-backdrop-filter: blur(10px) saturate(0.6); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.dialog-head h2 { margin: 0; font-family: var(--font-display); font-size: 1.2rem; font-weight: 500; letter-spacing: -0.02em; }
.dialog-head [data-close] { flex-shrink: 0; width: 2.4rem; min-width: 2.4rem; min-height: 2.4rem; padding: 0; border-radius: 999px; background: var(--surface-3); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.65rem; margin-top: 1.4rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.dialog-actions button { min-width: 6.5rem; }
#confirm-message { margin: 0.4rem 0 0; line-height: 1.65; color: var(--muted); }

/* ————— Forms ————— */
label { display: block; margin: 1rem 0 0.75rem; color: var(--muted); font-size: 0.72rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.1em; }
input, select, textarea {
  width: 100%;
  padding: 0.4rem 0.75rem;
  min-height: 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.2s ease, background 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.08);
  outline: none;
}
/* Resize downwards only: dragging sideways would push past the dialog edge. */
textarea { min-height: 4rem; resize: vertical; max-width: 100%; }
/* Scrollbar inset (same technique as dialog above): a transparent border
   keeps an overflowing note's scrollbar inside the rounded corners; padding
   gives the inset back. At rest the edge line is an inset outline (exactly
   where the 1px border was, so textareas line up with inputs); focused, the
   field rule above drops the outline, so the line becomes a ring under the
   glow. */
textarea {
  --ta-gut: 4px;
  border-color: transparent;
  border-width: var(--ta-gut);
  padding: calc(0.4rem + 1px - var(--ta-gut)) calc(0.75rem + 1px - var(--ta-gut));
  outline: 1px solid var(--border-strong);
  outline-offset: -1px;
}
textarea:focus { border-color: transparent; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55), 0 0 0 4px rgba(255, 255, 255, 0.08); }
input::placeholder { color: var(--muted-2); }
/* Missing mandatory field: red edge, kept visible while focused. */
input.fld-invalid, select.fld-invalid, textarea.fld-invalid,
input.fld-invalid:focus, select.fld-invalid:focus, textarea.fld-invalid:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-bg);
}
textarea.fld-invalid, textarea.fld-invalid:focus { border-color: transparent; outline-color: var(--red); }
textarea.fld-invalid:focus { box-shadow: 0 0 0 1px var(--red), 0 0 0 3px var(--red-bg); }
/* Number fields never show the browser's up/down stepper: amounts are typed. */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a0a0a5' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.3rem;
  cursor: pointer;
}
/* Date-time fields wear the select chevron instead of the browser's own
   arrow/calendar icon (Android drew a small off-centre caret). The native
   picker button stays clickable, invisible, over the chevron; the value
   starts at the same inset as every other field. */
input[type="datetime-local"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a0a0a5' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.3rem;
  text-align: left;
  cursor: pointer;
}
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 2.3rem;
  height: auto;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
input[type="datetime-local"]::-webkit-date-and-time-value { margin: 0; text-align: left; }
/* Firefox draws its own calendar button, which cannot be hidden and opens
   the picker itself: no second, dead chevron next to it. */
@supports (-moz-appearance: none) {
  input[type="datetime-local"] { background-image: none; padding-right: 0.75rem; }
}
input[type="datetime-local"]::-webkit-datetime-edit,
input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper { padding: 0; line-height: inherit; }
#trade-form, #account-dialog-body, #ledger-dialog-body, #group-dialog-body, #settings-dialog-body { display: grid; gap: 0.15rem; padding-bottom: 0.5rem; }
/* Settings body is a flex item of the fixed-height dialog AND a grid parent
   of .set-layout: without min-height:0 + a shrinkable row, tall tabs (Sync)
   force the layout past the dialog box and the panel scrollbar never appears. */
#settings-dialog-body { min-height: 0; grid-template-rows: minmax(0, 1fr); }
#settings-dialog-body > .set-layout { min-height: 0; }
#trade-form label:first-child { margin-top: 0.25rem; }
#trade-form button.primary, #account-dialog-body button.primary, #ledger-dialog-body button.primary, #group-dialog-body button.primary { width: 100%; margin-top: 1.4rem; margin-bottom: 0.5rem; min-height: 3.1rem; font-size: 1rem; }
.fld-locked { margin-top: 1rem; padding: 0.7rem 0.85rem; background: var(--accent-soft); border: 1px dashed var(--accent-line); border-radius: var(--radius); font-size: 0.9rem; color: var(--muted); }
.fld-label { color: var(--muted); }
/* Multi-recipient transfer rows: one tx, N outputs. Fixed box, fluid rows —
   amounts truncate inside their own row, never resizing the dialog. */
#t-recipients { display: grid; gap: 0.5rem; margin-top: 0.5rem; }
#t-rec-list { display: grid; gap: 0.6rem; }
.rec-row { display: grid; gap: 0.4rem; padding: 0.7rem 0.8rem; border: 1px solid var(--border); border-radius: var(--radius); background: rgba(255,255,255,0.015); }
.rec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.rec-grid label { display: grid; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); min-width: 0; }
.rec-grid input, .rec-grid select { min-width: 0; }
.rec-spend-wrap { display: flex; flex-direction: row; align-items: center; gap: 0.45rem; font-size: 0.85rem; color: var(--muted); }
.rec-spend-wrap input { width: auto; }
.rec-remove { justify-self: start; }
#t-rec-add { justify-self: start; }
@media (max-width: 560px) { .rec-grid { grid-template-columns: 1fr; } }
#t-symbol-locked { color: var(--accent); font-weight: 700; }
details.adv, details.opt { margin-top: 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.4rem 0.9rem; background: transparent; transition: border-color 0.2s ease; }
details.adv[open], details.opt[open] { border-color: var(--border-strong); }
details.adv summary, details.opt summary { color: var(--muted); font-size: 0.88rem; font-weight: 600; cursor: pointer; min-height: 2rem; line-height: 2rem; }
details.opt + details.opt { margin-top: 0.65rem; }

/* Duplicate tx ID dialog (record-form prompt + card review): the hash on
   top, a short lead, one row per record with the account standing out
   (color dot + name, "this record" tag) and its date · type · amount muted
   below, then a one-line hint. Rows truncate, the box never resizes. */
#txdup-dialog[open] { width: min(480px, 94vw); }
#txdup-dialog .dialog-head { margin-bottom: 0.6rem; }
#txdup-hash {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--amber);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#txdup-message { margin: 1rem 0 0; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
/* Rows have a fixed height so the list shows exactly five; from the sixth
   on it scrolls inside its own box (the dialog itself stays put). */
#txdup-dialog {
  --txdup-row: calc(3.55rem + 2px);
  --txdup-gap: 0.45rem;
}
#txdup-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: var(--txdup-gap);
  max-height: calc(5 * var(--txdup-row) + 4 * var(--txdup-gap));
  overflow-y: auto;
  overscroll-behavior: contain;
}
#txdup-list.is-scrolling { padding-right: 0.35rem; scrollbar-width: thin; }
#txdup-list.has-more {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 1.75rem), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 1.75rem), transparent);
}
#txdup-list li {
  box-sizing: border-box;
  height: var(--txdup-row);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: 1.25rem 1.05rem;
  align-items: center;
  column-gap: 0.6rem;
  row-gap: 0.15rem;
  padding: 0.55rem 0.8rem;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#txdup-list .txdup-dot {
  grid-row: 1 / span 2;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 999px;
  background: var(--dot, var(--muted));
}
#txdup-list .txdup-acc {
  line-height: 1.25rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#txdup-list .txdup-meta {
  grid-column: 2 / span 2;
  line-height: 1.05rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#txdup-list .txdup-this {
  line-height: 1.2;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  white-space: nowrap;
}
#txdup-hint { margin: 0.9rem 0 0; font-size: 0.82rem; line-height: 1.5; }
