/* ==========================================================================
   KutSocial · Mastodon 5.0 UX Features
   - Floating & minimizable composer + draft pill
   - Compact pill visibility dropdown
   - Refined post layout (spacing, typography, action bar)
   Uses theme CSS variables so both light and dark modes work seamlessly.
   ========================================================================== */

/* 1. Inline composer floating header & backdrop (hidden until floating) */
.m5-floating-header {
    display: none;
}

#m5-floating-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay-bg, rgba(0, 0, 0, 0.42));
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 2390;
}

#m5-floating-backdrop.show {
    display: block;
}

.composer-card.m5-floating:not(.zen-mode) {
    position: fixed !important;
    left: 50%;
    bottom: 22px !important;
    top: auto !important;
    transform: translateX(-50%);
    width: min(600px, calc(100vw - 32px)) !important;
    max-height: calc(100dvh - 44px) !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 0 16px 0 !important;
    background: var(--surface-elevated, var(--surface-bg, #1b1b24)) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: 1px solid var(--border-strong, var(--border-color)) !important;
    border-radius: 16px !important;
    box-shadow: 0 24px 64px var(--shadow-color, rgba(0, 0, 0, 0.65)) !important;
    z-index: 2400 !important;
}

.composer-card.m5-floating:not(.zen-mode) .m5-floating-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 18px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 4px;
}

.m5-floating-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text-color);
}

.m5-floating-title .material-icons-outlined {
    font-size: 18px;
    color: var(--primary);
}

.m5-floating-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.m5-floating-btn {
    width: 30px !important;
    min-width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 9999px !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--text-muted) !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.m5-floating-btn:hover {
    background: var(--surface-hover, rgba(255, 255, 255, 0.08)) !important;
    color: var(--text-color) !important;
    transform: none !important;
}

.composer-card.m5-floating:not(.zen-mode) .composer-header,
.composer-card.m5-floating:not(.zen-mode) .composer-context-bar,
.composer-card.m5-floating:not(.zen-mode) .cw-input-container {
    padding-left: 18px;
    padding-right: 18px;
}

.composer-card.m5-floating:not(.zen-mode) .composer-header {
    padding-top: 12px;
    padding-bottom: 10px;
}

.composer-card.m5-floating:not(.zen-mode) .composer-toolbar {
    padding: 12px 18px 0 18px;
    margin-top: 4px;
    border-top: 1px solid var(--border-color);
}

.composer-card.m5-floating:not(.zen-mode) .composer-textarea {
    min-height: 120px;
    max-height: 42dvh;
    overflow-y: auto;
}

.composer-card.m5-floating.m5-minimized {
    display: none !important;
}

/* Minimalist collapsed inline composer on top of timeline (expands & floats on click) */
#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) {
    padding: 12px 16px !important;
    cursor: text;
}

#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) .composer-toolbar,
#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) .m5-mobile-composer-meta,
#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) .composer-context-bar,
#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) .cw-input-container,
#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) #composer-media-preview,
#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) #composer-poll-container {
    display: none !important;
}

#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) .composer-header {
    margin-bottom: 0 !important;
    align-items: center;
}

#tab-feed > .composer-card:not(.m5-floating):not(.zen-mode) .composer-textarea {
    min-height: 36px !important;
    height: 36px !important;
    max-height: 36px !important;
    padding: 7px 0 !important;
    resize: none !important;
    overflow: hidden !important;
    cursor: text;
}

.composer-card {
    position: relative;
}

#tab-feed > .composer-card.m5-drag-active:not(.m5-floating):not(.zen-mode) {
    min-height: 102px !important;
}

.m5-drop-overlay {
    display: none;
    position: absolute;
    inset: 6px;
    z-index: 30;
    pointer-events: none;
    border: 2px dashed var(--primary);
    border-radius: 12px;
    background: color-mix(in srgb, var(--primary) 12%, var(--surface-elevated, var(--bg-color, #16161d)));
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    padding: 14px 16px;
    text-align: center;
}

.m5-drop-overlay.show {
    display: flex;
}

.m5-drop-overlay .material-icons-outlined {
    font-size: 24px;
    color: var(--primary);
}

.m5-drop-overlay-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text-color);
}

.m5-drop-overlay-sub {
    font-size: 11.5px;
    color: var(--text-muted);
}

/* Modal composer anchored bottom-center on desktop, bottom-sheet on mobile */
#modal-composer.m5-floating-composer {
    align-items: flex-end;
    justify-content: center;
    padding: 0 16px 18px 16px;
    background: var(--overlay-bg, rgba(0, 0, 0, 0.45));
}

#modal-composer.m5-floating-composer .modal-card {
    border-radius: 16px !important;
    background: var(--surface-elevated, var(--bg-color)) !important;
}

