/* =====================================================================
   Clinic PIN lock / setup (Pinpad/passcode.html)

   A calm, flat screen for a clinician unlocking the app on their own.
   Tokens and the mist page background come from template/UnifiedAppShell.css
   (the page opts in with <body class="mode-clinician">). Reference: the
   "PIN lock" screen of tools/design-preview/preview.src.html.

   White card on cool mist, navy ink, flat light blue-grey keys, ONE action
   colour (orange) for Unlock, a 3px cyan focus ring. No gradients, 3D edges,
   glow or lift.
   ===================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Column flex: the card centres itself vertically in the space above the
   legal footer that LegalConsent.js appends to <body>. */
body.mode-clinician {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: 32px;
    font-size: 15px;
    line-height: 1.5;
}

body.mode-clinician .sx-legal-footer {
    margin-top: 32px;
}

body.mode-clinician :is(button, a, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid var(--sx-focus);
    outline-offset: 2px;
}

/* ----------------------------- Card ----------------------------- */
body.mode-clinician .container {
    /* column flex so #error can sit right under the PIN field (order below) */
    display: flex;
    flex-direction: column;
    width: min(380px, calc(100% - 32px));
    margin: auto;
    padding: 32px 28px 28px;
    border: 1px solid var(--sx-line);
    border-radius: var(--sx-radius);
    background: var(--sx-surface);
    box-shadow: var(--sx-shadow);
    text-align: center;
}

/* Lock mark: a thin-line royal-blue padlock on a primary-tint disc. Decorative. */
body.mode-clinician .container::before {
    content: '';
    display: block;
    flex: none;
    width: 48px;
    height: 48px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23114488' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='11' width='14' height='9' rx='2'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E") center / 22px no-repeat,
        var(--sx-primary-tint);
}

body.mode-clinician .container h2 {
    margin: 0;
    color: var(--sx-ink);
    font-family: var(--sx-font-display);
    font-size: 21px;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.pin-account-meta {
    margin: 6px 0 0;
    color: var(--sx-ink-3);
    font-size: 13.5px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.pin-account-meta:empty {
    display: none;
}

/* --------------------- PIN display + reveal button ---------------------
   The (read-only) password input is the display box. Its own bullets are
   hidden and a row of six dots is drawn over it instead, filled as digits
   are entered (syncPinDots() in passcode.html). While the reveal button is
   held the input turns to type=text and the digits show through. */
.pin-input-shell {
    position: relative;
    margin: 18px 0 18px;
}

.pin-input-shell .pin-code-input {
    display: block;
    width: 100%;
    height: 52px;
    min-width: 0;
    padding: 0 48px;
    border: 1px solid var(--sx-line-strong);
    border-radius: var(--sx-radius-sm);
    background: var(--sx-surface-2);
    color: transparent;
    caret-color: transparent;
    font-family: var(--sx-font-display);
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.3em;
    text-align: center;
    text-indent: 0.3em;
    box-shadow: none;
    transition: border-color 0.12s ease, background-color 0.12s ease;
}

.pin-input-shell .pin-code-input[type="text"] {
    color: var(--sx-ink);
}

.pin-input-shell .pin-code-input::placeholder {
    color: transparent;
}

.pin-dots {
    position: absolute;
    inset: 0 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    pointer-events: none;
}

.pin-dots i {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--sx-ink);
}

.pin-dots i.off {
    border: 2px solid var(--sx-line-strong);
    background: transparent;
}

.pin-input-shell .pin-code-input[type="text"] ~ .pin-dots {
    visibility: hidden;
}

.pin-visibility-btn {
    position: absolute;
    top: 50%;
    right: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    margin-top: -20px;
    border: 0;
    border-radius: var(--sx-radius-sm);
    background: transparent;
    color: var(--sx-ink-3);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.12s ease;
}

.pin-visibility-btn svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.pin-visibility-btn:hover {
    background: #e2eaf7;
}

.pin-visibility-btn:active {
    background: #d3dff2;
}

/* Wrong / missing code: the field takes the accent colour and shakes once
   (see flagPinError() in passcode.html). It stays until the next key press. */
.pin-input-shell.is-error {
    animation: pin-shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.pin-input-shell.is-error .pin-code-input {
    border-color: var(--sx-primary);
    background: var(--sx-t-orange);
}

.pin-input-shell.is-error .pin-dots i.off {
    border-color: #e3a89d;
}

@keyframes pin-shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(3px); }
    30%, 50%, 70% { transform: translateX(-5px); }
    40%, 60% { transform: translateX(5px); }
}

