/* =========================================================
   Story Feature - Styles
   queermeet Stories (Instagram-artiges 24h Story Feature)
   ========================================================= */

/* ========== STORY BAR ========== */
.story-bar {
    margin-bottom: 15px;
    padding: 12px 0;
    background: var(--bg-primary);
    border-radius: 16px;
    border: 1px solid var(--border-light);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.story-bar-scroll {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 4px 16px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.story-bar-scroll::-webkit-scrollbar {
    display: none;
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    flex-shrink: 0;
    min-width: 68px;
}

.story-avatar-wrapper {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045, #833ab4);
    background-size: 300% 300%;
    animation: storyRingGradient 3s ease infinite;
    position: relative;
    transition: transform 0.2s ease;
}

.story-item:hover .story-avatar-wrapper {
    transform: scale(1.05);
}

@keyframes storyRingGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.story-avatar-wrapper.viewed {
    background: var(--border-medium);
    animation: none;
}

.story-avatar-wrapper.story-add {
    background: var(--primary-gradient);
    animation: none;
}

.story-avatar-wrapper.has-story {
    /* Gradient ring for unseen stories - already default */
}

.story-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--bg-primary);
    background-color: var(--bg-secondary);
}

.story-add-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-color, #667eea);
    color: white;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-primary);
    line-height: 1;
}

.story-username {
    font-size: 11px;
    color: var(--text-secondary);
    max-width: 68px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

/* Placeholder wenn keine Stories vorhanden */
.story-bar-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* ========== STORY EDITOR ========== */
.story-editor-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10001;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overscroll-behavior: none;
    touch-action: none;
    -webkit-overflow-scrolling: auto;
}

.story-editor-overlay.active {
    display: flex;
}

.story-editor-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}

.story-editor-header-left,
.story-editor-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.story-editor-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.story-editor-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

.story-editor-close {
    font-size: 22px;
}

.story-editor-undo,
.story-editor-redo {
    font-size: 18px;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.story-editor-undo:disabled,
.story-editor-redo:disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

.story-editor-canvas-container {
    position: relative;
    width: auto;
    max-width: min(400px, 100%);
    aspect-ratio: 9 / 16;
    max-height: 80vh;
    max-height: 80dvh;
    height: 80vh;
    height: 80dvh;
    overflow: hidden;
    border-radius: 12px;
    touch-action: none;
    margin: 0 auto;
}

.story-editor-canvas {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 12px;
}

/* Text-Input-Overlay im Editor */
.story-text-input-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 25%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 5;
}

.story-text-input-overlay.active {
    display: flex;
}

/* Text-Formatierungs-Leiste */
.story-text-format-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.story-format-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.story-format-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.story-format-btn.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: white;
}

.story-text-input {
    width: 80%;
    max-width: 320px;
    padding: 12px 16px;
    font-size: 22px;
    font-weight: 400;
    text-align: center;
    color: white;
    background: transparent;
    border: none;
    outline: none;
    caret-color: white;
}

.story-text-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

/* Crop-Overlay */
.story-crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    z-index: 6;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.story-crop-overlay.active {
    display: block;
}

.story-crop-dim {
    position: absolute;
    background: rgba(0, 0, 0, 0.55);
    pointer-events: none;
}

.story-crop-dim-top {
    top: 0;
    left: 0;
    right: 0;
}

.story-crop-dim-bottom {
    bottom: 0;
    left: 0;
    right: 0;
}

.story-crop-dim-left {
    left: 0;
    position: absolute;
}

.story-crop-dim-right {
    right: 0;
    position: absolute;
}

.story-crop-box {
    position: absolute;
    border: 2px solid white;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
    cursor: move;
    touch-action: none;
}

.story-crop-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(to right, rgba(255,255,255,0.2) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.2) 1px, transparent 1px);
    background-size: 33.33% 33.33%;
    pointer-events: none;
}

.story-crop-handle {
    position: absolute;
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    z-index: 2;
    touch-action: none;
}

