/* Grimnir Radio - Core Application Styles */

/* Hide x-cloak elements until Alpine loads */
[x-cloak] {
    display: none !important;
}

/* Dashboard Layout */
.dashboard-layout {
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    min-width: 260px;
    max-width: 260px;
    transition: width 0.3s ease, min-width 0.3s ease, max-width 0.3s ease;
    z-index: 100;
    position: relative;
    flex-shrink: 0;
    overflow: hidden;
}

/* Text elements - prepare for animation */
.sidebar .sidebar-text {
    display: inline-block;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
}

/* Collapsed sidebar styles - triggered by body class */
body.sidebar-collapsed .sidebar {
    width: 52px;
    min-width: 52px;
    max-width: 52px;
    overflow: hidden;
}

body.sidebar-collapsed .sidebar nav {
    overflow: hidden;
    padding: 0.5rem 0;
}

body.sidebar-collapsed .sidebar nav .nav {
    overflow: hidden;
}

/* Hide text with transform (smoother than display:none) */
body.sidebar-collapsed .sidebar .sidebar-text {
    opacity: 0;
    transform: translateX(-20px);
    position: absolute;
    pointer-events: none;
}

/* Hide section headers when collapsed */
body.sidebar-collapsed .sidebar .sidebar-section {
    display: none;
}

/* Center nav items when collapsed */
body.sidebar-collapsed .sidebar .nav-link {
    justify-content: center;
    text-align: center;
    padding: 0.5rem 0;
    width: 100%;
    margin: 0;
}

body.sidebar-collapsed .sidebar .nav-link i {
    font-size: 1.1rem;
    margin: 0 !important;
}

body.sidebar-collapsed .sidebar .nav-item {
    margin: 0;
    padding: 0;
}

/* Center header when collapsed */
body.sidebar-collapsed .sidebar .sidebar-header {
    justify-content: center;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 0;
    overflow: hidden;
}

body.sidebar-collapsed .sidebar .sidebar-header a {
    justify-content: center;
}

body.sidebar-collapsed .sidebar .sidebar-header .sidebar-toggle {
    padding: 0.25rem 0.5rem;
}

/* Hide toggle button text, keep icon */
body.sidebar-collapsed .sidebar .sidebar-toggle {
    margin: 0.25rem auto 0;
}

/* Hide user info text, center icon when collapsed */
body.sidebar-collapsed .sidebar .user-info {
    justify-content: center;
}

body.sidebar-collapsed .sidebar .user-info > div {
    display: none;
}

/* Stack user action buttons vertically when collapsed */
body.sidebar-collapsed .sidebar .user-actions {
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
}

body.sidebar-collapsed .sidebar .user-actions .btn {
    flex: none;
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Hide bottom padding section overflow when collapsed */
body.sidebar-collapsed .sidebar > .p-2.border-top {
    padding: 0.5rem 0 !important;
    overflow: hidden;
}

.sidebar .nav-link {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.125rem;
    display: flex;
    align-items: center;
    position: relative;
}

.sidebar .nav-link:hover {
    background: var(--bs-tertiary-bg);
}

.sidebar .nav-link.active {
    font-weight: 500;
}

/* On-Air Status */
.on-air-indicator {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.badge.on-air {
    background: var(--bs-danger) !important;
    animation: pulse 1s infinite;
}

/* Audio Preview Player */
.preview-playing {
    background: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: white !important;
    animation: preview-pulse 1s ease-in-out infinite;
}

@keyframes preview-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(var(--bs-primary-rgb), 0.7);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(var(--bs-primary-rgb), 0);
    }
}

/* Highlight the row containing the playing track */
tr:has(.preview-playing) {
    background: rgba(var(--bs-primary-rgb), 0.1) !important;
}

/* Media Cards */
.media-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.media-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.media-card .waveform-preview {
    height: 48px;
    background: var(--bs-tertiary-bg);
}

/* Waveform Component */
.waveform-container {
    position: relative;
    background: var(--bs-dark);
    border-radius: 4px;
    overflow: hidden;
}

.waveform-container .cue-point {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    z-index: 10;
}

.waveform-container .cue-point.intro-end {
    background: var(--bs-success);
}

.waveform-container .cue-point.outro-start {
    background: var(--bs-warning);
}

/* Audio Meters */
.audio-meter {
    display: flex;
    gap: 2px;
    height: 100%;
}