/* ----------------------------- Keypad ----------------------------- */
.pinpad {
    display: grid;
    gap: 14px;
    width: 100%;
    max-width: 270px;
    margin: 0 auto 20px;
}

.pinpad-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    justify-items: center;
}

/* Every key is the same: a flat light blue-grey disc with dark text.
   Pressing it just darkens the fill. */
.pin-btn {
    width: 100%;
    max-width: 76px;
    min-width: 56px;
    aspect-ratio: 1 / 1;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #eef3fb;
    color: var(--sx-ink);
    font-family: var(--sx-font-display);
    font-size: 26px;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    box-shadow: none;
    transition: background-color 0.1s ease;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Clear and backspace are functions, not digits: same key, quieter glyph. */
.pin-btn[aria-label="Clear PIN"],
.pin-btn[aria-label="Backspace"] {
    color: var(--sx-ink-3);
    font-size: 20px;
}

@media (hover: hover) {
    .pin-btn:hover {
        background: #e2eaf7;
    }
}

.pin-btn:active {
    background: #d3dff2;
}

/* ----------------------- Unlock / confirm buttons ----------------------- */
.pin-primary-btn {
    width: 100%;
    min-height: 44px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: var(--sx-radius-sm);
    background: var(--sx-primary);
    color: #fff;
    font-family: var(--sx-font-display);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    transition: background-color 0.12s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.pin-primary-btn:hover {
    background: var(--sx-primary-hover);
}

.pin-primary-btn:active {
    background: #9d2b17;
}

/* quiet text link */
.pin-forgot-btn {
    align-self: center;
    min-height: 40px;
    margin-top: 6px;
    padding: 8px 14px;
    border: 0;
    border-radius: var(--sx-radius-sm);
    background: transparent;
    color: var(--sx-primary-ink);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.12s ease;
}

.pin-forgot-btn:hover {
    background: var(--sx-primary-tint);
    text-decoration: underline;
}

/* Status line (errors + "PIN updated" info). It is last in the markup but
   ordered to sit directly under the PIN field so it is visible above the
   keypad on small phones. */
#error {
    order: 1;
    margin: -6px 0 16px;
    color: #8f1f10;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.4;
}

#error:empty {
    margin: 0;
}

.pinpad,
.pin-primary-btn,
.pin-forgot-btn {
    order: 2;
}

#error:not(:empty) {
    padding: 10px 14px;
    border: 1px solid #f0b9b0;
    border-radius: var(--sx-radius-sm);
    background: var(--sx-t-orange);
}

#error.is-info:not(:empty) {
    border-color: #b7e2d3;
    background: var(--sx-t-green);
    color: var(--sx-t-green-ink);
}

/* ------------------------- Confirm-new-PIN dialog ------------------------- */
.pin-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(7, 23, 81, 0.55);
}

.pin-confirm-overlay[hidden] {
    display: none;
}

.pin-confirm-card {
    width: min(100%, 380px);
    padding: 26px 24px 24px;
    border: 1px solid var(--sx-line);
    border-radius: var(--sx-radius);
    background: var(--sx-surface);
    box-shadow: 0 24px 60px rgba(7, 23, 81, 0.28);
    text-align: center;
}

.pin-confirm-card h3 {
    margin: 0 0 8px;
    color: var(--sx-ink);
    font-family: var(--sx-font-display);
    font-size: 1.2rem;
    font-weight: 700;
}

