/**
 * DGtalQr Futuristic Smart Writer & AI Copilot CSS
 * Next-Generation Real-Time Ghost Text, Predictive Autocomplete & Grammar Linter
 */

/* ==========================================================================
   1. GHOST TEXT OVERLAY LAYER (PIXEL-PERFECT CARET CONTINUATION)
   ========================================================================== */
.sw-ghost-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    pointer-events: none !important;
    background: transparent !important;
    color: transparent !important;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    overflow: hidden !important;
    z-index: 2147483646 !important;
    box-sizing: border-box !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    margin: 0 !important;
    border-color: transparent !important;
}

.sw-ghost-overlay.active {
    display: block !important;
}

.sw-ghost-completion {
    color: #94a3b8 !important;
    opacity: 0.85;
    font-weight: 400;
    font-style: italic;
    background: linear-gradient(90deg, #94a3b8 0%, #cbd5e1 50%, #94a3b8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    animation: sw-shimmer 3s ease-in-out infinite;
    display: inline;
}

@keyframes sw-shimmer {
    0%, 100% { opacity: 0.75; }
    50% { opacity: 0.95; }
}

.sw-ghost-tab-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-style: normal;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 1px 6px;
    margin-left: 6px;
    border-radius: 4px;
    background: rgba(15, 23, 42, 0.08);
    color: #64748b;
    border: 1px solid rgba(148, 163, 184, 0.3);
    vertical-align: middle;
}

/* ==========================================================================
   2. FLOATING COPILOT SUGGESTION PILL BAR (DOCKABLE & NON-INTRUSIVE)
   ========================================================================== */
.sw-copilot-pillbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2147483647;
    align-items: center;
    gap: 6px;
    height: 28px;
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4), 0 0 14px rgba(14, 165, 233, 0.25);
    border-radius: 9999px;
    padding: 0 8px 0 6px;
    opacity: 1;
    visibility: visible;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 95vw;
    box-sizing: border-box;
    pointer-events: auto;
}

.sw-copilot-pillbar.active {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.sw-copilot-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 9px;
    box-shadow: 0 0 6px rgba(6, 182, 212, 0.5);
    flex-shrink: 0;
}

.sw-copilot-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 19px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #f1f5f9;
    font-size: 11px;
    font-weight: 500;
    padding: 0 7px;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    line-height: 1;
}

.sw-copilot-chip:hover {
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.25) 0%, rgba(59, 130, 246, 0.25) 100%);
    border-color: rgba(6, 182, 212, 0.5);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(6, 182, 212, 0.25);
}

.sw-copilot-chip-idx {
    font-size: 9.5px;
    opacity: 0.6;
    background: rgba(255, 255, 255, 0.15);
    padding: 0 4px;
    border-radius: 4px;
    line-height: 1.2;
}

.sw-pillbar-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 14px;
    line-height: 1;
    padding: 0 3px;
    cursor: pointer;
    margin-left: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.15s ease;
}

.sw-pillbar-close:hover {
    color: #f87171;
}

.sw-copilot-sentence-chip {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(6, 182, 212, 0.2) 100%);
    border-color: rgba(16, 185, 129, 0.4);
    color: #6ee7b7;
    font-weight: 600;
}

.sw-copilot-sentence-chip:hover {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.35) 0%, rgba(6, 182, 212, 0.35) 100%);
    border-color: #10b981;
    color: #ffffff;
}

.sw-copilot-fix-chip {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.3) 0%, rgba(245, 158, 11, 0.3) 100%) !important;
    border: 1.5px solid #f59e0b !important;
    color: #fef08a !important;
    font-weight: 700 !important;
    animation: sw-pulse-fix 2s infinite;
}

.sw-copilot-fix-chip:hover {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.45) 0%, rgba(245, 158, 11, 0.45) 100%) !important;
    border-color: #fbbf24 !important;
    color: #ffffff !important;
    transform: translateY(-1px);
}

@keyframes sw-pulse-fix {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
    50% { box-shadow: 0 0 10px rgba(245, 158, 11, 0.6); }
}

/* ==========================================================================
   3. FLOATING HUD WIDGET (SLEEK, NON-DISTURBING TOP-RIGHT DOCKED BADGE)
   ========================================================================== */
.sw-hud-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2147483647;
    flex-direction: column;
    align-items: flex-end;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    pointer-events: auto;
    box-sizing: border-box;
    transition: opacity 0.22s ease;
}

.sw-hud-container.active {
    display: flex !important;
}

/* While actively typing, dim the HUD trigger badge slightly so it never distracts the writer */
.sw-hud-container.sw-typing .sw-hud-pill {
    opacity: 0.35 !important;
}

/* Micro-Orb / Pill */
.sw-hud-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 8px;
    background: rgba(15, 23, 42, 0.78);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25), 0 0 10px rgba(6, 182, 212, 0.15);
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.22s ease;
    user-select: none;
    opacity: 0.75;
}