.story-crop-handle-tl { top: -18px; left: -18px; cursor: nw-resize; }
.story-crop-handle-tr { top: -18px; right: -18px; cursor: ne-resize; }
.story-crop-handle-bl { bottom: -18px; left: -18px; cursor: sw-resize; }
.story-crop-handle-br { bottom: -18px; right: -18px; cursor: se-resize; }

/* Crop Aktions-Buttons (Speichern / Abbrechen) */
.story-crop-actions {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    z-index: 10;
}

.story-crop-save-btn {
    padding: 12px 28px;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    background: #34C759;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: background 0.15s ease, transform 0.1s ease;
}

.story-crop-save-btn:active {
    transform: scale(0.96);
    background: #2aa94b;
}

.story-crop-cancel-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background 0.15s ease, transform 0.1s ease;
}

.story-crop-cancel-btn:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.3);
}

/* Aktiver Crop-Button */
.story-editor-btn.active {
    background: rgba(255, 255, 255, 0.4);
    border: 2px solid white;
}

/* Farb-Auswahl im Editor */
.story-color-picker {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    gap: 8px;
    z-index: 10;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.story-color-picker.active {
    display: flex;
}

.story-color-option {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.story-color-option:hover,
.story-color-option.selected {
    transform: scale(1.15);
    border-color: white;
}

/* Privatsphäre-Toggle */
.story-visibility-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.story-visibility-toggle:hover {
    background: rgba(255, 255, 255, 0.35);
}

.story-visibility-icon {
    font-size: 16px;
}

/* Editor Footer / Posten-Button */
.story-editor-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    z-index: 10;
    background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
}

.story-post-btn {
    background: var(--primary-gradient, linear-gradient(135deg, #667eea 0%, #764ba2 100%));
    color: white;
    border: none;
    padding: 12px 28px;
    border-radius: 25px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.story-post-btn:hover {
    transform: scale(1.03);
}

.story-post-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Toolbar im Editor */
.story-editor-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Draggable Text-Elemente */
.story-text-element {
    position: absolute;
    padding: 6px 12px;
    font-weight: 400;
    line-height: 1.25;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    transition: outline 0.15s ease;
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 85%;
    text-align: center;
}

.story-text-element:hover {
    outline: 2px dashed rgba(255, 255, 255, 0.5);
}

.story-text-element.dragging {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    z-index: 100;
}

/* Resize-Handle: standardmäßig versteckt */
.story-text-resize-handle {
    display: none;
}

/* Nur auf Geräten mit Maus (Desktop) anzeigen */
@media (hover: hover) and (pointer: fine) {
    .story-text-resize-handle {
        display: block;
        position: absolute;
        right: -4px;
        bottom: -4px;
        width: 14px;
        height: 14px;
        cursor: nwse-resize;
        border-right: 2.5px solid rgba(255, 255, 255, 0.7);
        border-bottom: 2.5px solid rgba(255, 255, 255, 0.7);
        border-radius: 0 0 3px 0;
        opacity: 0;
        transition: opacity 0.15s ease;
        z-index: 10;
    }

    .story-text-element:hover .story-text-resize-handle {
        opacity: 1;
    }
}

/* ========== STORY VIEWER ========== */
.story-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.97);
    z-index: 10002;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overscroll-behavior: none;
    touch-action: pan-y;
}

.story-viewer-overlay.active {
    display: flex;
}

.story-viewer-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    aspect-ratio: 9 / 16;
    max-height: 90vh;
    overflow: hidden;
    border-radius: 12px;
    background: #000;
}

/* Progress Bars */
.story-progress-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 3px;
    padding: 8px 8px 0;
    z-index: 10;
}

.story-progress-bar {
    flex: 1;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

.story-progress-fill {
    height: 100%;
    background: white;
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
}

.story-progress-fill.completed {
    width: 100%;
}

/* Viewer Header */
.story-viewer-header {
    position: absolute;
    top: 14px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 10;
}

.story-viewer-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.story-viewer-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
}