.pin-confirm-card p {
    margin: 0;
    color: var(--sx-ink-2);
    line-height: 1.5;
}

.pin-confirm-value {
    margin: 18px 0 22px;
    padding: 14px 16px;
    border: 1px solid var(--sx-line);
    border-radius: var(--sx-radius-sm);
    background: var(--sx-surface-2);
    color: var(--sx-ink);
    font-family: var(--sx-font-display);
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.35em;
    text-indent: 0.35em;
}

.pin-confirm-actions {
    display: flex;
    gap: 12px;
}

.pin-confirm-actions button {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
}

.secondary-action-btn {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--sx-line-strong);
    border-radius: var(--sx-radius-sm);
    background: var(--sx-surface);
    color: var(--sx-ink);
    font-family: var(--sx-font-display);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    transition: background-color 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.secondary-action-btn:hover {
    background: var(--sx-surface-2);
}

.secondary-action-btn:active {
    background: #e2eaf7;
}

.pin-confirm-actions .pin-primary-btn {
    flex: 1.5 1 0;
    padding: 10px;
}

/* --------- Forgot-PIN dialog (rendered by template/AuthSecurity.js) ---------
   Mirrors the same dialog in index.css: navy scrim, white card, orange
   primary, outline secondary. */
.auth-reset-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(7, 23, 81, 0.55);
}

.auth-reset-card {
    display: grid;
    gap: 8px;
    width: min(520px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 22px;
    border: 1px solid var(--sx-line);
    border-radius: var(--sx-radius);
    background: var(--sx-surface);
    box-shadow: 0 24px 60px rgba(7, 23, 81, 0.28);
    color: var(--sx-ink);
    text-align: left;
}

.auth-reset-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.auth-reset-card h3 {
    margin: 0 0 2px;
    color: var(--sx-ink);
    font-family: var(--sx-font-display);
    font-size: 1.2rem;
    font-weight: 600;
}

.auth-reset-sub,
.auth-reset-hint,
.auth-reset-countdown,
.auth-reset-method-label,
.auth-reset-card label {
    color: var(--sx-ink-2);
}

.auth-reset-sub,
.auth-reset-hint {
    margin: 0 0 6px;
    font-size: 0.9rem;
    line-height: 1.45;
}

.auth-reset-card label {
    font-size: 0.86rem;
    font-weight: 600;
}

.auth-reset-status {
    min-height: 20px;
    color: #b42318;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.4;
}

.auth-reset-rules li {
    color: var(--sx-ink-3);
    font-size: 0.84rem;
}

.auth-reset-rules li.is-valid {
    color: var(--sx-t-green-ink);
    font-weight: 600;
}

/* A plain notice, not a banner: the spam-folder reminder matters, but it does
   not need to shout. */
.auth-reset-spam-alert {
    margin: 2px 0 4px;
    padding: 10px 12px;
    border: 1px solid #ecd28a;
    border-radius: var(--sx-radius-sm);
    background: var(--sx-t-amber);
    color: var(--sx-t-amber-ink);
    font-family: var(--sx-font-display);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    text-align: center;
    line-height: 1.3;
}

.auth-reset-card input,
.auth-reset-card select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--sx-line-strong);
    border-radius: var(--sx-radius-sm);
    background: var(--sx-surface);
    color: var(--sx-ink);
    font: inherit;
}

.auth-reset-card input::placeholder {
    color: var(--sx-ink-3);
    opacity: 1;
}

.auth-reset-card input[type="radio"] {
    width: auto;
    min-height: 0;
    accent-color: var(--sx-primary);
}

.auth-reset-card input:focus,
.auth-reset-card select:focus {
    border-color: var(--sx-royal);
    outline: 3px solid var(--sx-focus);
    outline-offset: 1px;
}

.auth-reset-methods,
.auth-reset-rules {
    display: grid;
    gap: 6px;
}

.auth-reset-methods[hidden] {
    display: none;
}