.sw-hud-pill:hover,
.sw-hud-drawer.open ~ .sw-hud-pill {
    opacity: 1;
    background: rgba(15, 23, 42, 0.95);
    border-color: rgba(6, 182, 212, 0.55);
    box-shadow: 0 6px 20px rgba(6, 182, 212, 0.35);
    transform: translateY(-1px);
}

.sw-hud-orb-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #38bdf8;
}

.sw-hud-dot {
    position: absolute;
    top: -3px;
    right: -4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 6px #10b981;
    animation: sw-pulse 2.2s infinite;
}

.sw-hud-dot.has-issues {
    background: #f59e0b;
    box-shadow: 0 0 6px #f59e0b;
}

@keyframes sw-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.6; }
}

.sw-hud-title {
    font-size: 11px;
    font-weight: 700;
    color: #e2e8f0;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.sw-hud-counter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.25);
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: #fca5a5;
    font-size: 9.5px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 9999px;
    line-height: 1.2;
}

.sw-hud-counter.clean {
    background: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.45);
    color: #6ee7b7;
}

/* Expanded HUD Drawer */
.sw-hud-drawer {
    position: absolute;
    right: 0;
    width: 310px;
    max-width: calc(100vw - 32px);
    background: rgba(15, 23, 42, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.55), 0 0 25px rgba(6, 182, 212, 0.2);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: #f8fafc;
    display: none;
    flex-direction: column;
    gap: 10px;
    z-index: 2147483647 !important;
}

.sw-hud-drawer.open {
    display: flex;
    animation: sw-hudFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes sw-hudFadeIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.sw-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

.sw-close-drawer-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #94a3b8;
    font-size: 16px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
}

.sw-close-drawer-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.4);
}

.sw-drawer-title {
    font-size: 12.5px;
    font-weight: 700;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sw-drawer-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    padding: 8px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    text-align: center;
}

.sw-stat-num {
    font-size: 14px;
    font-weight: 800;
    color: #38bdf8;
}

.sw-stat-label {
    font-size: 9.5px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.sw-fixall-btn {
    background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    color: #ffffff;
    border: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.35);
    transition: all 0.2s ease;
}

.sw-fixall-btn:hover {
    background: linear-gradient(135deg, #0891b2 0%, #2563eb 100%);
    box-shadow: 0 6px 16px rgba(6, 182, 212, 0.45);
    transform: translateY(-1px);
}

.sw-issues-list {
    max-height: 160px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sw-issue-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
}

.sw-issue-original {
    color: #f87171;
    text-decoration: line-through;
    margin-right: 4px;
}

.sw-issue-suggestion {
    color: #34d399;
    font-weight: 700;
}

.sw-issue-apply-btn {
    background: rgba(52, 211, 153, 0.2);
    border: 1px solid rgba(52, 211, 153, 0.4);
    color: #6ee7b7;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sw-issue-apply-btn:hover {
    background: #10b981;
    color: #ffffff;
}

@media (max-width: 640px) {
    .sw-hud-title {
        display: none;
    }
    .sw-hud-pill {
        padding: 0 6px;
        height: 26px;
    }
}

/* ==========================================================================
   4. INLINE GRAMMAR & SPELL CORRECTION POPOVER
   ========================================================================== */
.sw-correction-popover {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 2147483647;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.45), 0 0 20px rgba(56, 189, 248, 0.2);
    border-radius: 12px;
    padding: 10px 14px;
    color: #ffffff;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 12px;
    flex-direction: column;
    gap: 6px;
    min-width: 200px;
    max-width: 300px;
    box-sizing: border-box;
}

.sw-correction-popover.active {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.sw-popover-desc {
    font-size: 11px;
    color: #94a3b8;
    line-height: 1.4;
}

.sw-popover-replace-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

.sw-popover-replace-btn:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

.sw-popover-ignore-btn {
    background: none;
    border: none;
    color: #64748b;
    font-size: 10.5px;
    cursor: pointer;
    text-align: right;
    padding: 2px 0 0 0;
}

.sw-popover-ignore-btn:hover {
    color: #94a3b8;
    text-decoration: underline;
}

/* Underline Highlight in Rich or Plain Text */
.sw-grammar-error {
    text-decoration: underline wavy #f59e0b !important;
    text-underline-offset: 3px;
    cursor: pointer;
}

.sw-spell-error {
    text-decoration: underline wavy #ef4444 !important;
    text-underline-offset: 3px;
    cursor: pointer;
}

/* ==========================================================================
   5. MOBILE TAP-TO-COMPLETE FLOATING PILL
   ========================================================================== */
.sw-mobile-tab-btn {
    display: none !important;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(50px);
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    border: 1px solid rgba(6, 182, 212, 0.4);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35), 0 0 15px rgba(6, 182, 212, 0.3);
    color: #ffffff;
    padding: 8px 18px;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 700;
    align-items: center;
    gap: 8px;
    z-index: 2147483647 !important;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    max-width: 90vw;
}

.sw-mobile-tab-btn.visible {
    display: flex !important;
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}
