/* Ranking Styles */
:root {
    --box-height: 50px;
    --box-width: 120px;
    --header-height: 60px;
    --type-selector-height: 50px;
}

.ranking {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    /* Allow outer container to scroll vertically; avoid nested scrollbars */
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

.ranking__header {
    position: sticky;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    background: rgba(255,255,255,0.95);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    color: var(--color-text);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--color-gray-200);
    flex-shrink: 0;
}

.ranking__header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.ranking__header h2 {
    margin: 0;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--color-text);
}

.ranking__controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.ranking__select {
    padding: 0.5rem;
    border: 1px solid var(--color-cloud-white);
    background: transparent;
    color: var(--color-cloud-white);
    border-radius: 4px;
    font-family: var(--font-primary);
    min-width: 150px;
}

.ranking__select option {
    background: var(--color-primary);
    color: var(--color-cloud-white);
}

/* Deprecated: .btn--submit replaced by .btn variants */

.race-row {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    background: white;
    padding: 1.5rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
}

.race-title {
    font-family: var(--font-primary);
    font-weight: 700;
    font-size: 1.2rem;
    margin: 0 0 1rem;
    color: var(--color-text);
}

.race-content {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.placement-boxes {
    display: flex;
    gap: 2px;
    min-width: calc(var(--box-width) * 3 + 4px);
}

.placement-box {
    width: var(--box-width);
    height: var(--box-height);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-primary);
    font-weight: 600;
    position: relative;
    border: 2px dashed rgba(0,0,0,0.2);
}

.placement-box.empty {
    background: transparent;
}

.placement-box.etta {
    background: var(--color-gold);
    color: var(--color-text);
    border: 2px dashed rgba(0,0,0,0.4);
}

.placement-box.tvaa {
    background: var(--color-silver);
    color: var(--color-text);
    border: 2px dashed rgba(0,0,0,0.4);
}

.placement-box.trea {
    background: var(--color-bronze);
    color: var(--color-text);
    border: 2px dashed rgba(0,0,0,0.4);
}

.placement-box.has-horse {
    border-style: solid;
}

.horses-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
}

.horse-card {
    width: var(--box-width);
    height: var(--box-height);
    background: var(--color-horse-bg);
    color: var(--color-cloud-white);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: move;
    -webkit-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    font-family: var(--font-primary);
    font-size: 0.9rem;
    position: relative;
}

.horse-card.scratched {
    opacity: 0.5;
    text-decoration: line-through;
    cursor: not-allowed;
}

.horse-card.selected {
    opacity: 0.5;
}

.horse-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

/* Drag and drop visual feedback */
.placement-box.drag-over {
    background-color: rgba(0,0,0,0.1);
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    :root {
        --box-width: 100px;
    }
}

@media (max-width: 768px) {
    .race-content {
        flex-direction: column;
    }
    
    .placement-boxes {
        width: 100%;
        justify-content: space-between;
    }
    
    .horses-grid {
        justify-content: center;
    }
}

/* Alerts centralized in styles.css */

#rankingContainer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    /* Let the whole screen scroll instead of inner lists */
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--color-background-light);
}

/* Accessibility utilities moved to styles.css */

.ranking__type-selector {
    position: sticky;
    top: var(--header-height);
    left: 0;
    width: 100%;
    min-height: var(--type-selector-height);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-gray-200);
    background: var(--color-background-light);
    z-index: 99;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    flex-shrink: 0;
}

.ranking__races {
    flex: 1 1 auto;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(260px, 1fr);
    gap: 0.75rem;
    overflow-x: auto;
    overflow-y: visible;
    padding: 0.75rem;
    margin-top: 0;
    position: relative;
    z-index: 1;
}

/* Race card styling to match dashboard cards */
.race-element {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--border-radius-lg);
    background: var(--color-background-light);
    box-shadow: var(--shadow-sm);
    min-width: 260px;
}

.race-header {
    padding-bottom: 0.25rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--color-gray-200);
}

.race-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.horses-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.4rem;
    /* Remove inner scrollbar; allow list to grow */
    max-height: none;
    overflow: visible;
}