/* 2. Minimized Draft Pill */
#m5-composer-pill {
    display: none;
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 2350;
    width: auto !important;
    max-width: min(440px, calc(100vw - 32px));
    margin: 0 !important;
    padding: 9px 14px !important;
    border-radius: 9999px !important;
    border: 1px solid var(--border-strong, var(--border-color)) !important;
    background: var(--surface-elevated, var(--card-bg)) !important;
    color: var(--text-color) !important;
    box-shadow: 0 10px 30px var(--shadow-color, rgba(0, 0, 0, 0.45)) !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13.5px;
}

#m5-composer-pill.show {
    display: inline-flex;
}

#m5-composer-pill:hover {
    border-color: var(--primary) !important;
    transform: translateX(-50%) translateY(-1px);
}

#m5-composer-pill .m5-pill-icon {
    font-size: 18px;
    color: var(--primary);
    flex-shrink: 0;
}

#m5-composer-pill .m5-pill-label {
    font-weight: 700;
    flex-shrink: 0;
}

#m5-composer-pill .m5-pill-snippet {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

#m5-composer-pill .m5-pill-expand {
    font-size: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* 3. Compact Visibility Dropdown Pill */
.m5-vis-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.m5-vis-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

button.m5-vis-pill {
    width: auto !important;
    margin: 0 !important;
    padding: 5px 10px 5px 11px !important;
    height: 32px;
    border-radius: 9999px !important;
    border: 1px solid var(--border-color) !important;
    background: var(--input-bg, var(--surface-hover)) !important;
    background-image: none !important;
    box-shadow: none !important;
    color: var(--text-color) !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    white-space: nowrap;
}

button.m5-vis-pill:hover {
    background: var(--surface-hover) !important;
    border-color: var(--border-strong, var(--primary)) !important;
    transform: none !important;
}

.m5-vis-pill .material-icons-outlined {
    font-size: 16px;
    color: var(--primary);
}

.m5-vis-pill .m5-vis-caret {
    font-size: 16px;
    color: var(--text-muted);
}

.m5-vis-menu {
    position: fixed;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: 280px;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    background: var(--menu-bg, var(--surface-elevated)) !important;
    border: 1px solid var(--border-strong, var(--border-color)) !important;
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 14px 36px var(--shadow-color, rgba(0, 0, 0, 0.55));
    z-index: 2600;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.m5-vis-menu[hidden] {
    display: none !important;
}

button.m5-vis-option {
    width: 100% !important;
    margin: 0 !important;
    padding: 8px 10px !important;
    border: none !important;
    border-radius: 8px !important;
    background: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    color: var(--text-color) !important;
    display: flex !important;
    align-items: flex-start;
    gap: 10px;
    text-align: left;
    cursor: pointer;
}

button.m5-vis-option:hover,
button.m5-vis-option.selected {
    background: var(--surface-hover, rgba(255, 255, 255, 0.08)) !important;
    transform: none !important;
}

.m5-vis-option-icon {
    font-size: 18px;
    color: var(--text-muted);
    margin-top: 2px;
    flex-shrink: 0;
}

button.m5-vis-option.selected .m5-vis-option-icon {
    color: var(--primary);
}

.m5-vis-option-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    gap: 1px;
}

.m5-vis-option-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
}

.m5-vis-option-desc {
    font-size: 11.5px;
    font-weight: 400;
    color: var(--text-muted);
    line-height: 1.3;
}

.m5-vis-option-check {
    font-size: 17px;
    color: var(--primary);
    opacity: 0;
    align-self: center;
    flex-shrink: 0;
}

button.m5-vis-option.selected .m5-vis-option-check {
    opacity: 1;
}

/* 4. Refined Post Layout (Mastodon 5.0 spacing & typography, keeping widths intact) */
.toot-card {
    padding: 18px 20px;
}

.toot-author-line {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
    flex-wrap: nowrap;
}

.toot-author-name {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    flex-shrink: 0;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toot-author-handle {
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.toot-content {
    line-height: 1.56;
    margin-top: 6px;
}

.toot-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-top: 12px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .toot-card {
        padding: 14px 14px;
    }
    .composer-card.m5-floating:not(.zen-mode) {
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        transform: none !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92dvh;
        border-radius: 16px 16px 0 0 !important;
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .composer-card.m5-floating:not(.zen-mode) .m5-mobile-composer-meta {
        padding: 4px 18px 0 18px;
        margin-bottom: 8px;
    }

    .composer-card.m5-floating:not(.zen-mode) .composer-toolbar {
        padding: 10px 18px 0 18px;
    }

    #modal-composer.m5-floating-composer {
        padding: 0;
    }

    #modal-composer.m5-floating-composer .modal-card {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 16px 16px 0 0 !important;
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #m5-composer-pill {
        bottom: calc(68px + env(safe-area-inset-bottom, 0px));
        max-width: calc(100vw - 92px);
        left: 16px;
        transform: none;
    }

    #m5-composer-pill:hover {
        transform: none;
    }
}
