/* Shared UI pieces for Bandi Monitor pages (needs tokens.css). Classes are prefixed with bm-
   so they never collide with the app's own rules in index.html. */

:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.bm-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

/* ---- Buttons */
.bm-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
          border: 1px solid transparent; border-radius: var(--r-md); font: 600 14px/1.2 var(--font-sans); text-decoration: none;
          cursor: pointer; -webkit-tap-highlight-color: transparent;
          transition: background-color .14s var(--ease), border-color .14s var(--ease), color .14s var(--ease), opacity .14s var(--ease); }
.bm-btn--primary { background: var(--brand); color: var(--on-brand); }
.bm-btn--primary:hover { background: var(--brand-hover); }
.bm-btn--ghost { background: var(--panel); border-color: var(--line); color: var(--text); }
.bm-btn--ghost:hover { background: var(--brand-soft); border-color: var(--brand-line); }
.bm-btn--block { width: 100%; }
.bm-btn:disabled { cursor: default; opacity: .6; }
.bm-btn[aria-busy="true"] { cursor: progress; }
.bm-btn .bm-icon { width: 18px; height: 18px; }

.bm-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75;
           stroke-linecap: round; stroke-linejoin: round; }

/* ---- Fields */
.bm-field { display: grid; gap: 6px; }
.bm-field label { font: 500 13px/1.3 var(--font-sans); color: var(--text); }
.bm-input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-md);
            background: var(--sunk); color: var(--text); font: 400 15px/1.2 var(--font-sans); outline-offset: 4px;
            transition: border-color .14s var(--ease), background-color .14s var(--ease); }
.bm-input::placeholder { color: var(--text-3); }
.bm-input:focus { border-color: var(--brand); background: var(--panel); }
.bm-input[aria-invalid="true"] { border-color: var(--urgent); }
.bm-field-error { display: flex; align-items: flex-start; gap: 6px; margin: 0; font-size: 13px; line-height: 1.4; color: var(--urgent); }
.bm-field-error:empty { display: none; }
.bm-field-error .bm-icon { width: 16px; height: 16px; margin-top: 1px; }

/* ---- Toasts: inverse bars stacked bottom-right (top on phones) */
.bm-toasts { position: fixed; z-index: 2000; display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
             right: max(20px, calc(env(safe-area-inset-right) + 12px)); bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
             width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.bm-toast { --accent: var(--toast-info); position: relative; display: flex; align-items: center; gap: 10px; min-height: 48px; max-width: 100%; padding: 8px 8px 8px 16px; border-radius: var(--r-toast);
            background: var(--toast-bg); color: var(--toast-fg); box-shadow: var(--shadow);
            font: 400 14px/1.4 var(--font-sans); font-feature-settings: "cv11", "ss01"; pointer-events: auto; }
.bm-toast[data-kind="warning"] { --accent: var(--toast-warn); }
.bm-toast[data-kind="error"] { --accent: var(--toast-error); }
.bm-toast__icon { color: var(--accent); }
.bm-toast__msg { flex: 1; min-width: 0; margin: 0; padding: 4px 0; overflow-wrap: anywhere; }
.bm-toast :focus-visible { outline-color: var(--toast-focus); }
.bm-toast__action { min-height: 32px; padding: 0 12px; border: 0; border-radius: var(--r-sm); background: var(--toast-action);
                    color: var(--toast-action-ink); font: 600 13px/1 var(--font-sans); white-space: nowrap; cursor: pointer;
                    transition: background-color .14s var(--ease); }
.bm-toast__action:hover { background: var(--toast-action-hover); }
.bm-toast__close { position: relative; display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0;
                   border-radius: var(--r-sm); background: transparent; color: var(--toast-fg-2); cursor: pointer;
                   transition: background-color .14s var(--ease), color .14s var(--ease); }
.bm-toast__close::after { content: ""; position: absolute; inset: -6px; }
.bm-toast__close:hover { background: var(--toast-hover); color: var(--toast-fg); }
.bm-toast__close .bm-icon { width: 16px; height: 16px; }
/* The time bar is clipped by its own track so buttons keep unclipped focus rings */
.bm-toast__track { position: absolute; left: 0; right: 0; bottom: 0; height: var(--r-toast); overflow: hidden;
                   border-radius: 0 0 var(--r-toast) var(--r-toast); pointer-events: none; }
.bm-toast__bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--accent); opacity: .9;
                 transform-origin: left center; }

/* ---- Segmented control: a sunk track, the pressed option lifted onto the panel */
.bm-seg { display: flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--sunk); }
.bm-seg button { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 0 8px;
                 border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2); cursor: pointer;
                 font: 500 13px/1 var(--font-sans); white-space: nowrap;
                 transition: background-color .14s var(--ease), color .14s var(--ease); }