.story-viewer-username {
    color: white;
    font-size: 14px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.story-viewer-time {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.story-viewer-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background 0.2s ease;
}

.story-viewer-close:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Story Bild im Viewer */
.story-viewer-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

/* Touch-Bereiche für Navigation */
.story-viewer-touch-left,
.story-viewer-touch-right {
    position: absolute;
    top: 60px;
    bottom: 0;
    width: 40%;
    z-index: 5;
    cursor: pointer;
}

.story-viewer-touch-left {
    left: 0;
}

.story-viewer-touch-right {
    right: 0;
    width: 60%;
}

/* Text-Overlay im Viewer */
.story-viewer-text-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 3;
}

.story-viewer-text-item {
    position: absolute;
    font-weight: 400;
    line-height: 1.25;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    white-space: pre-wrap;
    word-break: break-word;
    text-align: center;
    padding: 4px 10px;
    max-width: 85%;
}

/* Reaktions-Leiste */
.story-reactions-bar {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 24px;
    padding: 6px 10px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.story-reaction-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 16px;
    transition: background 0.15s ease, transform 0.15s ease;
    display: flex;
    align-items: center;
    gap: 3px;
    line-height: 1;
}

.story-reaction-btn span {
    font-size: 12px;
    min-width: 0;
}

.story-reaction-btn span:empty {
    display: none;
}

.story-reaction-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.1);
}

.story-reaction-btn.active {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

/* Delete-Button für eigene Stories */
.story-viewer-delete {
    position: absolute;
    bottom: 64px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 59, 48, 0.8);
    border: none;
    color: white;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    z-index: 10;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background 0.2s ease;
}

.story-viewer-delete:hover {
    background: rgba(255, 59, 48, 1);
}

/* ========== UPLOAD SPINNER ========== */
.story-upload-spinner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    z-index: 20;
    border-radius: 12px;
}

.story-upload-spinner.active {
    display: flex;
}

.story-upload-spinner-inner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: storySpinner 0.8s linear infinite;
}

@keyframes storySpinner {
    to { transform: rotate(360deg); }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .story-bar {
        margin-bottom: 10px;
        border-radius: 12px;
    }
    
    .story-avatar-wrapper {
        width: 56px;
        height: 56px;
    }
    
    .story-item {
        min-width: 60px;
    }
    
    .story-username {
        font-size: 10px;
        max-width: 60px;
    }
    
    .story-editor-canvas-container {
        max-width: 100%;
        border-radius: 0;
        height: calc(100vh - 120px);
        height: calc(100dvh - 120px);
        max-height: calc(100vh - 120px);
        max-height: calc(100dvh - 120px);
    }
    
    .story-editor-canvas {
        border-radius: 0;
    }
    
    .story-viewer-container {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}

@media (max-width: 480px) {
    .story-bar-scroll {
        gap: 10px;
        padding: 4px 12px;
    }
    
    .story-avatar-wrapper {
        width: 52px;
        height: 52px;
    }
    
    .story-add-badge {
        width: 20px;
        height: 20px;
        font-size: 14px;
    }
    
    .story-item {
        min-width: 56px;
    }
    
    .story-username {
        font-size: 10px;
        max-width: 56px;
    }
}

/* ========== MOD DELETE REASON MODAL ========== */
.story-mod-delete-content {
    max-width: 360px;
}

.story-mod-delete-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 8px;
    background: #fff;
    color: #333;
    appearance: auto;
    -webkit-appearance: auto;
}

.story-mod-delete-notes {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 8px;
    resize: vertical;
    font-family: inherit;
    background: #fff;
    color: #333;
    box-sizing: border-box;
}

.story-mod-delete-error {
    color: #FF3B30;
    font-size: 13px;
    margin-top: 6px;
    text-align: left;
}

[data-theme="dark"] .story-mod-delete-select {
    background: #2c2c2e;
    color: #fff;
    border-color: #555;
}

[data-theme="dark"] .story-mod-delete-notes {
    background: #2c2c2e;
    color: #fff;
    border-color: #555;
}

/* ========== DARK MODE ========== */
[data-theme="dark"] .story-bar {
    background: var(--bg-primary);
    border-color: var(--border-medium);
}

[data-theme="dark"] .story-avatar {
    border-color: var(--bg-primary);
}

[data-theme="dark"] .story-add-badge {
    border-color: var(--bg-primary);
}
