/* ============================================================
   NORHI Scribe — Dictate + Hide Widgets
   Self-contained, no Tailwind, no CSS variable dependencies.
   Ported from NUAMP source.css lines 1253-1472 (2026-05-14).

   Colors inlined for portability:
     --color-widget-dictate: #7c2d12  (terracotta)
     --color-widget-hide:    #5c6460  (gray, the fleet's muted text grey)
     --color-widget-success: #166534  (the fleet's success text green)
   ============================================================ */

/* Desktop FAB stack (right edge, vertical) */
#widget-fab-stack {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9990;
    display: flex;
    flex-direction: column;  /* hide on top, dictate on bottom */
    gap: 12px;
    align-items: flex-end;
    transition: opacity 0.25s ease;
}

#widget-fab-stack.widgets-hidden {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Stepped aside: a keyboard-focused control sits under the buttons (dictate.js, the last block); the stack's own
   opacity transition applies, and it comes back as soon as focus moves on */
#widget-fab-stack.widgets-aside,
#dictate-mobile-mount.widgets-aside {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ============================================================
   HIDE WIDGET BUTTON (top of FAB stack)
   ============================================================ */
.hw-fab {
    position: relative;
    z-index: 9990;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    background: #5c6460;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: manipulation;
    box-shadow: 0 4px 16px rgba(92, 100, 96, 0.2);
    opacity: 0.8;  /* at rest: the white icon clears 3:1 on its own fill (3.87:1 over white) */
}
@media (hover: hover) {
    .hw-fab:hover {
        box-shadow: 0 6px 20px rgba(92, 100, 96, 0.25);
        opacity: 1;
    }
}
/* full strength while it has keyboard focus: at the rest opacity the focus ring drew at 2.84:1 */
.hw-fab:focus-visible {
    opacity: 1;
}
/* On a touch screen the button meets the 44px floor (it was 40px: the one floating control under it). */
@media (pointer: coarse) {
    .hw-fab { width: 44px; height: 44px; }
}

/* ============================================================
   DICTATE WIDGET — direct-to-field voice dictation
   ============================================================ */
.dw-fab {
    position: relative;
    z-index: 9990;
    width: 48px;
    height: 48px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    background: #7c2d12;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: manipulation;
    box-shadow: 0 4px 16px rgba(124, 45, 18, 0.25);
}
.dw-fab:hover {
    box-shadow: 0 6px 20px rgba(124, 45, 18, 0.3);
}
.dw-fab.recording {
    /* box-shadow driven by JS audio analyser; no CSS animation */
}
.dw-fab.processing {
    opacity: 0.7;
    cursor: wait;
}
.dw-fab.success-flash {
    background: #166534;
    transition: background 0.4s ease;
}

/* Field being targeted for dictation — subtle terracotta outline */
.dictate-target {
    outline: 2px solid #7c2d12 !important;
    outline-offset: 2px;
    transition: outline 0.2s ease;
}

/* ============================================================
   MOBILE DICTATE WIDGET
   Right-side ghost stack — hide button + dictate button
   Only visible on phones/PWA (max-width: 768px)
   Desktop FAB stack is hidden on mobile
   ============================================================ */

#dictate-mobile-mount {
    display: none;  /* shown on mobile via media query below */
    /* top transitions when dictate.js re-centers it around the keyboard */
    transition: opacity 0.25s ease, top 0.2s ease;
}

.dw-fab-mobile {
    width: 52px;
    height: 52px;
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    background: #7c2d12;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(124, 45, 18, 0.35);
    opacity: 0.6;  /* at rest: the white icon clears 3:1 on its own fill (3.37:1 over white) */
    transition: opacity 0.2s ease, transform 0.15s ease;
    touch-action: manipulation;
}
.dw-fab-mobile:active {
    transform: scale(0.95);
    opacity: 1;
}
.dw-fab-mobile.recording,
.dw-fab-mobile.processing,
.dw-fab-mobile.success-flash {
    opacity: 1;
}
.dw-fab-mobile.processing {
    cursor: wait;
}
.dw-fab-mobile.success-flash {
    background: #166534;
    transition: background 0.4s ease, opacity 0.2s ease;
}

.hw-fab-mobile {
    width: 40px;
    height: 40px;
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    background: #5c6460;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(92, 100, 96, 0.25);
    opacity: 0.8;  /* at rest: as the desktop hide button */
    transition: opacity 0.2s ease, transform 0.15s ease;
    touch-action: manipulation;
}
.hw-fab-mobile:active {
    transform: scale(0.95);
    opacity: 1;
}

#dictate-mobile-mount.mobile-widgets-hidden {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Mobile layout: the mic rests in the top bar (the person, 2026-11-10, dr10-rail B / dr10-rail2); nothing floats over
   the page. Still position:fixed and a child of <body>, so it stays above any sheet or dialog; the bar never scrolls
   (the app shell is one screen high), so a fixed mic and the bar stay together. --dictate-rest tells dictate.js that
   recenter() has nothing to do here and that the wide voice ring is not drawn. The bar's content row is 31px high
   between two --header-pad: the button is a 44px tap target centred on that row and draws a 31px tile. */
/* Up to 767px only: the widths where the bar shows Menu. At 768px exactly the bar shows its links and the account
   name; a name longer than about nine characters pushed the first link under a mic resting there (measured
   2026-11-10), so at 768px the mic floats at the right edge, as on every wider tablet. */
@media (max-width: 767px) {
    #widget-fab-stack {
        display: none !important;
    }
    #dictate-mobile-mount {
        --dictate-rest: bar;
        display: flex;
        align-items: center;
        position: fixed;
        top: calc(env(safe-area-inset-top, 0px) + var(--header-pad, 8px) - 6.5px);
        right: calc(var(--dictate-bar-right, 108px) + env(safe-area-inset-right, 0px));
        z-index: 9995;
    }
    /* The bar keeps the mic's place free: on a phone the Menu button starts 52px further left, so a long name
       shortens before it reaches the mic. */
    body:has(#dictate-mobile-mount) .kb-nav-toggle { margin-left: 52px; }
    /* Hide has nothing to hide, and the mic does not step aside: it covers no content. The button and both functions stay. */
    #dictate-mobile-mount #hide-mobile-fab { display: none; }
    #dictate-mobile-mount.widgets-aside { opacity: 1 !important; pointer-events: auto !important; }

    .dw-fab-mobile {
        position: relative;
        width: 44px;
        height: 44px;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        opacity: 1;
    }
    .dw-fab-mobile::before {
        content: "";
        position: absolute;
        inset: 6.5px 0;
        border: 1px solid rgba(255, 255, 255, 0.45);
        border-radius: 8px;
        transition: background 0.2s ease, box-shadow 0.2s ease;
    }
    .dw-fab-mobile svg { position: relative; width: 20px; height: 20px; }
    .dw-fab-mobile:active { transform: none; }
    .dw-fab-mobile:active::before { background: rgba(255, 255, 255, 0.16); }
    /* Recording must read at a glance, and without the ring (no level exists under reduced motion): a white tile,
       the terracotta icon. The ring follows the voice where a level is published. */
    .dw-fab-mobile.recording { color: #7c2d12; }
    .dw-fab-mobile.recording::before {
        background: #ffffff;
        border-color: #ffffff;
        box-shadow: 0 0 0 calc(2px + var(--dictate-level, 0) * 4px) rgba(255, 255, 255, 0.45);
    }
    .dw-fab-mobile.processing { opacity: 0.6; }
    .dw-fab-mobile.success-flash { background: transparent; }
    .dw-fab-mobile.success-flash::before { background: #166534; border-color: #ffffff; }
}

