/**
 * Popup/Dialog System Styles for rpg.actor
 * 
 * Design philosophy:
 * - Brown/parchment theme consistent with RPG aesthetic
 * - Semantic colors ONLY where meaning is important (toast types)
 * - Buttons use simple filled/outlined pattern for hierarchy
 * - Square corners, clean and readable
 */

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */

.popup-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    max-width: 90vw;
    text-align: center;
    /* Default: neutral brown */
    background: var(--ink, #2c2416);
    color: var(--parchment, #f4f1e8);
    border-left: 4px solid var(--ink-light, #5c4a2e);
}

.popup-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Semantic toast colors - left border accent only */
.popup-toast-info {
    border-left-color: #4a7c9b;
}

.popup-toast-success {
    border-left-color: #3d7a4a;
}

.popup-toast-warning {
    border-left-color: #b8860b;
}

.popup-toast-error {
    border-left-color: #9b3d3d;
}

/* ============================================
   MODAL OVERLAY
   ============================================ */

.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.popup-overlay.show {
    opacity: 1;
}

/* ============================================
   MODAL BOX
   ============================================ */

.popup-modal {
    background: var(--parchment, #f4f1e8);
    border: 2px solid var(--ink, #2c2416);
    min-width: 300px;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.popup-overlay.show .popup-modal {
    transform: scale(1);
}

.popup-modal-header {
    background: var(--ink, #2c2416);
    color: var(--parchment, #f4f1e8);
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 1rem;
}

.popup-modal-body {
    padding: 1.25rem 1rem;
    color: var(--ink, #2c2416);
    font-size: 0.95rem;
    line-height: 1.5;
}

.popup-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(44, 36, 22, 0.15);
}

/* ============================================
   BUTTONS
   
   Hierarchy:
   - Primary (confirm/submit): filled ink, stands out
   - Secondary (cancel/dismiss): outlined, subdued
   ============================================ */

.popup-btn {
    font-family: inherit;
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid var(--ink, #2c2416);
    background: transparent;
    color: var(--ink, #2c2416);
}

.popup-btn:hover {
    background: rgba(44, 36, 22, 0.1);
}

.popup-btn:active {
    background: rgba(44, 36, 22, 0.2);
}

.popup-btn:focus {
    outline: 2px solid var(--ink, #2c2416);
    outline-offset: 2px;
}

/* Primary action - filled, prominent */
.popup-btn-confirm,
.popup-btn-success {
    background: var(--ink, #2c2416);
    color: var(--parchment, #f4f1e8);
    border-color: var(--ink, #2c2416);
}

.popup-btn-confirm:hover,
.popup-btn-success:hover {
    background: var(--ink-light, #5c4a2e);
    border-color: var(--ink-light, #5c4a2e);
}

/* Secondary/cancel - outlined, neutral */
.popup-btn-cancel {
    background: transparent;
    color: var(--ink, #2c2416);
    border-color: var(--ink-light, #5c4a2e);
}

.popup-btn-cancel:hover {
    background: rgba(44, 36, 22, 0.08);
}

/* Danger action - for destructive operations */
.popup-btn-danger,
.popup-btn-error {
    background: #8b3a3a;
    color: var(--parchment, #f4f1e8);
    border-color: #8b3a3a;
}

.popup-btn-danger:hover,
.popup-btn-error:hover {
    background: #a04545;
    border-color: #a04545;
}

/* Info/neutral - outlined */
.popup-btn-info {
    background: transparent;
    color: var(--ink, #2c2416);
    border-color: var(--ink, #2c2416);
}

.popup-btn-info:hover {
    background: rgba(44, 36, 22, 0.1);
}

/* Warning - for cautionary actions */
.popup-btn-warning {
    background: #8b7355;
    color: var(--parchment, #f4f1e8);
    border-color: #8b7355;
}

.popup-btn-warning:hover {
    background: #9e846a;
    border-color: #9e846a;
}

/* ============================================
   MODAL TYPE VARIANTS
   Header accent for semantic meaning
   ============================================ */

.popup-modal-success .popup-modal-header {
    background: #3d5a45;
}

.popup-modal-error .popup-modal-header,
.popup-modal-danger .popup-modal-header {
    background: #5a3d3d;
}

.popup-modal-warning .popup-modal-header {
    background: #5a4d3d;
}

.popup-modal-info .popup-modal-header {
    background: #3d4d5a;
}

/* ============================================
   VALIDATION POPUP STYLES
   ============================================ */

.validate-modal {
    min-width: 350px;
    max-width: 450px;
}

.validate-form-group {
    margin-bottom: 1.25rem;
}

.validate-form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--ink, #2c2416);
}

.validate-form-group input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
    border: 1px solid var(--ink-light, #5c4a2e);
    background: var(--parchment, #f4f1e8);
    color: var(--ink, #2c2416);
    box-sizing: border-box;
}

.validate-form-group input[type="text"]:focus {
    outline: 2px solid var(--ink, #2c2416);
    outline-offset: 1px;
}

.validate-form-group .hint {
    font-size: 0.8rem;
    color: rgba(44, 36, 22, 0.7);
    margin-top: 0.3rem;
}

.validate-divider {
    border-top: 1px solid rgba(44, 36, 22, 0.15);
    margin: 1rem 0;
}

.validate-scope-option {
    display: block;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--ink-light, #5c4a2e);
    cursor: pointer;
    transition: background 0.15s ease;
}

.validate-scope-option:hover {
    background: rgba(44, 36, 22, 0.05);
}

.validate-scope-option input[type="radio"] {
    margin-right: 0.5rem;
    accent-color: var(--ink, #2c2416);
}

.validate-scope-option .scope-label {
    font-weight: 600;
    color: var(--ink, #2c2416);
}

.validate-scope-option .scope-desc {
    display: block;
    font-size: 0.85rem;
    color: rgba(44, 36, 22, 0.7);
    margin-top: 0.25rem;
    margin-left: 1.5rem;
}

.validate-scope-option.selected {
    background: rgba(44, 36, 22, 0.08);
    border-color: var(--ink, #2c2416);
}

/* Custom Confidence field selector */
.custom-fields-container {
    display: none;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(44, 36, 22, 0.03);
    border: 1px solid rgba(44, 36, 22, 0.15);
}

.custom-fields-container.show {
    display: block;
}

.custom-fields-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink, #2c2416);
    margin-bottom: 0.5rem;
}

.custom-fields-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.field-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-family: inherit;
    background: transparent;
    border: 1px solid var(--ink-light, #5c4a2e);
    color: var(--ink, #2c2416);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.field-chip:hover {
    background: rgba(44, 36, 22, 0.08);
}

.field-chip.selected {
    background: var(--ink, #2c2416);
    color: var(--parchment, #f4f1e8);
    border-color: var(--ink, #2c2416);
}

.field-chip input[type="checkbox"] {
    display: none;
}

/* Your validation display - now just a simple button */
.change-validation-btn {
    padding: 0.25rem 0.75rem !important;
    font-size: 0.8rem !important;
}

/* Master footer styles */
.master-footer {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    border-top: 1px solid rgba(44, 36, 22, 0.15);
    background: transparent;
}

.master-footer.master-none {
    color: rgba(44, 36, 22, 0.5);
    font-style: italic;
}

.master-footer.master-valid {
    color: var(--ink, #2c2416);
}

.master-footer strong {
    font-weight: 600;
}

.master-footer .master-link {
    color: var(--ink, #2c2416);
    text-decoration: none;
}

.master-footer .master-link:hover {
    text-decoration: underline;
}

.master-footer .master-link.master-outdated {
    color: #8b6914;
}

.master-footer .outdated-note {
    font-size: 0.8rem;
    color: #8b6914;
    font-style: italic;
}

/* ============================================
   WIDGET MODAL
   ============================================ */

.widget-modal {
    max-width: 520px;
    min-width: 340px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 92vh;
    transition: max-width .3s ease, min-width .3s ease;
}

.widget-modal.widget-minimized {
    max-width: 340px;
    min-width: 280px;
}

.widget-modal-body {
    padding: 1rem 1.25rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.widget-system-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.82rem;
    color: var(--ink-light, #5c4a2e);
}

.widget-system-selector label {
    font-weight: 600;
    white-space: nowrap;
}

.widget-system-selector select {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid rgba(44, 36, 22, 0.25);
    border-radius: 4px;
    background: var(--parchment, #f4f1e8);
    color: var(--ink, #2c2416);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
}

/* -- Widget stage (contains the zoomed widget) -- */
.widget-stage {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 360px;
    padding: 0.5rem 0;
    overflow: visible;
    transition: min-height .3s ease;
}

.widget-minimized .widget-stage {
    min-height: 220px;
}

.widget-stage rpg-actor-widget {
    display: block;
}

/* -- Speech / Bluesky toggle section -- */
.widget-speech-section {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(44, 36, 22, 0.15);
}

.widget-speech-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--ink-light, #5c4a2e);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.widget-speech-toggle input[type="checkbox"] {
    accent-color: var(--ink, #2c2416);
    width: 15px;
    height: 15px;
    cursor: pointer;
    flex-shrink: 0;
}

.widget-custom-phrases {
    margin-top: 0.5rem;
}

.widget-phrases-label {
    display: block;
    font-size: 0.78rem;
    color: var(--ink-light, #5c4a2e);
    margin-bottom: 0.3rem;
}

.widget-phrases-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.4rem 0.5rem;
    border: 1px solid rgba(44, 36, 22, 0.25);
    border-radius: 4px;
    background: var(--parchment, #f4f1e8);
    color: var(--ink, #2c2416);
    font-family: inherit;
    font-size: 0.78rem;
    line-height: 1.4;
    resize: vertical;
    max-height: 8rem;
}

.widget-phrases-input::placeholder {
    color: var(--ink-light, #5c4a2e);
    opacity: 0.5;
}

/* -- Embed code section -- */
.widget-embed-section {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(44, 36, 22, 0.15);
}

.widget-embed-label {
    font-size: 0.8rem;
    color: var(--ink-light, #5c4a2e);
    margin: 0 0 0.4rem;
}

.widget-embed-code {
    background: var(--ink, #2c2416);
    color: var(--parchment, #f4f1e8);
    font-family: 'Courier New', monospace;
    font-size: 0.68rem;
    line-height: 1.5;
    padding: 0.5rem 0.6rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0 0 0.5rem;
    border: 1px solid var(--ink-light, #5c4a2e);
    border-radius: 3px;
    max-height: 6rem;
}

.widget-copy-btn {
    width: 100%;
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
}

/* ============================================
   WIDGET MODAL — MOBILE
   ============================================ */

@media (max-width: 600px) {
    /* Full-screen takeover on mobile */
    .widget-modal {
        max-width: 100vw;
        min-width: 0;
        width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        height: 100vh;
        height: 100dvh;
        border: none;
    }

    .popup-overlay:has(.widget-modal) {
        align-items: stretch;
    }

    .widget-modal.widget-minimized {
        max-width: 100vw;
        min-width: 0;
    }

    .widget-modal-body {
        padding: 0.75rem;
    }

    /* Smaller widget stage on mobile */
    .widget-stage {
        min-height: 280px;
    }

    .widget-minimized .widget-stage {
        min-height: 200px;
    }

    /* Stack selectors vertically on narrow screens */
    .widget-system-selector {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .widget-system-selector select {
        width: 100%;
    }

    .widget-embed-code {
        font-size: 0.62rem;
    }

    .widget-phrases-input {
        font-size: 0.82rem; /* easier to type on mobile */
    }

    /* Sticky close button at bottom so it's always reachable */
    .widget-modal .popup-modal-actions {
        position: sticky;
        bottom: 0;
        background: var(--parchment, #f4f1e8);
        z-index: 2;
    }
}

@media (max-width: 380px) {
    .widget-stage {
        min-height: 240px;
    }

    .widget-stage rpg-actor-widget {
        zoom: 0.85;
    }

    .widget-embed-code {
        font-size: 0.58rem;
    }
}

/* ============================================
   WELCOME POPUP (new-user first visit)
   ============================================ */

.welcome-popup {
    max-width: 420px;
    text-align: center;
}

.welcome-popup-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem 1.25rem !important;
}

.welcome-sprite-container {
    width: 96px;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-great {
    font-size: 1.2rem;
    margin: 0;
    color: var(--ink, #2c2416);
}

.welcome-great strong {
    color: var(--accent, #8b5e3c);
}

.welcome-explain {
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--ink-light, #5c4a2e);
    margin: 0;
    text-align: center;
    max-width: 340px;
}

.welcome-explain a {
    color: var(--accent, #8b5e3c);
    text-decoration: underline;
}

.welcome-actions {
    display: flex;
    justify-content: center !important;
    gap: 0.75rem;
    width: 100%;
    padding-top: 0.5rem;
    border-top: none !important;
}

.welcome-enter-btn {
    flex: 1;
    max-width: 150px;
}

.welcome-roll-btn {
    flex: 1;
    max-width: 150px;
    border: 3px solid var(--accent, #8b5e3c) !important;
}

/* ============================================
   AVATAR CROP POPUP
   ============================================ */

.avatar-crop-modal {
    max-width: 580px;
}

.avatar-crop-body {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
}

.avatar-crop-container {
    position: relative;
    cursor: crosshair;
    flex-shrink: 0;
    border: 1px solid var(--ink-light, #5c4a2e);
}

.avatar-crop-canvas {
    display: block;
}

.avatar-crop-region {
    position: absolute;
    cursor: move;
    box-sizing: border-box;
    /* Resize handle visual hint - bottom-right corner */
}

.avatar-crop-region::after {
    content: '';
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    border-right: 3px solid #fff;
    border-bottom: 3px solid #fff;
    cursor: nwse-resize;
    pointer-events: none;
}

.avatar-crop-preview-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.avatar-crop-label {
    font-size: 0.8rem;
    color: var(--ink-light, #5c4a2e);
    font-weight: 600;
}

.avatar-crop-preview {
    width: 64px;
    height: 64px;
    border: 2px solid var(--ink, #2c2416);
    image-rendering: auto;
}
