/**
 * Starlog - Sci-Fi Chat Widget
 */

.starlog-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 340px;
    height: calc(100vh - 40px);
    max-height: calc(100vh - 40px);
    background: linear-gradient(135deg, 
        rgba(8, 12, 20, 0.98) 0%,
        rgba(15, 25, 40, 0.98) 50%,
        rgba(10, 18, 30, 0.98) 100%
    );
    border: 1px solid rgba(80, 200, 255, 0.3);
    border-radius: 4px;
    box-shadow: 
        0 0 40px rgba(80, 200, 255, 0.1),
        inset 0 0 60px rgba(80, 200, 255, 0.03),
        0 20px 60px rgba(0, 0, 0, 0.5);
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.starlog-widget::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0,
        transparent 2px,
        rgba(80, 200, 255, 0.01) 2px,
        rgba(80, 200, 255, 0.01) 4px
    );
    pointer-events: none;
    z-index: 100;
}

.starlog-widget::after {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px solid rgba(80, 200, 255, 0.1);
    border-radius: 2px;
    pointer-events: none;
    z-index: 100;
}

/* ============================================
   Starlog Info Overlay - Sol Alt
   ============================================ */
.starlog-info {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 999998;
    font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    font-size: 9px;
    letter-spacing: 0.5px;
    line-height: 1.6;
    color: rgba(80, 200, 255, 0.35);
    text-transform: uppercase;
    pointer-events: none;
    user-select: none;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.starlog-info:hover {
    opacity: 1;
    pointer-events: auto;
}

.starlog-info-line {
    white-space: nowrap;
}

.starlog-info span {
    color: rgba(80, 200, 255, 0.5);
}

/* Signal pulse */
#starlog-signal {
    animation: signal-pulse 2s ease-in-out infinite;
}

@keyframes signal-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; color: rgba(100, 255, 150, 0.7); }
}

/* Glitch effect on hover */
.starlog-info:hover .starlog-info-line {
    animation: info-glitch 0.1s ease;
}

@keyframes info-glitch {
    0% { transform: translateX(0); }
    25% { transform: translateX(-1px); }
    50% { transform: translateX(1px); }
    75% { transform: translateX(-1px); }
    100% { transform: translateX(0); }
}

/* HEADER */
.starlog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(90deg, 
        rgba(80, 200, 255, 0.1) 0%,
        transparent 50%,
        rgba(80, 200, 255, 0.1) 100%
    );
    border-bottom: 1px solid rgba(80, 200, 255, 0.2);
    position: relative;
    flex-shrink: 0;
    z-index: 10;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

.starlog-header:hover {
    background: linear-gradient(90deg, 
        rgba(80, 200, 255, 0.15) 0%,
        rgba(80, 200, 255, 0.05) 50%,
        rgba(80, 200, 255, 0.15) 100%
    );
}

.starlog-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 3px;
    color: rgba(80, 200, 255, 0.9);
    text-transform: uppercase;
}

.starlog-icon {
    font-size: 14px;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { 
        opacity: 0.6;
        text-shadow: 0 0 5px rgba(80, 200, 255, 0.5);
    }
    50% { 
        opacity: 1;
        text-shadow: 0 0 15px rgba(80, 200, 255, 0.8);
    }
}

.starlog-status {
    width: 6px;
    height: 6px;
    background: #0f0;
    border-radius: 50%;
    animation: status-blink 1.5s ease-in-out infinite;
    box-shadow: 0 0 8px #0f0;
}

@keyframes status-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.starlog-toggle {
    background: none;
    border: 1px solid rgba(80, 200, 255, 0.3);
    color: rgba(80, 200, 255, 0.7);
    width: 24px;
    height: 24px;
    border-radius: 2px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.starlog-toggle:hover {
    background: rgba(80, 200, 255, 0.1);
    border-color: rgba(80, 200, 255, 0.5);
    color: rgba(80, 200, 255, 1);
}

/* Minimized */
.starlog-widget.minimized .starlog-body {
    display: none;
}

.starlog-widget.minimized {
    height: auto;
    max-height: none;
}

.starlog-widget.minimized .starlog-toggle {
    transform: rotate(90deg);
}

/* MESSAGES */
.starlog-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    z-index: 5;
}

.starlog-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(80, 200, 255, 0.3) transparent;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.starlog-messages::-webkit-scrollbar {
    width: 6px;
}

.starlog-messages::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.starlog-messages::-webkit-scrollbar-thumb {
    background: rgba(80, 200, 255, 0.4);
    border-radius: 3px;
}

.starlog-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(80, 200, 255, 0.6);
}

/* Message item - border color set by JS */
.starlog-message {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border-left: 2px solid #666;
    border-radius: 0 4px 4px 0;
    animation: message-fade-in 0.3s ease;
    position: relative;
}