.horse-element {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--color-gray-200);
    border-radius: var(--border-radius-sm);
    cursor: grab;
    background: var(--color-gray-50);
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
}
.horse-element:hover { background: var(--color-primary-light); border-color: var(--color-regal-purple); transition: background 0.15s ease, border-color 0.15s ease; }

.horse-element.hidden { display: none; }

.horse-number {
    font-weight: 800;
    color: var(--color-regal-purple);
}

.horse-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 110px;
}

/* Fix for Firefox */
@supports (-moz-appearance:none) {
    .ranking__races {
        height: auto;
    }
}

/* Bottom button positioning */
.ranking__submit-btn {
    position: sticky;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 0.7rem;
    background: var(--color-imperial-gold, #D4AF37);
    color: var(--color-charcoal-black, #222222);
    font-weight: 600;
    border: none;
    z-index: 99;
    cursor: pointer;
    margin: 0;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

/* Ensure type buttons are styled properly */
.ranking__type-btn { flex: 0 0 auto; padding: 0.4rem 0.8rem; border-radius: 9999px; }
.ranking__type-btn.is-active { background: var(--color-regal-purple); color: var(--color-cloud-white); border-color: var(--color-regal-purple); }

/* Make home button always visible */
.ranking__home-btn,
.ranking__back-btn {
    background: none;
    border: none;
    color: var(--color-primary);
    font-size: 1.2rem;
    width: 30px;
    height: 30px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Remove horizontal variant for full ranking to enforce vertical */

.status-banner {
    background: var(--color-background-light);
    color: var(--color-text);
    padding: 0.5rem 0.75rem;
    font-weight: 600;
    border-radius: var(--border-radius-md);
    margin: 6px 8px;
    border: 1px solid var(--color-gray-200);
}

.race-nav {
    display: flex;
    gap: 0.4rem;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--color-gray-200);
    background: var(--color-background-light);
    position: sticky;
    top: calc(var(--header-height) + var(--type-selector-height));
    z-index: 9;
    overflow-x: auto;
}
.race-chip {
    border: 1px solid var(--color-gray-300);
    background: var(--color-background-light);
    color: var(--color-text);
    padding: 0.25rem 0.5rem;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.race-chip.complete { border-color: var(--color-emerald-green, #3A9D23); color: var(--color-emerald-green, #3A9D23); }
.race-chip.partial { border-color: var(--color-royal-blue, #264D73); color: var(--color-royal-blue, #264D73); }
.race-chip.empty { opacity: 0.6; }

/* Full ranking vertical layout */
.full-ranking-container {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    width: 100%;
    /* No inner scrollbar; outer container manages scroll */
    overflow: visible;
    padding-bottom: 0.5rem;
    max-height: none;
}
.full-ranking-item {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-gray-300);
    border-radius: 6px;
    background: var(--color-gray-50);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: grab;
}
.full-ranking-item:hover { background: var(--color-primary-light); border-color: var(--color-regal-purple); }
.full-ranking-item .drag-handle { margin-left: auto; color: var(--color-gray-500); }
.full-ranking-item.drag-over { outline: 2px dashed var(--color-regal-purple); background: var(--color-primary-light); }

/* Placement boxes are hidden - no longer needed */
.placements-container { display: none; }

/* Read-only full ranking preview list (shown under Vinnare/Trio) */
.full-ranking-preview { margin-top: 0.5rem; display: grid; grid-template-columns: 1fr; gap: 0.25rem; }
.full-ranking-preview .full-ranking-item.preview { height: 28px; display: grid; grid-template-columns: 26px 28px 1fr; align-items: center; border-radius: var(--border-radius-sm); background: var(--color-background-light); border: 1px solid var(--color-gray-200); padding: 0 0.4rem; }
.full-ranking-preview .full-ranking-item.preview .position { text-align: right; padding-right: 6px; font-weight: 700; color: var(--color-regal-purple); }
.full-ranking-preview .full-ranking-item.preview .horse-number { font-weight: 700; color: var(--color-text); }
.full-ranking-preview .full-ranking-item.preview .horse-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-horse .horse-number { font-weight: 800; min-width: 24px; text-align: center; font-size: 1rem; border-radius: 50%; background: var(--color-cloud-white); color: var(--color-regal-purple); width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; box-shadow: inset 0 0 0 2px rgba(93,63,211,.15); }
.selected-horse .horse-name { flex-grow: 1; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.selected-horse .remove-horse { font-size: 14px; cursor: pointer; margin-left: auto; }

/* Actions footer + buttons */
.ranking__actions {
    position: sticky;
    bottom: 0;
    z-index: 12;
    background: var(--color-background-light);
    border-top: 1px solid var(--color-gray-200);
    padding: 0.6rem;
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    box-shadow: 0 -2px 6px rgba(0,0,0,0.05);
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
}
.btn { flex: 0 0 auto; }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

/* Closed state disables interaction */
.ranking.is-closed .horse-element,
.ranking.is-closed .full-ranking-item { opacity: 0.6; cursor: not-allowed; pointer-events: none; }
.full-ranking-item {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background: var(--color-gray-100);
    border-radius: 4px;
    border: 1px solid var(--color-gray-300);
    cursor: grab;
    flex: 0 0 auto;
    min-width: 150px;
    margin-bottom: 0.25rem;
}

.full-ranking-item .position {
    font-weight: bold;
    color: var(--color-regal-purple);
    margin-right: 0.5rem;
}

.full-ranking-item .horse-number {
    font-weight: bold;
    background: var(--color-regal-purple);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.5rem;
}

.full-ranking-item .horse-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.full-ranking-item .drag-handle {
    margin-left: auto;
    cursor: grab;
    color: var(--color-gray-500);
}

/* Unified ranking list styles */
.unified-ranking-container {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.unified-ranking-item {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background: var(--color-gray-50);
    border-radius: 4px;
    border: 1px solid var(--color-gray-300);
    cursor: grab;
    flex: 0 0 auto;
    min-width: 150px;
    margin-bottom: 0.25rem;
    transition: all 0.2s ease;
}

.unified-ranking-item:hover {
    background: var(--color-primary-light);
    border-color: var(--color-regal-purple);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(93, 63, 211, 0.1);
}

.unified-ranking-item .position-number {
    font-weight: bold;
    color: var(--color-regal-purple);
    margin-right: 0.5rem;
    min-width: 20px;
}

.unified-ranking-item .horse-number {
    font-weight: bold;
    background: var(--color-regal-purple);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.5rem;
}

.unified-ranking-item .horse-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--color-text);
}

.unified-ranking-item .drag-handle {
    margin-left: auto;
    cursor: grab;
    color: var(--color-gray-500);
    font-size: 14px;
}

.unified-ranking-item.drag-over {
    outline: 2px dashed var(--color-regal-purple);
    background: var(--color-primary-light);
}

/* Highlighting for selected horses in Vinnare and Trio views */
.unified-ranking-item.selected-horse-highlight {
    background: var(--color-imperial-gold) !important;
    border-color: var(--color-imperial-gold) !important;
    color: var(--color-cloud-white) !important;
    box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3) !important;
}

.unified-ranking-item.selected-horse-highlight .horse-name {
    color: var(--color-cloud-white) !important;
}

.unified-ranking-item.selected-horse-highlight .position-number {
    color: var(--color-cloud-white) !important;
}

.unified-ranking-item.selected-horse-highlight .horse-number {
    background: var(--color-cloud-white) !important;
    color: var(--color-imperial-gold) !important;
}



/* Remove horizontal variant of placements to keep vertical layout only */

/* Responsive adjustments */
@media (max-width: 768px) {
    .ranking__type-selector {
        top: 55px;
        padding: 0.4rem;
    }
    
    .ranking__type-btn {
        padding: 0.5rem 0.7rem;
        font-size: 0.85rem;
    }
    
    /* no horizontal variant */
    
    .full-ranking-item {
        min-width: 120px;
    }
} 