.bm-seg button:hover { color: var(--text); }
.bm-seg button[aria-pressed="true"], .bm-seg button[aria-checked="true"] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(15, 14, 30, .12); }
.bm-seg .bm-icon { width: 16px; height: 16px; }

/* ---- Avatar: initials on iris wash, a 36px face inside a 44px target */
.bm-avatar { position: relative; flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0;
             border-radius: 50%; background: transparent; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.bm-avatar__face { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--brand-line);
                   background: var(--brand-soft); color: var(--brand-ink); font: 600 14px/1 var(--font-display); letter-spacing: .02em;
                   transition: background-color .14s var(--ease), border-color .14s var(--ease); }
.bm-avatar:hover .bm-avatar__face, .bm-avatar[aria-expanded="true"] .bm-avatar__face { background: var(--mid); border-color: var(--brand); }
/* The ring sits 4px outside the visible face (the target itself is 4px wider) */
.bm-avatar:focus-visible { outline-offset: 0; border-radius: 50%; }
.bm-avatar:disabled { cursor: default; }
.bm-avatar:disabled .bm-avatar__face { border-color: var(--line); background: var(--sunk); }

/* ---- User menu: a popover under the avatar, a bottom sheet on phones. It floats, so it may cast the float shadow. */
.bm-usermenu { position: fixed; z-index: 1500; min-width: 260px; max-width: calc(100vw - 16px); padding: 6px;
               background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-lg);
               box-shadow: var(--shadow-float); transform-origin: top right;
               font: 400 14px/1.4 var(--font-sans); font-feature-settings: "cv11", "ss01"; }
.bm-usermenu__handle { display: none; }
.bm-usermenu:focus { outline: none; }
.bm-usermenu__who { padding: 10px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--rule); }
.bm-usermenu__name { margin: 0; font: 600 15px/1.3 var(--font-display); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.bm-usermenu__email { margin: 2px 0 0; font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.bm-usermenu__list { display: grid; gap: 2px; }
.bm-usermenu__item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px; border: 0;
                     border-radius: var(--r-sm); background: transparent; color: var(--text); cursor: pointer; text-align: left;
                     font: 500 14px/1.2 var(--font-sans); transition: background-color .14s var(--ease); }
.bm-usermenu__item .bm-icon { color: var(--text-2); }
.bm-usermenu__item:hover, .bm-usermenu__item:focus { background: var(--brand-soft); outline: none; }
.bm-usermenu__item:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: var(--r-sm); }
.bm-usermenu__theme { display: grid; gap: 8px; padding: 8px 10px 10px; }
.bm-usermenu__label { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.bm-usermenu__label .bm-icon { color: var(--text-2); }
.bm-usermenu__seg button:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: var(--r-sm); }

.bm-usermenu.is-sheet { top: auto; right: 0; left: 0; bottom: 0; min-width: 0; max-width: none; max-height: calc(100dvh - 24px); overflow: auto;
                        padding: 0 12px calc(12px + env(safe-area-inset-bottom));
                        border-width: 1px 0 0; border-radius: 16px 16px 0 0; transform-origin: bottom center; }
/* Only the handle and the name block drag the sheet; the rest scrolls natively */
.bm-usermenu.is-sheet :is(.bm-usermenu__handle, .bm-usermenu__who) { touch-action: none; }
.bm-usermenu.is-sheet .bm-usermenu__handle { display: block; height: 22px; cursor: grab; }
.bm-usermenu.is-sheet .bm-usermenu__handle::before { content: ""; display: block; width: 36px; height: 4px; margin: 9px auto 0; border-radius: 2px;
                                                     background: var(--text-3); opacity: .45; }
.bm-usermenu.is-sheet.is-dragging .bm-usermenu__handle { cursor: grabbing; }
.bm-usermenu.is-sheet .bm-usermenu__who { padding: 4px 10px 14px; }
.bm-usermenu.is-sheet .bm-usermenu__item { min-height: 48px; }
.bm-scrim { position: fixed; inset: 0; z-index: 1499; background: var(--scrim); touch-action: none; }

@media (pointer: coarse) {
  .bm-usermenu__item, .bm-seg button { min-height: 44px; }
}

@media (max-width: 600px) {
  .bm-toasts { top: calc(env(safe-area-inset-top) + 12px); bottom: auto;
               left: calc(env(safe-area-inset-left) + 12px); right: calc(env(safe-area-inset-right) + 12px);
               width: auto; align-items: stretch; flex-direction: column-reverse; }
}
@media (pointer: coarse), (max-width: 600px) {
  .bm-toast__action { min-height: 44px; }
  .bm-toast__close { width: 44px; height: 44px; }
  .bm-toast__close::after { inset: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .bm-btn, .bm-input, .bm-toast__action, .bm-toast__close, .bm-seg button, .bm-avatar__face, .bm-usermenu__item { transition: none; }
  .bm-toast__bar { visibility: hidden; }
}
