/* ==========================================================================
   SOMANOTES — QUICK DISCHARGE WORKSPACE (additions on top of progress-oneshot.css)
   ==========================================================================

   Location:  /static/css/quickdc.css
   Depends:   css/progress-oneshot.css (must load first)
   Activator: data-page="quickdc" on body (body also has .pn-page for theme)

   DESIGN DISCIPLINE
   ---------------------------------------------------------------------------
   This file adds ONLY the chrome that progress-oneshot doesn't already have.
   Everything inherits the pn-* palette (single cyan accent, no magenta, no
   secondary hues). Affordances are terminal-correct:
     - No pulses, no flashes, no decorative animations.
     - No iOS/marketing toggles. Use a square checkbox.
     - Glow appears only on :focus (matches pn-textarea behaviour).
     - Pending state is a subtle background tint — no blinking caret, no
       dashed underline, no settle animation.
   If a future addition needs magenta or a second accent, that's a sign the
   feature should go on its own page, not get bolted onto this one.
   ========================================================================== */


/* ==========================================================================
   S0  KILL THE FILM-GRAIN OVERLAY
   progress-oneshot.css paints a 512x512 fractal-noise SVG via .pn-page::before.
   On retina + mobile displays the tile reads as visible splotches instead of
   subtle grain. Scoped override keeps the effect for /progress-note and drops
   it here.
   ========================================================================== */

.pn-page[data-page="quickdc"]::before {
    display: none;
}


/* ==========================================================================
   S1  PATIENT ATTACH ROW — two-column field group
   ========================================================================== */

.qd-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--pn-space-md);
}

.qd-field-half {
    display: flex;
    flex-direction: column;
}

.qd-field-optional {
    color: var(--pn-fg-muted);
    font-weight: 400;
    font-size: var(--pn-text-xs);
    letter-spacing: normal;
    text-transform: none;
    margin-left: var(--pn-space-xs);
}


/* ==========================================================================
   S2  TEXT / SELECT INPUTS — patient label + attach dropdown
   Match pn-textarea exactly (background, border, focus glow). Single-line.
   ========================================================================== */

.qd-text-input,
.qd-select-input {
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-sm);
    color: var(--pn-fg-primary);
    background: var(--pn-bg-input);
    border: 1px solid var(--pn-border-default);
    border-radius: 2px;
    padding: var(--pn-space-sm) var(--pn-space-md);
    outline: none;
    transition: border-color var(--pn-duration) var(--pn-easing);
    height: 36px;
    box-sizing: border-box;
    width: 100%;
}

.qd-text-input::placeholder {
    color: var(--pn-fg-muted);
}

.qd-text-input:focus,
.qd-select-input:focus {
    border-color: var(--pn-accent);
    box-shadow: var(--pn-glow-accent);
}

.qd-select-input {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: var(--pn-space-xl);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M2 4 L5 7 L8 4' stroke='%239a9ab0' stroke-width='1' fill='none'/></svg>");
    background-repeat: no-repeat;
    background-position: right var(--pn-space-md) center;
    cursor: pointer;
}

.qd-select-input option {
    background: var(--pn-bg-elevated);
    color: var(--pn-fg-primary);
}


/* ==========================================================================
   S3  VERBOSE CHECKBOX — terminal-style square, not iOS slider
   ========================================================================== */

.qd-toggle-row {
    display: flex;
    align-items: center;
}

.qd-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--pn-space-sm);
    cursor: pointer;
    user-select: none;
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-xs);
    color: var(--pn-fg-secondary);
    letter-spacing: var(--pn-tracking-wide);
}