.auth-reset-rules {
    margin: 2px 0 4px;
    padding: 0;
    list-style: none;
}

.auth-reset-radio {
    display: grid;
    grid-template-columns: auto minmax(96px, auto) minmax(140px, 1fr);
    align-items: center;
    gap: 8px;
}

.auth-reset-radio.is-disabled {
    opacity: 0.6;
}

.auth-reset-radio-main {
    justify-self: start;
    font-weight: 600;
}

.auth-reset-radio-detail {
    justify-self: end;
    color: var(--sx-ink-3);
    font-size: 0.84rem;
    text-align: right;
    white-space: nowrap;
}

.auth-reset-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.auth-reset-primary,
.auth-reset-secondary,
.auth-reset-close,
.auth-reset-toggle {
    appearance: none;
    width: auto;
    min-height: 44px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    transition: background-color 0.12s ease, border-color 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.auth-reset-primary,
.auth-reset-secondary {
    width: 100%;
    border-radius: var(--sx-radius-sm);
    font-family: var(--sx-font-display);
    font-size: 0.98rem;
}

.auth-reset-primary {
    border: 1px solid transparent;
    background: var(--sx-primary);
    color: #fff;
}

.auth-reset-secondary {
    border: 1px solid var(--sx-line-strong);
    background: var(--sx-surface);
    color: var(--sx-ink);
}

.auth-reset-close,
.auth-reset-toggle {
    min-height: 40px;
    padding: 6px 12px;
    border: 1px solid var(--sx-line-strong);
    border-radius: var(--sx-radius-sm);
    background: var(--sx-surface);
    color: var(--sx-ink-2);
    font-size: 0.82rem;
}

.auth-reset-close:hover,
.auth-reset-toggle:hover,
.auth-reset-secondary:hover:not(:disabled) {
    background: var(--sx-surface-2);
}

.auth-reset-primary:hover:not(:disabled) {
    background: var(--sx-primary-hover);
}

.auth-reset-primary:disabled,
.auth-reset-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.auth-reset-success-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin: 0 auto 8px;
    border-radius: 50%;
    background: var(--sx-t-green);
    color: var(--sx-t-green-ink);
    font-size: 1.6rem;
    font-weight: 700;
}

.auth-reset-success-title,
.auth-reset-success-copy {
    color: var(--sx-ink);
    text-align: center;
}

/* --- Responsive --- */
@media (max-width: 700px) {
    body.mode-clinician {
        padding-top: 16px;
    }

    body.mode-clinician .container {
        width: calc(100% - 24px);
        padding: 26px 18px 22px;
    }

    .pin-btn {
        max-width: 72px;
        min-width: 52px;
        font-size: 24px;
    }

    .pinpad,
    .pinpad-row {
        gap: 12px;
    }

    .pinpad {
        max-width: 264px;
    }

    .pin-confirm-card {
        padding: 22px 18px 20px;
    }

    .pin-confirm-value {
        padding: 12px 10px;
        font-size: 1.3rem;
    }

    .auth-reset-card {
        padding: 16px;
    }

    .auth-reset-radio {
        grid-template-columns: auto minmax(64px, auto) minmax(84px, 1fr);
        gap: 6px;
    }

    .auth-reset-radio-detail {
        font-size: 0.76rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pin-input-shell.is-error {
        animation: none;
    }

    .pin-btn,
    .pin-visibility-btn,
    .pin-primary-btn,
    .pin-forgot-btn,
    .secondary-action-btn,
    .pin-input-shell .pin-code-input,
    .auth-reset-primary,
    .auth-reset-secondary,
    .auth-reset-close,
    .auth-reset-toggle {
        transition: none !important;
    }
}

/* Forgot password/PIN: account not found on this device */
.auth-reset-card input.is-invalid {
    border-color: #b42318;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.16);
    animation: auth-reset-shake 0.36s ease;
}

@keyframes auth-reset-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
    .auth-reset-card input.is-invalid { animation: none; }
}
