/* ═══════════════════════════════════════════════════════════════════════
   Guidance System — In-app tooltips, introductions, and help components
   Integrates with the existing --phmod-* design tokens.
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── PageIntro ─── */
.phmod-page-intro {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    margin-bottom: 1.25rem;
    background: color-mix(in srgb, var(--phmod-brand-primary, #2563eb) 6%, white);
    border: 1px solid color-mix(in srgb, var(--phmod-brand-primary, #2563eb) 20%, white);
    border-left: 3px solid var(--phmod-brand-primary, #2563eb);
    border-radius: var(--phmod-radius, 8px);
    font-size: var(--phmod-text-sm, 0.8125rem);
    line-height: 1.6;
    color: var(--phmod-color-text, #1e293b);
}

.phmod-page-intro__icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    color: var(--phmod-brand-primary, #2563eb);
}

.phmod-page-intro__icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.phmod-page-intro__content {
    flex: 1;
    min-width: 0;
}

.phmod-page-intro__title {
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.phmod-page-intro__text {
    margin: 0;
    color: var(--phmod-color-text-muted, #475569);
}

.phmod-page-intro__dismiss {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--phmod-color-text-muted, #475569);
    border-radius: 4px;
    line-height: 1;
}

.phmod-page-intro__dismiss:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--phmod-color-text, #1e293b);
}

/* ─── SectionIntro ─── */
.phmod-section-intro {
    margin: -0.25rem 0 1rem;
    font-size: var(--phmod-text-sm, 0.8125rem);
    color: var(--phmod-color-text-muted, #475569);
    line-height: 1.6;
    font-style: italic;
}

/* ─── FieldTooltip ─── */
.phmod-field-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.phmod-field-tooltip__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 4px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--phmod-color-text-muted, #94a3b8);
    border-radius: 50%;
    vertical-align: middle;
    transition: color 0.15s ease;
}

.phmod-field-tooltip__trigger:hover,
.phmod-field-tooltip__trigger:focus-visible {
    color: var(--phmod-brand-primary, #2563eb);
}

.phmod-field-tooltip__trigger:focus-visible {
    outline: 2px solid var(--phmod-brand-primary, #2563eb);
    outline-offset: 2px;
}

.phmod-field-tooltip__trigger svg {
    width: 14px;
    height: 14px;
    display: block;
}

.phmod-field-tooltip__popover {
    display: none;
    position: absolute;
    z-index: 1000;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: 320px;
    padding: 0.625rem 0.75rem;
    background: var(--phmod-color-surface, #ffffff);
    border: 1px solid var(--phmod-color-border, #e2e8f0);
    border-radius: var(--phmod-radius, 8px);
    box-shadow: var(--phmod-shadow-md, 0 4px 12px rgba(0, 0, 0, 0.12));
    font-size: var(--phmod-text-sm, 0.8125rem);
    line-height: 1.5;
    color: var(--phmod-color-text, #1e293b);
    font-weight: 400;
    font-style: normal;
    text-align: left;
}

.phmod-field-tooltip__popover--visible {
    display: block;
}

/* Arrow */
.phmod-field-tooltip__popover::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--phmod-color-surface, #ffffff);
}

.phmod-field-tooltip__popover::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 7px solid transparent;
    border-top-color: var(--phmod-color-border, #e2e8f0);
}

/* Bottom placement */
.phmod-field-tooltip__popover--bottom {
    bottom: auto;
    top: calc(100% + 8px);
}

.phmod-field-tooltip__popover--bottom::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--phmod-color-surface, #ffffff);
}

.phmod-field-tooltip__popover--bottom::before {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--phmod-color-border, #e2e8f0);
}

/* ─── WorkflowPrompt ─── */
.phmod-workflow-prompt {
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    background: color-mix(in srgb, var(--phmod-brand-primary, #2563eb) 4%, white);
    border: 1px solid color-mix(in srgb, var(--phmod-brand-primary, #2563eb) 15%, white);
    border-left: 3px solid var(--phmod-brand-primary, #2563eb);
    border-radius: var(--phmod-radius, 8px);
}

.phmod-workflow-prompt__heading {
    font-size: var(--phmod-text-base, 0.875rem);
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--phmod-color-text, #1e293b);
}

.phmod-workflow-prompt__body {
    font-size: var(--phmod-text-sm, 0.8125rem);
    color: var(--phmod-color-text-muted, #475569);
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

.phmod-workflow-prompt__body:last-child {
    margin-bottom: 0;
}

.phmod-workflow-prompt__actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ─── Mobile ─── */
@media (max-width: 767px) {
    .phmod-page-intro {
        flex-direction: column;
        gap: 0.5rem;
    }

    .phmod-page-intro__dismiss {
        align-self: flex-end;
        margin-top: -2rem;
    }

    .phmod-field-tooltip__popover {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        transform: none;
        max-width: none;
        width: 100%;
        border-radius: var(--phmod-radius-lg, 12px) var(--phmod-radius-lg, 12px) 0 0;
        padding: 1rem;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .phmod-field-tooltip__popover::after,
    .phmod-field-tooltip__popover::before {
        display: none;
    }
}

/* ─── Glossary Trigger ─── */
.phmod-glossary-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background: transparent;
    border: 1px solid var(--phmod-color-border, #e2e8f0);
    border-radius: var(--phmod-radius, 8px);
    color: var(--phmod-color-text-muted, #475569);
    font-size: var(--phmod-text-sm, 0.8125rem);
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    line-height: 1;
    white-space: nowrap;
}

.phmod-glossary-trigger:hover,
.phmod-glossary-trigger:focus-visible {
    color: var(--phmod-brand-primary, #2563eb);
    border-color: var(--phmod-brand-primary, #2563eb);
    background: color-mix(in srgb, var(--phmod-brand-primary, #2563eb) 4%, transparent);
}

.phmod-glossary-trigger:focus-visible {
    outline: 2px solid var(--phmod-brand-primary, #2563eb);
    outline-offset: 2px;
}

/* ─── Glossary Backdrop ─── */
.phmod-glossary-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.3);
    animation: phmod-glossary-fade-in 0.2s ease;
}

@keyframes phmod-glossary-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ─── Glossary Panel ─── */
.phmod-glossary-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    width: 360px;
    max-width: 100%;
    background: var(--phmod-color-surface, #ffffff);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.phmod-glossary-panel--open {
    transform: translateX(0);
}

.phmod-glossary-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--phmod-color-border, #e2e8f0);
    flex-shrink: 0;
}

.phmod-glossary-panel__title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--phmod-color-text, #1e293b);
    margin: 0;
}

.phmod-glossary-panel__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--phmod-color-text-muted, #475569);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.phmod-glossary-panel__close:hover,
.phmod-glossary-panel__close:focus-visible {
    background: rgba(0, 0, 0, 0.06);
    color: var(--phmod-color-text, #1e293b);
}

.phmod-glossary-panel__close:focus-visible {
    outline: 2px solid var(--phmod-brand-primary, #2563eb);
    outline-offset: 2px;
}

/* ─── Glossary Search ─── */
.phmod-glossary-panel__search-wrap {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--phmod-color-border, #e2e8f0);
    flex-shrink: 0;
}

.phmod-glossary__search {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--phmod-color-border, #e2e8f0);
    border-radius: var(--phmod-radius, 8px);
    font-size: var(--phmod-text-sm, 0.8125rem);
    color: var(--phmod-color-text, #1e293b);
    background: var(--phmod-color-surface, #ffffff);
    outline: none;
    transition: border-color 0.15s ease;
}

.phmod-glossary__search::placeholder {
    color: var(--phmod-color-text-muted, #94a3b8);
}

.phmod-glossary__search:focus {
    border-color: var(--phmod-brand-primary, #2563eb);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--phmod-brand-primary, #2563eb) 20%, transparent);
}

/* ─── Glossary Body ─── */
.phmod-glossary-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1.25rem 1.5rem;
    -webkit-overflow-scrolling: touch;
}

/* ─── Glossary Term ─── */
.phmod-glossary__term {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--phmod-color-border-light, #f1f5f9);
}

.phmod-glossary__term:last-child {
    border-bottom: none;
}

.phmod-glossary__term-name {
    font-size: var(--phmod-text-base, 0.875rem);
    font-weight: 600;
    color: var(--phmod-color-text, #1e293b);
    margin-bottom: 0.25rem;
}

.phmod-glossary__term-def {
    font-size: var(--phmod-text-sm, 0.8125rem);
    color: var(--phmod-color-text-muted, #475569);
    line-height: 1.6;
    margin: 0;
}

.phmod-glossary__empty {
    font-size: var(--phmod-text-sm, 0.8125rem);
    color: var(--phmod-color-text-muted, #94a3b8);
    font-style: italic;
    text-align: center;
    padding: 2rem 0;
    margin: 0;
}

/* ─── Glossary Mobile ─── */
@media (max-width: 767px) {
    .phmod-glossary-panel {
        width: 100%;
    }
}

/* ─── FirstTimeOrientation ─── */
.phmod-orientation-overlay {
    position: fixed;
    inset: 0;
    z-index: 100010;
    overflow: auto;
}

.phmod-orientation-step {
    width: 340px;
    max-width: calc(100vw - 2rem);
    background: var(--phmod-color-surface, #ffffff);
    border-radius: var(--phmod-radius-lg, 12px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    padding: 1.25rem;
    outline: none;
    animation: phmod-orientation-pop 0.2s ease;
}

@keyframes phmod-orientation-pop {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.phmod-orientation-step__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.phmod-orientation-step__counter {
    font-size: var(--phmod-text-xs, 0.6875rem);
    font-weight: 600;
    color: var(--phmod-brand-primary, #2563eb);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.phmod-orientation-step__skip {
    background: none;
    border: none;
    font-size: var(--phmod-text-xs, 0.6875rem);
    color: var(--phmod-color-text-muted, #94a3b8);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.phmod-orientation-step__skip:hover {
    color: var(--phmod-color-text, #1e293b);
    background: rgba(0, 0, 0, 0.04);
}

.phmod-orientation-step__title {
    font-size: var(--phmod-text-md, 1rem);
    font-weight: 600;
    color: var(--phmod-color-text, #1e293b);
    margin: 0 0 0.375rem;
}

.phmod-orientation-step__body {
    font-size: var(--phmod-text-sm, 0.8125rem);
    color: var(--phmod-color-text-muted, #475569);
    line-height: 1.6;
    margin: 0 0 1rem;
}

.phmod-orientation-step__nav {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.phmod-orientation-replay {
    background: none;
    border: none;
    color: var(--phmod-brand-primary, #2563eb);
    font-size: var(--phmod-text-sm, 0.8125rem);
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}

.phmod-orientation-replay:hover {
    text-decoration-style: solid;
}

/* ─── Orientation Mobile ─── */
@media (max-width: 767px) {
    .phmod-orientation-step {
        position: fixed !important;
        bottom: 1rem !important;
        left: 1rem !important;
        right: 1rem !important;
        top: auto !important;
        transform: none !important;
        width: auto;
        max-width: none;
    }
}

/* ─── Print ─── */
@media print {
    .phmod-field-tooltip__trigger,
    .phmod-field-tooltip__popover,
    .phmod-page-intro__dismiss,
    .phmod-workflow-prompt__actions,
    .phmod-glossary-trigger,
    .phmod-glossary-panel,
    .phmod-glossary-backdrop,
    .phmod-orientation-overlay {
        display: none !important;
    }

    .phmod-page-intro {
        border: none;
        padding: 0;
        margin-bottom: 0.5rem;
        background: none;
    }
}