.qd-toggle input {
    /* Hide the native checkbox; we render our own ::before via the slider span. */
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.qd-toggle-slider {
    position: relative;
    width: 14px;
    height: 14px;
    background: var(--pn-bg-input);
    border: 1px solid var(--pn-border-default);
    border-radius: 2px;
    flex-shrink: 0;
    transition: border-color var(--pn-duration) var(--pn-easing);
}

.qd-toggle input:checked + .qd-toggle-slider {
    border-color: var(--pn-accent);
}

.qd-toggle input:checked + .qd-toggle-slider::after {
    /* Cyan check mark — drawn with two borders, no glow, no animation. */
    content: '';
    position: absolute;
    top: 1px;
    left: 4px;
    width: 4px;
    height: 8px;
    border-right: 1.5px solid var(--pn-accent);
    border-bottom: 1.5px solid var(--pn-accent);
    transform: rotate(45deg);
}

.qd-toggle input:focus-visible + .qd-toggle-slider {
    box-shadow: var(--pn-glow-accent);
}

.qd-toggle-label {
    /* Hook reserved for future detail text — kept transparent so it doesn't
       fight the parent .qd-toggle styling. */
}


/* ==========================================================================
   S4  SAVE BUTTON — sibling of Copy in the output actions bar
   Identical shape and accent as pn-btn-copy. WHY same colour: keeping the
   action row monochrome reduces visual noise while the doctor scans the note.
   ========================================================================== */

.qd-btn-save {
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-xs);
    color: var(--pn-accent);
    background: transparent;
    border: 1px solid var(--pn-accent-dim);
    border-radius: 2px;
    padding: var(--pn-space-xs) var(--pn-space-md);
    letter-spacing: var(--pn-tracking-wide);
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color var(--pn-duration) var(--pn-easing);
    height: 28px;
}

.qd-btn-save:hover:not(:disabled) {
    border-color: var(--pn-accent);
}

.qd-btn-save:focus-visible {
    outline: none;
    box-shadow: var(--pn-glow-accent);
    border-color: var(--pn-accent);
}

.qd-btn-save:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}


/* ==========================================================================
   S4B  RECENT SAVED QUICK NOTES
   ========================================================================== */

.qd-saved-notes {
    border-top: 1px solid var(--pn-border-default);
    padding: var(--pn-space-md);
    background: rgba(255, 255, 255, 0.015);
    min-height: 150px;
    max-height: 260px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: var(--pn-space-sm);
}

.qd-saved-notes-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--pn-space-md);
}

.qd-saved-notes-title {
    margin: 0;
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-xs);
    letter-spacing: var(--pn-tracking-wide);
    text-transform: uppercase;
    color: var(--pn-fg-secondary);
}

.qd-saved-notes-refresh,
.qd-saved-note-action {
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-xs);
    color: var(--pn-accent);
    background: transparent;
    border: 1px solid var(--pn-accent-dim);
    border-radius: 2px;
    padding: var(--pn-space-xs) var(--pn-space-sm);
    letter-spacing: var(--pn-tracking-wide);
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color var(--pn-duration) var(--pn-easing);
}

.qd-saved-notes-refresh:hover,
.qd-saved-note-action:hover {
    border-color: var(--pn-accent);
}

.qd-saved-notes-status {
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-xs);
    color: var(--pn-fg-muted);
}

.qd-saved-notes-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: var(--pn-space-sm);
}

.qd-saved-note {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--pn-space-md);
    align-items: start;
    border: 1px solid var(--pn-border-default);
    border-radius: 2px;
    padding: var(--pn-space-sm);
    background: rgba(0, 0, 0, 0.16);
}

.qd-saved-note-main {
    min-width: 0;
}

.qd-saved-note-title {
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-sm);
    color: var(--pn-fg-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qd-saved-note-meta,
.qd-saved-note-preview {
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-xs);
    color: var(--pn-fg-muted);
}

.qd-saved-note-preview {
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qd-saved-note-actions {
    display: flex;
    gap: var(--pn-space-xs);
}

.qd-saved-note-action.danger {
    color: #ff8f8f;
    border-color: rgba(255, 143, 143, 0.35);
}


/* ==========================================================================
   S5  EDITABLE POST-STREAM OUTPUT
   Cursor + caret colour only. No outline, no animation.
   ========================================================================== */

.qd-output.qd-editable {
    cursor: text;
    caret-color: var(--pn-accent);
}


/* ==========================================================================
   S6  HIGHLIGHT-AND-REGENERATE — floating selection toolbar
   Quiet rectangle. Static border. No pulse. Slot the input + two buttons
   inline like a terminal command bar.
   ========================================================================== */

.qd-selection-toolbar {
    position: fixed;
    z-index: 9999;
    display: none;
    align-items: center;
    gap: var(--pn-space-sm);
    padding: var(--pn-space-sm) var(--pn-space-md);
    background: var(--pn-bg-elevated);
    border: 1px solid var(--pn-border-strong);
    border-radius: 2px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
    min-width: 360px;
    max-width: 520px;
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-sm);
    color: var(--pn-fg-primary);
}

