/*
    TotmDictation's mic button - see Mobile-Dictation-Plan.md section 4.

    Every colour comes from a Tokens.css variable and nothing here depends on Theme.css, which is
    disabled under Tradie Classic. Dark.css and Professional.css redefine those same tokens, so the
    button follows all six theme combinations with no colour-only duplicates. The listening red is
    --danger: it means "recording", like a phone's own record button, so it isn't themed away.
*/

/* .totm-dictation-wrap > .totm-dictation-box (the textarea and the button) > .totm-dictation-status */

/* Start below any floats before the box. A bare textarea is inline-block, so it flowed after
   floated siblings (the H&S questionnaire's float: left risk-level buttons); the wrap is a block,
   which would start behind them, and the box's position: relative then paints it on top of them
   and swallows their taps. */
.totm-dictation-wrap {
    clear: both;
}

.totm-dictation-box {
    position: relative;
}

/* Room under the text for the button, so a long note never runs underneath it. No bottom margin,
   so the button's bottom: 8px is measured from the textarea's own edge; the status line below
   gives the spacing back. */
.totm-dictation-box textarea.totm-dictation-field {
    padding-bottom: 48px;
    margin-bottom: 0;
    /* No side margins either: the box is exactly the field, so the button's corner is its corner. */
    margin-left: 0;
    margin-right: 0;
    /* Block, so there's no inline-block baseline gap under it pushing the button off its edge. */
    display: block;
    /* content-box, so the 48px is added under the typing area rather than taken out of it: a box
       with a fixed height (the H&S questionnaire's 60px, CoC's inline 65px, Provide Memo's 80px
       !important) otherwise kept as little as 0-24px to type in. */
    box-sizing: content-box;
    /* Full width of its box. Under content-box that is "stretch", not 100% (which would add the
       padding and border on top); 100% minus a typical padding and border stays as the fallback.
       !important beats a view's inline width (Generic Form fields are built with style="width: 99%"). */
    width: calc(100% - 22px) !important;
    width: -webkit-fill-available !important;
    width: -moz-available !important;
    width: stretch !important;
}

/* H&S questionnaire boxes sit indented by their 10px margin (Mobile.css); with the field's own
   side margins taken off above, the wrap keeps that indent. The top 10px moves to the wrap's
   padding too: as a margin it collapsed into the wrap's and was lost in the clearance past the
   floated risk-level buttons, leaving the box 6px under "Details of task:" instead of 16px. */
.totm-dictation-box textarea.totm-dictation-field.QuestionnaireMultiTextAnswer {
    margin-top: 0;
}

.totm-dictation-wrap:has(> .totm-dictation-box > textarea.QuestionnaireMultiTextAnswer) {
    margin-left: 10px;
    margin-right: 10px;
    padding-top: 10px;
}

/* A box locked after its mic was attached (Generic Form fields are made readonly once built)
   shows no mic. */
.totm-dictation-box textarea[readonly] ~ .totm-dictation-mic,
.totm-dictation-box textarea:disabled ~ .totm-dictation-mic {
    display: none;
}

/* !important: Theme.css and Professional.css colour field borders with their own !important rules. */
.totm-dictation-wrap.totm-dictation-active textarea.totm-dictation-field {
    border-color: var(--danger) !important;
}

/* Compound selector and explicit sizes: Mobile.css forces every button to 16px !important and
   jQuery Mobile styles bare buttons, so nothing here relies on inheriting. */
.totm-dictation-box button.totm-dictation-mic,
button.totm-dictation-mic.totm-dictation-mic-inline {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 40px;
    height: 40px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.totm-dictation-box button.totm-dictation-mic i,

button.totm-dictation-mic.totm-dictation-mic-inline i {
    font-size: 18px;
    line-height: 1;
}

.totm-dictation-box button.totm-dictation-mic:focus-visible,

button.totm-dictation-mic.totm-dictation-mic-inline:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.totm-dictation-box button.totm-dictation-mic.totm-dictation-listening,

button.totm-dictation-mic.totm-dictation-mic-inline.totm-dictation-listening {
    background: var(--danger);
    border-color: var(--danger);
    color: #FFFFFF;
    animation: totm-dictation-pulse 1.4s ease-out infinite;
}

@keyframes totm-dictation-pulse {
    0% { box-shadow: 0 0 0 0 rgba(214, 69, 69, 0.45); }
    100% { box-shadow: 0 0 0 10px rgba(214, 69, 69, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .totm-dictation-box button.totm-dictation-mic.totm-dictation-listening,
    button.totm-dictation-mic.totm-dictation-mic-inline.totm-dictation-listening {
        animation: none;
        box-shadow: 0 0 0 4px rgba(214, 69, 69, 0.3);
    }
}

/* The line under the box: "Listening" plus the words still being worked out, or a message. It
   wraps, so the whole phrase can be read as it's heard (a single line cut most of it off at phone
   width); it keeps at least one line's height so the button below doesn't jump when it empties. */
.totm-dictation-status {
    min-height: var(--totm-dictation-status-height, 22px);
    line-height: 1.4;
    padding: 2px 0;
    box-sizing: border-box;
    font-size: 13px;
    color: var(--text-muted);
    white-space: normal;
    overflow-wrap: anywhere;
}

.totm-dictation-active .totm-dictation-status .totm-dictation-state {
    color: var(--danger);
}

.totm-dictation-active .totm-dictation-status .totm-dictation-state::before {
    content: "\25CF\00A0";
    /* Decorative: kept out of the accessible name (Mobile-Professional-Theme-Design.md). */
    content: "\25CF\00A0" / "";
}

.totm-dictation-status .totm-dictation-heard {
    font-style: italic;
}

.totm-dictation-status.totm-dictation-error {
    color: var(--danger);
}

/* The full-screen note editor's mic: in the bar, in front of Done, rather than in a box corner
   (TotmDictation.attachMic's placement). Same 44px height as Done, so the bar doesn't change. */
button.totm-dictation-mic.totm-dictation-mic-inline {
    position: static;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
}

/* Its status line sits between the bar and the note, lined up with the bar's own padding. Empty
   (not listening) it takes no room, so the note keeps the whole screen. */
.totm-dictation-status.totm-dictation-status-inline {
    flex: 0 0 auto;
    min-height: 0;
    padding: 0 var(--space-3);
}

.totm-dictation-status.totm-dictation-status-inline:not(:empty) {
    padding-top: 4px;
    padding-bottom: 4px;
}

/* Settings > Layout: the line under "Voice typing on this device" when it can't be changed. */
.SettingsDictationDeviceNote {
    margin: 4px 0 0 28px;
    font-size: 0.85em;
    color: var(--text-muted);
}