.audio-meter .meter-bar {
    flex: 1;
    display: flex;
    flex-direction: column-reverse;
    gap: 1px;
}

.audio-meter .segment {
    flex: 1;
    background: var(--bs-secondary-bg);
    transition: background 0.1s;
}

.audio-meter .segment.active.green { background: var(--bs-success); }
.audio-meter .segment.active.yellow { background: var(--bs-warning); }
.audio-meter .segment.active.red { background: var(--bs-danger); }

/* Calendar Events */
.fc-event {
    cursor: pointer;
    border: none !important;
}

.fc-event.event-media {
    background: var(--bs-primary) !important;
}

.fc-event.event-smart_block {
    background: var(--bs-info) !important;
}

.fc-event.event-hard_item {
    background: var(--bs-warning) !important;
    color: var(--bs-dark) !important;
}

.fc-event.event-stopset {
    background: var(--bs-secondary) !important;
}

.fc-event.event-live {
    background: var(--bs-danger) !important;
}

/* Clock Editor */
.clock-wheel {
    position: relative;
    width: 100%;
    padding-bottom: 100%;
    border-radius: 50%;
    background: var(--bs-tertiary-bg);
    border: 2px solid var(--bs-border-color);
}

.clock-wheel .slot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: 0 0;
}

.clock-wheel .slot-label {
    position: absolute;
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Drag and Drop */
.dragging {
    opacity: 0.5;
}

.drop-target {
    outline: 2px dashed var(--bs-primary);
    outline-offset: -2px;
}

.drop-target.active {
    background: rgba(var(--bs-primary-rgb), 0.1);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--bs-border-color);
    border-radius: 0.5rem;
    padding: 3rem;
    text-align: center;
    transition: all 0.2s ease;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--bs-primary);
    background: rgba(var(--bs-primary-rgb), 0.05);
}

.upload-zone.uploading {
    pointer-events: none;
}

/* Tables */
.table-hover tbody tr:hover {
    cursor: pointer;
}

.table .actions {
    opacity: 0;
    transition: opacity 0.15s;
}

.table tr:hover .actions {
    opacity: 1;
}

/* Search Results */
.search-result {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--bs-border-color);
    cursor: pointer;
}

.search-result:hover {
    background: var(--bs-tertiary-bg);
}

.search-result:last-child {
    border-bottom: none;
}

/* Loading States */
.htmx-request {
    position: relative;
}

.htmx-request::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(var(--bs-body-bg-rgb), 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

/* Form Improvements */
.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label {
    color: var(--bs-primary);
}

/* Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1040;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1039;
    }
}

/* Global Audio Player - Floating & Draggable */
.global-player {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    max-width: calc(100vw - 40px);
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    z-index: 1050;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    cursor: default;
    overflow: hidden;
}

.global-player-header {
    background: var(--bs-tertiary-bg);
    padding: 8px 12px;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--bs-border-color);
    user-select: none;
}

.global-player-header .drag-handle {
    color: var(--bs-secondary);
    font-size: 0.75rem;
}

.global-player.dragging {
    opacity: 0.9;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

/* Minimized state */
.global-player.minimized {
    width: auto;
    min-width: 200px;
}

.global-player.minimized .global-player-body {
    display: none;
}

.global-player-body {
    padding: 12px;
}

.global-player-progress {
    height: 4px;
    background: var(--bs-secondary-bg);
    cursor: pointer;
    border-radius: 2px;
    margin-bottom: 8px;
}

.global-player-progress-bar {
    height: 100%;
    background: var(--bs-primary);
    width: 0%;
    transition: width 0.1s linear;
    border-radius: 2px;
}

.player-artwork {
    width: 48px;
    height: 48px;
    background: var(--bs-secondary-bg);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.player-artwork img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.player-artwork i {
    font-size: 1.5rem;
    color: var(--bs-secondary);
}

.player-info {
    min-width: 0;
}

/* Live indicator */
.global-player.is-live #playerPlayIcon {
    color: var(--bs-danger);
}

.global-player.is-live::before {
    content: 'LIVE';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bs-danger);
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    padding: 1px 6px;
    border-radius: 2px;
    animation: pulse 1.5s infinite;
}

/* Body class when player is visible - no longer needed for floating player */
body.player-active {
    /* padding removed - player is now floating */
}

/* Print Styles */
@media print {
    .sidebar,
    header,
    .btn,
    .no-print {
        display: none !important;
    }

    main {
        padding: 0 !important;
    }
}