.qd-selection-toolbar.visible {
    display: flex;
}

.qd-selection-toolbar.streaming {
    /* Streaming state shows only by disabling the input + relabeling the
       button. No flashing borders, no pulses. Doctor can read while it works. */
    border-color: var(--pn-accent-dim);
}

.qd-selection-toolbar .qd-rewrite-label {
    color: var(--pn-fg-muted);
    font-size: var(--pn-text-xs);
    letter-spacing: var(--pn-tracking-wide);
    text-transform: lowercase;
    flex-shrink: 0;
}

.qd-selection-toolbar .qd-rewrite-input {
    flex: 1;
    min-width: 0;
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-sm);
    color: var(--pn-fg-primary);
    background: var(--pn-bg-input);
    border: 1px solid var(--pn-border-default);
    border-radius: 2px;
    padding: var(--pn-space-xs) var(--pn-space-sm);
    outline: none;
    transition: border-color var(--pn-duration) var(--pn-easing);
    height: 28px;
}

.qd-selection-toolbar .qd-rewrite-input::placeholder {
    color: var(--pn-fg-muted);
}

.qd-selection-toolbar .qd-rewrite-input:focus {
    border-color: var(--pn-accent);
    box-shadow: var(--pn-glow-accent);
}

.qd-selection-toolbar .qd-rewrite-input:disabled {
    opacity: 0.5;
}

.qd-selection-toolbar .qd-rewrite-submit,
.qd-selection-toolbar .qd-rewrite-cancel {
    font-family: var(--pn-font-mono);
    font-size: var(--pn-text-xs);
    letter-spacing: var(--pn-tracking-wide);
    text-transform: uppercase;
    background: transparent;
    border: 1px solid var(--pn-border-default);
    border-radius: 2px;
    padding: var(--pn-space-xs) var(--pn-space-md);
    color: var(--pn-fg-secondary);
    cursor: pointer;
    transition: border-color var(--pn-duration) var(--pn-easing);
    height: 28px;
    flex-shrink: 0;
}

.qd-selection-toolbar .qd-rewrite-submit {
    color: var(--pn-accent);
    border-color: var(--pn-accent-dim);
}

.qd-selection-toolbar .qd-rewrite-submit:hover:not(:disabled) {
    border-color: var(--pn-accent);
}

.qd-selection-toolbar .qd-rewrite-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.qd-selection-toolbar .qd-rewrite-cancel {
    color: var(--pn-fg-muted);
    padding: var(--pn-space-xs) var(--pn-space-sm);
    min-width: 28px;
}

.qd-selection-toolbar .qd-rewrite-cancel:hover {
    color: var(--pn-fg-secondary);
    border-color: var(--pn-border-strong);
}


/* ==========================================================================
   S7  IN-PLACE STREAMING SPAN — subtle background tint, no caret, no flash
   The pending replacement reads as plain text with a faint cyan wash so the
   doctor can see WHERE the rewrite is landing. No motion. When done, the
   span is unwrapped by JS — the wash disappears with the wrapper.
   ========================================================================== */

.qd-span-pending {
    background: var(--pn-accent-ghost);
    transition: background-color var(--pn-duration) var(--pn-easing);
}

.qd-span-pending.done {
    background: transparent;
}


/* ==========================================================================
   S8  RESPONSIVE — narrow widths
   Stack the patient-attach row. Pin the toolbar to the bottom so a thumb can
   reach it (selection bounding rect math is unreliable on phones).
   ========================================================================== */

@media (max-width: 900px) {
    .qd-field-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .qd-selection-toolbar {
        top: auto !important;
        left: 8px !important;
        right: 8px !important;
        bottom: 16px !important;
        min-width: 0;
        max-width: none;
        flex-wrap: wrap;
    }
    .qd-selection-toolbar .qd-rewrite-input {
        flex: 1 1 100%;
        order: 1;
    }
    .qd-selection-toolbar .qd-rewrite-label {
        order: 0;
    }
    .qd-selection-toolbar .qd-rewrite-submit {
        order: 2;
        flex: 1;
    }
    .qd-selection-toolbar .qd-rewrite-cancel {
        order: 3;
    }
}
