/* Shared form parts: save bar (common/save_bar.html), changed-field marker, help icon (common/help_icon.html) and the one toast area. */
.app-save-bar { --app-dirty: light-dark(#b25e00, #ffc46b); --app-dirty-bg: light-dark(#fff1d6, #4a3410); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-top: 16px; padding: 12px 16px; border: 1px solid var(--tblr-border-color); border-radius: var(--tblr-border-radius-lg, 8px); background: var(--tblr-bg-surface); z-index: 20; }
.app-save-bar.in-card { margin: 0; border-width: 1px 0 0; border-radius: 0 0 var(--tblr-card-border-radius, 8px) var(--tblr-card-border-radius, 8px); }
.app-save-bar.is-sticky { position: sticky; bottom: calc(var(--app-mobile-nav-height, 0px) + 8px); box-shadow: 0 -4px 18px rgba(15, 23, 42, .10); }
.app-save-bar.in-card.is-sticky { bottom: var(--app-mobile-nav-height, 0px); border-radius: 0; }
.app-save-status { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-save-status strong { display: block; font-size: 14px; }
.app-save-status small { display: block; font-size: 12px; color: var(--tblr-secondary); }
.app-save-icon { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--tblr-bg-surface-secondary); color: var(--tblr-secondary); }
.app-save-bar[data-state="dirty"] .app-save-icon { background: var(--app-dirty-bg); color: var(--app-dirty); }
.app-save-bar[data-state="saving"] .app-save-icon { border: 2px solid var(--tblr-border-color); border-top-color: var(--tblr-primary); background: transparent; animation: app-save-spin .8s linear infinite; }
.app-save-bar[data-state="saved"] .app-save-icon { background: var(--tblr-success-lt); color: var(--tblr-success); }
.app-save-bar[data-state="error"] .app-save-icon { background: var(--tblr-danger-lt); color: var(--tblr-danger); }
.app-save-bar[data-state="error"] [data-save-title] { color: var(--tblr-danger); }
/* An optional "Powód zmiany" field inside the bar (save_bar.html with reason=…). */
.app-save-reason { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; flex: 1 1 320px; max-width: 560px; }
.app-save-reason .form-control { flex: 1 1 200px; min-width: 0; }
.app-save-reason .invalid-feedback { flex-basis: 100%; }
.app-save-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.app-save-actions [hidden] { display: none !important; }
@keyframes app-save-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .app-save-bar[data-state="saving"] .app-save-icon { animation: none; } }

/* A changed field is marked on its left edge; a switch or tile gets an underline. */
.app-field-dirty { box-shadow: inset 3px 0 0 light-dark(#d08a1a, #ffc46b); }
.form-check.app-field-dirty, .form-selectgroup-item.app-field-dirty { box-shadow: none; }
.form-check.app-field-dirty .form-check-label, .form-selectgroup-item.app-field-dirty strong { text-decoration: underline 2px light-dark(#d08a1a, #ffc46b); text-underline-offset: 4px; }

/* One place for every short message (common/toast.js, A7): desktop bottom right, phone centred above the
   bottom menu and a sticky save bar. Errors are red and stay until closed. */
.app-toasts { --app-toast-bg: #1d273b; position: fixed; right: 24px; bottom: var(--app-toast-bottom, 24px); z-index: 1090; display: grid; gap: 8px; width: max-content; max-width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.app-toasts.is-top { top: 12px; bottom: auto; }
.app-toasts.is-left { right: auto; left: 24px; }
.app-toasts.is-waiting { opacity: 0; }
.app-toasts.is-waiting .app-toast { pointer-events: none; }
.app-toasts > div:empty { display: none; }
.app-toast { position: relative; pointer-events: auto; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 4px 4px 4px 14px; border-radius: 10px; background: var(--app-toast-bg); color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: app-toast-in .18s ease-out; }
html[data-bs-theme="dark"] .app-toasts { --app-toast-bg: #2b3448; }
html[data-bs-theme="dark"] .app-toast { border: 1px solid rgba(255, 255, 255, .18); }
.app-toast-text { flex: 1; min-width: 0; padding: 8px 0; overflow-wrap: anywhere; }
.app-toast > .bi { flex: none; font-size: 18px; }
.app-toast-success > .bi { color: #2fb344; }
.app-toast-info > .bi { color: #74b4ff; }
.app-toast-danger { background: #8f1d1d; }
html[data-bs-theme="dark"] .app-toast-danger { background: #6d1b1b; }
.app-toast-danger > .bi { color: #fff; }
.app-toast-action { flex: none; min-height: 44px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: #ffe066; font-weight: 600; white-space: nowrap; }
.app-toast-danger .app-toast-action { color: #fff; text-decoration: underline; }
.app-toast-action:hover, .app-toast-close:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.app-toast-close { display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: rgba(255, 255, 255, .8); font-size: 16px; }
.app-toast :focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.app-toast-bar { position: absolute; left: 10px; right: 10px; bottom: 3px; height: 2px; border-radius: 2px; background: rgba(255, 255, 255, .35); transform-origin: left; }
@keyframes app-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .app-toast { animation: none; } .app-toast-bar { display: none; } }
@media (max-width: 991.98px) {
  .app-toasts { right: auto; left: 50%; transform: translateX(-50%); bottom: var(--app-toast-bottom, calc(var(--app-mobile-nav-height, 0px) + 12px)); width: calc(100vw - 24px); max-width: 480px; }
}
@media (max-width: 575.98px) {
  .app-toast-danger { display: grid; grid-template-columns: auto minmax(0, 1fr) 44px; column-gap: 10px; }
  .app-toast-danger > .bi { grid-column: 1; grid-row: 1; }
  .app-toast-danger .app-toast-text { grid-column: 2; grid-row: 1; }
  .app-toast-danger .app-toast-close { grid-column: 3; grid-row: 1; }
  .app-toast-danger .app-toast-action { grid-column: 2; grid-row: 2; justify-self: start; padding-left: 0; }
}

/* Autosave state next to a title (AppAutosave in common/toast.js): cart and count save every change
   on their own, so they show "Zapisywanie… / Zapisano 14:32" instead of a toast per change. */
.app-autosave { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; font-size: 13px; font-weight: 400; color: var(--tblr-secondary); white-space: nowrap; }
.app-autosave:empty { display: none; }
.app-autosave[data-state="error"] { color: var(--tblr-danger); font-weight: 600; }
.app-autosave[data-state="saved"] .bi { color: var(--tblr-success); }

@media (max-width: 767.98px) {
  .app-save-bar { padding: 10px 12px; gap: 8px; }
  .app-save-bar.is-sticky:not(.in-card) { margin-left: -8px; margin-right: -8px; }
  .app-save-actions { width: 100%; margin-left: 0; flex-wrap: nowrap; }
  .app-save-actions .btn { flex: 1 1 0; min-height: 44px; white-space: normal; }
  .app-save-bar:not(.has-changes) { flex-wrap: nowrap; }
  .app-save-bar:not(.has-changes) .app-save-actions { width: auto; margin-left: auto; }
  .app-save-bar:not(.has-changes) .app-save-actions .btn { flex: none; }
  .app-save-bar:not(.has-changes) [data-save-undo] { display: none; }
  /* The optional reason gets its own full-width row under the status and the buttons. */
  .app-save-bar:has(.app-save-reason) { flex-wrap: wrap; }
  .app-save-reason { order: 1; flex-basis: 100%; max-width: none; }
}

/* The one help icon (common/help_icon.html, common/help_popovers.js, A7): grey "i", 32 px target on a
   computer, 44 px on a phone or touch screen; the bubble has a short title and 1–3 sentences. */
.app-help-i { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 32px; height: 32px; margin: -6px 0; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--tblr-secondary); font-size: 16px; line-height: 1; vertical-align: middle; cursor: pointer; }
.app-help-i:hover, .app-help-i[aria-expanded="true"] { color: var(--tblr-link-color); background: var(--tblr-bg-surface-secondary); }
.app-help-i:focus-visible { outline: 3px solid var(--tblr-link-color); outline-offset: 1px; }
@media (max-width: 767.98px), (pointer: coarse) { .app-help-i { width: 44px; height: 44px; margin: -10px -6px -10px 0; } }
.app-help-pop { --tblr-popover-max-width: 300px; --bs-popover-max-width: 300px; font-size: 13.5px; }
.app-help-pop .popover-header { font-size: 13.5px; font-weight: 600; }
.app-help-pop .popover-body { line-height: 1.45; }
/* In fields side by side (common/field_rows.js) a help button must not make a one-line label taller
   than its neighbours: it keeps its touch size but overlaps the line, so label texts stay level too. */
:is(.row, [data-field-row]) > * > .form-label > .app-help-i { margin-block: -4px; vertical-align: top; }

/* Touch targets on a phone (A7): buttons and form fields at least 44 px tall everywhere, small
   ones and dialog footers included. The rule is phone-only, so dense desktop tables are not affected.
   It is a floor: !important keeps module rules (e.g. a 36 px toolbar on a computer) from lowering it
   on a phone; a module that wants a taller control on a phone marks its own value !important. */
@media (max-width: 767.98px) {
  .btn:not(.btn-close), .form-control:not([type="color"]):not(textarea), .form-select,
  .ts-wrapper.form-select .ts-control, .ts-wrapper.form-control .ts-control { min-height: 44px !important; }
  .btn.btn-icon, .btn.btn-action { min-width: 44px; }
  .modal-footer .btn-link { padding-left: 8px; padding-right: 8px; }
}