@keyframes message-fade-in {
    from {
        opacity: 0;
        transform: translateX(10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.starlog-message:hover {
    background: rgba(255, 255, 255, 0.04);
}

.starlog-message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

/* Callsign color set by JS */
.starlog-callsign {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.starlog-time {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.3);
    letter-spacing: 1px;
}

.starlog-message-text {
    font-size: 12px;
    line-height: 1.5;
    color: rgba(200, 220, 240, 0.85);
    word-wrap: break-word;
}

/* System messages - gray, italic */
.starlog-message--system {
    background: rgba(100, 100, 100, 0.05);
    font-style: italic;
}

.starlog-message--system:hover {
    background: rgba(100, 100, 100, 0.08);
}

.starlog-message--system .starlog-message-text {
    color: rgba(180, 180, 180, 0.7);
}

/* Empty */
.starlog-empty {
    text-align: center;
    padding: 30px;
    color: rgba(80, 200, 255, 0.4);
    font-size: 11px;
    letter-spacing: 2px;
}

/* INPUT */
.starlog-input-area {
    padding: 12px;
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(80, 200, 255, 0.15);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.starlog-input-wrapper {
    position: relative;
}

#starlog-input {
    width: 100%;
    background: rgba(8, 15, 25, 0.95);
    border: 1px solid rgba(80, 200, 255, 0.3);
    border-radius: 4px;
    padding: 12px 50px 28px 14px;
    color: rgba(200, 220, 240, 0.9);
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
    font-size: 12px;
    line-height: 1.4;
    resize: none;
    transition: border-color 0.3s ease, background 0.3s ease;
    box-sizing: border-box;
    min-height: 80px;
    -webkit-appearance: none;
}

#starlog-input:focus {
    outline: none;
    border-color: rgba(80, 200, 255, 0.5);
    background: rgba(10, 20, 35, 0.98);
    box-shadow: 0 0 20px rgba(80, 200, 255, 0.1);
}

#starlog-input::placeholder {
    color: rgba(80, 200, 255, 0.3);
    font-style: italic;
}

.starlog-char-count {
    position: absolute;
    bottom: 8px;
    left: 14px;
    font-size: 9px;
    color: rgba(80, 200, 255, 0.4);
    letter-spacing: 1px;
    z-index: 5;
}

/* Send Button */
#starlog-send {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    background: linear-gradient(180deg, rgba(80, 200, 255, 0.2) 0%, rgba(80, 200, 255, 0.1) 100%);
    border: 1px solid rgba(80, 200, 255, 0.4);
    border-radius: 4px;
    color: rgba(80, 200, 255, 0.9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    z-index: 5;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: bold;
}

#starlog-send::before {
    content: '↵';
}

#starlog-send:hover:not(:disabled) {
    background: linear-gradient(180deg, rgba(80, 200, 255, 0.35) 0%, rgba(80, 200, 255, 0.2) 100%);
    border-color: rgba(80, 200, 255, 0.7);
    color: #50c8ff;
    box-shadow: 0 0 15px rgba(80, 200, 255, 0.3);
    transform: scale(1.05);
}

#starlog-send:active:not(:disabled) {
    transform: scale(0.95);
}

#starlog-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#starlog-send.sending::before {
    content: '◎';
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Error */
.starlog-error {
    padding: 8px 12px;
    margin-bottom: 10px;
    background: rgba(255, 80, 80, 0.15);
    border: 1px solid rgba(255, 80, 80, 0.4);
    border-radius: 4px;
    color: rgba(255, 150, 150, 0.95);
    font-size: 10px;
    text-align: center;
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* ============================================
   Mobile Backdrop Overlay
   ============================================ */
.starlog-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 999990;
    touch-action: none;
}

.starlog-backdrop.active {
    display: block;
}

/* ============================================
   RESPONSIVE - TABLET
   ============================================ */
@media (max-width: 768px) {
    .starlog-widget {
        right: 10px;
        bottom: 10px;
        width: 300px;
        height: 60vh;
        max-height: 60vh;
    }
    
    .starlog-info {
        left: 10px;
        bottom: 10px;
        font-size: 8px;
    }
}

/* ============================================
   RESPONSIVE - MOBILE (Tam Ekran)
   ============================================ */
@media (max-width: 480px) {
    /* Widget - minimized durumda alt kısımda */
    .starlog-widget.minimized {
        position: fixed;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        border-radius: 16px 16px 0 0;
        border: 1px solid rgba(80, 200, 255, 0.3);
        border-bottom: none;
        z-index: 999999;
    }
    
    /* Widget - açık durumda tam ekran */
    .starlog-widget:not(.minimized) {
        position: fixed;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        border: none !important;
        z-index: 999999;
    }
    
    /* Body tam ekranı kaplasın */
    .starlog-widget:not(.minimized) .starlog-body {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    /* Messages scroll alanı */
    .starlog-widget:not(.minimized) .starlog-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
    }
    
    /* Input alanı sabit kalmalı */
    .starlog-widget:not(.minimized) .starlog-input-area {
        flex-shrink: 0;
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 20px));
    }
    
    #starlog-input {
        font-size: 16px !important; /* iOS zoom engelle */
        min-height: 70px;
    }
    
    /* Header mobilde biraz daha büyük touch area */
    .starlog-header {
        padding: 16px;
        min-height: 56px;
    }
    
    /* Toggle butonu daha büyük */
    .starlog-toggle {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    /* Info overlay mobilde gizle açıkken */
    .starlog-info {
        display: none;
    }
}

/* ============================================
   Body scroll lock when chat is open on mobile
   ============================================ */
body.starlog-open {
    overflow: hidden !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    touch-action: none !important;
}

/* Hide everything else when chat is open */
body.starlog-open > *:not(.starlog-widget):not(.starlog-backdrop) {
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Ensure widget stays visible */
body.starlog-open .starlog-widget {
    visibility: visible !important;
    pointer-events: auto !important;
}

body.starlog-open .starlog-backdrop {
    visibility: visible !important;
}
